Commit 309a1d98 by Nicolas Capens

Add helper functions to the lexer to tokenize strings that have different…

Add helper functions to the lexer to tokenize strings that have different classifications in ES2 and ES3. Bug 19331817 Change-Id: I4e1c190e23aa63b03ef8f57930102d01e496f107 Reviewed-on: https://swiftshader-review.googlesource.com/2311Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent a6a79ab0
......@@ -54,6 +54,8 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
static int string_input(char* buf, int max_size, yyscan_t yyscanner);
static int check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner);
static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
%}
%option noyywrap nounput never-interactive
......@@ -89,10 +91,10 @@ O [0-7]
"lowp" { return(LOW_PRECISION); }
"precision" { return(PRECISION); }
"attribute" { if (context->shaderVersion < 300) return(ATTRIBUTE); return reserved_word(yyscanner); }
"attribute" { return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
"const" { return(CONST_QUAL); }
"uniform" { return(UNIFORM); }
"varying" { if (context->shaderVersion < 300) return(VARYING); return reserved_word(yyscanner); }
"varying" { return ES2_keyword_ES3_reserved(context, VARYING); }
"break" { return(BREAK); }
"continue" { return(CONTINUE); }
......@@ -102,13 +104,13 @@ O [0-7]
"if" { return(IF); }
"else" { return(ELSE); }
"switch" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SWITCH); }
"case" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CASE); }
"default" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(DEFAULT); }
"switch" { return ES2_reserved_ES3_keyword(context, SWITCH); }
"case" { return ES2_reserved_ES3_keyword(context, CASE); }
"default" { return ES2_reserved_ES3_keyword(context, DEFAULT); }
"centroid" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CENTROID); }
"flat" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(FLAT); }
"smooth" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SMOOTH); }
"centroid" { return ES2_reserved_ES3_keyword(context, CENTROID); }
"flat" { return ES2_reserved_ES3_keyword(context, FLAT); }
"smooth" { return ES2_reserved_ES3_keyword(context, SMOOTH); }
"in" { return(IN_QUAL); }
"out" { return(OUT_QUAL); }
......@@ -142,8 +144,8 @@ O [0-7]
"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
"sampler3D" { context->lexAfterType = true; return SAMPLER3D; }
"sampler3DRect" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3DRECT; }
"sampler2DShadow" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER2DSHADOW; }
"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
"struct" { context->lexAfterType = true; return(STRUCT); }
......@@ -383,6 +385,30 @@ int reserved_word(yyscan_t yyscanner) {
return 0;
}
int ES2_reserved_ES3_keyword(TParseContext *context, int token)
{
yyscan_t yyscanner = (yyscan_t) context->scanner;
if (context->shaderVersion < 300)
{
return reserved_word(yyscanner);
}
return token;
}
int ES2_keyword_ES3_reserved(TParseContext *context, int token)
{
yyscan_t yyscanner = (yyscan_t) context->scanner;
if (context->shaderVersion >= 300)
{
return reserved_word(yyscanner);
}
return token;
}
void yyerror(TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
......
......@@ -1003,6 +1003,8 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
static int string_input(char* buf, int max_size, yyscan_t yyscanner);
static int check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner);
static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
#define INITIAL 0
#define COMMENT 1
......@@ -1372,7 +1374,7 @@ YY_RULE_SETUP
YY_BREAK
case 11:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return(ATTRIBUTE); return reserved_word(yyscanner); }
{ return ES2_keyword_ES3_reserved(context, ATTRIBUTE); }
YY_BREAK
case 12:
YY_RULE_SETUP
......@@ -1384,7 +1386,7 @@ YY_RULE_SETUP
YY_BREAK
case 14:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return(VARYING); return reserved_word(yyscanner); }
{ return ES2_keyword_ES3_reserved(context, VARYING); }
YY_BREAK
case 15:
YY_RULE_SETUP
......@@ -1416,27 +1418,27 @@ YY_RULE_SETUP
YY_BREAK
case 22:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SWITCH); }
{ return ES2_reserved_ES3_keyword(context, SWITCH); }
YY_BREAK
case 23:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CASE); }
{ return ES2_reserved_ES3_keyword(context, CASE); }
YY_BREAK
case 24:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(DEFAULT); }
{ return ES2_reserved_ES3_keyword(context, DEFAULT); }
YY_BREAK
case 25:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CENTROID); }
{ return ES2_reserved_ES3_keyword(context, CENTROID); }
YY_BREAK
case 26:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(FLAT); }
{ return ES2_reserved_ES3_keyword(context, FLAT); }
YY_BREAK
case 27:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SMOOTH); }
{ return ES2_reserved_ES3_keyword(context, SMOOTH); }
YY_BREAK
case 28:
YY_RULE_SETUP
......@@ -1548,11 +1550,11 @@ YY_RULE_SETUP
YY_BREAK
case 55:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3DRECT; }
{ return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
YY_BREAK
case 56:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER2DSHADOW; }
{ return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
YY_BREAK
case 57:
YY_RULE_SETUP
......@@ -3128,6 +3130,30 @@ int reserved_word(yyscan_t yyscanner) {
return 0;
}
int ES2_reserved_ES3_keyword(TParseContext *context, int token)
{
yyscan_t yyscanner = (yyscan_t) context->scanner;
if (context->shaderVersion < 300)
{
return reserved_word(yyscanner);
}
return token;
}
int ES2_keyword_ES3_reserved(TParseContext *context, int token)
{
yyscan_t yyscanner = (yyscan_t) context->scanner;
if (context->shaderVersion >= 300)
{
return reserved_word(yyscanner);
}
return token;
}
void yyerror(TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment