diff options
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/SymbolTable.h')
-rw-r--r-- | src/3rdparty/angle/src/compiler/translator/SymbolTable.h | 173 |
1 files changed, 103 insertions, 70 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/SymbolTable.h b/src/3rdparty/angle/src/compiler/translator/SymbolTable.h index dfc65cb957..2706149e3c 100644 --- a/src/3rdparty/angle/src/compiler/translator/SymbolTable.h +++ b/src/3rdparty/angle/src/compiler/translator/SymbolTable.h @@ -109,13 +109,8 @@ class TVariable : public TSymbol unionArray(0) { } - virtual ~TVariable() - { - } - virtual bool isVariable() const - { - return true; - } + ~TVariable() override {} + bool isVariable() const override { return true; } TType &getType() { return type; @@ -133,40 +128,67 @@ class TVariable : public TSymbol type.setQualifier(qualifier); } - ConstantUnion *getConstPointer() - { - if (!unionArray) - unionArray = new ConstantUnion[type.getObjectSize()]; + const TConstantUnion *getConstPointer() const { return unionArray; } - return unionArray; - } - - ConstantUnion *getConstPointer() const - { - return unionArray; - } - - void shareConstPointer(ConstantUnion *constArray) - { - if (unionArray == constArray) - return; - - delete[] unionArray; - unionArray = constArray; - } + void shareConstPointer(const TConstantUnion *constArray) { unionArray = constArray; } private: TType type; bool userType; // we are assuming that Pool Allocator will free the memory // allocated to unionArray when this object is destroyed. - ConstantUnion *unionArray; + const TConstantUnion *unionArray; +}; + +// Immutable version of TParameter. +struct TConstParameter +{ + TConstParameter() + : name(nullptr), + type(nullptr) + { + } + explicit TConstParameter(const TString *n) + : name(n), + type(nullptr) + { + } + explicit TConstParameter(const TType *t) + : name(nullptr), + type(t) + { + } + TConstParameter(const TString *n, const TType *t) + : name(n), + type(t) + { + } + + // Both constructor arguments must be const. + TConstParameter(TString *n, TType *t) = delete; + TConstParameter(const TString *n, TType *t) = delete; + TConstParameter(TString *n, const TType *t) = delete; + + const TString *name; + const TType *type; }; // The function sub-class of symbols and the parser will need to // share this definition of a function parameter. struct TParameter { + // Destructively converts to TConstParameter. + // This method resets name and type to nullptrs to make sure + // their content cannot be modified after the call. + TConstParameter turnToConst() + { + const TString *constName = name; + const TType *constType = type; + name = nullptr; + type = nullptr; + return TConstParameter(constName, constType); + } + TString *name; TType *type; }; @@ -175,27 +197,21 @@ struct TParameter class TFunction : public TSymbol { public: - TFunction(TOperator o) - : TSymbol(0), - returnType(TType(EbtVoid, EbpUndefined)), - op(o), - defined(false) - { - } - TFunction(const TString *name, const TType &retType, TOperator tOp = EOpNull, const char *ext = "") + TFunction(const TString *name, + const TType *retType, + TOperator tOp = EOpNull, + const char *ext = "") : TSymbol(name), returnType(retType), - mangledName(TFunction::mangleName(*name)), + mangledName(nullptr), op(tOp), - defined(false) + defined(false), + mHasPrototypeDeclaration(false) { relateToExtension(ext); } - virtual ~TFunction(); - virtual bool isFunction() const - { - return true; - } + ~TFunction() override; + bool isFunction() const override { return true; } static TString mangleName(const TString &name) { @@ -206,19 +222,23 @@ class TFunction : public TSymbol return TString(mangledName.c_str(), mangledName.find_first_of('(')); } - void addParameter(TParameter &p) - { + void addParameter(const TConstParameter &p) + { parameters.push_back(p); - mangledName = mangledName + p.type->getMangledName(); + mangledName = nullptr; } - const TString &getMangledName() const + const TString &getMangledName() const override { - return mangledName; + if (mangledName == nullptr) + { + mangledName = buildMangledName(); + } + return *mangledName; } const TType &getReturnType() const { - return returnType; + return *returnType; } TOperator getBuiltInOp() const @@ -226,31 +246,30 @@ class TFunction : public TSymbol return op; } - void setDefined() - { - defined = true; - } - bool isDefined() - { - return defined; - } + void setDefined() { defined = true; } + bool isDefined() { return defined; } + void setHasPrototypeDeclaration() { mHasPrototypeDeclaration = true; } + bool hasPrototypeDeclaration() const { return mHasPrototypeDeclaration; } size_t getParamCount() const { return parameters.size(); } - const TParameter &getParam(size_t i) const + const TConstParameter &getParam(size_t i) const { return parameters[i]; } private: - typedef TVector<TParameter> TParamList; + const TString *buildMangledName() const; + + typedef TVector<TConstParameter> TParamList; TParamList parameters; - TType returnType; - TString mangledName; + const TType *returnType; + mutable const TString *mangledName; TOperator op; bool defined; + bool mHasPrototypeDeclaration; }; // Interface block name sub-symbol @@ -364,27 +383,39 @@ class TSymbolTable : angle::NonCopyable { TVariable *constant = new TVariable( NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1)); - constant->getConstPointer()->setIConst(value); + TConstantUnion *unionArray = new TConstantUnion[1]; + unionArray[0].setIConst(value); + constant->shareConstPointer(unionArray); return insert(level, constant); } - void insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, TType *rvalue, const char *name, - TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0); + bool insertConstIntExt(ESymbolLevel level, const char *ext, const char *name, int value) + { + TVariable *constant = + new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1)); + TConstantUnion *unionArray = new TConstantUnion[1]; + unionArray[0].setIConst(value); + constant->shareConstPointer(unionArray); + return insert(level, ext, constant); + } + + void insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, + const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0); - void insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name, - TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0) + void insertBuiltIn(ESymbolLevel level, const TType *rvalue, const char *name, + const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0) { insertBuiltIn(level, EOpNull, "", rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); } - void insertBuiltIn(ESymbolLevel level, const char *ext, TType *rvalue, const char *name, - TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0) + void insertBuiltIn(ESymbolLevel level, const char *ext, const TType *rvalue, const char *name, + const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0) { insertBuiltIn(level, EOpNull, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); } - void insertBuiltIn(ESymbolLevel level, TOperator op, TType *rvalue, const char *name, - TType *ptype1, TType *ptype2 = 0, TType *ptype3 = 0, TType *ptype4 = 0, TType *ptype5 = 0) + void insertBuiltIn(ESymbolLevel level, TOperator op, const TType *rvalue, const char *name, + const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0) { insertBuiltIn(level, op, "", rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); } @@ -405,6 +436,8 @@ class TSymbolTable : angle::NonCopyable { if (!SupportsPrecision(type.type)) return false; + if (type.type == EbtUInt) + return false; // ESSL 3.00.4 section 4.5.4 if (type.isAggregate()) return false; // Not allowed to set for aggregate types int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1; |