Add support for unsigned integer literals in the shading language.

TRAC #23080 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2405 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8c788e8d
...@@ -57,6 +57,7 @@ static int reserved_word(yyscan_t yyscanner); ...@@ -57,6 +57,7 @@ static int reserved_word(yyscan_t yyscanner);
static int ES2_reserved_ES3_keyword(TParseContext *context, int token); static int ES2_reserved_ES3_keyword(TParseContext *context, int token);
static int ES2_keyword_ES3_reserved(TParseContext *context, int token); static int ES2_keyword_ES3_reserved(TParseContext *context, int token);
static int ES2_ident_ES3_keyword(TParseContext *context, int token); static int ES2_ident_ES3_keyword(TParseContext *context, int token);
static int uint_constant(TParseContext *context);
%} %}
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
...@@ -294,6 +295,9 @@ O [0-7] ...@@ -294,6 +295,9 @@ O [0-7]
0{O}+ { 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;} 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}+ { yylval->lex.i = static_cast<int>(strtol(yytext, 0, 0)); return(INTCONSTANT); }
0[xX]{H}+[uU] { return uint_constant(context); }
0{O}+[uU] { return uint_constant(context); }
{D}+[uU] { return uint_constant(context); }
{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); }
{D}+"."{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); }
...@@ -437,6 +441,22 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token) ...@@ -437,6 +441,22 @@ int ES2_ident_ES3_keyword(TParseContext *context, int token)
return token; return token;
} }
int uint_constant(TParseContext *context)
{
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
yyscan_t yyscanner = (yyscan_t) context->scanner;
if (context->shaderVersion < 300)
{
context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover();
return 0;
}
yylval->lex.u = static_cast<unsigned int>(strtol(yytext, 0, 0));
return UINTCONSTANT;
}
void yyerror(TParseContext* context, const char* reason) { void yyerror(TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
......
...@@ -55,6 +55,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -55,6 +55,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
TString *string; TString *string;
float f; float f;
int i; int i;
unsigned int u;
bool b; bool b;
}; };
TSymbol* symbol; TSymbol* symbol;
...@@ -132,7 +133,7 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -132,7 +133,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT %token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT
%token <lex> SAMPLER3D SAMPLER3DRECT SAMPLER2DSHADOW %token <lex> SAMPLER3D SAMPLER3DRECT SAMPLER2DSHADOW
%token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT BOOLCONSTANT %token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT UINTCONSTANT BOOLCONSTANT
%token <lex> FIELD_SELECTION %token <lex> FIELD_SELECTION
%token <lex> LEFT_OP RIGHT_OP %token <lex> LEFT_OP RIGHT_OP
%token <lex> INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP %token <lex> INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
...@@ -227,6 +228,11 @@ primary_expression ...@@ -227,6 +228,11 @@ primary_expression
unionArray->setIConst($1.i); unionArray->setIConst($1.i);
$$ = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $1.line); $$ = context->intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), $1.line);
} }
| UINTCONSTANT {
ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setUConst($1.u);
$$ = context->intermediate.addConstantUnion(unionArray, TType(EbtUInt, EbpUndefined, EvqConst), $1.line);
}
| FLOATCONSTANT { | FLOATCONSTANT {
ConstantUnion *unionArray = new ConstantUnion[1]; ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setFConst($1.f); unionArray->setFConst($1.f);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -111,53 +111,54 @@ extern int yydebug; ...@@ -111,53 +111,54 @@ extern int yydebug;
TYPE_NAME = 320, TYPE_NAME = 320,
FLOATCONSTANT = 321, FLOATCONSTANT = 321,
INTCONSTANT = 322, INTCONSTANT = 322,
BOOLCONSTANT = 323, UINTCONSTANT = 323,
FIELD_SELECTION = 324, BOOLCONSTANT = 324,
LEFT_OP = 325, FIELD_SELECTION = 325,
RIGHT_OP = 326, LEFT_OP = 326,
INC_OP = 327, RIGHT_OP = 327,
DEC_OP = 328, INC_OP = 328,
LE_OP = 329, DEC_OP = 329,
GE_OP = 330, LE_OP = 330,
EQ_OP = 331, GE_OP = 331,
NE_OP = 332, EQ_OP = 332,
AND_OP = 333, NE_OP = 333,
OR_OP = 334, AND_OP = 334,
XOR_OP = 335, OR_OP = 335,
MUL_ASSIGN = 336, XOR_OP = 336,
DIV_ASSIGN = 337, MUL_ASSIGN = 337,
ADD_ASSIGN = 338, DIV_ASSIGN = 338,
MOD_ASSIGN = 339, ADD_ASSIGN = 339,
LEFT_ASSIGN = 340, MOD_ASSIGN = 340,
RIGHT_ASSIGN = 341, LEFT_ASSIGN = 341,
AND_ASSIGN = 342, RIGHT_ASSIGN = 342,
XOR_ASSIGN = 343, AND_ASSIGN = 343,
OR_ASSIGN = 344, XOR_ASSIGN = 344,
SUB_ASSIGN = 345, OR_ASSIGN = 345,
LEFT_PAREN = 346, SUB_ASSIGN = 346,
RIGHT_PAREN = 347, LEFT_PAREN = 347,
LEFT_BRACKET = 348, RIGHT_PAREN = 348,
RIGHT_BRACKET = 349, LEFT_BRACKET = 349,
LEFT_BRACE = 350, RIGHT_BRACKET = 350,
RIGHT_BRACE = 351, LEFT_BRACE = 351,
DOT = 352, RIGHT_BRACE = 352,
COMMA = 353, DOT = 353,
COLON = 354, COMMA = 354,
EQUAL = 355, COLON = 355,
SEMICOLON = 356, EQUAL = 356,
BANG = 357, SEMICOLON = 357,
DASH = 358, BANG = 358,
TILDE = 359, DASH = 359,
PLUS = 360, TILDE = 360,
STAR = 361, PLUS = 361,
SLASH = 362, STAR = 362,
PERCENT = 363, SLASH = 363,
LEFT_ANGLE = 364, PERCENT = 364,
RIGHT_ANGLE = 365, LEFT_ANGLE = 365,
VERTICAL_BAR = 366, RIGHT_ANGLE = 366,
CARET = 367, VERTICAL_BAR = 367,
AMPERSAND = 368, CARET = 368,
QUESTION = 369 AMPERSAND = 369,
QUESTION = 370
}; };
#endif #endif
...@@ -173,6 +174,7 @@ typedef union YYSTYPE ...@@ -173,6 +174,7 @@ typedef union YYSTYPE
TString *string; TString *string;
float f; float f;
int i; int i;
unsigned int u;
bool b; bool b;
}; };
TSymbol* symbol; TSymbol* symbol;
......
...@@ -79,9 +79,9 @@ NEWLINE \n|\r|\r\n ...@@ -79,9 +79,9 @@ NEWLINE \n|\r|\r\n
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
PUNCTUATOR [][<>(){}.+-/*%^|&~=!:;,?] PUNCTUATOR [][<>(){}.+-/*%^|&~=!:;,?]
DECIMAL_CONSTANT [1-9][0-9]* DECIMAL_CONSTANT [1-9][0-9]*[uU]?
OCTAL_CONSTANT 0[0-7]* OCTAL_CONSTANT 0[0-7]*[uU]?
HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+ HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+[uU]?
DIGIT [0-9] DIGIT [0-9]
EXPONENT_PART [eE][+-]?{DIGIT}+ EXPONENT_PART [eE][+-]?{DIGIT}+
......
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
<ClInclude Include="Tokenizer.h" /> <ClInclude Include="Tokenizer.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="ExpressionParser.y" />
<None Include="Tokenizer.l" /> <None Include="Tokenizer.l" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
...@@ -96,5 +96,8 @@ ...@@ -96,5 +96,8 @@
<None Include="Tokenizer.l"> <None Include="Tokenizer.l">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</None> </None>
<None Include="ExpressionParser.y">
<Filter>Source Files</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
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