diff options
Diffstat (limited to 'src')
8 files changed, 21 insertions, 0 deletions
diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l index fa9aa506912..071918e5692 100644 --- a/src/compiler/glsl/glcpp/glcpp-lex.l +++ b/src/compiler/glsl/glcpp/glcpp-lex.l @@ -120,6 +120,11 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner); static int glcpp_lex_update_state_per_token (glcpp_parser_t *parser, int token) { + if (token != NEWLINE && token != SPACE && token != HASH_TOKEN && + !parser->lexing_version_directive) { + glcpp_parser_resolve_implicit_version(parser); + } + /* After the first non-space token in a line, we won't * allow any '#' to introduce a directive. */ if (token == NEWLINE) { @@ -285,6 +290,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? <HASH>version{HSPACE}+ { BEGIN INITIAL; yyextra->space_tokens = 0; + yyextra->lexing_version_directive = 1; RETURN_STRING_TOKEN (VERSION_TOKEN); } @@ -536,6 +542,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? } yyextra->space_tokens = 1; yyextra->lexing_directive = 0; + yyextra->lexing_version_directive = 0; yylineno++; yycolumn = 0; RETURN_TOKEN_NEVER_SKIP (NEWLINE); @@ -546,6 +553,7 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? glcpp_error(yylloc, yyextra, "Unterminated comment"); BEGIN DONE; /* Don't keep matching this rule forever. */ yyextra->lexing_directive = 0; + yyextra->lexing_version_directive = 0; if (! parser->last_token_was_newline) RETURN_TOKEN (NEWLINE); } diff --git a/src/compiler/glsl/glcpp/glcpp.h b/src/compiler/glsl/glcpp/glcpp.h index 70aa14b6ec0..d87e6b77dc5 100644 --- a/src/compiler/glsl/glcpp/glcpp.h +++ b/src/compiler/glsl/glcpp/glcpp.h @@ -176,6 +176,7 @@ struct glcpp_parser { struct hash_table *defines; active_list_t *active; int lexing_directive; + int lexing_version_directive; int space_tokens; int last_token_was_newline; int last_token_was_space; diff --git a/src/compiler/glsl/glcpp/tests/144-implicit-version.c b/src/compiler/glsl/glcpp/tests/144-implicit-version.c new file mode 100644 index 00000000000..7bf72fc19e9 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/144-implicit-version.c @@ -0,0 +1 @@ +int x = __VERSION__; diff --git a/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected b/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected new file mode 100644 index 00000000000..8c2dfd9ce30 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected @@ -0,0 +1 @@ +int x = 110; diff --git a/src/compiler/glsl/glcpp/tests/145-version-first.c b/src/compiler/glsl/glcpp/tests/145-version-first.c new file mode 100644 index 00000000000..f9fcfb08246 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/145-version-first.c @@ -0,0 +1,2 @@ +123 +#version 120 diff --git a/src/compiler/glsl/glcpp/tests/145-version-first.c.expected b/src/compiler/glsl/glcpp/tests/145-version-first.c.expected new file mode 100644 index 00000000000..f4092b04af7 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/145-version-first.c.expected @@ -0,0 +1,3 @@ +0:2(1): preprocessor error: #version must appear on the first line +123 + diff --git a/src/compiler/glsl/glcpp/tests/146-version-first-hash.c b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c new file mode 100644 index 00000000000..14dbe964bd6 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c @@ -0,0 +1,2 @@ +# +#version 120 diff --git a/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected new file mode 100644 index 00000000000..2872090333d --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected @@ -0,0 +1,3 @@ +0:1(3): preprocessor error: #version must appear on the first line + + |