Commit e7847b08 by Olli Etuaho

Unify declaration parsing code

Remove the unused identifierSymbol parameter from parseSingleDeclarator and unify the ordering of parameters and the code style of different declaration and declarator parsing functions. Some minor functional changes to array size handling are done mainly to unify error message generation. There's soon going to be more of these functions, so it's good to be systematic. TEST=angle_unittests, WebGL conformance tests BUG=angleproject:941 Change-Id: I03b0220de93ca5719fdb7c1790a5999b8cb5b225 Reviewed-on: https://chromium-review.googlesource.com/265202Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 33e98913
......@@ -673,9 +673,10 @@ bool TParseContext::arraySizeErrorCheck(const TSourceLoc& line, TIntermTyped* ex
{
TIntermConstantUnion* constant = expr->getAsConstantUnion();
if (constant == 0 || !constant->isScalarInt())
if (constant == nullptr || !constant->isScalarInt())
{
error(line, "array size must be a constant integer expression", "");
size = 1;
return true;
}
......@@ -1076,8 +1077,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
// Returns true on error, false if no error
//
bool TParseContext::executeInitializer(const TSourceLoc &line, const TString &identifier, TPublicType &pType,
TIntermTyped *initializer, TIntermNode *&intermNode)
TIntermTyped *initializer, TIntermNode **intermNode)
{
ASSERT(intermNode != nullptr);
TType type = TType(pType);
TVariable *variable = nullptr;
......@@ -1130,16 +1132,22 @@ bool TParseContext::executeInitializer(const TSourceLoc &line, const TString &id
return true;
}
}
if (qualifier != EvqConst) {
TIntermSymbol* intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(), variable->getType(), line);
intermNode = createAssign(EOpInitialize, intermSymbol, initializer, line);
if (intermNode == 0) {
if (qualifier != EvqConst)
{
TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(), variable->getName(),
variable->getType(), line);
*intermNode = createAssign(EOpInitialize, intermSymbol, initializer, line);
if (*intermNode == nullptr)
{
assignError(line, "=", intermSymbol->getCompleteString(), initializer->getCompleteString());
return true;
}
} else
intermNode = 0;
}
else
{
*intermNode = nullptr;
}
return false;
}
......@@ -1236,7 +1244,6 @@ TIntermAggregate *TParseContext::parseSingleDeclaration(TPublicType &publicType,
const TString &identifier)
{
TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierOrTypeLocation);
TIntermAggregate *aggregate = intermediate.makeAggregate(symbol, identifierOrTypeLocation);
mDeferredSingleDeclarationErrorCheck = (identifier == "");
......@@ -1253,15 +1260,17 @@ TIntermAggregate *TParseContext::parseSingleDeclaration(TPublicType &publicType,
recover();
if (variable && symbol)
{
symbol->setId(variable->getUniqueId());
}
}
return aggregate;
return intermediate.makeAggregate(symbol, identifierOrTypeLocation);
}
TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& indexLocation, TIntermTyped *indexExpression)
TIntermAggregate *TParseContext::parseSingleArrayDeclaration(TPublicType &publicType,
const TSourceLoc &identifierLocation,
const TString &identifier,
const TSourceLoc &indexLocation,
TIntermTyped *indexExpression)
{
mDeferredSingleDeclarationErrorCheck = false;
......@@ -1283,49 +1292,48 @@ TIntermAggregate* TParseContext::parseSingleArrayDeclaration(TPublicType &public
{
recover();
}
else
{
arrayType.setArraySize(size);
}
TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
TIntermAggregate* aggregate = intermediate.makeAggregate(symbol, identifierLocation);
// Make the type an array even if size check failed.
// This ensures useless error messages regarding the variable's non-arrayness won't follow.
arrayType.setArraySize(size);
TVariable *variable = nullptr;
if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
recover();
TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
if (variable && symbol)
{
symbol->setId(variable->getUniqueId());
}
return aggregate;
return intermediate.makeAggregate(symbol, identifierLocation);
}
TIntermAggregate* TParseContext::parseSingleInitDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer)
TIntermAggregate *TParseContext::parseSingleInitDeclaration(TPublicType &publicType,
const TSourceLoc &identifierLocation,
const TString &identifier,
const TSourceLoc &initLocation,
TIntermTyped *initializer)
{
mDeferredSingleDeclarationErrorCheck = false;
if (singleDeclarationErrorCheck(publicType, identifierLocation))
recover();
TIntermNode* intermNode;
if (!executeInitializer(identifierLocation, identifier, publicType, initializer, intermNode))
TIntermNode *intermNode = nullptr;
if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
{
//
// Build intermediate representation
//
return intermNode ? intermediate.makeAggregate(intermNode, initLocation) : NULL;
return intermNode ? intermediate.makeAggregate(intermNode, initLocation) : nullptr;
}
else
{
recover();
return NULL;
return nullptr;
}
}
TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &invariantLoc,
TIntermAggregate *TParseContext::parseInvariantDeclaration(const TSourceLoc &invariantLoc,
const TSourceLoc &identifierLoc,
const TString *identifier,
const TSymbol *symbol)
......@@ -1340,7 +1348,7 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
{
error(identifierLoc, "undeclared identifier declared as invariant", identifier->c_str());
recover();
return NULL;
return nullptr;
}
else
{
......@@ -1349,7 +1357,7 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
{
error(identifierLoc, "identifier should not be declared as invariant", identifier->c_str());
recover();
return NULL;
return nullptr;
}
symbolTable.addInvariantVarying(std::string(identifier->c_str()));
const TVariable *variable = getNamedVariable(identifierLoc, identifier, symbol);
......@@ -1364,7 +1372,8 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
}
}
TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier)
TIntermAggregate *TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier)
{
// If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
if (mDeferredSingleDeclarationErrorCheck)
......@@ -1374,9 +1383,6 @@ TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TInter
mDeferredSingleDeclarationErrorCheck = false;
}
TIntermSymbol* symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation);
TIntermAggregate* intermAggregate = intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
if (locationDeclaratorListCheck(identifierLocation, publicType))
recover();
......@@ -1386,13 +1392,17 @@ TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TInter
TVariable *variable = nullptr;
if (!declareVariable(identifierLocation, identifier, TType(publicType), &variable))
recover();
if (symbol && variable)
TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation);
if (variable && symbol)
symbol->setId(variable->getUniqueId());
return intermAggregate;
return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
}
TIntermAggregate* TParseContext::parseArrayDeclarator(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& arrayLocation, TIntermNode *declaratorList, TIntermTyped *indexExpression)
TIntermAggregate *TParseContext::parseArrayDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &arrayLocation, TIntermTyped *indexExpression)
{
// If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
if (mDeferredSingleDeclarationErrorCheck)
......@@ -1414,27 +1424,31 @@ TIntermAggregate* TParseContext::parseArrayDeclarator(TPublicType &publicType, c
}
else
{
TType arrayType = TType(publicType);
int size;
if (arraySizeErrorCheck(arrayLocation, indexExpression, size))
{
recover();
TType arrayType = TType(publicType);
}
arrayType.setArraySize(size);
TVariable *variable = nullptr;
if (!declareVariable(arrayLocation, identifier, arrayType, &variable))
if (!declareVariable(identifierLocation, identifier, arrayType, &variable))
recover();
TIntermSymbol *symbol = intermediate.addSymbol(0, identifier, arrayType, identifierLocation);
if (variable && symbol)
{
symbol->setId(variable->getUniqueId());
}
return intermediate.growAggregate(declaratorList, symbol, identifierLocation);
return intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
}
return nullptr;
}
TIntermAggregate* TParseContext::parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer)
TIntermAggregate *TParseContext::parseInitDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &initLocation, TIntermTyped *initializer)
{
// If the declaration starting this declarator list was empty (example: int,), some checks were not performed.
if (mDeferredSingleDeclarationErrorCheck)
......@@ -1447,25 +1461,25 @@ TIntermAggregate* TParseContext::parseInitDeclarator(TPublicType &publicType, TI
if (locationDeclaratorListCheck(identifierLocation, publicType))
recover();
TIntermNode* intermNode;
if (!executeInitializer(identifierLocation, identifier, publicType, initializer, intermNode))
TIntermNode *intermNode = nullptr;
if (!executeInitializer(identifierLocation, identifier, publicType, initializer, &intermNode))
{
//
// build the intermediate representation
//
if (intermNode)
{
return intermediate.growAggregate(declaratorList, intermNode, initLocation);
return intermediate.growAggregate(aggregateDeclaration, intermNode, initLocation);
}
else
{
return declaratorList;
return aggregateDeclaration;
}
}
else
{
recover();
return NULL;
return nullptr;
}
}
......
......@@ -124,19 +124,32 @@ struct TParseContext {
bool areAllChildConst(TIntermAggregate* aggrNode);
const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, int inputShaderVersion, bool *builtIn = 0);
bool executeInitializer(const TSourceLoc &line, const TString &identifier, TPublicType &pType,
TIntermTyped *initializer, TIntermNode *&intermNode);
TIntermTyped *initializer, TIntermNode **intermNode);
TPublicType addFullySpecifiedType(TQualifier qualifier, const TPublicType& typeSpecifier);
TPublicType addFullySpecifiedType(TQualifier qualifier, TLayoutQualifier layoutQualifier, const TPublicType& typeSpecifier);
TIntermAggregate *parseSingleDeclaration(TPublicType &publicType,
const TSourceLoc &identifierOrTypeLocation, const TString &identifier);
TIntermAggregate* parseSingleArrayDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& indexLocation, TIntermTyped *indexExpression);
TIntermAggregate* parseSingleInitDeclaration(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer);
TIntermAggregate* parseInvariantDeclaration(const TSourceLoc &invariantLoc, const TSourceLoc &identifierLoc, const TString *identifier, const TSymbol *symbol);
TIntermAggregate *parseSingleArrayDeclaration(TPublicType &publicType,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &indexLocation, TIntermTyped *indexExpression);
TIntermAggregate *parseSingleInitDeclaration(TPublicType &publicType,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &initLocation, TIntermTyped *initializer);
TIntermAggregate *parseInvariantDeclaration(const TSourceLoc &invariantLoc, const TSourceLoc &identifierLoc,
const TString *identifier, const TSymbol *symbol);
TIntermAggregate *parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier);
TIntermAggregate *parseArrayDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &arrayLocation, TIntermTyped *indexExpression);
TIntermAggregate *parseInitDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration,
const TSourceLoc &identifierLocation, const TString &identifier,
const TSourceLoc &initLocation, TIntermTyped *initializer);
TIntermAggregate* parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier);
TIntermAggregate* parseArrayDeclarator(TPublicType &publicType, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& arrayLocation, TIntermNode *declaratorList, TIntermTyped *indexExpression);
TIntermAggregate* parseInitDeclarator(TPublicType &publicType, TIntermAggregate *declaratorList, const TSourceLoc& identifierLocation, const TString &identifier, const TSourceLoc& initLocation, TIntermTyped *initializer);
void parseGlobalLayoutQualifier(const TPublicType &typeQualifier);
TFunction *addConstructorFunc(TPublicType publicType);
TIntermTyped* addConstructor(TIntermNode*, TType*, TOperator, TFunction*, const TSourceLoc&);
......
......@@ -883,11 +883,11 @@ init_declarator_list
}
| init_declarator_list COMMA identifier {
$$ = $1;
$$.intermAggregate = context->parseDeclarator($$.type, $1.intermAggregate, $3.symbol, @3, *$3.string);
$$.intermAggregate = context->parseDeclarator($$.type, $1.intermAggregate, @3, *$3.string);
}
| init_declarator_list COMMA identifier LEFT_BRACKET constant_expression RIGHT_BRACKET {
$$ = $1;
$$.intermAggregate = context->parseArrayDeclarator($$.type, @3, *$3.string, @4, $1.intermNode, $5);
$$.intermAggregate = context->parseArrayDeclarator($$.type, $1.intermAggregate, @3, *$3.string, @4, $5);
}
| init_declarator_list COMMA identifier EQUAL initializer {
$$ = $1;
......@@ -1534,11 +1534,11 @@ condition
context->recover();
}
| fully_specified_type identifier EQUAL initializer {
TIntermNode* intermNode;
TIntermNode *intermNode;
if (context->boolErrorCheck(@2, $1))
context->recover();
if (!context->executeInitializer(@2, *$2.string, $1, $4, intermNode))
if (!context->executeInitializer(@2, *$2.string, $1, $4, &intermNode))
$$ = $4;
else {
context->recover();
......
......@@ -3385,7 +3385,7 @@ yyreduce:
{
(yyval.interm) = (yyvsp[-2].interm);
(yyval.interm).intermAggregate = context->parseDeclarator((yyval.interm).type, (yyvsp[-2].interm).intermAggregate, (yyvsp[0].lex).symbol, (yylsp[0]), *(yyvsp[0].lex).string);
(yyval.interm).intermAggregate = context->parseDeclarator((yyval.interm).type, (yyvsp[-2].interm).intermAggregate, (yylsp[0]), *(yyvsp[0].lex).string);
}
break;
......@@ -3394,7 +3394,7 @@ yyreduce:
{
(yyval.interm) = (yyvsp[-5].interm);
(yyval.interm).intermAggregate = context->parseArrayDeclarator((yyval.interm).type, (yylsp[-3]), *(yyvsp[-3].lex).string, (yylsp[-2]), (yyvsp[-5].interm).intermNode, (yyvsp[-1].interm.intermTypedNode));
(yyval.interm).intermAggregate = context->parseArrayDeclarator((yyval.interm).type, (yyvsp[-5].interm).intermAggregate, (yylsp[-3]), *(yyvsp[-3].lex).string, (yylsp[-2]), (yyvsp[-1].interm.intermTypedNode));
}
break;
......@@ -4605,11 +4605,11 @@ yyreduce:
case 246:
{
TIntermNode* intermNode;
TIntermNode *intermNode;
if (context->boolErrorCheck((yylsp[-2]), (yyvsp[-3].interm.type)))
context->recover();
if (!context->executeInitializer((yylsp[-2]), *(yyvsp[-2].lex).string, (yyvsp[-3].interm.type), (yyvsp[0].interm.intermTypedNode), intermNode))
if (!context->executeInitializer((yylsp[-2]), *(yyvsp[-2].lex).string, (yyvsp[-3].interm.type), (yyvsp[0].interm.intermTypedNode), &intermNode))
(yyval.interm.intermTypedNode) = (yyvsp[0].interm.intermTypedNode);
else {
context->recover();
......
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