OSDN Git Service

Pass the shader version to the symbol table.
authorNicolas Capens <capn@google.com>
Wed, 18 Feb 2015 19:47:31 +0000 (14:47 -0500)
committerNicolas Capens <capn@google.com>
Mon, 23 Feb 2015 22:56:10 +0000 (22:56 +0000)
This refactoring prepares for version-specific builtin symbol lookups.

Bug 19331817

Change-Id: I65b46a2b35872802a249a45b2f97a1d3c1e35dfe
Reviewed-on: https://swiftshader-review.googlesource.com/2330
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/OpenGL/compiler/ParseHelper.cpp
src/OpenGL/compiler/SymbolTable.h
src/OpenGL/compiler/ValidateLimitations.cpp
src/OpenGL/compiler/glslang.l
src/OpenGL/compiler/glslang.y
src/OpenGL/compiler/glslang_lex.cpp
src/OpenGL/compiler/glslang_tab.cpp
src/OpenGL/libGLESv2/libGLESv2.cpp

index d9e9dfd..0b14803 100644 (file)
@@ -741,7 +741,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
 
     bool builtIn = false;
     bool sameScope = false;
-    TSymbol* symbol = symbolTable.find(identifier, &builtIn, &sameScope);
+    TSymbol* symbol = symbolTable.find(identifier, shaderVersion, &builtIn, &sameScope);
     if (symbol == 0 || !sameScope) {
         if (reservedErrorCheck(line, identifier))
             return true;
@@ -800,7 +800,7 @@ bool TParseContext::arrayErrorCheck(int line, TString& identifier, TPublicType t
 bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size, bool updateFlag, TSourceLoc line)
 {
     bool builtIn = false;
-    TSymbol* symbol = symbolTable.find(node->getSymbol(), &builtIn);
+    TSymbol* symbol = symbolTable.find(node->getSymbol(), shaderVersion, &builtIn);
     if (symbol == 0) {
         error(line, " undeclared identifier", node->getSymbol().c_str());
         return true;
@@ -813,7 +813,7 @@ bool TParseContext::arraySetMaxSize(TIntermSymbol *node, TType* type, int size,
     // special casing to test index value of gl_FragData. If the accessed index is >= gl_MaxDrawBuffers
     // its an error
     if (node->getSymbol() == "gl_FragData") {
-        TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", &builtIn);
+        TSymbol* fragData = symbolTable.find("gl_MaxDrawBuffers", shaderVersion, &builtIn);
         ASSERT(fragData);
 
         int fragDataValue = static_cast<TVariable*>(fragData)->getConstPointer()[0].getIConst();
@@ -974,9 +974,9 @@ const TFunction* TParseContext::findFunction(int line, TFunction* call, bool *bu
 {
     // First find by unmangled name to check whether the function name has been
     // hidden by a variable name or struct typename.
-    const TSymbol* symbol = symbolTable.find(call->getName(), builtIn);
+    const TSymbol* symbol = symbolTable.find(call->getName(), shaderVersion, builtIn);
     if (symbol == 0) {
-        symbol = symbolTable.find(call->getMangledName(), builtIn);
+        symbol = symbolTable.find(call->getMangledName(), shaderVersion, builtIn);
     }
 
     if (symbol == 0) {
@@ -1056,7 +1056,7 @@ bool TParseContext::executeInitializer(TSourceLoc line, TString& identifier, TPu
                 variable->shareConstPointer(initializer->getAsConstantUnion()->getUnionArrayPointer());
             }
         } else if (initializer->getAsSymbolNode()) {
-            const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol());
+            const TSymbol* symbol = symbolTable.find(initializer->getAsSymbolNode()->getSymbol(), shaderVersion);
             const TVariable* tVar = static_cast<const TVariable*>(symbol);
 
             ConstantUnion* constArray = tVar->getConstPointer();
index c2eb677..1abdd7a 100644 (file)
@@ -38,7 +38,8 @@
 //
 // Symbol base class.  (Can build functions or variables out of these...)
 //
-class TSymbol {    
+class TSymbol
+{
 public:
     POOL_ALLOCATOR_NEW_DELETE();
     TSymbol(const TString *n) :  name(n) { }
@@ -67,7 +68,8 @@ protected:
 // different values for different types polymorphically, so this is 
 // just simple and pragmatic.
 //
-class TVariable : public TSymbol {
+class TVariable : public TSymbol
+{
 public:
     TVariable(const TString *name, const TType& t, bool uT = false ) : TSymbol(name), type(t), userType(uT), unionArray(0), arrayInformationType(0) { }
     virtual ~TVariable() { }
@@ -111,7 +113,8 @@ protected:
 // The function sub-class of symbols and the parser will need to
 // share this definition of a function parameter.
 //
-struct TParameter {
+struct TParameter
+{
     TString *name;
     TType *type;
 };
@@ -119,7 +122,8 @@ struct TParameter {
 //
 // The function sub-class of a symbol.  
 //
-class TFunction : public TSymbol {
+class TFunction : public TSymbol
+{
 public:
     TFunction(TOperator o) :
         TSymbol(0),
@@ -142,7 +146,7 @@ public:
     }
 
     void addParameter(TParameter& p) 
-    { 
+    {
         parameters.push_back(p);
         mangledName = mangledName + p.type->getMangledName();
     }
@@ -173,7 +177,8 @@ protected:
 };
 
 
-class TSymbolTableLevel {
+class TSymbolTableLevel
+{
 public:
     typedef TMap<TString, TSymbol*> tLevel;
     typedef tLevel::const_iterator const_iterator;
@@ -214,7 +219,8 @@ protected:
        static int uniqueId;     // for unique identification in code generation
 };
 
-class TSymbolTable {
+class TSymbolTable
+{
 public:
     TSymbolTable()
     {
@@ -247,13 +253,13 @@ public:
     }
 
     void pop()
-    { 
-        delete table[currentLevel()]; 
-        table.pop_back(); 
+    {
+        delete table[currentLevel()];
+        table.pop_back();
         precisionStack.pop_back();
     }
 
-    bool insert(TSymbolsymbol)
+    bool insert(TSymbol &symbol)
     {
         return table[currentLevel()]->insert(symbol);
     }
@@ -287,7 +293,7 @@ public:
                return insert(*function);
        }
 
-    TSymbol* find(const TString& name, bool* builtIn = 0, bool *sameScope = 0) 
+    TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false) const
     {
         int level = currentLevel();
         TSymbol* symbol;
@@ -303,29 +309,35 @@ public:
         return symbol;
     }
 
-    TSymbol *findBuiltIn(const TString &name)
+    TSymbol *findBuiltIn(const TString &name, int shaderVersion) const
     {
         return table[0]->find(name);
     }
 
-    TSymbolTableLevel* getGlobalLevel() {
+    TSymbolTableLevel *getGlobalLevel() const
+    {
         assert(table.size() >= 2);
         return table[1];
     }
 
-    TSymbolTableLevel* getOuterLevel() {
+    TSymbolTableLevel *getOuterLevel() const
+    {
         assert(table.size() >= 2);
         return table[currentLevel() - 1];
     }
 
-    void relateToOperator(const char* name, TOperator op) {
+    void relateToOperator(const char* name, TOperator op)
+    {
         table[0]->relateToOperator(name, op);
     }
-    void relateToExtension(const char* name, const TString& ext) {
+
+    void relateToExtension(const char* name, const TString& ext)
+    {
         table[0]->relateToExtension(name, ext);
     }
 
-    bool setDefaultPrecision( const TPublicType& type, TPrecision prec ){
+    bool setDefaultPrecision(const TPublicType &type, TPrecision prec)
+    {
         if (IsSampler(type.type))
             return true;  // Skip sampler types for the time being
         if (type.type != EbtFloat && type.type != EbtInt)
@@ -359,8 +371,8 @@ public:
         return prec;
     }
 
-protected:    
-    int currentLevel() const { return static_cast<int>(table.size()) - 1; }
+protected:
+    int currentLevel() const { return static_cast<int>(table.size() - 1); }
 
     std::vector<TSymbolTableLevel*> table;
     typedef std::map< TBasicType, TPrecision > PrecisionStackLevel;
index 701abc5..54de034 100644 (file)
@@ -440,7 +440,7 @@ bool ValidateLimitations::validateFunctionCall(TIntermAggregate* node)
 
     bool valid = true;
     TSymbolTable& symbolTable = GetGlobalParseContext()->symbolTable;
-    TSymbol* symbol = symbolTable.find(node->getName());
+    TSymbol* symbol = symbolTable.find(node->getName(), GetGlobalParseContext()->shaderVersion);
     ASSERT(symbol && symbol->isFunction());
     TFunction* function = static_cast<TFunction*>(symbol);
     for (ParamIndex::const_iterator i = pIndex.begin();
index f4a74c1..c405ebf 100644 (file)
@@ -386,7 +386,7 @@ int check_type(yyscan_t yyscanner) {
     struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
     
     int token = IDENTIFIER;
-    TSymbol* symbol = yyextra->symbolTable.find(yytext);
+    TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
     if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
         TVariable* variable = static_cast<TVariable*>(symbol);
         if (variable->isUserType()) {
index 63be10e..a7cc14e 100644 (file)
@@ -1025,7 +1025,7 @@ function_prototype
         //
         // Redeclarations are allowed.  But, return types and parameter qualifiers must match.
         //
-        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName()));
+        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find($1->getMangledName(), context->shaderVersion));
         if (prevDec) {
             if (prevDec->getReturnType() != $1->getReturnType()) {
                 context->error($2.line, "overloaded functions must have the same return type", $1->getReturnType().getBasicString());
@@ -2129,7 +2129,7 @@ function_definition
     : function_prototype {
         TFunction* function = $1.function;
         
-        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName());
+        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
         
         if (builtIn)
         {
@@ -2137,7 +2137,7 @@ function_definition
             context->recover();
         }
         
-        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName()));
+        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
         //
         // Note:  'prevDec' could be 'function' if this is the first time we've seen function
         // as it would have just been put in the symbol table.  Otherwise, we're looking up
index 43c38cb..86b1b34 100644 (file)
@@ -3163,7 +3163,7 @@ int check_type(yyscan_t yyscanner) {
     struct yyguts_t* yyg = (struct yyguts_t*) yyscanner;
     
     int token = IDENTIFIER;
-    TSymbol* symbol = yyextra->symbolTable.find(yytext);
+    TSymbol* symbol = yyextra->symbolTable.find(yytext, yyextra->shaderVersion);
     if (yyextra->lexAfterType == false && symbol && symbol->isVariable()) {
         TVariable* variable = static_cast<TVariable*>(symbol);
         if (variable->isUserType()) {
index 0d4626e..6d65c3f 100644 (file)
@@ -3209,7 +3209,7 @@ yyreduce:
         //
         // Redeclarations are allowed.  But, return types and parameter qualifiers must match.
         //
-        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName()));
+        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find((yyvsp[(1) - (2)].interm.function)->getMangledName(), context->shaderVersion));
         if (prevDec) {
             if (prevDec->getReturnType() != (yyvsp[(1) - (2)].interm.function)->getReturnType()) {
                 context->error((yyvsp[(2) - (2)].lex).line, "overloaded functions must have the same return type", (yyvsp[(1) - (2)].interm.function)->getReturnType().getBasicString());
@@ -4671,7 +4671,7 @@ yyreduce:
     {
         TFunction* function = (yyvsp[(1) - (1)].interm).function;
         
-        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName());
+        const TSymbol *builtIn = context->symbolTable.findBuiltIn(function->getMangledName(), context->shaderVersion);
         
         if (builtIn)
         {
@@ -4679,7 +4679,7 @@ yyreduce:
             context->recover();
         }
         
-        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName()));
+        TFunction* prevDec = static_cast<TFunction*>(context->symbolTable.find(function->getMangledName(), context->shaderVersion));
         //
         // Note:  'prevDec' could be 'function' if this is the first time we've seen function
         // as it would have just been put in the symbol table.  Otherwise, we're looking up
index c781480..951a019 100644 (file)
@@ -2934,8 +2934,6 @@ const GLubyte* GL_APIENTRY glGetString(GLenum name)
 {\r
        TRACE("(GLenum name = 0x%X)", name);\r
 \r
-       es2::Context *context = es2::getContext();\r
-\r
        switch(name)\r
        {\r
        case GL_VENDOR:\r