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);
static int ES2_reserved_ES3_keyword(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 uint_constant(TParseContext *context);
%}
%option noyywrap nounput never-interactive
......@@ -294,6 +295,9 @@ O [0-7]
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); }
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}+"."{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)
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) {
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).
TString *string;
float f;
int i;
unsigned int u;
bool b;
};
TSymbol* symbol;
......@@ -132,7 +133,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT
%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> LEFT_OP RIGHT_OP
%token <lex> INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP
......@@ -227,6 +228,11 @@ primary_expression
unionArray->setIConst($1.i);
$$ = 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 {
ConstantUnion *unionArray = new ConstantUnion[1];
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;
TYPE_NAME = 320,
FLOATCONSTANT = 321,
INTCONSTANT = 322,
BOOLCONSTANT = 323,
FIELD_SELECTION = 324,
LEFT_OP = 325,
RIGHT_OP = 326,
INC_OP = 327,
DEC_OP = 328,
LE_OP = 329,
GE_OP = 330,
EQ_OP = 331,
NE_OP = 332,
AND_OP = 333,
OR_OP = 334,
XOR_OP = 335,
MUL_ASSIGN = 336,
DIV_ASSIGN = 337,
ADD_ASSIGN = 338,
MOD_ASSIGN = 339,
LEFT_ASSIGN = 340,
RIGHT_ASSIGN = 341,
AND_ASSIGN = 342,
XOR_ASSIGN = 343,
OR_ASSIGN = 344,
SUB_ASSIGN = 345,
LEFT_PAREN = 346,
RIGHT_PAREN = 347,
LEFT_BRACKET = 348,
RIGHT_BRACKET = 349,
LEFT_BRACE = 350,
RIGHT_BRACE = 351,
DOT = 352,
COMMA = 353,
COLON = 354,
EQUAL = 355,
SEMICOLON = 356,
BANG = 357,
DASH = 358,
TILDE = 359,
PLUS = 360,
STAR = 361,
SLASH = 362,
PERCENT = 363,
LEFT_ANGLE = 364,
RIGHT_ANGLE = 365,
VERTICAL_BAR = 366,
CARET = 367,
AMPERSAND = 368,
QUESTION = 369
UINTCONSTANT = 323,
BOOLCONSTANT = 324,
FIELD_SELECTION = 325,
LEFT_OP = 326,
RIGHT_OP = 327,
INC_OP = 328,
DEC_OP = 329,
LE_OP = 330,
GE_OP = 331,
EQ_OP = 332,
NE_OP = 333,
AND_OP = 334,
OR_OP = 335,
XOR_OP = 336,
MUL_ASSIGN = 337,
DIV_ASSIGN = 338,
ADD_ASSIGN = 339,
MOD_ASSIGN = 340,
LEFT_ASSIGN = 341,
RIGHT_ASSIGN = 342,
AND_ASSIGN = 343,
XOR_ASSIGN = 344,
OR_ASSIGN = 345,
SUB_ASSIGN = 346,
LEFT_PAREN = 347,
RIGHT_PAREN = 348,
LEFT_BRACKET = 349,
RIGHT_BRACKET = 350,
LEFT_BRACE = 351,
RIGHT_BRACE = 352,
DOT = 353,
COMMA = 354,
COLON = 355,
EQUAL = 356,
SEMICOLON = 357,
BANG = 358,
DASH = 359,
TILDE = 360,
PLUS = 361,
STAR = 362,
SLASH = 363,
PERCENT = 364,
LEFT_ANGLE = 365,
RIGHT_ANGLE = 366,
VERTICAL_BAR = 367,
CARET = 368,
AMPERSAND = 369,
QUESTION = 370
};
#endif
......@@ -173,6 +174,7 @@ typedef union YYSTYPE
TString *string;
float f;
int i;
unsigned int u;
bool b;
};
TSymbol* symbol;
......
......@@ -79,9 +79,9 @@ NEWLINE \n|\r|\r\n
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
PUNCTUATOR [][<>(){}.+-/*%^|&~=!:;,?]
DECIMAL_CONSTANT [1-9][0-9]*
OCTAL_CONSTANT 0[0-7]*
HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+
DECIMAL_CONSTANT [1-9][0-9]*[uU]?
OCTAL_CONSTANT 0[0-7]*[uU]?
HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+[uU]?
DIGIT [0-9]
EXPONENT_PART [eE][+-]?{DIGIT}+
......
......@@ -164,6 +164,7 @@
<ClInclude Include="Tokenizer.h" />
</ItemGroup>
<ItemGroup>
<None Include="ExpressionParser.y" />
<None Include="Tokenizer.l" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
......
......@@ -96,5 +96,8 @@
<None Include="Tokenizer.l">
<Filter>Source Files</Filter>
</None>
<None Include="ExpressionParser.y">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</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