Added missing files.

This commit is contained in:
bkaradzic 2012-07-10 21:31:47 -07:00
parent 98ebe1f076
commit 055131b7bb
201 changed files with 10897 additions and 0 deletions
3rdparty/glsl-optimizer/src/glsl/glcpp
.gitignoreREADMEglcpp-lex.cglcpp-lex.lglcpp-parse.cglcpp-parse.hglcpp-parse.yglcpp.cglcpp.hpp.c
tests
000-content-with-spaces.c000-content-with-spaces.c.expected001-define.c001-define.c.expected002-define-chain.c002-define-chain.c.expected003-define-chain-reverse.c003-define-chain-reverse.c.expected004-define-recursive.c004-define-recursive.c.expected005-define-composite-chain.c005-define-composite-chain.c.expected006-define-composite-chain-reverse.c006-define-composite-chain-reverse.c.expected007-define-composite-recursive.c007-define-composite-recursive.c.expected008-define-empty.c008-define-empty.c.expected009-undef.c009-undef.c.expected010-undef-re-define.c010-undef-re-define.c.expected011-define-func-empty.c011-define-func-empty.c.expected012-define-func-no-args.c012-define-func-no-args.c.expected013-define-func-1-arg-unused.c013-define-func-1-arg-unused.c.expected014-define-func-2-arg-unused.c014-define-func-2-arg-unused.c.expected015-define-object-with-parens.c015-define-object-with-parens.c.expected016-define-func-1-arg.c016-define-func-1-arg.c.expected017-define-func-2-args.c017-define-func-2-args.c.expected018-define-func-macro-as-parameter.c018-define-func-macro-as-parameter.c.expected019-define-func-1-arg-multi.c019-define-func-1-arg-multi.c.expected020-define-func-2-arg-multi.c020-define-func-2-arg-multi.c.expected021-define-func-compose.c021-define-func-compose.c.expected022-define-func-arg-with-parens.c022-define-func-arg-with-parens.c.expected023-define-extra-whitespace.c023-define-extra-whitespace.c.expected024-define-chain-to-self-recursion.c024-define-chain-to-self-recursion.c.expected025-func-macro-as-non-macro.c025-func-macro-as-non-macro.c.expected026-define-func-extra-newlines.c026-define-func-extra-newlines.c.expected027-define-chain-obj-to-func.c027-define-chain-obj-to-func.c.expected028-define-chain-obj-to-non-func.c028-define-chain-obj-to-non-func.c.expected029-define-chain-obj-to-func-with-args.c029-define-chain-obj-to-func-with-args.c.expected030-define-chain-obj-to-func-compose.c030-define-chain-obj-to-func-compose.c.expected031-define-chain-func-to-func-compose.c031-define-chain-func-to-func-compose.c.expected032-define-func-self-recurse.c032-define-func-self-recurse.c.expected033-define-func-self-compose.c033-define-func-self-compose.c.expected034-define-func-self-compose-non-func.c034-define-func-self-compose-non-func.c.expected035-define-func-self-compose-non-func-multi-token-argument.c035-define-func-self-compose-non-func-multi-token-argument.c.expected036-define-func-non-macro-multi-token-argument.c036-define-func-non-macro-multi-token-argument.c.expected037-finalize-unexpanded-macro.c037-finalize-unexpanded-macro.c.expected038-func-arg-with-commas.c038-func-arg-with-commas.c.expected039-func-arg-obj-macro-with-comma.c039-func-arg-obj-macro-with-comma.c.expected040-token-pasting.c040-token-pasting.c.expected041-if-0.c041-if-0.c.expected042-if-1.c042-if-1.c.expected043-if-0-else.c043-if-0-else.c.expected044-if-1-else.c044-if-1-else.c.expected

View file

