Added checks for webgl_ and _webgl_ reserved identifiers. This currently only checks variable and function names. Struct names and field names will be added in the another CL.
BUG=11
Review URL: http://codereview.appspot.com/1674050
git-svn-id: https://angleproject.googlecode.com/svn/trunk@346 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/ParseHelper.cpp b/src/compiler/ParseHelper.cpp
index 7211a2a..58f9f07 100644
--- a/src/compiler/ParseHelper.cpp
+++ b/src/compiler/ParseHelper.cpp
@@ -402,16 +402,29 @@
// For now, keep it simple: if it starts "gl_", it's reserved, independent
// of scope. Except, if the symbol table is at the built-in push-level,
// which is when we are parsing built-ins.
+// Also checks for "webgl_" and "_webgl_" reserved identifiers if parsing a
+// webgl shader.
//
// Returns true if there was an error.
//
bool TParseContext::reservedErrorCheck(int line, const TString& identifier)
{
+ static const char* reservedErrMsg = "reserved built-in name";
if (!symbolTable.atBuiltInLevel()) {
if (identifier.substr(0, 3) == TString("gl_")) {
- error(line, "reserved built-in name", "gl_", "");
+ error(line, reservedErrMsg, "gl_", "");
return true;
}
+ if (spec == EShSpecWebGL) {
+ if (identifier.substr(0, 6) == TString("webgl_")) {
+ error(line, reservedErrMsg, "webgl_", "");
+ return true;
+ }
+ if (identifier.substr(0, 7) == TString("_webgl_")) {
+ error(line, reservedErrMsg, "_webgl_", "");
+ return true;
+ }
+ }
if (identifier.find("__") != TString::npos) {
//error(line, "Two consecutive underscores are reserved for future use.", identifier.c_str(), "", "");
//return true;
diff --git a/src/compiler/ParseHelper.h b/src/compiler/ParseHelper.h
index 718ff32..8fb6214 100644
--- a/src/compiler/ParseHelper.h
+++ b/src/compiler/ParseHelper.h
@@ -36,14 +36,15 @@
// they can be passed to the parser without needing a global.
//
struct TParseContext {
- TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage L, TInfoSink& is) :
- intermediate(interm), symbolTable(symt), infoSink(is), language(L), treeRoot(0),
+ TParseContext(TSymbolTable& symt, TIntermediate& interm, EShLanguage l, EShSpec s, TInfoSink& is) :
+ intermediate(interm), symbolTable(symt), infoSink(is), language(l), spec(s), treeRoot(0),
recoveredFromError(false), numErrors(0), lexAfterType(false), loopNestingLevel(0),
inTypeParen(false), contextPragma(true, false) { }
TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
TInfoSink& infoSink;
EShLanguage language; // vertex or fragment language (future: pack or unpack)
+ EShSpec spec; // The language specification compiler conforms to - GLES2 or WebGL.
TIntermNode* treeRoot; // root of parse tree being created
bool recoveredFromError; // true if a parse error has occurred, but we continue to parse
int numErrors;
diff --git a/src/compiler/ShHandle.h b/src/compiler/ShHandle.h
index b0dccc4..51640b5 100644
--- a/src/compiler/ShHandle.h
+++ b/src/compiler/ShHandle.h
@@ -58,7 +58,9 @@
public:
TCompiler(EShLanguage l, EShSpec s) : language(l), spec(s), haveValidObjectCode(false) { }
virtual ~TCompiler() { }
+
EShLanguage getLanguage() { return language; }
+ EShSpec getSpec() { return spec; }
virtual TInfoSink& getInfoSink() { return infoSink; }
virtual bool compile(TIntermNode* root) = 0;
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index d12ea4b..5818043 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -170,7 +170,9 @@
else
symbolTable = &symbolTables[language];
- TParseContext parseContext(*symbolTable, intermediate, language, infoSink);
+ // TODO(alokp): Investigate if a parse-context is necessary here and
+ // if symbol-table can be shared between GLES2 and WebGL specs.
+ TParseContext parseContext(*symbolTable, intermediate, language, EShSpecGLES2, infoSink);
GlobalParseContext = &parseContext;
@@ -263,7 +265,7 @@
GenerateBuiltInSymbolTable(resources, infoSink, &symbolTable, compiler->getLanguage());
- TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), infoSink);
+ TParseContext parseContext(symbolTable, intermediate, compiler->getLanguage(), compiler->getSpec(), infoSink);
parseContext.initializeExtensionBehavior();
GlobalParseContext = &parseContext;