Commit 2c1239f5 by Nicolas Capens

Add support for unsigned integer literals in the shading language.

Bug 19331817 Change-Id: I5a4a3f7aba4f758a3e8b4b5ff7c09e26bc9b7430 Reviewed-on: https://swiftshader-review.googlesource.com/2314Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent e4b1b1d8
......@@ -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_identifier_ES3_keyword(TParseContext *context, int token);
static int uint_constant(TParseContext *context);
%}
%option noyywrap nounput never-interactive
......@@ -283,6 +284,9 @@ O [0-7]
0{O}+ { yylval->lex.i = strtol(yytext, 0, 0); return(INTCONSTANT); }
0{D}+ { context->error(yylineno, "Invalid Octal number.", yytext); context->recover(); return 0;}
{D}+ { yylval->lex.i = 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); }
......@@ -429,6 +433,22 @@ int ES2_identifier_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;
......
......@@ -54,6 +54,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;
......@@ -130,7 +131,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
......@@ -223,6 +224,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.
......@@ -98,53 +98,54 @@
TYPE_NAME = 314,
FLOATCONSTANT = 315,
INTCONSTANT = 316,
BOOLCONSTANT = 317,
FIELD_SELECTION = 318,
LEFT_OP = 319,
RIGHT_OP = 320,
INC_OP = 321,
DEC_OP = 322,
LE_OP = 323,
GE_OP = 324,
EQ_OP = 325,
NE_OP = 326,
AND_OP = 327,
OR_OP = 328,
XOR_OP = 329,
MUL_ASSIGN = 330,
DIV_ASSIGN = 331,
ADD_ASSIGN = 332,
MOD_ASSIGN = 333,
LEFT_ASSIGN = 334,
RIGHT_ASSIGN = 335,
AND_ASSIGN = 336,
XOR_ASSIGN = 337,
OR_ASSIGN = 338,
SUB_ASSIGN = 339,
LEFT_PAREN = 340,
RIGHT_PAREN = 341,
LEFT_BRACKET = 342,
RIGHT_BRACKET = 343,
LEFT_BRACE = 344,
RIGHT_BRACE = 345,
DOT = 346,
COMMA = 347,
COLON = 348,
EQUAL = 349,
SEMICOLON = 350,
BANG = 351,
DASH = 352,
TILDE = 353,
PLUS = 354,
STAR = 355,
SLASH = 356,
PERCENT = 357,
LEFT_ANGLE = 358,
RIGHT_ANGLE = 359,
VERTICAL_BAR = 360,
CARET = 361,
AMPERSAND = 362,
QUESTION = 363
UINTCONSTANT = 317,
BOOLCONSTANT = 318,
FIELD_SELECTION = 319,
LEFT_OP = 320,
RIGHT_OP = 321,
INC_OP = 322,
DEC_OP = 323,
LE_OP = 324,
GE_OP = 325,
EQ_OP = 326,
NE_OP = 327,
AND_OP = 328,
OR_OP = 329,
XOR_OP = 330,
MUL_ASSIGN = 331,
DIV_ASSIGN = 332,
ADD_ASSIGN = 333,
MOD_ASSIGN = 334,
LEFT_ASSIGN = 335,
RIGHT_ASSIGN = 336,
AND_ASSIGN = 337,
XOR_ASSIGN = 338,
OR_ASSIGN = 339,
SUB_ASSIGN = 340,
LEFT_PAREN = 341,
RIGHT_PAREN = 342,
LEFT_BRACKET = 343,
RIGHT_BRACKET = 344,
LEFT_BRACE = 345,
RIGHT_BRACE = 346,
DOT = 347,
COMMA = 348,
COLON = 349,
EQUAL = 350,
SEMICOLON = 351,
BANG = 352,
DASH = 353,
TILDE = 354,
PLUS = 355,
STAR = 356,
SLASH = 357,
PERCENT = 358,
LEFT_ANGLE = 359,
RIGHT_ANGLE = 360,
VERTICAL_BAR = 361,
CARET = 362,
AMPERSAND = 363,
QUESTION = 364
};
#endif
......@@ -161,6 +162,7 @@ typedef union YYSTYPE
TString *string;
float f;
int i;
unsigned int u;
bool b;
};
TSymbol* symbol;
......
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton implementation for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
Foundation, Inc.
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -45,7 +46,7 @@
#define YYBISON 1
/* Bison version. */
#define YYBISON_VERSION "2.4.2"
#define YYBISON_VERSION "2.4.1"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
......@@ -224,7 +225,7 @@ typedef short int yytype_int16;
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", msgid)
......@@ -624,18 +625,9 @@ static const yytype_uint8 yystos[] =
/* Like YYERROR except do call yyerror. This remains here temporarily
to ease the transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go. However,
YYFAIL appears to be in use. Nevertheless, it is formally deprecated
in Bison 2.4.2's NEWS entry, where a plan to phase it out is
discussed. */
Once GCC version 2 has supplanted version 1, this can go. */
#define YYFAIL goto yyerrlab
#if defined YYFAIL
/* This is here to suppress warnings from the GCC cpp's
-Wunused-macros. Normally we don't worry about that warning, but
some users do, and we want to make it easy for users to remove
YYFAIL uses, which will produce warnings from Bison 2.5. */
#endif
#define YYRECOVERING() (!!yyerrstatus)
......@@ -692,7 +684,7 @@ while (YYID (0))
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
# if YYLTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \
(Loc).first_line, (Loc).first_column, \
......
......@@ -78,9 +78,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}+
......
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