Commit 15ae36c4 by Alexis Hetu Committed by Alexis Hétu

Support for @ in the parser

Added support for @ in the parser and replaced all instances of $N.line by @N. Change-Id: I7a18278ee0cd5deb90609508abbda2af656daaa4 Reviewed-on: https://swiftshader-review.googlesource.com/3526Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 70415e40
...@@ -484,9 +484,9 @@ struct TPublicType ...@@ -484,9 +484,9 @@ struct TPublicType
bool array; bool array;
int arraySize; int arraySize;
TType* userDef; TType* userDef;
int line; TSourceLoc line;
void setBasic(TBasicType bt, TQualifier q, int ln = 0) void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln)
{ {
type = bt; type = bt;
layoutQualifier = TLayoutQualifier::create(); layoutQualifier = TLayoutQualifier::create();
......
...@@ -8,7 +8,7 @@ struct TParseContext; ...@@ -8,7 +8,7 @@ struct TParseContext;
extern int glslang_initialize(TParseContext* context); extern int glslang_initialize(TParseContext* context);
extern int glslang_finalize(TParseContext* context); extern int glslang_finalize(TParseContext* context);
extern int glslang_scan(int count, extern int glslang_scan(size_t count,
const char* const string[], const char* const string[],
const int length[], const int length[],
TParseContext* context); TParseContext* context);
......
...@@ -51,7 +51,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -51,7 +51,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#define YY_INPUT(buf, result, max_size) \ #define YY_INPUT(buf, result, max_size) \
result = string_input(buf, max_size, yyscanner); result = string_input(buf, max_size, yyscanner);
static int string_input(char* buf, int max_size, yyscan_t yyscanner); 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 check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner); 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);
...@@ -64,7 +64,7 @@ static int floatsuffix_check(TParseContext* context); ...@@ -64,7 +64,7 @@ static int floatsuffix_check(TParseContext* context);
%} %}
%option noyywrap nounput never-interactive %option noyywrap nounput never-interactive
%option yylineno reentrant bison-bridge %option yylineno reentrant bison-bridge bison-locations
%option stack %option stack
%option extra-type="TParseContext*" %option extra-type="TParseContext*"
%x COMMENT FIELDS %x COMMENT FIELDS
...@@ -389,18 +389,15 @@ O [0-7] ...@@ -389,18 +389,15 @@ O [0-7]
[ \t\v\n\f\r] { } [ \t\v\n\f\r] { }
<*><<EOF>> { context->AfterEOF = true; yyterminate(); } <*><<EOF>> { context->AfterEOF = true; yyterminate(); }
<*>. { context->warning(yylineno, "Unknown char", yytext, ""); return 0; } <*>. { context->warning(*yylloc, "Unknown char", yytext, ""); return 0; }
%% %%
int string_input(char* buf, int max_size, yyscan_t yyscanner) yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
{
int len = 0;
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->preprocessor.lex(&token);
len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if ((len > 0) && (len < max_size)) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner); yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line), yyscanner);
...@@ -430,7 +427,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -430,7 +427,7 @@ int check_type(yyscan_t yyscanner) {
int reserved_word(yyscan_t yyscanner) { int reserved_word(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
yyextra->error(yylineno, "Illegal use of reserved word", yytext, ""); yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
yyextra->recover(); yyextra->recover();
return 0; return 0;
} }
...@@ -481,13 +478,13 @@ int uint_constant(TParseContext *context) ...@@ -481,13 +478,13 @@ int uint_constant(TParseContext *context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
return 0; return 0;
} }
if (!atoi_clamp(yytext, &(yylval->lex.i))) if (!atoi_clamp(yytext, &(yylval->lex.i)))
yyextra->warning(yylineno, "Integer overflow", yytext, ""); yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return UINTCONSTANT; return UINTCONSTANT;
} }
...@@ -498,13 +495,13 @@ int floatsuffix_check(TParseContext* context) ...@@ -498,13 +495,13 @@ int floatsuffix_check(TParseContext* context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
return 0; return 0;
} }
if (!atof_clamp(yytext, &(yylval->lex.f))) if (!atof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(yylineno, "Float overflow", yytext, ""); yyextra->warning(*yylloc, "Float overflow", yytext, "");
return(FLOATCONSTANT); return(FLOATCONSTANT);
} }
...@@ -513,7 +510,7 @@ int int_constant(yyscan_t yyscanner) { ...@@ -513,7 +510,7 @@ int int_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atoi_clamp(yytext, &(yylval->lex.i))) if (!atoi_clamp(yytext, &(yylval->lex.i)))
yyextra->warning(yylineno, "Integer overflow", yytext, ""); yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return INTCONSTANT; return INTCONSTANT;
} }
...@@ -521,17 +518,17 @@ int float_constant(yyscan_t yyscanner) { ...@@ -521,17 +518,17 @@ int float_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atof_clamp(yytext, &(yylval->lex.f))) if (!atof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(yylineno, "Float overflow", yytext, ""); yyextra->warning(*yylloc, "Float overflow", yytext, "");
return FLOATCONSTANT; return FLOATCONSTANT;
} }
void yyerror(TParseContext* context, const char* reason) { void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
if (context->AfterEOF) { if (context->AfterEOF) {
context->error(yylineno, reason, "unexpected EOF"); context->error(*lloc, reason, "unexpected EOF");
} else { } else {
context->error(yylineno, reason, yytext); context->error(*lloc, reason, yytext);
} }
context->recover(); context->recover();
} }
...@@ -555,7 +552,7 @@ int glslang_finalize(TParseContext* context) { ...@@ -555,7 +552,7 @@ int glslang_finalize(TParseContext* context) {
return 0; return 0;
} }
int glslang_scan(int count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL, context->scanner); yyrestart(NULL, context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1), context->scanner); yyset_lineno(EncodeSourceLoc(0, 1), context->scanner);
......
...@@ -1038,7 +1038,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp). ...@@ -1038,7 +1038,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#define YY_INPUT(buf, result, max_size) \ #define YY_INPUT(buf, result, max_size) \
result = string_input(buf, max_size, yyscanner); result = string_input(buf, max_size, yyscanner);
static int string_input(char* buf, int max_size, yyscan_t yyscanner); 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 check_type(yyscan_t yyscanner);
static int reserved_word(yyscan_t yyscanner); 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);
...@@ -1089,6 +1089,8 @@ struct yyguts_t ...@@ -1089,6 +1089,8 @@ struct yyguts_t
YYSTYPE * yylval_r; YYSTYPE * yylval_r;
YYLTYPE * yylloc_r;
}; /* end struct yyguts_t */ }; /* end struct yyguts_t */
static int yy_init_globals (yyscan_t yyscanner ); static int yy_init_globals (yyscan_t yyscanner );
...@@ -1097,6 +1099,8 @@ static int yy_init_globals (yyscan_t yyscanner ); ...@@ -1097,6 +1099,8 @@ static int yy_init_globals (yyscan_t yyscanner );
* from bison output in section 1.*/ * from bison output in section 1.*/
# define yylval yyg->yylval_r # define yylval yyg->yylval_r
# define yylloc yyg->yylloc_r
int yylex_init (yyscan_t* scanner); int yylex_init (yyscan_t* scanner);
int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
...@@ -1134,6 +1138,10 @@ YYSTYPE * yyget_lval (yyscan_t yyscanner ); ...@@ -1134,6 +1138,10 @@ YYSTYPE * yyget_lval (yyscan_t yyscanner );
void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
YYLTYPE *yyget_lloc (yyscan_t yyscanner );
void yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
*/ */
...@@ -1251,10 +1259,10 @@ static int input (yyscan_t yyscanner ); ...@@ -1251,10 +1259,10 @@ static int input (yyscan_t yyscanner );
#define YY_DECL_IS_OURS 1 #define YY_DECL_IS_OURS 1
extern int yylex \ extern int yylex \
(YYSTYPE * yylval_param ,yyscan_t yyscanner); (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
#define YY_DECL int yylex \ #define YY_DECL int yylex \
(YYSTYPE * yylval_param , yyscan_t yyscanner) (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
#endif /* !YY_DECL */ #endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng /* Code executed at the beginning of each rule, after yytext and yyleng
...@@ -1287,6 +1295,8 @@ YY_DECL ...@@ -1287,6 +1295,8 @@ YY_DECL
yylval = yylval_param; yylval = yylval_param;
yylloc = yylloc_param;
if ( !yyg->yy_init ) if ( !yyg->yy_init )
{ {
yyg->yy_init = 1; yyg->yy_init = 1;
...@@ -2087,7 +2097,7 @@ case YY_STATE_EOF(FIELDS): ...@@ -2087,7 +2097,7 @@ case YY_STATE_EOF(FIELDS):
YY_BREAK YY_BREAK
case 243: case 243:
YY_RULE_SETUP YY_RULE_SETUP
{ context->warning(yylineno, "Unknown char", yytext, ""); return 0; } { context->warning(*yylloc, "Unknown char", yytext, ""); return 0; }
YY_BREAK YY_BREAK
case 244: case 244:
YY_RULE_SETUP YY_RULE_SETUP
...@@ -3088,6 +3098,18 @@ void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) ...@@ -3088,6 +3098,18 @@ void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
yylval = yylval_param; yylval = yylval_param;
} }
YYLTYPE *yyget_lloc (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yylloc;
}
void yyset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yylloc = yylloc_param;
}
/* User-visible API */ /* User-visible API */
/* yylex_init is special because it creates the scanner itself, so it is /* yylex_init is special because it creates the scanner itself, so it is
...@@ -3263,14 +3285,11 @@ void yyfree (void * ptr , yyscan_t yyscanner) ...@@ -3263,14 +3285,11 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #define YYTABLES_NAME "yytables"
int string_input(char* buf, int max_size, yyscan_t yyscanner) yy_size_t string_input(char* buf, yy_size_t max_size, yyscan_t yyscanner) {
{
int len = 0;
pp::Token token; pp::Token token;
yyget_extra(yyscanner)->preprocessor.lex(&token); yyget_extra(yyscanner)->preprocessor.lex(&token);
len = token.type == pp::Token::LAST ? 0 : token.text.size(); yy_size_t len = token.type == pp::Token::LAST ? 0 : token.text.size();
if ((len > 0) && (len < max_size)) if (len < max_size)
memcpy(buf, token.text.c_str(), len); memcpy(buf, token.text.c_str(), len);
yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line),yyscanner); yyset_lineno(EncodeSourceLoc(token.location.file, token.location.line),yyscanner);
...@@ -3300,7 +3319,7 @@ int check_type(yyscan_t yyscanner) { ...@@ -3300,7 +3319,7 @@ int check_type(yyscan_t yyscanner) {
int reserved_word(yyscan_t yyscanner) { int reserved_word(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
yyextra->error(yylineno, "Illegal use of reserved word", yytext, ""); yyextra->error(*yylloc, "Illegal use of reserved word", yytext, "");
yyextra->recover(); yyextra->recover();
return 0; return 0;
} }
...@@ -3351,13 +3370,13 @@ int uint_constant(TParseContext *context) ...@@ -3351,13 +3370,13 @@ int uint_constant(TParseContext *context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, ""); context->error(*yylloc, "Unsigned integers are unsupported prior to GLSL ES 3.00", yytext, "");
context->recover(); context->recover();
return 0; return 0;
} }
if (!atoi_clamp(yytext, &(yylval->lex.i))) if (!atoi_clamp(yytext, &(yylval->lex.i)))
yyextra->warning(yylineno, "Integer overflow", yytext, ""); yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return UINTCONSTANT; return UINTCONSTANT;
} }
...@@ -3368,13 +3387,13 @@ int floatsuffix_check(TParseContext* context) ...@@ -3368,13 +3387,13 @@ int floatsuffix_check(TParseContext* context)
if (context->shaderVersion < 300) if (context->shaderVersion < 300)
{ {
context->error(yylineno, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext); context->error(*yylloc, "Floating-point suffix unsupported prior to GLSL ES 3.00", yytext);
context->recover(); context->recover();
return 0; return 0;
} }
if (!atof_clamp(yytext, &(yylval->lex.f))) if (!atof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(yylineno, "Float overflow", yytext, ""); yyextra->warning(*yylloc, "Float overflow", yytext, "");
return(FLOATCONSTANT); return(FLOATCONSTANT);
} }
...@@ -3383,7 +3402,7 @@ int int_constant(yyscan_t yyscanner) { ...@@ -3383,7 +3402,7 @@ int int_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atoi_clamp(yytext, &(yylval->lex.i))) if (!atoi_clamp(yytext, &(yylval->lex.i)))
yyextra->warning(yylineno, "Integer overflow", yytext, ""); yyextra->warning(*yylloc, "Integer overflow", yytext, "");
return INTCONSTANT; return INTCONSTANT;
} }
...@@ -3391,17 +3410,17 @@ int float_constant(yyscan_t yyscanner) { ...@@ -3391,17 +3410,17 @@ int float_constant(yyscan_t yyscanner) {
struct yyguts_t* yyg = (struct yyguts_t*) yyscanner; struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
if (!atof_clamp(yytext, &(yylval->lex.f))) if (!atof_clamp(yytext, &(yylval->lex.f)))
yyextra->warning(yylineno, "Float overflow", yytext, ""); yyextra->warning(*yylloc, "Float overflow", yytext, "");
return FLOATCONSTANT; return FLOATCONSTANT;
} }
void yyerror(TParseContext* context, const char* reason) { void yyerror(YYLTYPE* lloc, TParseContext* context, const char* reason) {
struct yyguts_t* yyg = (struct yyguts_t*) context->scanner; struct yyguts_t* yyg = (struct yyguts_t*) context->scanner;
if (context->AfterEOF) { if (context->AfterEOF) {
context->error(yylineno, reason, "unexpected EOF"); context->error(*lloc, reason, "unexpected EOF");
} else { } else {
context->error(yylineno, reason, yytext); context->error(*lloc, reason, yytext);
} }
context->recover(); context->recover();
} }
...@@ -3425,7 +3444,7 @@ int glslang_finalize(TParseContext* context) { ...@@ -3425,7 +3444,7 @@ int glslang_finalize(TParseContext* context) {
return 0; return 0;
} }
int glslang_scan(int count, const char* const string[], const int length[], int glslang_scan(size_t count, const char* const string[], const int length[],
TParseContext* context) { TParseContext* context) {
yyrestart(NULL,context->scanner); yyrestart(NULL,context->scanner);
yyset_lineno(EncodeSourceLoc(0, 1),context->scanner); yyset_lineno(EncodeSourceLoc(0, 1),context->scanner);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -32,6 +32,14 @@ ...@@ -32,6 +32,14 @@
This special exception was added by the Free Software Foundation in This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */ version 2.2 of Bison. */
/* "%code requires" blocks. */
#define YYLTYPE TSourceLoc
#define YYLTYPE_IS_DECLARED 1
/* Tokens. */ /* Tokens. */
#ifndef YYTOKENTYPE #ifndef YYTOKENTYPE
...@@ -218,4 +226,18 @@ typedef union YYSTYPE ...@@ -218,4 +226,18 @@ typedef union YYSTYPE
#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
typedef struct YYLTYPE
{
int first_line;
int first_column;
int last_line;
int last_column;
} YYLTYPE;
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
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