Commit cce8965d by Olli Etuaho Committed by Commit Bot

Remove most of the remaining logic from glslang.y

Move most of the logic in glslang.y to ParseContext. This will make it easier to change the code in the future. Only a few specific bits of logic are kept in glslang.y: * Disabling a parsing rule when a given shading language version is being parsed. This makes it easier to check the grammar against the grammar in the GLSL ES specs. * Scoping calls that need to be paired with another call. It's much easier to check these for correctness when the paired calls are next to each other. BUG=angleproject:911 TEST=angle_unittests Change-Id: I52f42a1fc0f28463ca4b237dc6e88345e5173064 Reviewed-on: https://chromium-review.googlesource.com/539640 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 83dde7b9
...@@ -738,7 +738,7 @@ inline const char *getWorkGroupSizeString(size_t dimension) ...@@ -738,7 +738,7 @@ inline const char *getWorkGroupSizeString(size_t dimension)
} }
// //
// This is just for debug print out, carried along with the definitions above. // This is just for debug and error message print out, carried along with the definitions above.
// //
inline const char *getQualifierString(TQualifier q) inline const char *getQualifierString(TQualifier q)
{ {
......
...@@ -569,24 +569,18 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -569,24 +569,18 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
symbolTable.push(); // ESSL3_BUILTINS symbolTable.push(); // ESSL3_BUILTINS
symbolTable.push(); // ESSL3_1_BUILTINS symbolTable.push(); // ESSL3_1_BUILTINS
TPublicType integer;
integer.initializeBasicType(EbtInt);
TPublicType floatingPoint;
floatingPoint.initializeBasicType(EbtFloat);
switch (shaderType) switch (shaderType)
{ {
case GL_FRAGMENT_SHADER: case GL_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(integer, EbpMedium); symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
break; break;
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh); symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
break; break;
case GL_COMPUTE_SHADER: case GL_COMPUTE_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh); symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh); symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
break; break;
default: default:
assert(false && "Language not supported"); assert(false && "Language not supported");
...@@ -603,9 +597,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -603,9 +597,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
// It isn't specified whether Sampler2DRect has default precision. // It isn't specified whether Sampler2DRect has default precision.
initSamplerDefaultPrecision(EbtSampler2DRect); initSamplerDefaultPrecision(EbtSampler2DRect);
TPublicType atomicCounter; symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
atomicCounter.initializeBasicType(EbtAtomicCounter);
symbolTable.setDefaultPrecision(atomicCounter, EbpHigh);
InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable); InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
...@@ -617,9 +609,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources) ...@@ -617,9 +609,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType) void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{ {
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd); ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
TPublicType sampler; symbolTable.setDefaultPrecision(samplerType, EbpLow);
sampler.initializeBasicType(samplerType);
symbolTable.setDefaultPrecision(sampler, EbpLow);
} }
void TCompiler::setResourceString() void TCompiler::setResourceString()
......
...@@ -84,36 +84,6 @@ TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node) ...@@ -84,36 +84,6 @@ TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node)
return blockNode; return blockNode;
} }
// For "if" test nodes. There are three children; a condition,
// a true path, and a false path. The two paths are in the
// nodePair.
//
// Returns the node created.
TIntermNode *TIntermediate::addIfElse(TIntermTyped *cond,
TIntermNodePair nodePair,
const TSourceLoc &line)
{
// For compile time constant conditions, prune the code now.
if (cond->getAsConstantUnion())
{
if (cond->getAsConstantUnion()->getBConst(0) == true)
{
return EnsureBlock(nodePair.node1);
}
else
{
return EnsureBlock(nodePair.node2);
}
}
TIntermIfElse *node =
new TIntermIfElse(cond, EnsureBlock(nodePair.node1), EnsureBlock(nodePair.node2));
node->setLine(line);
return node;
}
TIntermTyped *TIntermediate::AddComma(TIntermTyped *left, TIntermTyped *TIntermediate::AddComma(TIntermTyped *left,
TIntermTyped *right, TIntermTyped *right,
const TSourceLoc &line, const TSourceLoc &line,
...@@ -225,24 +195,6 @@ TIntermTyped *TIntermediate::AddSwizzle(TIntermTyped *baseExpression, ...@@ -225,24 +195,6 @@ TIntermTyped *TIntermediate::AddSwizzle(TIntermTyped *baseExpression,
return node; return node;
} }
//
// Add branches.
//
TIntermBranch *TIntermediate::addBranch(TOperator branchOp, const TSourceLoc &line)
{
return addBranch(branchOp, 0, line);
}
TIntermBranch *TIntermediate::addBranch(TOperator branchOp,
TIntermTyped *expression,
const TSourceLoc &line)
{
TIntermBranch *node = new TIntermBranch(branchOp, expression);
node->setLine(line);
return node;
}
TIntermTyped *TIntermediate::foldAggregateBuiltIn(TIntermAggregate *aggregate, TIntermTyped *TIntermediate::foldAggregateBuiltIn(TIntermAggregate *aggregate,
TDiagnostics *diagnostics) TDiagnostics *diagnostics)
{ {
......
...@@ -34,7 +34,6 @@ class TIntermediate ...@@ -34,7 +34,6 @@ class TIntermediate
const TSourceLoc &line, const TSourceLoc &line,
TDiagnostics *diagnostics); TDiagnostics *diagnostics);
static TIntermBlock *EnsureBlock(TIntermNode *node); static TIntermBlock *EnsureBlock(TIntermNode *node);
TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &line);
static TIntermTyped *AddTernarySelection(TIntermTyped *cond, static TIntermTyped *AddTernarySelection(TIntermTyped *cond,
TIntermTyped *trueExpression, TIntermTyped *trueExpression,
TIntermTyped *falseExpression, TIntermTyped *falseExpression,
...@@ -51,8 +50,6 @@ class TIntermediate ...@@ -51,8 +50,6 @@ class TIntermediate
const TType &type, const TType &type,
const TSourceLoc &line); const TSourceLoc &line);
TIntermBranch *addBranch(TOperator, const TSourceLoc &);
TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
static TIntermTyped *AddSwizzle(TIntermTyped *baseExpression, static TIntermTyped *AddSwizzle(TIntermTyped *baseExpression,
const TVectorFields &fields, const TVectorFields &fields,
const TSourceLoc &dotLocation); const TSourceLoc &dotLocation);
......
...@@ -193,6 +193,10 @@ class TParseContext : angle::NonCopyable ...@@ -193,6 +193,10 @@ class TParseContext : angle::NonCopyable
TIntermNode *body, TIntermNode *body,
const TSourceLoc &loc); const TSourceLoc &loc);
// For "if" test nodes. There are three children: a condition, a true path, and a false path.
// The two paths are in TIntermNodePair code.
TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &loc);
void addFullySpecifiedType(TPublicType *typeSpecifier); void addFullySpecifiedType(TPublicType *typeSpecifier);
TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder, TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
const TPublicType &typeSpecifier); const TPublicType &typeSpecifier);
...@@ -254,7 +258,11 @@ class TParseContext : angle::NonCopyable ...@@ -254,7 +258,11 @@ class TParseContext : angle::NonCopyable
TIntermTyped *initializer, TIntermTyped *initializer,
TIntermDeclaration *declarationOut); TIntermDeclaration *declarationOut);
void parseDefaultPrecisionQualifier(const TPrecision precision,
const TPublicType &type,
const TSourceLoc &loc);
void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder); void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction, TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
const TSourceLoc &location); const TSourceLoc &location);
TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype, TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
...@@ -267,7 +275,16 @@ class TParseContext : angle::NonCopyable ...@@ -267,7 +275,16 @@ class TParseContext : angle::NonCopyable
TFunction *parseFunctionHeader(const TPublicType &type, TFunction *parseFunctionHeader(const TPublicType &type,
const TString *name, const TString *name,
const TSourceLoc &location); const TSourceLoc &location);
TFunction *addNonConstructorFunc(const TString *name, const TSourceLoc &loc);
TFunction *addConstructorFunc(const TPublicType &publicType); TFunction *addConstructorFunc(const TPublicType &publicType);
TParameter parseParameterDeclarator(const TPublicType &publicType,
const TString *name,
const TSourceLoc &nameLoc);
TParameter parseParameterArrayDeclarator(const TString *identifier,
const TSourceLoc &identifierLoc,
TIntermTyped *arraySize,
const TSourceLoc &arrayLoc,
TPublicType *type);
TIntermTyped *addIndexExpression(TIntermTyped *baseExpression, TIntermTyped *addIndexExpression(TIntermTyped *baseExpression,
const TSourceLoc &location, const TSourceLoc &location,
...@@ -277,6 +294,13 @@ class TParseContext : angle::NonCopyable ...@@ -277,6 +294,13 @@ class TParseContext : angle::NonCopyable
const TString &fieldString, const TString &fieldString,
const TSourceLoc &fieldLocation); const TSourceLoc &fieldLocation);
// Parse declarator for a single field
TField *parseStructDeclarator(TString *identifier, const TSourceLoc &loc);
TField *parseStructArrayDeclarator(TString *identifier,
const TSourceLoc &loc,
TIntermTyped *arraySize,
const TSourceLoc &arraySizeLoc);
TFieldList *combineStructFieldLists(TFieldList *processedFields, TFieldList *combineStructFieldLists(TFieldList *processedFields,
const TFieldList *newlyAddedFields, const TFieldList *newlyAddedFields,
const TSourceLoc &location); const TSourceLoc &location);
...@@ -317,6 +341,12 @@ class TParseContext : angle::NonCopyable ...@@ -317,6 +341,12 @@ class TParseContext : angle::NonCopyable
int intValue, int intValue,
const TSourceLoc &intValueLine); const TSourceLoc &intValueLine);
TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc); TTypeQualifierBuilder *createTypeQualifierBuilder(const TSourceLoc &loc);
TStorageQualifierWrapper *parseGlobalStorageQualifier(TQualifier qualifier,
const TSourceLoc &loc);
TStorageQualifierWrapper *parseVaryingQualifier(const TSourceLoc &loc);
TStorageQualifierWrapper *parseInQualifier(const TSourceLoc &loc);
TStorageQualifierWrapper *parseOutQualifier(const TSourceLoc &loc);
TStorageQualifierWrapper *parseInOutQualifier(const TSourceLoc &loc);
TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier,
TLayoutQualifier rightQualifier, TLayoutQualifier rightQualifier,
const TSourceLoc &rightQualifierLocation); const TSourceLoc &rightQualifierLocation);
...@@ -351,7 +381,7 @@ class TParseContext : angle::NonCopyable ...@@ -351,7 +381,7 @@ class TParseContext : angle::NonCopyable
TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc); TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc); TIntermBranch *addBranch(TOperator op, TIntermTyped *expression, const TSourceLoc &loc);
void checkTextureOffsetConst(TIntermAggregate *functionCall); void checkTextureOffsetConst(TIntermAggregate *functionCall);
void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall); void checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
......
...@@ -130,8 +130,8 @@ struct TConstParameter ...@@ -130,8 +130,8 @@ struct TConstParameter
TConstParameter(const TString *n, TType *t) = delete; TConstParameter(const TString *n, TType *t) = delete;
TConstParameter(TString *n, const TType *t) = delete; TConstParameter(TString *n, const TType *t) = delete;
const TString *name; const TString *const name;
const TType *type; const TType *const type;
}; };
// The function sub-class of symbols and the parser will need to // The function sub-class of symbols and the parser will need to
...@@ -150,7 +150,7 @@ struct TParameter ...@@ -150,7 +150,7 @@ struct TParameter
return TConstParameter(constName, constType); return TConstParameter(constName, constType);
} }
TString *name; const TString *name;
TType *type; TType *type;
}; };
...@@ -446,18 +446,11 @@ class TSymbolTable : angle::NonCopyable ...@@ -446,18 +446,11 @@ class TSymbolTable : angle::NonCopyable
void dump(TInfoSink &infoSink) const; void dump(TInfoSink &infoSink) const;
bool setDefaultPrecision(const TPublicType &type, TPrecision prec) void setDefaultPrecision(TBasicType type, TPrecision prec)
{ {
if (!SupportsPrecision(type.getBasicType()))
return false;
if (type.getBasicType() == 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; int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
// Uses map operator [], overwrites the current value // Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type.getBasicType()] = prec; (*precisionStack[indexOfLastElement])[type] = prec;
return true;
} }
// Searches down the precisionStack for a precision qualifier // Searches down the precisionStack for a precision qualifier
......
...@@ -242,9 +242,9 @@ class TType ...@@ -242,9 +242,9 @@ class TType
{ {
} }
explicit TType(const TPublicType &p); explicit TType(const TPublicType &p);
explicit TType(TStructure *userDef, TPrecision p = EbpUndefined) explicit TType(TStructure *userDef)
: type(EbtStruct), : type(EbtStruct),
precision(p), precision(EbpUndefined),
qualifier(EvqTemporary), qualifier(EvqTemporary),
invariant(false), invariant(false),
memoryQualifier(TMemoryQualifier::create()), memoryQualifier(TMemoryQualifier::create()),
...@@ -525,16 +525,27 @@ struct TTypeSpecifierNonArray ...@@ -525,16 +525,27 @@ struct TTypeSpecifierNonArray
// true if the type was defined by a struct specifier rather than a reference to a type name. // true if the type was defined by a struct specifier rather than a reference to a type name.
bool isStructSpecifier; bool isStructSpecifier;
void initialize(TBasicType bt, const TSourceLoc &ln) void initialize(TBasicType aType, const TSourceLoc &aLine)
{ {
type = bt; ASSERT(aType != EbtStruct);
type = aType;
primarySize = 1; primarySize = 1;
secondarySize = 1; secondarySize = 1;
userDef = nullptr; userDef = nullptr;
line = ln; line = aLine;
isStructSpecifier = false; isStructSpecifier = false;
} }
void initializeStruct(TType *aUserDef, bool aIsStructSpecifier, const TSourceLoc &aLine)
{
type = EbtStruct;
primarySize = 1;
secondarySize = 1;
userDef = aUserDef;
line = aLine;
isStructSpecifier = aIsStructSpecifier;
}
void setAggregate(unsigned char size) { primarySize = size; } void setAggregate(unsigned char size) { primarySize = size; }
void setMatrix(unsigned char columns, unsigned char rows) void setMatrix(unsigned char columns, unsigned char rows)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment