Fix nested struct scope support in GL backend.
Basically we should be able to reuse a struct name once the previous
use is out of the scope, or we can reuse it if we are in a inner scope
than where it is defined before.
BUG=368910
BUG=angle:618
TEST=conformance/glsl/bugs/nested-structs-with-same-name.html
Change-Id: Icfac76b844deaca0c8a0501d7426ff3802e657dc
Reviewed-on: https://chromium-review.googlesource.com/199137
Reviewed-by: Nicolas Capens <nicolascapens@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/compiler/translator/OutputGLSLBase.h b/src/compiler/translator/OutputGLSLBase.h
index dbbb7b5..1f751e2 100644
--- a/src/compiler/translator/OutputGLSLBase.h
+++ b/src/compiler/translator/OutputGLSLBase.h
@@ -7,7 +7,7 @@
#ifndef CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
#define CROSSCOMPILERGLSL_OUTPUTGLSLBASE_H_
-#include <set>
+#include <vector>
#include "compiler/translator/intermediate.h"
#include "compiler/translator/LoopInfo.h"
@@ -57,14 +57,19 @@
private:
bool structDeclared(const TStructure* structure) const;
void declareStruct(const TStructure* structure);
+ void pushDeclaredStructsScope();
+ void popDeclaredStructsScope();
TInfoSinkBase& mObjSink;
bool mDeclaringVariables;
- // Structs are declared as the tree is traversed. This set contains all
- // the structs already declared. It is maintained so that a struct is
- // declared only once.
- typedef std::set<TString> DeclaredStructs;
+ // Structs are declared as the tree is traversed. This list contains all
+ // the structs already declared within a scope. It is maintained so that
+ // a struct is declared only once within a scope.
+ typedef std::vector<TStructure *> ScopedDeclaredStructs;
+ // This vector contains all the structs from the global scope to the
+ // current scope. When the traverser exits a scope, the scope is discarded.
+ typedef std::vector<ScopedDeclaredStructs> DeclaredStructs;
DeclaredStructs mDeclaredStructs;
// Stack of loops that need to be unrolled.