summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/glslang.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/compiler/glslang.l')
-rw-r--r--src/3rdparty/angle/src/compiler/glslang.l310
1 files changed, 150 insertions, 160 deletions
diff --git a/src/3rdparty/angle/src/compiler/glslang.l b/src/3rdparty/angle/src/compiler/glslang.l
index 140a9aeb2d..60663f9a6b 100644
--- a/src/3rdparty/angle/src/compiler/glslang.l
+++ b/src/3rdparty/angle/src/compiler/glslang.l
@@ -47,20 +47,23 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable : 4102)
#endif
-#define YY_USER_ACTION yylval->lex.line = yylineno;
+#define YY_USER_ACTION \
+ yylloc->first_file = yylloc->last_file = yycolumn; \
+ yylloc->first_line = yylloc->last_line = yylineno;
+
#define YY_INPUT(buf, result, max_size) \
result = string_input(buf, max_size, yyscanner);
static yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner);
static int check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner);
+static int int_constant(yyscan_t yyscanner);
+static int float_constant(yyscan_t yyscanner);
%}
%option noyywrap nounput never-interactive
-%option yylineno reentrant bison-bridge
-%option stack
+%option yylineno reentrant bison-bridge bison-locations
%option extra-type="TParseContext*"
-%x COMMENT FIELDS
D [0-9]
L [a-zA-Z_]
@@ -70,73 +73,60 @@ O [0-7]
%%
-%{
- TParseContext* context = yyextra;
-%}
-
- /* Single-line comments */
-"//"[^\n]* ;
-
- /* Multi-line comments */
-"/*" { yy_push_state(COMMENT, yyscanner); }
-<COMMENT>. |
-<COMMENT>\n ;
-<COMMENT>"*/" { yy_pop_state(yyscanner); }
-
-"invariant" { return(INVARIANT); }
-"highp" { return(HIGH_PRECISION); }
-"mediump" { return(MEDIUM_PRECISION); }
-"lowp" { return(LOW_PRECISION); }
-"precision" { return(PRECISION); }
-
-"attribute" { return(ATTRIBUTE); }
-"const" { return(CONST_QUAL); }
-"uniform" { return(UNIFORM); }
-"varying" { return(VARYING); }
-
-"break" { return(BREAK); }
-"continue" { return(CONTINUE); }
-"do" { return(DO); }
-"for" { return(FOR); }
-"while" { return(WHILE); }
-
-"if" { return(IF); }
-"else" { return(ELSE); }
-
-"in" { return(IN_QUAL); }
-"out" { return(OUT_QUAL); }
-"inout" { return(INOUT_QUAL); }
-
-"float" { context->lexAfterType = true; return(FLOAT_TYPE); }
-"int" { context->lexAfterType = true; return(INT_TYPE); }
-"void" { context->lexAfterType = true; return(VOID_TYPE); }
-"bool" { context->lexAfterType = true; return(BOOL_TYPE); }
-"true" { yylval->lex.b = true; return(BOOLCONSTANT); }
-"false" { yylval->lex.b = false; return(BOOLCONSTANT); }
-
-"discard" { return(DISCARD); }
-"return" { return(RETURN); }
-
-"mat2" { context->lexAfterType = true; return(MATRIX2); }
-"mat3" { context->lexAfterType = true; return(MATRIX3); }
-"mat4" { context->lexAfterType = true; return(MATRIX4); }
-
-"vec2" { context->lexAfterType = true; return (VEC2); }
-"vec3" { context->lexAfterType = true; return (VEC3); }
-"vec4" { context->lexAfterType = true; return (VEC4); }
-"ivec2" { context->lexAfterType = true; return (IVEC2); }
-"ivec3" { context->lexAfterType = true; return (IVEC3); }
-"ivec4" { context->lexAfterType = true; return (IVEC4); }
-"bvec2" { context->lexAfterType = true; return (BVEC2); }
-"bvec3" { context->lexAfterType = true; return (BVEC3); }
-"bvec4" { context->lexAfterType = true; return (BVEC4); }
-
-"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
-"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
-"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
-"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
-
-"struct" { context->lexAfterType = true; return(STRUCT); }
+"invariant" { return INVARIANT; }
+"highp" { return HIGH_PRECISION; }
+"mediump" { return MEDIUM_PRECISION; }
+"lowp" { return LOW_PRECISION; }
+"precision" { return PRECISION; }
+
+"attribute" { return ATTRIBUTE; }
+"const" { return CONST_QUAL; }
+"uniform" { return UNIFORM; }
+"varying" { return VARYING; }
+
+"break" { return BREAK; }
+"continue" { return CONTINUE; }
+"do" { return DO; }
+"for" { return FOR; }
+"while" { return WHILE; }
+
+"if" { return IF; }
+"else" { return ELSE; }
+
+"in" { return IN_QUAL; }
+"out" { return OUT_QUAL; }
+"inout" { return INOUT_QUAL; }
+
+"float" { return FLOAT_TYPE; }
+"int" { return INT_TYPE; }
+"void" { return VOID_TYPE; }
+"bool" { return BOOL_TYPE; }
+"true" { yylval->lex.b = true; return BOOLCONSTANT; }
+"false" { yylval->lex.b = false; return BOOLCONSTANT; }
+
+"discard" { return DISCARD; }
+"return" { return RETURN; }
+
+"mat2" { return MATRIX2; }
+"mat3" { return MATRIX3; }
+"mat4" { return MATRIX4; }
+
+"vec2" { return VEC2; }
+"vec3" { return VEC3; }
+"vec4" { return VEC4; }
+"ivec2" { return IVEC2; }
+"ivec3" { return IVEC3; }
+"ivec4" { return IVEC4; }
+"bvec2" { return BVEC2; }
+"bvec3" { return BVEC3; }
+"bvec4" { return BVEC4; }
+
+"sampler2D" { return SAMPLER2D; }
+"samplerCube" { return SAMPLERCUBE; }
+"samplerExternalOES" { return SAMPLER_EXTERNAL_OES; }
+"sampler2DRect" { return SAMPLER2DRECT; }
+
+"struct" { return STRUCT; }
"asm" { return reserved_word(yyscanner); }
@@ -183,13 +173,11 @@ O [0-7]
"fvec3" { return reserved_word(yyscanner); }
"fvec4" { return reserved_word(yyscanner); }
-"sampler1D" { return reserved_word(yyscanner); }
-"sampler3D" { return reserved_word(yyscanner); }
-
-"sampler1DShadow" { return reserved_word(yyscanner); }
-"sampler2DShadow" { return reserved_word(yyscanner); }
-
-"sampler3DRect" { return reserved_word(yyscanner); }
+"sampler1D" { return reserved_word(yyscanner); }
+"sampler3D" { return reserved_word(yyscanner); }
+"sampler1DShadow" { return reserved_word(yyscanner); }
+"sampler2DShadow" { return reserved_word(yyscanner); }
+"sampler3DRect" { return reserved_word(yyscanner); }
"sampler2DRectShadow" { return reserved_word(yyscanner); }
"sizeof" { return reserved_word(yyscanner); }
@@ -203,72 +191,64 @@ O [0-7]
return check_type(yyscanner);
}
-0[xX]{H}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
-0{O}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
-0{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
-{D}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
-
-{D}+{E} { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
-{D}+"."{D}*({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
-"."{D}+({E})? { yylval->lex.f = static_cast<float>(atof_dot(yytext)); return(FLOATCONSTANT); }
-
-"+=" { return(ADD_ASSIGN); }
-"-=" { return(SUB_ASSIGN); }
-"*=" { return(MUL_ASSIGN); }
-"/=" { return(DIV_ASSIGN); }
-"%=" { return(MOD_ASSIGN); }
-"<<=" { return(LEFT_ASSIGN); }
-">>=" { return(RIGHT_ASSIGN); }
-"&=" { return(AND_ASSIGN); }
-"^=" { return(XOR_ASSIGN); }
-"|=" { return(OR_ASSIGN); }
-
-"++" { return(INC_OP); }
-"--" { return(DEC_OP); }
-"&&" { return(AND_OP); }
-"||" { return(OR_OP); }
-"^^" { return(XOR_OP); }
-"<=" { return(LE_OP); }
-">=" { return(GE_OP); }
-"==" { return(EQ_OP); }
-"!=" { return(NE_OP); }
-"<<" { return(LEFT_OP); }
-">>" { return(RIGHT_OP); }
-";" { context->lexAfterType = false; return(SEMICOLON); }
-("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
-("}"|"%>") { return(RIGHT_BRACE); }
-"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
-":" { return(COLON); }
-"=" { context->lexAfterType = false; return(EQUAL); }
-"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
-")" { context->inTypeParen = false; return(RIGHT_PAREN); }
-("["|"<:") { return(LEFT_BRACKET); }
-("]"|":>") { return(RIGHT_BRACKET); }
-"." { BEGIN(FIELDS); return(DOT); }
-"!" { return(BANG); }
-"-" { return(DASH); }
-"~" { return(TILDE); }
-"+" { return(PLUS); }
-"*" { return(STAR); }
-"/" { return(SLASH); }
-"%" { return(PERCENT); }
-"<" { return(LEFT_ANGLE); }
-">" { return(RIGHT_ANGLE); }
-"|" { return(VERTICAL_BAR); }
-"^" { return(CARET); }
-"&" { return(AMPERSAND); }
-"?" { return(QUESTION); }
-
-<FIELDS>{L}({L}|{D})* {
- BEGIN(INITIAL);
- yylval->lex.string = NewPoolTString(yytext);
- return FIELD_SELECTION;
-}
-<FIELDS>[ \t\v\f\r] {}
-
-[ \t\v\n\f\r] { }
-<*><<EOF>> { context->AfterEOF = true; yyterminate(); }
-<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; }
+0[xX]{H}+ { return int_constant(yyscanner); }
+0{O}+ { return int_constant(yyscanner); }
+{D}+ { return int_constant(yyscanner); }
+
+{D}+{E} { return float_constant(yyscanner); }
+{D}+"."{D}*({E})? { return float_constant(yyscanner); }
+"."{D}+({E})? { return float_constant(yyscanner); }
+
+"+=" { return ADD_ASSIGN; }
+"-=" { return SUB_ASSIGN; }
+"*=" { return MUL_ASSIGN; }
+"/=" { return DIV_ASSIGN; }
+"%=" { return MOD_ASSIGN; }
+"<<=" { return LEFT_ASSIGN; }
+">>=" { return RIGHT_ASSIGN; }
+"&=" { return AND_ASSIGN; }
+"^=" { return XOR_ASSIGN; }
+"|=" { return OR_ASSIGN; }
+
+"++" { return INC_OP; }
+"--" { return DEC_OP; }
+"&&" { return AND_OP; }
+"||" { return OR_OP; }
+"^^" { return XOR_OP; }
+"<=" { return LE_OP; }
+">=" { return GE_OP; }
+"==" { return EQ_OP; }
+"!=" { return NE_OP; }
+"<<" { return LEFT_OP; }
+">>" { return RIGHT_OP; }
+";" { return SEMICOLON; }
+("{"|"<%") { return LEFT_BRACE; }
+("}"|"%>") { return RIGHT_BRACE; }
+"," { return COMMA; }
+":" { return COLON; }
+"=" { return EQUAL; }
+"(" { return LEFT_PAREN; }
+")" { return RIGHT_PAREN; }
+("["|"<:") { return LEFT_BRACKET; }
+("]"|":>") { return RIGHT_BRACKET; }
+"." { return DOT; }
+"!" { return BANG; }
+"-" { return DASH; }
+"~" { return TILDE; }
+"+" { return PLUS; }
+"*" { return STAR; }
+"/" { return SLASH; }
+"%" { return PERCENT; }
+"<" { return LEFT_ANGLE; }
+">" { return RIGHT_ANGLE; }
+"|" { return VERTICAL_BAR; }
+"^" { return CARET; }
+"&" { return AMPERSAND; }
+"?" { return QUESTION; }
+
+[ \t\v\n\f\r] { }
+<<EOF>> { yyterminate(); }
+. { assert(false); return 0; }
%%
@@ -278,7 +258,8 @@ yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if (len < max_size)
memcpy(buf, token.text.c_str(), len);
- yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
+ yyset_column(token.location.file, yyscanner);
+ yyset_lineno(token.location.line, yyscanner);
if (len >= max_size)
YY_FATAL_ERROR("Input buffer overflow");
@@ -292,12 +273,10 @@ int check_type(yyscan_t yyscanner) {
int token = IDENTIFIER;
TSymbol* symbol = yyextra->symbolTable.find(yytext);
- if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
+ if (symbol && symbol->isVariable()) {
TVariable* variable = static_cast<TVariable*>(symbol);
- if (variable->isUserType()) {
- yyextra->lexAfterType = true;
+ if (variable->isUserType())
token = TYPE_NAME;
- }
}
yylval->lex.symbol = symbol;
return token;
@@ -306,22 +285,32 @@ int check_type(yyscan_t yyscanner) {
int reserved_word(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
- yyextra->error(yylineno, "Illegal use of reserved word", yytext, "");
+ yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
yyextra->recover();
return 0;
}
-void yyerror(TParseContext* context, const char* reason) {
- struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
-
- if (context->AfterEOF) {
- context->error(yylineno, reason, "unexpected EOF");
- } else {
- context->error(yylineno, reason, yytext);
- }
+void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) {
+ context->error(*lloc, reason, yyget_text(context->scanner));
context->recover();
}
+int int_constant(yyscan_t yyscanner) {
+ struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
+
+ if (!atoi_clamp(yytext, &(yylval->lex.i)))
+ yyextra->warning(*yylloc, "Integer overflow", yytext, "");
+ return INTCONSTANT;
+}
+
+int float_constant(yyscan_t yyscanner) {
+ struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
+
+ if (!atof_clamp(yytext, &(yylval->lex.f)))
+ yyextra->warning(*yylloc, "Float overflow", yytext, "");
+ return FLOATCONSTANT;
+}
+
int glslang_initialize(TParseContext* context) {
yyscan_t scanner = NULL;
if (yylex_init_extra(context, &scanner))
@@ -344,12 +333,13 @@ int glslang_finalize(TParseContext* context) {
int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) {
yyrestart(NULL, context->scanner);
- yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
- context->AfterEOF = false;
+ yyset_column(0, context->scanner);
+ yyset_lineno(1, context->scanner);
// Initialize preprocessor.
if (!context->preprocessor.init(count, string, length))
return 1;
+ context->preprocessor.setMaxTokenLength(SH_MAX_TOKEN_LENGTH);
// Define extension macros.
const TExtensionBehavior& extBehavior = context->extensionBehavior();