Add a getNamedVariable helper method to TParseContext.
This method will be useful in more than one place, since we need
to get a TType from an indentifier when parsing invariant
declarations.
BUG=angle:711
Change-Id: I1c1befbdcc93ea626428fb4e313b8c6326c158f6
Reviewed-on: https://chromium-review.googlesource.com/212937
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 605612a..5eceb14 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -1018,6 +1018,45 @@
//
/////////////////////////////////////////////////////////////////////////////////
+const TVariable *TParseContext::getNamedVariable(const TSourceLoc &location,
+ const TString *name,
+ const TSymbol *symbol)
+{
+ const TVariable *variable = NULL;
+
+ if (!symbol)
+ {
+ error(location, "undeclared identifier", name->c_str());
+ recover();
+ }
+ else if (!symbol->isVariable())
+ {
+ error(location, "variable expected", name->c_str());
+ recover();
+ }
+ else
+ {
+ variable = static_cast<const TVariable*>(symbol);
+
+ if (symbolTable.findBuiltIn(variable->getName(), shaderVersion) &&
+ !variable->getExtension().empty() &&
+ extensionErrorCheck(location, variable->getExtension()))
+ {
+ recover();
+ }
+ }
+
+ if (!variable)
+ {
+ TType type(EbtFloat, EbpUndefined);
+ TVariable *fakeVariable = new TVariable(name, type);
+ symbolTable.declare(fakeVariable);
+ variable = fakeVariable;
+ }
+
+ return variable;
+}
+
//
// Look up a function name in the symbol table, and make sure it is a function.
//