@ -0,0 +1,8 @@
glcpp
glcpp-parse.output
*.o
*.lo
*.la
.libs
*~
tests/*.out

View file

@ -0,0 +1,32 @@
glcpp -- GLSL "C" preprocessor
This is a simple preprocessor designed to provide the preprocessing
needs of the GLSL language. The requirements for this preprocessor are
specified in the GLSL 1.30 specification availble from:
http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.30.10.pdf
This specification is not precise on some semantics, (for example,
#define and #if), defining these merely "as is standard for C++
preprocessors". To fill in these details, I've been using a draft of
the C99 standard as available from:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
Any downstream compiler accepting output from glcpp should be prepared
to encounter and deal with the following preprocessor macros:
#line
#pragma
#extension
All other macros will be handles according to the GLSL specification
and will not appear in the output.
Known limitations
-----------------
The __LINE__ and __FILE__ macros are not yet supported.
A file that ends with a function-like macro name as the last
non-whitespace token will result in a parse error, (where it should be
passed through as is).

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,324 @@
%{
/*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "glcpp.h"
#include "glcpp-parse.h"
/* Flex annoyingly generates some functions without making them
* static. Let's declare them here. */
int glcpp_get_column (yyscan_t yyscanner);
void glcpp_set_column (int column_no , yyscan_t yyscanner);
#ifdef _MSC_VER
#define YY_NO_UNISTD_H
#endif
#define YY_NO_INPUT
#define YY_USER_ACTION \
do { \
yylloc->first_column = yycolumn + 1; \
yylloc->first_line = yylineno; \
yycolumn += yyleng; \
} while(0);
#define YY_USER_INIT \
do { \
yylineno = 1; \
yycolumn = 1; \
yylloc->source = 0; \
} while(0)
%}
%option bison-bridge bison-locations reentrant noyywrap
%option extra-type="glcpp_parser_t *"
%option prefix="glcpp_"
%option stack
%option never-interactive
%x DONE COMMENT UNREACHABLE SKIP
SPACE [[:space:]]
NONSPACE [^[:space:]]
NEWLINE [\n]
HSPACE [ \t]
HASH ^{HSPACE}*#{HSPACE}*
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
PUNCTUATION [][(){}.&*~!/%<>^|;,=+-]
OTHER [^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
DIGITS [0-9][0-9]*
DECIMAL_INTEGER [1-9][0-9]*[uU]?
OCTAL_INTEGER 0[0-7]*[uU]?
HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
%%
/* Implicitly switch between SKIP and INITIAL (non-skipping);
* don't switch if some other state was explicitly set.
*/
glcpp_parser_t *parser = yyextra;
if (YY_START == 0 || YY_START == SKIP) {
if (parser->lexing_if || parser->skip_stack == NULL || parser->skip_stack->type == SKIP_NO_SKIP) {
BEGIN 0;
} else {
BEGIN SKIP;
}
}
/* Single-line comments */
"//"[^\n]* {
}
/* Multi-line comments */
"/*" { yy_push_state(COMMENT, yyscanner); }
<COMMENT>[^*\n]*
<COMMENT>[^*\n]*\n { yylineno++; yycolumn = 0; return NEWLINE; }
<COMMENT>"*"+[^*/\n]*
<COMMENT>"*"+[^*/\n]*\n { yylineno++; yycolumn = 0; return NEWLINE; }
<COMMENT>"*"+"/" {
yy_pop_state(yyscanner);
if (yyextra->space_tokens)
return SPACE;
}
{HASH}version {
yylval->str = ralloc_strdup (yyextra, yytext);
yyextra->space_tokens = 0;
return HASH_VERSION;
}
/* glcpp doesn't handle #extension, #version, or #pragma directives.
* Simply pass them through to the main compiler's lexer/parser. */
{HASH}(extension|pragma)[^\n]+ {
yylval->str = ralloc_strdup (yyextra, yytext);
yylineno++;
yycolumn = 0;
return OTHER;
}
{HASH}line{HSPACE}+{DIGITS}{HSPACE}+{DIGITS}{HSPACE}*$ {
/* Eat characters until the first digit is
* encountered
*/
char *ptr = yytext;
while (!isdigit(*ptr))
ptr++;
/* Subtract one from the line number because
* yylineno is zero-based instead of
* one-based.
*/
yylineno = strtol(ptr, &ptr, 0) - 1;
yylloc->source = strtol(ptr, NULL, 0);
}
{HASH}line{HSPACE}+{DIGITS}{HSPACE}*$ {
/* Eat characters until the first digit is
* encountered
*/
char *ptr = yytext;
while (!isdigit(*ptr))
ptr++;
/* Subtract one from the line number because
* yylineno is zero-based instead of
* one-based.
*/
yylineno = strtol(ptr, &ptr, 0) - 1;
}
<SKIP,INITIAL>{
{HASH}ifdef {
yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
return HASH_IFDEF;
}
{HASH}ifndef {
yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
return HASH_IFNDEF;
}
{HASH}if/[^_a-zA-Z0-9] {
yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
return HASH_IF;
}
{HASH}elif {
yyextra->lexing_if = 1;
yyextra->space_tokens = 0;
return HASH_ELIF;
}
{HASH}else {
yyextra->space_tokens = 0;
return HASH_ELSE;
}
{HASH}endif {
yyextra->space_tokens = 0;
return HASH_ENDIF;
}
}
<SKIP>[^\n] ;
{HASH}error.* {
char *p;
for (p = yytext; !isalpha(p[0]); p++); /* skip " # " */
p += 5; /* skip "error" */
glcpp_error(yylloc, yyextra, "#error%s", p);
}
{HASH}define{HSPACE}+/{IDENTIFIER}"(" {
yyextra->space_tokens = 0;
return HASH_DEFINE_FUNC;
}
{HASH}define {
yyextra->space_tokens = 0;
return HASH_DEFINE_OBJ;
}
{HASH}undef {
yyextra->space_tokens = 0;
return HASH_UNDEF;
}
{HASH} {
yyextra->space_tokens = 0;
return HASH;
}
{DECIMAL_INTEGER} {
yylval->str = ralloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
{OCTAL_INTEGER} {
yylval->str = ralloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
{HEXADECIMAL_INTEGER} {
yylval->str = ralloc_strdup (yyextra, yytext);
return INTEGER_STRING;
}
"<<" {
return LEFT_SHIFT;
}
">>" {
return RIGHT_SHIFT;
}
"<=" {
return LESS_OR_EQUAL;
}
">=" {
return GREATER_OR_EQUAL;
}
"==" {
return EQUAL;
}
"!=" {
return NOT_EQUAL;
}
"&&" {
return AND;
}
"||" {
return OR;
}
"##" {
return PASTE;
}
"defined" {
return DEFINED;
}
{IDENTIFIER} {
yylval->str = ralloc_strdup (yyextra, yytext);
return IDENTIFIER;
}
{PUNCTUATION} {
return yytext[0];
}
{OTHER}+ {
yylval->str = ralloc_strdup (yyextra, yytext);
return OTHER;
}
{HSPACE}+ {
if (yyextra->space_tokens) {
return SPACE;
}
}
<SKIP,INITIAL>\n {
yyextra->lexing_if = 0;
yylineno++;
yycolumn = 0;
return NEWLINE;
}
/* Handle missing newline at EOF. */
<INITIAL><<EOF>> {
BEGIN DONE; /* Don't keep matching this rule forever. */
yyextra->lexing_if = 0;
return NEWLINE;
}
/* We don't actually use the UNREACHABLE start condition. We
only have this action here so that we can pretend to call some
generated functions, (to avoid "defined but not used"
warnings. */
<UNREACHABLE>. {
unput('.');
yy_top_state(yyextra);
}
%%
void
glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader)
{
yy_scan_string(shader, parser->scanner);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,135 @@
/* A Bison parser, made by GNU Bison 2.3. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
COMMA_FINAL = 258,
DEFINED = 259,
ELIF_EXPANDED = 260,
HASH = 261,
HASH_DEFINE_FUNC = 262,
HASH_DEFINE_OBJ = 263,
HASH_ELIF = 264,
HASH_ELSE = 265,
HASH_ENDIF = 266,
HASH_IF = 267,
HASH_IFDEF = 268,
HASH_IFNDEF = 269,
HASH_UNDEF = 270,
HASH_VERSION = 271,
IDENTIFIER = 272,
IF_EXPANDED = 273,
INTEGER = 274,
INTEGER_STRING = 275,
NEWLINE = 276,
OTHER = 277,
PLACEHOLDER = 278,
SPACE = 279,
PASTE = 280,
OR = 281,
AND = 282,
NOT_EQUAL = 283,
EQUAL = 284,
GREATER_OR_EQUAL = 285,
LESS_OR_EQUAL = 286,
RIGHT_SHIFT = 287,
LEFT_SHIFT = 288,
UNARY = 289
};
#endif
/* Tokens. */
#define COMMA_FINAL 258
#define DEFINED 259
#define ELIF_EXPANDED 260
#define HASH 261
#define HASH_DEFINE_FUNC 262
#define HASH_DEFINE_OBJ 263
#define HASH_ELIF 264
#define HASH_ELSE 265
#define HASH_ENDIF 266
#define HASH_IF 267
#define HASH_IFDEF 268
#define HASH_IFNDEF 269
#define HASH_UNDEF 270
#define HASH_VERSION 271
#define IDENTIFIER 272
#define IF_EXPANDED 273
#define INTEGER 274
#define INTEGER_STRING 275
#define NEWLINE 276
#define OTHER 277
#define PLACEHOLDER 278
#define SPACE 279
#define PASTE 280
#define OR 281
#define AND 282
#define NOT_EQUAL 283
#define EQUAL 284
#define GREATER_OR_EQUAL 285
#define LESS_OR_EQUAL 286
#define RIGHT_SHIFT 287
#define LEFT_SHIFT 288
#define UNARY 289
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,121 @@
/*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "glcpp.h"
#include "main/mtypes.h"
#include "main/shaderobj.h"
extern int yydebug;
void
_mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
struct gl_shader *sh)
{
*ptr = sh;
}
/* Read from fp until EOF and return a string of everything read.
*/
static char *
load_text_fp (void *ctx, FILE *fp)
{
#define CHUNK 4096
char *text = NULL;
size_t text_size = 0;
size_t total_read = 0;
size_t bytes;
while (1) {
if (total_read + CHUNK + 1 > text_size) {
text_size = text_size ? text_size * 2 : CHUNK + 1;
text = reralloc_size (ctx, text, text_size);
if (text == NULL) {
fprintf (stderr, "Out of memory\n");
return NULL;
}
}
bytes = fread (text + total_read, 1, CHUNK, fp);
total_read += bytes;
if (bytes < CHUNK) {
break;
}
}
text[total_read] = '\0';
return text;
}
static char *
load_text_file(void *ctx, const char *filename)
{
char *text;
FILE *fp;
if (filename == NULL || strcmp (filename, "-") == 0)
return load_text_fp (ctx, stdin);
fp = fopen (filename, "r");
if (fp == NULL) {
fprintf (stderr, "Failed to open file %s: %s\n",
filename, strerror (errno));
return NULL;
}
text = load_text_fp (ctx, fp);
fclose(fp);
return text;
}
int
main (int argc, char *argv[])
{
char *filename = NULL;
void *ctx = ralloc(NULL, void*);
char *info_log = ralloc_strdup(ctx, "");
const char *shader;
int ret;
if (argc) {
filename = argv[1];
}
shader = load_text_file (ctx, filename);
if (shader == NULL)
return 1;
ret = preprocess(ctx, &shader, &info_log, NULL, API_OPENGL);
printf("%s", shader);
fprintf(stderr, "%s", info_log);
ralloc_free(ctx);
return ret;
}

View file

@ -0,0 +1,222 @@
/*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef GLCPP_H
#define GLCPP_H
#include <stdint.h>
#include "../ralloc.h"
#include "program/hash_table.h"
#define yyscan_t void*
/* Some data types used for parser values. */
typedef struct string_node {
const char *str;
struct string_node *next;
} string_node_t;
typedef struct string_list {
string_node_t *head;
string_node_t *tail;
} string_list_t;
typedef struct token token_t;
typedef struct token_list token_list_t;
typedef union YYSTYPE
{
intmax_t ival;
char *str;
string_list_t *string_list;
token_t *token;
token_list_t *token_list;
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
typedef struct YYLTYPE {
int first_line;
int first_column;
int last_line;
int last_column;
unsigned source;
} YYLTYPE;
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC(Rhs, N).last_line; \
(Current).last_column = YYRHSLOC(Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC(Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC(Rhs, 0).last_column; \
} \
(Current).source = 0; \
} while (0)
struct token {
int type;
YYSTYPE value;
YYLTYPE location;
};
typedef struct token_node {
token_t *token;
struct token_node *next;
} token_node_t;
struct token_list {
token_node_t *head;
token_node_t *tail;
token_node_t *non_space_tail;
};
typedef struct argument_node {
token_list_t *argument;
struct argument_node *next;
} argument_node_t;
typedef struct argument_list {
argument_node_t *head;
argument_node_t *tail;
} argument_list_t;
typedef struct glcpp_parser glcpp_parser_t;
typedef enum {
TOKEN_CLASS_IDENTIFIER,
TOKEN_CLASS_IDENTIFIER_FINALIZED,
TOKEN_CLASS_FUNC_MACRO,
TOKEN_CLASS_OBJ_MACRO
} token_class_t;
token_class_t
glcpp_parser_classify_token (glcpp_parser_t *parser,
const char *identifier,
int *parameter_index);
typedef struct {
int is_function;
string_list_t *parameters;
const char *identifier;
token_list_t *replacements;
} macro_t;
typedef struct expansion_node {
macro_t *macro;
token_node_t *replacements;
struct expansion_node *next;
} expansion_node_t;
typedef enum skip_type {
SKIP_NO_SKIP,
SKIP_TO_ELSE,
SKIP_TO_ENDIF
} skip_type_t;
typedef struct skip_node {
skip_type_t type;
YYLTYPE loc; /* location of the initial #if/#elif/... */
struct skip_node *next;
} skip_node_t;
typedef struct active_list {
const char *identifier;
token_node_t *marker;
struct active_list *next;
} active_list_t;
struct glcpp_parser {
yyscan_t scanner;
struct hash_table *defines;
active_list_t *active;
int lexing_if;
int space_tokens;
int newline_as_space;
int in_control_line;
int paren_count;
skip_node_t *skip_stack;
token_list_t *lex_from_list;
token_node_t *lex_from_node;
char *output;
char *info_log;
int error;
};
struct gl_extensions;
glcpp_parser_t *
glcpp_parser_create (const struct gl_extensions *extensions, int api);
int
glcpp_parser_parse (glcpp_parser_t *parser);
void
glcpp_parser_destroy (glcpp_parser_t *parser);
int
preprocess(void *ralloc_ctx, const char **shader, char **info_log,
const struct gl_extensions *extensions, int api);
/* Functions for writing to the info log */
void
glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
void
glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...);
/* Generated by glcpp-lex.l to glcpp-lex.c */
int
glcpp_lex_init_extra (glcpp_parser_t *parser, yyscan_t* scanner);
void
glcpp_lex_set_source_string(glcpp_parser_t *parser, const char *shader);
int
glcpp_lex (YYSTYPE *lvalp, YYLTYPE *llocp, yyscan_t scanner);
int
glcpp_lex_destroy (yyscan_t scanner);
/* Generated by glcpp-parse.y to glcpp-parse.c */
int
yyparse (glcpp_parser_t *parser);
#endif

View file

@ -0,0 +1,165 @@
/*
* Copyright © 2010 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "glcpp.h"
#include "main/core.h" /* for isblank() on MSVC */
void
glcpp_error (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
{
va_list ap;
parser->error = 1;
ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
"preprocessor error: ",
locp->source,
locp->first_line,
locp->first_column);
va_start(ap, fmt);
ralloc_vasprintf_append(&parser->info_log, fmt, ap);
va_end(ap);
ralloc_strcat(&parser->info_log, "\n");
}
void
glcpp_warning (YYLTYPE *locp, glcpp_parser_t *parser, const char *fmt, ...)
{
va_list ap;
ralloc_asprintf_append(&parser->info_log, "%u:%u(%u): "
"preprocessor warning: ",
locp->source,
locp->first_line,
locp->first_column);
va_start(ap, fmt);
ralloc_vasprintf_append(&parser->info_log, fmt, ap);
va_end(ap);
ralloc_strcat(&parser->info_log, "\n");
}
/* Searches backwards for '^ *#' from a given starting point. */
static int
in_directive(const char *shader, const char *ptr)
{
assert(ptr >= shader);
/* Search backwards for '#'. If we find a \n first, it doesn't count */
for (; ptr >= shader && *ptr != '#'; ptr--) {
if (*ptr == '\n')
return 0;
}
if (ptr >= shader) {
/* Found '#'...look for spaces preceded by a newline */
for (ptr--; ptr >= shader && isblank(*ptr); ptr--);
// FIXME: I don't think the '\n' case can happen
if (ptr < shader || *ptr == '\n')
return 1;
}
return 0;
}
/* Remove any line continuation characters in preprocessing directives.
* However, ignore any in GLSL code, as "There is no line continuation
* character" (1.30 page 9) in GLSL.
*/
static char *
remove_line_continuations(glcpp_parser_t *ctx, const char *shader)
{
int in_continued_line = 0;
int extra_newlines = 0;
char *clean = ralloc_strdup(ctx, "");
const char *search_start = shader;
const char *newline;
while ((newline = strchr(search_start, '\n')) != NULL) {
const char *backslash = NULL;
/* # of characters preceding the newline. */
int n = newline - shader;
/* Find the preceding '\', if it exists */
if (n >= 1 && newline[-1] == '\\')
backslash = newline - 1;
else if (n >= 2 && newline[-1] == '\r' && newline[-2] == '\\')
backslash = newline - 2;
/* Double backslashes don't count (the backslash is escaped) */
if (backslash != NULL && backslash[-1] == '\\') {
backslash = NULL;
}
if (backslash != NULL) {
/* We found a line continuation, but do we care? */
if (!in_continued_line) {
if (in_directive(shader, backslash)) {
in_continued_line = 1;
extra_newlines = 0;
}
}
if (in_continued_line) {
/* Copy everything before the \ */
ralloc_strncat(&clean, shader, backslash - shader);
shader = newline + 1;
extra_newlines++;
}
} else if (in_continued_line) {
/* Copy everything up to and including the \n */
ralloc_strncat(&clean, shader, newline - shader + 1);
shader = newline + 1;
/* Output extra newlines to make line numbers match */
for (; extra_newlines > 0; extra_newlines--)
ralloc_strcat(&clean, "\n");
in_continued_line = 0;
}
search_start = newline + 1;
}
ralloc_strcat(&clean, shader);
return clean;
}
int
preprocess(void *ralloc_ctx, const char **shader, char **info_log,
const struct gl_extensions *extensions, int api)
{
int errors;
glcpp_parser_t *parser = glcpp_parser_create (extensions, api);
*shader = remove_line_continuations(parser, *shader);
glcpp_lex_set_source_string (parser, *shader);
glcpp_parser_parse (parser);
if (parser->skip_stack)
glcpp_error (&parser->skip_stack->loc, parser, "Unterminated #if\n");
ralloc_strcat(info_log, parser->info_log);
ralloc_steal(ralloc_ctx, parser->output);
*shader = parser->output;
errors = parser->error;
glcpp_parser_destroy (parser);
return errors;
}

View file

@ -0,0 +1 @@
this is four tokens

View file

@ -0,0 +1,2 @@
this is four tokens

View file

@ -0,0 +1,2 @@
#define foo 1
foo

View file

@ -0,0 +1,3 @@
1

View file

@ -0,0 +1,3 @@
#define foo 1
#define bar foo
bar

View file

@ -0,0 +1,4 @@
1

View file

@ -0,0 +1,3 @@
#define bar foo
#define foo 1
bar

View file

@ -0,0 +1,6 @@
#define foo bar
#define bar baz
#define baz foo
foo
bar
baz

View file

@ -0,0 +1,7 @@
foo
bar
baz

View file

@ -0,0 +1,3 @@
#define foo 1
#define bar a foo
bar

View file

@ -0,0 +1,4 @@
a 1

View file

@ -0,0 +1,3 @@
#define bar a foo
#define foo 1
bar

View file

@ -0,0 +1,6 @@
#define foo a bar
#define bar b baz
#define baz c foo
foo
bar
baz

View file

@ -0,0 +1,7 @@
a b c foo
b c a bar
c a b baz

View file

@ -0,0 +1,2 @@
#define foo
foo

View file

@ -0,0 +1,3 @@

View file

@ -0,0 +1,4 @@
#define foo 1
foo
#undef foo
foo

View file

@ -0,0 +1,5 @@
1
foo

View file

@ -0,0 +1,6 @@
#define foo 1
foo
#undef foo
foo
#define foo 2
foo

View file

@ -0,0 +1,7 @@
1
foo
2

View file

@ -0,0 +1,2 @@
#define foo()
foo()

View file

@ -0,0 +1,2 @@
#define foo() bar
foo()

View file

@ -0,0 +1,3 @@
bar

View file

@ -0,0 +1,2 @@
#define foo(x) 1
foo(bar)

View file

@ -0,0 +1,2 @@
#define foo(x,y) 1
foo(bar,baz)

View file

@ -0,0 +1,4 @@
#define foo ()1
foo()
#define bar ()2
bar()

View file

@ -0,0 +1,5 @@
()1()
()2()

View file

@ -0,0 +1,2 @@
#define foo(x) ((x)+1)
foo(bar)

View file

@ -0,0 +1,3 @@
((bar)+1)

View file

@ -0,0 +1,2 @@
#define foo(x,y) ((x)*(y))
foo(bar,baz)

View file

@ -0,0 +1,3 @@
((bar)*(baz))

View file

@ -0,0 +1,3 @@
#define x 0
#define foo(x) x
foo(1)

View file

@ -0,0 +1,2 @@
#define foo(x) (x)
foo(this is more than one word)

View file

@ -0,0 +1,3 @@
(this is more than one word)

View file

@ -0,0 +1,2 @@
#define foo(x,y) x,two fish,red fish,y
foo(one fish, blue fish)

View file

@ -0,0 +1,3 @@
one fish,two fish,red fish,blue fish

View file

@ -0,0 +1,3 @@
#define bar(x) (1+(x))
#define foo(y) (2*(y))
foo(bar(3))

View file

@ -0,0 +1,4 @@
(2*((1+(3))))

View file

@ -0,0 +1,2 @@
#define foo(x) (x)
foo(argument(including parens)for the win)

View file

@ -0,0 +1,3 @@
(argument(including parens)for the win)

View file

@ -0,0 +1,8 @@
#define noargs() 1
# define onearg(foo) foo
# define twoargs( x , y ) x y
# define threeargs( a , b , c ) a b c
noargs ( )
onearg ( 2 )
twoargs ( 3 , 4 )
threeargs ( 5 , 6 , 7 )

View file

@ -0,0 +1,9 @@
1
2
3 4
5 6 7

View file

@ -0,0 +1,3 @@
#define foo foo
#define bar foo
bar

View file

@ -0,0 +1,2 @@
#define foo(bar) bar
foo bar

View file

@ -0,0 +1,3 @@
foo bar

View file

@ -0,0 +1,6 @@
#define foo(a) bar
foo
(
1
)

View file

@ -0,0 +1,3 @@
#define failure() success
#define foo failure()
foo

View file

@ -0,0 +1,4 @@
success

View file

@ -0,0 +1,3 @@
#define success() failure
#define foo success
foo

View file

@ -0,0 +1,4 @@
success

View file

@ -0,0 +1,3 @@
#define bar(failure) failure
#define foo bar(success)
foo

View file

@ -0,0 +1,4 @@
#define baz(failure) failure
#define bar(failure) failure
#define foo bar(baz(success))
foo

View file

@ -0,0 +1,4 @@
#define baz(failure) failure
#define bar(failure) failure
#define foo() bar(baz(success))
foo()

View file

@ -0,0 +1,2 @@
#define foo(a) foo(2*(a))
foo(3)

View file

@ -0,0 +1,3 @@
foo(2*(3))

View file

@ -0,0 +1,2 @@
#define foo(a) foo(2*(a))
foo(foo(3))

View file

@ -0,0 +1,3 @@
foo(2*(foo(2*(3))))

View file

@ -0,0 +1,2 @@
#define foo(bar) bar
foo(foo)

View file

@ -0,0 +1,2 @@
#define foo(bar) bar
foo(1+foo)

View file

@ -0,0 +1,3 @@
#define bar success
#define foo(x) x
foo(more bar)

View file

@ -0,0 +1,3 @@
#define expand(x) expand(x once)
#define foo(x) x
foo(expand(just))

View file

@ -0,0 +1,4 @@
expand(just once)

View file

@ -0,0 +1,2 @@
#define foo(x) success
foo(argument (with,embedded , commas) -- tricky)

View file

@ -0,0 +1,3 @@
success

View file

@ -0,0 +1,3 @@
#define foo(a) (a)
#define bar two,words
foo(bar)

View file

@ -0,0 +1,4 @@
(two,words)

View file

@ -0,0 +1,2 @@
#define paste(a,b) a ## b
paste(one , token)

View file

@ -0,0 +1,3 @@
onetoken

View file

@ -0,0 +1,5 @@
success_1
#if 0
failure
#endif
success_2

View file

@ -0,0 +1,6 @@
success_1
success_2

View file

@ -0,0 +1,5 @@
success_1
#if 1
success_2
#endif
success_3

View file

@ -0,0 +1,6 @@
success_1
success_2
success_3

View file

@ -0,0 +1,7 @@
success_1
#if 0
failure
#else
success_2
#endif
success_3

View file

@ -0,0 +1,8 @@
success_1
success_2
success_3

View file

@ -0,0 +1,7 @@
success_1
#if 1
success_2
#else
failure
#endif
success_3

View file

@ -0,0 +1,8 @@
success_1
success_2
success_3

Some files were not shown because too many files have changed in this diff Show more