Commit 1c809955 by John Kessenich

Add ability to treat keywords as identifiers in versions that had not yet reserved the keyword.

Used this for precision keywords and double matrix keywords. Also added a few missing reserved words. Also removed redundant "syntax error" when there is a parse error. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@20423 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent 59ddbafb
#version 120 #version 120
lowp vec3 a; float lowp;
mediump float b; float mediump;
highp int c; float highp;
precision highp float; float precision;
in vec4 i; in vec4 i;
out vec4 o; out vec4 o;
......
...@@ -6,11 +6,11 @@ int a = 0xffffffff; // 32 bits, a gets the value -1 ...@@ -6,11 +6,11 @@ int a = 0xffffffff; // 32 bits, a gets the value -1
//int b = 0xffffffffU; // ERROR: can't convert uint to int //int b = 0xffffffffU; // ERROR: can't convert uint to int
uint c = 0xffffffff; // 32 bits, c gets the value 0xFFFFFFFF uint c = 0xffffffff; // 32 bits, c gets the value 0xFFFFFFFF
//uint d = 0xffffffffU; // 32 bits, d gets the value 0xFFFFFFFF //uint d = 0xffffffffU; // 32 bits, d gets the value 0xFFFFFFFF
int e = -1; // the literal is “1”, then negation is performed, int e = -1; // the literal is "1", then negation is performed,
// and the resulting non-literal 32-bit signed // and the resulting non-literal 32-bit signed
// bit pattern of 0xFFFFFFFF is assigned, giving e // bit pattern of 0xFFFFFFFF is assigned, giving e
// the value of -1. // the value of -1.
//uint f = -1u; // the literal is “1u”, then negation is performed, //uint f = -1u; // the literal is "1u", then negation is performed,
// and the resulting non-literal 32-bit unsigned // and the resulting non-literal 32-bit unsigned
// bit pattern of 0xFFFFFFFF is assigned, giving f // bit pattern of 0xFFFFFFFF is assigned, giving f
// the value of 0xFFFFFFFF. // the value of 0xFFFFFFFF.
......
...@@ -69,6 +69,11 @@ LF [lL][fF] ...@@ -69,6 +69,11 @@ LF [lL][fF]
#include "ParseHelper.h" #include "ParseHelper.h"
#include "glslang_tab.cpp.h" #include "glslang_tab.cpp.h"
int PaIdentOrReserved(bool reserved, TParseContext&, int line, char* text, YYSTYPE* pyylval);
int PaPrecisionKeyword(TParseContext&, int line, char* text, YYSTYPE* pyylval, int keyword);
int PaMatNxM(TParseContext&, int line, char* text, YYSTYPE* pyylval, int keyword);
int PaDMat(TParseContext&, int line, char* text, YYSTYPE* pyylval, int keyword);
/* windows only pragma */ /* windows only pragma */
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(disable : 4102) #pragma warning(disable : 4102)
...@@ -101,19 +106,27 @@ TSourceLoc yylineno; ...@@ -101,19 +106,27 @@ TSourceLoc yylineno;
"attribute" { pyylval->lex.line = yylineno; return(ATTRIBUTE); } "attribute" { pyylval->lex.line = yylineno; return(ATTRIBUTE); }
"const" { pyylval->lex.line = yylineno; return(CONST); } "const" { pyylval->lex.line = yylineno; return(CONST); }
"patch" { pyylval->lex.line = yylineno; return(PATCH); }
"sample" { pyylval->lex.line = yylineno; return(SAMPLE); }
"uniform" { pyylval->lex.line = yylineno; return(UNIFORM); } "uniform" { pyylval->lex.line = yylineno; return(UNIFORM); }
"varying" { pyylval->lex.line = yylineno; return(VARYING); }
"buffer" { pyylval->lex.line = yylineno; return(BUFFER); } "buffer" { pyylval->lex.line = yylineno; return(BUFFER); }
"shared" { pyylval->lex.line = yylineno; return(SHARED); } "shared" { pyylval->lex.line = yylineno; return(SHARED); }
"coherent" { pyylval->lex.line = yylineno; return(COHERENT); } "coherent" { pyylval->lex.line = yylineno; return(COHERENT); }
"volatile" { pyylval->lex.line = yylineno; return(VOLATILE); } "volatile" { pyylval->lex.line = yylineno; return(VOLATILE); }
"restrict" { pyylval->lex.line = yylineno; return(RESTRICT); } "restrict" { pyylval->lex.line = yylineno; return(RESTRICT); }
"readonly" { pyylval->lex.line = yylineno; return(READONLY); } "readonly" { pyylval->lex.line = yylineno; return(READONLY); }
"writeonly" { pyylval->lex.line = yylineno; return(WRITEONLY); } "writeonly" { pyylval->lex.line = yylineno; return(WRITEONLY); }
"varying" { pyylval->lex.line = yylineno; return(VARYING); }
"layout" { pyylval->lex.line = yylineno; return(LAYOUT); } "layout" { pyylval->lex.line = yylineno; return(LAYOUT); }
"centroid" { pyylval->lex.line = yylineno; return(CENTROID); }
"flat" { pyylval->lex.line = yylineno; return(FLAT); }
"smooth" { pyylval->lex.line = yylineno; return(SMOOTH); }
"noperspective" { pyylval->lex.line = yylineno; return(NOPERSPECTIVE); }
"patch" { pyylval->lex.line = yylineno; return(PATCH); }
"sample" { pyylval->lex.line = yylineno; return(SAMPLE); }
"break" { pyylval->lex.line = yylineno; return(BREAK); } "break" { pyylval->lex.line = yylineno; return(BREAK); }
"continue" { pyylval->lex.line = yylineno; return(CONTINUE); } "continue" { pyylval->lex.line = yylineno; return(CONTINUE); }
"do" { pyylval->lex.line = yylineno; return(DO); } "do" { pyylval->lex.line = yylineno; return(DO); }
...@@ -126,21 +139,19 @@ TSourceLoc yylineno; ...@@ -126,21 +139,19 @@ TSourceLoc yylineno;
"if" { pyylval->lex.line = yylineno; return(IF); } "if" { pyylval->lex.line = yylineno; return(IF); }
"else" { pyylval->lex.line = yylineno; return(ELSE); } "else" { pyylval->lex.line = yylineno; return(ELSE); }
"subroutine" { pyylval->lex.line = yylineno; return(SUBROUTINE); }
"in" { pyylval->lex.line = yylineno; return(IN); } "in" { pyylval->lex.line = yylineno; return(IN); }
"out" { pyylval->lex.line = yylineno; return(OUT); } "out" { pyylval->lex.line = yylineno; return(OUT); }
"inout" { pyylval->lex.line = yylineno; return(INOUT); } "inout" { pyylval->lex.line = yylineno; return(INOUT); }
"centroid" { pyylval->lex.line = yylineno; return(CENTROID); }
"noperspective" { pyylval->lex.line = yylineno; return(NOPERSPECTIVE); }
"flat" { pyylval->lex.line = yylineno; return(FLAT); }
"smooth" { pyylval->lex.line = yylineno; return(SMOOTH); }
"precise" { pyylval->lex.line = yylineno; return(PRECISE); } "precise" { pyylval->lex.line = yylineno; return(PRECISE); }
"invariant" { pyylval->lex.line = yylineno; return(INVARIANT); } "invariant" { pyylval->lex.line = yylineno; return(INVARIANT); }
"precision" { pyylval->lex.line = yylineno; return(PRECISION); } "highp" { return PaPrecisionKeyword(parseContext, yylineno, yytext, pyylval, HIGH_PRECISION); }
"highp" { pyylval->lex.line = yylineno; return(HIGH_PRECISION); } "mediump" { return PaPrecisionKeyword(parseContext, yylineno, yytext, pyylval, MEDIUM_PRECISION); }
"mediump" { pyylval->lex.line = yylineno; return(MEDIUM_PRECISION); } "lowp" { return PaPrecisionKeyword(parseContext, yylineno, yytext, pyylval, LOW_PRECISION); }
"lowp" { pyylval->lex.line = yylineno; return(LOW_PRECISION); } "precision" { return PaPrecisionKeyword(parseContext, yylineno, yytext, pyylval, PRECISION); }
"float" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(FLOAT); } "float" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(FLOAT); }
"double" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DOUBLE); } "double" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DOUBLE); }
...@@ -153,34 +164,34 @@ TSourceLoc yylineno; ...@@ -153,34 +164,34 @@ TSourceLoc yylineno;
"discard" { pyylval->lex.line = yylineno; return(DISCARD); } "discard" { pyylval->lex.line = yylineno; return(DISCARD); }
"return" { pyylval->lex.line = yylineno; return(RETURN); } "return" { pyylval->lex.line = yylineno; return(RETURN); }
"subroutine" { pyylval->lex.line = yylineno; return(SUBROUTINE); }
"atomic_uint" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(ATOMIC_UINT); }
"mat2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT2); } "mat2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT2); }
"mat3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT3); } "mat3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT3); }
"mat4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT4); } "mat4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT4); }
"mat2x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT2X2); } "mat2x2" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT2X2); }
"mat2x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT2X3); } "mat2x3" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT2X3); }
"mat2x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT2X4); } "mat2x4" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT2X4); }
"mat3x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT3X2); } "mat3x2" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT3X2); }
"mat3x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT3X3); } "mat3x3" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT3X3); }
"mat3x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT3X4); } "mat3x4" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT3X4); }
"mat4x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT4X2); } "mat4x2" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT4X2); }
"mat4x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT4X3); } "mat4x3" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT4X3); }
"mat4x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(MAT4X4); } "mat4x4" { return PaMatNxM(parseContext, yylineno, yytext, pyylval, MAT4X4); }
"dmat2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT2); } "dmat2" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT2); }
"dmat3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT3); } "dmat3" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT3); }
"dmat4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT4); } "dmat4" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT4); }
"dmat2x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT2X2); } "dmat2x2" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT2X2); }
"dmat2x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT2X3); } "dmat2x3" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT2X3); }
"dmat2x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT2X4); } "dmat2x4" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT2X4); }
"dmat3x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT3X2); } "dmat3x2" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT3X2); }
"dmat3x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT3X3); } "dmat3x3" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT3X3); }
"dmat3x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT3X4); } "dmat3x4" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT3X4); }
"dmat4x2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT4X2); } "dmat4x2" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT4X2); }
"dmat4x3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT4X3); } "dmat4x3" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT4X3); }
"dmat4x4" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(DMAT4X4); } "dmat4x4" { return PaDMat(parseContext, yylineno, yytext, pyylval, DMAT4X4); }
"atomic_uint" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return(ATOMIC_UINT); }
"vec2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC2); } "vec2" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC2); }
"vec3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC3); } "vec3" { pyylval->lex.line = yylineno; parseContext.lexAfterType = true; return (VEC3); }
...@@ -283,6 +294,8 @@ TSourceLoc yylineno; ...@@ -283,6 +294,8 @@ TSourceLoc yylineno;
"this" { PaReservedWord(); return 0; } "this" { PaReservedWord(); return 0; }
"packed" { PaReservedWord(); return 0; } "packed" { PaReservedWord(); return 0; }
"resource" { PaReservedWord(); return 0; }
"goto" { PaReservedWord(); return 0; } "goto" { PaReservedWord(); return 0; }
"inline" { PaReservedWord(); return 0; } "inline" { PaReservedWord(); return 0; }
...@@ -299,6 +312,9 @@ TSourceLoc yylineno; ...@@ -299,6 +312,9 @@ TSourceLoc yylineno;
"fixed" { PaReservedWord(); return 0; } "fixed" { PaReservedWord(); return 0; }
"unsigned" { PaReservedWord(); return 0; } "unsigned" { PaReservedWord(); return 0; }
"superp" { bool reserved = (parseContext.profile == EEsProfile || parseContext.version >= 130);
return PaIdentOrReserved(reserved, parseContext, yylineno, yytext, pyylval); }
"input" { PaReservedWord(); return 0; } "input" { PaReservedWord(); return 0; }
"output" { PaReservedWord(); return 0; } "output" { PaReservedWord(); return 0; }
...@@ -311,6 +327,8 @@ TSourceLoc yylineno; ...@@ -311,6 +327,8 @@ TSourceLoc yylineno;
"sampler3DRect" { PaReservedWord(); return 0; } "sampler3DRect" { PaReservedWord(); return 0; }
"filter" { PaReservedWord(); return 0; }
"sizeof" { PaReservedWord(); return 0; } "sizeof" { PaReservedWord(); return 0; }
"cast" { PaReservedWord(); return 0; } "cast" { PaReservedWord(); return 0; }
...@@ -493,11 +511,11 @@ void yyerror(char *s) ...@@ -493,11 +511,11 @@ void yyerror(char *s)
if (parseContext.AfterEOF) { if (parseContext.AfterEOF) {
if (cpp->tokensBeforeEOF == 1) { if (cpp->tokensBeforeEOF == 1) {
GlobalParseContext->error(yylineno, "syntax error", "pre-mature EOF", s, ""); GlobalParseContext->error(yylineno, "", "pre-mature EOF", s, "");
GlobalParseContext->recover(); GlobalParseContext->recover();
} }
} else { } else {
GlobalParseContext->error(yylineno, "syntax error", yytext, s, ""); GlobalParseContext->error(yylineno, "", yytext, s, "");
GlobalParseContext->recover(); GlobalParseContext->recover();
} }
} }
...@@ -522,7 +540,56 @@ int PaIdentOrType(TString& id, TParseContext& parseContextLocal, TSymbol*& symbo ...@@ -522,7 +540,56 @@ int PaIdentOrType(TString& id, TParseContext& parseContextLocal, TSymbol*& symbo
return IDENTIFIER; return IDENTIFIER;
} }
int PaParseComment(int &lineno, TParseContext& parseContextLocal) int PaIdentOrReserved(bool reserved, TParseContext& parseContext, int line, char* text, YYSTYPE* pyylval)
{
if (reserved)
PaReservedWord();
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol);
}
int PaPrecisionKeyword(TParseContext& parseContext, int line, char* text, YYSTYPE* pyylval, int keyword)
{
if (parseContext.profile == EEsProfile || parseContext.version >= 130)
return keyword;
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol);
}
int PaMatNxM(TParseContext& parseContext, int line, char* text, YYSTYPE* pyylval, int keyword)
{
if (parseContext.version > 110)
return keyword;
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol);
}
int PaDMat(TParseContext& parseContext, int line, char* text, YYSTYPE* pyylval, int keyword)
{
if (parseContext.profile == EEsProfile && parseContext.version >= 300) {
PaReservedWord();
return 0;
}
if (parseContext.profile != EEsProfile && parseContext.version >= 400)
return keyword;
pyylval->lex.line = line;
pyylval->lex.string = NewPoolTString(text);
return PaIdentOrType(*pyylval->lex.string, parseContext, pyylval->lex.symbol);
}
int PaParseComment(int& lineno, TParseContext& parseContextLocal)
{ {
int transitionFlag = 0; int transitionFlag = 0;
int nextChar; int nextChar;
......
...@@ -73,6 +73,7 @@ Jutta Degener, 1995 ...@@ -73,6 +73,7 @@ Jutta Degener, 1995
#endif #endif
%} %}
%union { %union {
struct { struct {
TSourceLoc line; TSourceLoc line;
...@@ -1664,6 +1665,7 @@ storage_qualifier ...@@ -1664,6 +1665,7 @@ storage_qualifier
parseContext.checkDeprecated($1.line, ENoProfile, 140, "attribute"); parseContext.checkDeprecated($1.line, ENoProfile, 140, "attribute");
parseContext.requireNotRemoved($1.line, ECoreProfile, 420, "attribute"); parseContext.requireNotRemoved($1.line, ECoreProfile, 420, "attribute");
parseContext.requireNotRemoved($1.line, EEsProfile, 300, "attribute");
if (parseContext.globalErrorCheck($1.line, parseContext.symbolTable.atGlobalLevel(), "attribute")) if (parseContext.globalErrorCheck($1.line, parseContext.symbolTable.atGlobalLevel(), "attribute"))
parseContext.recover(); parseContext.recover();
...@@ -1674,6 +1676,7 @@ storage_qualifier ...@@ -1674,6 +1676,7 @@ storage_qualifier
| VARYING { | VARYING {
parseContext.checkDeprecated($1.line, ENoProfile, 140, "varying"); parseContext.checkDeprecated($1.line, ENoProfile, 140, "varying");
parseContext.requireNotRemoved($1.line, ECoreProfile, 420, "varying"); parseContext.requireNotRemoved($1.line, ECoreProfile, 420, "varying");
parseContext.requireNotRemoved($1.line, EEsProfile, 300, "varying");
if (parseContext.globalErrorCheck($1.line, parseContext.symbolTable.atGlobalLevel(), "varying")) if (parseContext.globalErrorCheck($1.line, parseContext.symbolTable.atGlobalLevel(), "varying"))
parseContext.recover(); parseContext.recover();
......
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