summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h')
-rw-r--r--3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h105
1 files changed, 95 insertions, 10 deletions
diff --git a/3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h b/3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
index 9028dd76245..8dc154cdc55 100644
--- a/3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
+++ b/3rdparty/bgfx/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
@@ -87,6 +87,12 @@ public:
virtual const TString& getName() const { return *name; }
virtual void changeName(const TString* newName) { name = newName; }
+ virtual void addPrefix(const char* prefix)
+ {
+ TString newName(prefix);
+ newName.append(*name);
+ changeName(NewPoolTString(newName.c_str()));
+ }
virtual const TString& getMangledName() const { return getName(); }
virtual TFunction* getAsFunction() { return 0; }
virtual const TFunction* getAsFunction() const { return 0; }
@@ -192,6 +198,7 @@ struct TParameter {
TString *name;
TType* type;
TIntermTyped* defaultValue;
+ TBuiltInVariable declaredBuiltIn;
void copyParam(const TParameter& param)
{
if (param.name)
@@ -200,6 +207,7 @@ struct TParameter {
name = 0;
type = param.type->clone();
defaultValue = param.defaultValue;
+ declaredBuiltIn = param.declaredBuiltIn;
}
};
@@ -211,21 +219,29 @@ public:
explicit TFunction(TOperator o) :
TSymbol(0),
op(o),
- defined(false), prototyped(false), defaultParamCount(0) { }
+ defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0) { }
TFunction(const TString *name, const TType& retType, TOperator tOp = EOpNull) :
TSymbol(name),
mangledName(*name + '('),
op(tOp),
- defined(false), prototyped(false), defaultParamCount(0) { returnType.shallowCopy(retType); }
- virtual TFunction* clone() const;
+ defined(false), prototyped(false), implicitThis(false), illegalImplicitThis(false), defaultParamCount(0)
+ {
+ returnType.shallowCopy(retType);
+ declaredBuiltIn = retType.getQualifier().builtIn;
+ }
+ virtual TFunction* clone() const override;
virtual ~TFunction();
- virtual TFunction* getAsFunction() { return this; }
- virtual const TFunction* getAsFunction() const { return this; }
+ virtual TFunction* getAsFunction() override { return this; }
+ virtual const TFunction* getAsFunction() const override { return this; }
+ // Install 'p' as the (non-'this') last parameter.
+ // Non-'this' parameters are reflected in both the list of parameters and the
+ // mangled name.
virtual void addParameter(TParameter& p)
{
assert(writable);
+ p.declaredBuiltIn = p.type->getQualifier().builtIn;
parameters.push_back(p);
p.type->appendMangledName(mangledName);
@@ -233,15 +249,35 @@ public:
defaultParamCount++;
}
- virtual const TString& getMangledName() const { return mangledName; }
- virtual const TType& getType() const { return returnType; }
- virtual TType& getWritableType() { return returnType; }
+ // Install 'this' as the first parameter.
+ // 'this' is reflected in the list of parameters, but not the mangled name.
+ virtual void addThisParameter(TType& type, const char* name)
+ {
+ TParameter p = { NewPoolTString(name), new TType, nullptr };
+ p.type->shallowCopy(type);
+ parameters.insert(parameters.begin(), p);
+ }
+
+ virtual void addPrefix(const char* prefix) override
+ {
+ TSymbol::addPrefix(prefix);
+ mangledName.insert(0, prefix);
+ }
+
+ virtual const TString& getMangledName() const override { return mangledName; }
+ virtual const TType& getType() const override { return returnType; }
+ virtual TBuiltInVariable getDeclaredBuiltInType() const { return declaredBuiltIn; }
+ virtual TType& getWritableType() override { return returnType; }
virtual void relateToOperator(TOperator o) { assert(writable); op = o; }
virtual TOperator getBuiltInOp() const { return op; }
virtual void setDefined() { assert(writable); defined = true; }
virtual bool isDefined() const { return defined; }
virtual void setPrototyped() { assert(writable); prototyped = true; }
virtual bool isPrototyped() const { return prototyped; }
+ virtual void setImplicitThis() { assert(writable); implicitThis = true; }
+ virtual bool hasImplicitThis() const { return implicitThis; }
+ virtual void setIllegalImplicitThis() { assert(writable); illegalImplicitThis = true; }
+ virtual bool hasIllegalImplicitThis() const { return illegalImplicitThis; }
// Return total number of parameters
virtual int getParamCount() const { return static_cast<int>(parameters.size()); }
@@ -253,7 +289,7 @@ public:
virtual TParameter& operator[](int i) { assert(writable); return parameters[i]; }
virtual const TParameter& operator[](int i) const { return parameters[i]; }
- virtual void dump(TInfoSink &infoSink) const;
+ virtual void dump(TInfoSink &infoSink) const override;
protected:
explicit TFunction(const TFunction&);
@@ -262,10 +298,17 @@ protected:
typedef TVector<TParameter> TParamList;
TParamList parameters;
TType returnType;
+ TBuiltInVariable declaredBuiltIn;
+
TString mangledName;
TOperator op;
bool defined;
bool prototyped;
+ bool implicitThis; // True if this function is allowed to see all members of 'this'
+ bool illegalImplicitThis; // True if this function is not supposed to have access to dynamic members of 'this',
+ // even if it finds member variables in the symbol table.
+ // This is important for a static member function that has member variables in scope,
+ // but is not allowed to use them, or see hidden symbols instead.
int defaultParamCount;
};
@@ -313,7 +356,7 @@ protected:
class TSymbolTableLevel {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
- TSymbolTableLevel() : defaultPrecision(0), anonId(0) { }
+ TSymbolTableLevel() : defaultPrecision(0), anonId(0), thisLevel(false) { }
~TSymbolTableLevel();
bool insert(TSymbol& symbol, bool separateNameSpaces)
@@ -471,6 +514,9 @@ public:
TSymbolTableLevel* clone() const;
void readOnly();
+ void setThisLevel() { thisLevel = true; }
+ bool isThisLevel() const { return thisLevel; }
+
protected:
explicit TSymbolTableLevel(TSymbolTableLevel&);
TSymbolTableLevel& operator=(TSymbolTableLevel&);
@@ -482,6 +528,8 @@ protected:
tLevel level; // named mappings
TPrecisionQualifier *defaultPrecision;
int anonId;
+ bool thisLevel; // True if this level of the symbol table is a structure scope containing member function
+ // that are supposed to see anonymous access to member variables.
};
class TSymbolTable {
@@ -538,6 +586,20 @@ public:
table.push_back(new TSymbolTableLevel);
}
+ // Make a new symbol-table level to represent the scope introduced by a structure
+ // containing member functions, such that the member functions can find anonymous
+ // references to member variables.
+ //
+ // 'thisSymbol' should have a name of "" to trigger anonymous structure-member
+ // symbol finds.
+ void pushThis(TSymbol& thisSymbol)
+ {
+ assert(thisSymbol.getName().size() == 0);
+ table.push_back(new TSymbolTableLevel);
+ table.back()->setThisLevel();
+ insert(thisSymbol);
+ }
+
void pop(TPrecisionQualifier *p)
{
table[currentLevel()]->getPreviousDefaultPrecisions(p);
@@ -624,6 +686,8 @@ public:
}
}
+ // Normal find of a symbol, that can optionally say whether the symbol was found
+ // at a built-in level or the current top-scope level.
TSymbol* find(const TString& name, bool* builtIn = 0, bool *currentScope = 0)
{
int level = currentLevel();
@@ -641,6 +705,27 @@ public:
return symbol;
}
+ // Find of a symbol that returns how many layers deep of nested
+ // structures-with-member-functions ('this' scopes) deep the symbol was
+ // found in.
+ TSymbol* find(const TString& name, int& thisDepth)
+ {
+ int level = currentLevel();
+ TSymbol* symbol;
+ thisDepth = 0;
+ do {
+ if (table[level]->isThisLevel())
+ ++thisDepth;
+ symbol = table[level]->find(name);
+ --level;
+ } while (symbol == 0 && level >= 0);
+
+ if (! table[level + 1]->isThisLevel())
+ thisDepth = 0;
+
+ return symbol;
+ }
+
bool isFunctionNameVariable(const TString& name) const
{
if (separateNameSpaces)