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. TRAC #23218 Signed-off-by: Geoff Lang Signed-off-by: Nicolas Capens Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2389 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 5f8d9b46
......@@ -54,6 +54,8 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
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 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); }
......@@ -141,9 +143,9 @@ O [0-7]
"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
"sampler3D" { if (context->shaderVersion < 300) return reserved_word(yyscanner); 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; }
"sampler3D" { return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
"sampler3DRect" { return ES2_reserved_ES3_keyword(context, SAMPLER3DRECT); }
"sampler2DShadow" { return ES2_reserved_ES3_keyword(context, SAMPLER2DSHADOW); }
"sampler2DRect" { context->lexAfterType = true; return SAMPLER2DRECT; }
"struct" { context->lexAfterType = true; return(STRUCT); }
......@@ -380,6 +382,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;
......
......@@ -994,6 +994,8 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
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 ES2_reserved_ES3_keyword(TParseContext *context, int token);
static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
#define INITIAL 0
#define COMMENT 1
......@@ -1358,7 +1360,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
......@@ -1370,7 +1372,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
......@@ -1402,27 +1404,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
......@@ -1530,15 +1532,15 @@ YY_RULE_SETUP
YY_BREAK
case 54:
YY_RULE_SETUP
{ if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3D; }
{ return ES2_reserved_ES3_keyword(context, SAMPLER3D); }
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
......@@ -3114,6 +3116,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