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)
}
//
// 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)
{
......
......@@ -569,24 +569,18 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
symbolTable.push(); // ESSL3_BUILTINS
symbolTable.push(); // ESSL3_1_BUILTINS
TPublicType integer;
integer.initializeBasicType(EbtInt);
TPublicType floatingPoint;
floatingPoint.initializeBasicType(EbtFloat);
switch (shaderType)
{
case GL_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(integer, EbpMedium);
symbolTable.setDefaultPrecision(EbtInt, EbpMedium);
break;
case GL_VERTEX_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
break;
case GL_COMPUTE_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
symbolTable.setDefaultPrecision(EbtInt, EbpHigh);
symbolTable.setDefaultPrecision(EbtFloat, EbpHigh);
break;
default:
assert(false && "Language not supported");
......@@ -603,9 +597,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
// It isn't specified whether Sampler2DRect has default precision.
initSamplerDefaultPrecision(EbtSampler2DRect);
TPublicType atomicCounter;
atomicCounter.initializeBasicType(EbtAtomicCounter);
symbolTable.setDefaultPrecision(atomicCounter, EbpHigh);
symbolTable.setDefaultPrecision(EbtAtomicCounter, EbpHigh);
InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
......@@ -617,9 +609,7 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
TPublicType sampler;
sampler.initializeBasicType(samplerType);
symbolTable.setDefaultPrecision(sampler, EbpLow);
symbolTable.setDefaultPrecision(samplerType, EbpLow);
}
void TCompiler::setResourceString()
......
......@@ -84,36 +84,6 @@ TIntermBlock *TIntermediate::EnsureBlock(TIntermNode *node)
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 *right,
const TSourceLoc &line,
......@@ -225,24 +195,6 @@ TIntermTyped *TIntermediate::AddSwizzle(TIntermTyped *baseExpression,
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,
TDiagnostics *diagnostics)
{
......
......@@ -34,7 +34,6 @@ class TIntermediate
const TSourceLoc &line,
TDiagnostics *diagnostics);
static TIntermBlock *EnsureBlock(TIntermNode *node);
TIntermNode *addIfElse(TIntermTyped *cond, TIntermNodePair code, const TSourceLoc &line);
static TIntermTyped *AddTernarySelection(TIntermTyped *cond,
TIntermTyped *trueExpression,
TIntermTyped *falseExpression,
......@@ -51,8 +50,6 @@ class TIntermediate
const TType &type,
const TSourceLoc &line);
TIntermBranch *addBranch(TOperator, const TSourceLoc &);
TIntermBranch *addBranch(TOperator, TIntermTyped *, const TSourceLoc &);
static TIntermTyped *AddSwizzle(TIntermTyped *baseExpression,
const TVectorFields &fields,
const TSourceLoc &dotLocation);
......
......@@ -193,6 +193,10 @@ class TParseContext : angle::NonCopyable
TIntermNode *body,
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);
TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
const TPublicType &typeSpecifier);
......@@ -254,7 +258,11 @@ class TParseContext : angle::NonCopyable
TIntermTyped *initializer,
TIntermDeclaration *declarationOut);
void parseDefaultPrecisionQualifier(const TPrecision precision,
const TPublicType &type,
const TSourceLoc &loc);
void parseGlobalLayoutQualifier(const TTypeQualifierBuilder &typeQualifierBuilder);
TIntermFunctionPrototype *addFunctionPrototypeDeclaration(const TFunction &parsedFunction,
const TSourceLoc &location);
TIntermFunctionDefinition *addFunctionDefinition(TIntermFunctionPrototype *functionPrototype,
......@@ -267,7 +275,16 @@ class TParseContext : angle::NonCopyable
TFunction *parseFunctionHeader(const TPublicType &type,
const TString *name,
const TSourceLoc &location);
TFunction *addNonConstructorFunc(const TString *name, const TSourceLoc &loc);
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,
const TSourceLoc &location,
......@@ -277,6 +294,13 @@ class TParseContext : angle::NonCopyable
const TString &fieldString,
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,
const TFieldList *newlyAddedFields,
const TSourceLoc &location);
......@@ -317,6 +341,12 @@ class TParseContext : angle::NonCopyable
int intValue,
const TSourceLoc &intValueLine);
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 rightQualifier,
const TSourceLoc &rightQualifierLocation);
......@@ -351,7 +381,7 @@ class TParseContext : angle::NonCopyable
TIntermTyped *addComma(TIntermTyped *left, TIntermTyped *right, 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 checkImageMemoryAccessForBuiltinFunctions(TIntermAggregate *functionCall);
......
......@@ -130,8 +130,8 @@ struct TConstParameter
TConstParameter(const TString *n, TType *t) = delete;
TConstParameter(TString *n, const TType *t) = delete;
const TString *name;
const TType *type;
const TString *const name;
const TType *const type;
};
// The function sub-class of symbols and the parser will need to
......@@ -150,7 +150,7 @@ struct TParameter
return TConstParameter(constName, constType);
}
TString *name;
const TString *name;
TType *type;
};
......@@ -446,18 +446,11 @@ class TSymbolTable : angle::NonCopyable
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;
// Uses map operator [], overwrites the current value
(*precisionStack[indexOfLastElement])[type.getBasicType()] = prec;
return true;
(*precisionStack[indexOfLastElement])[type] = prec;
}
// Searches down the precisionStack for a precision qualifier
......
......@@ -242,9 +242,9 @@ class TType
{
}
explicit TType(const TPublicType &p);
explicit TType(TStructure *userDef, TPrecision p = EbpUndefined)
explicit TType(TStructure *userDef)
: type(EbtStruct),
precision(p),
precision(EbpUndefined),
qualifier(EvqTemporary),
invariant(false),
memoryQualifier(TMemoryQualifier::create()),
......@@ -525,16 +525,27 @@ struct TTypeSpecifierNonArray
// true if the type was defined by a struct specifier rather than a reference to a type name.
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;
secondarySize = 1;
userDef = nullptr;
line = ln;
line = aLine;
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 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