Commit 613ef31a by alokp@chromium.org

Added checks for webgl_ and _webgl_ reserved identifiers. This currently only…

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
parent bad6c2a4
......@@ -402,16 +402,29 @@ bool TParseContext::globalErrorCheck(int line, bool global, const char* token)
// 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;
......
......@@ -36,14 +36,15 @@ struct TPragma {
// 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;
......
......@@ -58,7 +58,9 @@ class TCompiler : public TShHandleBase {
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;
......
......@@ -170,7 +170,9 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, EShLanguage language
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 @@ int ShCompile(
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;
......
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