Commit 92ba7794 by alokp@chromium.org

Refactor class to represent structure.

We had a TTypeLine to represent a structure field, which simply encapsulated a TType and line number. The line number was only used during parsing for error reporting. There is no need to store a line number because it is already available in the parser token. TEST=WebGL conformance tests R=kbr@chromium.org Review URL: https://codereview.appspot.com/9223045 git-svn-id: https://angleproject.googlecode.com/svn/trunk@2198 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent bdb34e88
...@@ -1041,10 +1041,10 @@ bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, Co ...@@ -1041,10 +1041,10 @@ bool CompareStruct(const TType& leftNodeType, ConstantUnion* rightUnionArray, Co
int index = 0; int index = 0;
for (size_t j = 0; j < structSize; j++) { for (size_t j = 0; j < structSize; j++) {
int size = (*fields)[j].type->getObjectSize(); int size = (*fields)[j]->getObjectSize();
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
if ((*fields)[j].type->getBasicType() == EbtStruct) { if ((*fields)[j]->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j].type, &rightUnionArray[index], &leftUnionArray[index])) if (!CompareStructure(*(*fields)[j], &rightUnionArray[index], &leftUnionArray[index]))
return false; return false;
} else { } else {
if (leftUnionArray[index] != rightUnionArray[index]) if (leftUnionArray[index] != rightUnionArray[index])
......
...@@ -87,7 +87,7 @@ void TOutputGLSLBase::writeVariableType(const TType& type) ...@@ -87,7 +87,7 @@ void TOutputGLSLBase::writeVariableType(const TType& type)
ASSERT(structure != NULL); ASSERT(structure != NULL);
for (size_t i = 0; i < structure->size(); ++i) for (size_t i = 0; i < structure->size(); ++i)
{ {
const TType* fieldType = (*structure)[i].type; const TType* fieldType = (*structure)[i];
ASSERT(fieldType != NULL); ASSERT(fieldType != NULL);
if (writeVariablePrecision(fieldType->getPrecision())) if (writeVariablePrecision(fieldType->getPrecision()))
out << " "; out << " ";
...@@ -143,7 +143,7 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type, ...@@ -143,7 +143,7 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type,
ASSERT(structure != NULL); ASSERT(structure != NULL);
for (size_t i = 0; i < structure->size(); ++i) for (size_t i = 0; i < structure->size(); ++i)
{ {
const TType* fieldType = (*structure)[i].type; const TType* fieldType = (*structure)[i];
ASSERT(fieldType != NULL); ASSERT(fieldType != NULL);
pConstUnion = writeConstantUnion(*fieldType, pConstUnion); pConstUnion = writeConstantUnion(*fieldType, pConstUnion);
if (i != structure->size() - 1) out << ", "; if (i != structure->size() - 1) out << ", ";
......
...@@ -1025,7 +1025,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1025,7 +1025,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
for (size_t i = 0; i < fields->size(); i++) for (size_t i = 0; i < fields->size(); i++)
{ {
const TType *fieldType = (*fields)[i].type; const TType *fieldType = (*fields)[i];
node->getLeft()->traverse(this); node->getLeft()->traverse(this);
out << "." + decorateField(fieldType->getFieldName(), node->getLeft()->getType()) + " == "; out << "." + decorateField(fieldType->getFieldName(), node->getLeft()->getType()) + " == ";
...@@ -2226,7 +2226,7 @@ TString OutputHLSL::typeString(const TType &type) ...@@ -2226,7 +2226,7 @@ TString OutputHLSL::typeString(const TType &type)
for (unsigned int i = 0; i < fields.size(); i++) for (unsigned int i = 0; i < fields.size(); i++)
{ {
const TType &field = *fields[i].type; const TType &field = *fields[i];
string += " " + typeString(field) + " " + decorate(field.getFieldName()) + arrayString(field) + ";\n"; string += " " + typeString(field) + " " + decorate(field.getFieldName()) + arrayString(field) + ";\n";
} }
...@@ -2351,7 +2351,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -2351,7 +2351,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
for (unsigned int i = 0; i < fields.size(); i++) for (unsigned int i = 0; i < fields.size(); i++)
{ {
const TType &field = *fields[i].type; const TType &field = *fields[i];
structure += " " + typeString(field) + " " + decorateField(field.getFieldName(), type) + arrayString(field) + ";\n"; structure += " " + typeString(field) + " " + decorateField(field.getFieldName(), type) + arrayString(field) + ";\n";
} }
...@@ -2365,7 +2365,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -2365,7 +2365,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
for (unsigned int i = 0; i < fields.size(); i++) for (unsigned int i = 0; i < fields.size(); i++)
{ {
ctorParameters.push_back(*fields[i].type); ctorParameters.push_back(*fields[i]);
} }
} }
else if (parameters) else if (parameters)
...@@ -2540,7 +2540,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con ...@@ -2540,7 +2540,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con
for (size_t i = 0; i < structure->size(); i++) for (size_t i = 0; i < structure->size(); i++)
{ {
const TType *fieldType = (*structure)[i].type; const TType *fieldType = (*structure)[i];
constUnion = writeConstantUnion(*fieldType, constUnion); constUnion = writeConstantUnion(*fieldType, constUnion);
......
...@@ -659,7 +659,7 @@ bool TParseContext::containsSampler(TType& type) ...@@ -659,7 +659,7 @@ bool TParseContext::containsSampler(TType& type)
if (type.getBasicType() == EbtStruct) { if (type.getBasicType() == EbtStruct) {
TTypeList& structure = *type.getStruct(); TTypeList& structure = *type.getStruct();
for (unsigned int i = 0; i < structure.size(); ++i) { for (unsigned int i = 0; i < structure.size(); ++i) {
if (containsSampler(*structure[i].type)) if (containsSampler(*structure[i]))
return true; return true;
} }
} }
...@@ -1139,7 +1139,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type ...@@ -1139,7 +1139,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
if (type->isArray()) if (type->isArray())
newNode = constructStruct(node, &elementType, 1, node->getLine(), false); newNode = constructStruct(node, &elementType, 1, node->getLine(), false);
else if (op == EOpConstructStruct) else if (op == EOpConstructStruct)
newNode = constructStruct(node, (*memberTypes).type, 1, node->getLine(), false); newNode = constructStruct(node, *memberTypes, 1, node->getLine(), false);
else else
newNode = constructBuiltIn(type, op, node, node->getLine(), false); newNode = constructBuiltIn(type, op, node, node->getLine(), false);
...@@ -1170,7 +1170,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type ...@@ -1170,7 +1170,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
if (type->isArray()) if (type->isArray())
newNode = constructStruct(*p, &elementType, paramCount+1, node->getLine(), true); newNode = constructStruct(*p, &elementType, paramCount+1, node->getLine(), true);
else if (op == EOpConstructStruct) else if (op == EOpConstructStruct)
newNode = constructStruct(*p, (memberTypes[paramCount]).type, paramCount+1, node->getLine(), true); newNode = constructStruct(*p, memberTypes[paramCount], paramCount+1, node->getLine(), true);
else else
newNode = constructBuiltIn(type, op, *p, node->getLine(), true); newNode = constructBuiltIn(type, op, *p, node->getLine(), true);
...@@ -1430,10 +1430,10 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n ...@@ -1430,10 +1430,10 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion(); TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
for ( index = 0; index < fields->size(); ++index) { for ( index = 0; index < fields->size(); ++index) {
if ((*fields)[index].type->getFieldName() == identifier) { if ((*fields)[index]->getFieldName() == identifier) {
break; break;
} else { } else {
instanceSize += (*fields)[index].type->getObjectSize(); instanceSize += (*fields)[index]->getObjectSize();
} }
} }
......
...@@ -52,7 +52,7 @@ void TType::buildMangledName(TString& mangledName) ...@@ -52,7 +52,7 @@ void TType::buildMangledName(TString& mangledName)
{// support MSVC++6.0 {// support MSVC++6.0
for (unsigned int i = 0; i < structure->size(); ++i) { for (unsigned int i = 0; i < structure->size(); ++i) {
mangledName += '-'; mangledName += '-';
(*structure)[i].type->buildMangledName(mangledName); (*structure)[i]->buildMangledName(mangledName);
} }
} }
default: default:
...@@ -78,7 +78,7 @@ int TType::getStructSize() const ...@@ -78,7 +78,7 @@ int TType::getStructSize() const
if (structureSize == 0) if (structureSize == 0)
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++) for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++)
structureSize += ((*tl).type)->getObjectSize(); structureSize += (*tl)->getObjectSize();
return structureSize; return structureSize;
} }
...@@ -91,7 +91,7 @@ void TType::computeDeepestStructNesting() ...@@ -91,7 +91,7 @@ void TType::computeDeepestStructNesting()
int maxNesting = 0; int maxNesting = 0;
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); ++tl) { for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); ++tl) {
maxNesting = std::max(maxNesting, ((*tl).type)->getDeepestStructNesting()); maxNesting = std::max(maxNesting, (*tl)->getDeepestStructNesting());
} }
deepestStructNesting = 1 + maxNesting; deepestStructNesting = 1 + maxNesting;
...@@ -106,8 +106,8 @@ bool TType::isStructureContainingArrays() const ...@@ -106,8 +106,8 @@ bool TType::isStructureContainingArrays() const
for (TTypeList::const_iterator member = structure->begin(); member != structure->end(); member++) for (TTypeList::const_iterator member = structure->begin(); member != structure->end(); member++)
{ {
if (member->type->isArray() || if ((*member)->isArray() ||
member->type->isStructureContainingArrays()) (*member)->isStructureContainingArrays())
{ {
return true; return true;
} }
......
...@@ -14,14 +14,7 @@ ...@@ -14,14 +14,7 @@
class TType; class TType;
struct TPublicType; struct TPublicType;
// typedef TVector<TType*> TTypeList;
// Need to have association of line numbers to types in a list for building structs.
//
struct TTypeLine {
TType* type;
int line;
};
typedef TVector<TTypeLine> TTypeList;
inline TTypeList* NewPoolTTypeList() inline TTypeList* NewPoolTTypeList()
{ {
......
...@@ -133,7 +133,7 @@ void getUserDefinedVariableInfo(const TType& type, ...@@ -133,7 +133,7 @@ void getUserDefinedVariableInfo(const TType& type,
const TTypeList* structure = type.getStruct(); const TTypeList* structure = type.getStruct();
for (size_t i = 0; i < structure->size(); ++i) { for (size_t i = 0; i < structure->size(); ++i) {
const TType* fieldType = (*structure)[i].type; const TType* fieldType = (*structure)[i];
getVariableInfo(*fieldType, getVariableInfo(*fieldType,
name + "." + fieldType->getFieldName(), name + "." + fieldType->getFieldName(),
mappedName + "." + TIntermTraverser::hash(fieldType->getFieldName(), hashFunction), mappedName + "." + TIntermTraverser::hash(fieldType->getFieldName(), hashFunction),
......
...@@ -74,8 +74,8 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -74,8 +74,8 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
TTypeLine typeLine; TType* field;
TTypeList* typeList; TTypeList* structure;
}; };
} interm; } interm;
} }
...@@ -154,8 +154,8 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -154,8 +154,8 @@ extern void yyerror(TParseContext* context, const char* reason);
%type <interm.type> type_qualifier fully_specified_type type_specifier %type <interm.type> type_qualifier fully_specified_type type_specifier
%type <interm.type> type_specifier_no_prec type_specifier_nonarray %type <interm.type> type_specifier_no_prec type_specifier_nonarray
%type <interm.type> struct_specifier %type <interm.type> struct_specifier
%type <interm.typeLine> struct_declarator %type <interm.field> struct_declarator
%type <interm.typeList> struct_declarator_list struct_declaration struct_declaration_list %type <interm> struct_declarator_list struct_declaration struct_declaration_list
%type <interm.function> function_header function_declarator function_identifier %type <interm.function> function_header function_declarator function_identifier
%type <interm.function> function_header_with_parameters function_call_header %type <interm.function> function_header_with_parameters function_call_header
%type <interm> function_call_header_with_parameters function_call_header_no_parameters function_call_generic function_prototype %type <interm> function_call_header_with_parameters function_call_header_no_parameters function_call_generic function_prototype
...@@ -384,7 +384,7 @@ postfix_expression ...@@ -384,7 +384,7 @@ postfix_expression
} else { } else {
unsigned int i; unsigned int i;
for (i = 0; i < fields->size(); ++i) { for (i = 0; i < fields->size(); ++i) {
if ((*fields)[i].type->getFieldName() == *$3.string) { if ((*fields)[i]->getFieldName() == *$3.string) {
fieldFound = true; fieldFound = true;
break; break;
} }
...@@ -397,7 +397,7 @@ postfix_expression ...@@ -397,7 +397,7 @@ postfix_expression
$$ = $1; $$ = $1;
} }
else { else {
$$->setType(*(*fields)[i].type); $$->setType(*(*fields)[i]);
// change the qualifier of the return type, not of the structure field // change the qualifier of the return type, not of the structure field
// as the structure definition is shared between various structures. // as the structure definition is shared between various structures.
$$->getTypePointer()->setQualifier(EvqConst); $$->getTypePointer()->setQualifier(EvqConst);
...@@ -405,9 +405,9 @@ postfix_expression ...@@ -405,9 +405,9 @@ postfix_expression
} else { } else {
ConstantUnion *unionArray = new ConstantUnion[1]; ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setIConst(i); unionArray->setIConst(i);
TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, *(*fields)[i].type, $3.line); TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, *(*fields)[i], $3.line);
$$ = context->intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line); $$ = context->intermediate.addIndex(EOpIndexDirectStruct, $1, index, $2.line);
$$->setType(*(*fields)[i].type); $$->setType(*(*fields)[i]);
} }
} else { } else {
context->error($2.line, " no such field in structure", $3.string->c_str()); context->error($2.line, " no such field in structure", $3.string->c_str());
...@@ -1698,7 +1698,7 @@ struct_specifier ...@@ -1698,7 +1698,7 @@ struct_specifier
if (context->reservedErrorCheck($2.line, *$2.string)) if (context->reservedErrorCheck($2.line, *$2.string))
context->recover(); context->recover();
TType* structure = new TType($5, *$2.string); TType* structure = new TType($5.structure, *$2.string);
TVariable* userTypeDef = new TVariable($2.string, *structure, true); TVariable* userTypeDef = new TVariable($2.string, *structure, true);
if (! context->symbolTable.insert(*userTypeDef)) { if (! context->symbolTable.insert(*userTypeDef)) {
context->error($2.line, "redefinition", $2.string->c_str(), "struct"); context->error($2.line, "redefinition", $2.string->c_str(), "struct");
...@@ -1709,7 +1709,7 @@ struct_specifier ...@@ -1709,7 +1709,7 @@ struct_specifier
context->exitStructDeclaration(); context->exitStructDeclaration();
} }
| STRUCT LEFT_BRACE { if (context->enterStructDeclaration($2.line, *$2.string)) context->recover(); } struct_declaration_list RIGHT_BRACE { | STRUCT LEFT_BRACE { if (context->enterStructDeclaration($2.line, *$2.string)) context->recover(); } struct_declaration_list RIGHT_BRACE {
TType* structure = new TType($4, TString("")); TType* structure = new TType($4.structure, TString(""));
$$.setBasic(EbtStruct, EvqTemporary, $1.line); $$.setBasic(EbtStruct, EvqTemporary, $1.line);
$$.userDef = structure; $$.userDef = structure;
context->exitStructDeclaration(); context->exitStructDeclaration();
...@@ -1722,14 +1722,15 @@ struct_declaration_list ...@@ -1722,14 +1722,15 @@ struct_declaration_list
} }
| struct_declaration_list struct_declaration { | struct_declaration_list struct_declaration {
$$ = $1; $$ = $1;
for (unsigned int i = 0; i < $2->size(); ++i) { for (size_t i = 0; i < $2.structure->size(); ++i) {
for (unsigned int j = 0; j < $$->size(); ++j) { TType* field = (*$2.structure)[i];
if ((*$$)[j].type->getFieldName() == (*$2)[i].type->getFieldName()) { for (size_t j = 0; j < $$.structure->size(); ++j) {
context->error((*$2)[i].line, "duplicate field name in structure:", "struct", (*$2)[i].type->getFieldName().c_str()); if ((*$$.structure)[j]->getFieldName() == field->getFieldName()) {
context->error($2.line, "duplicate field name in structure:", "struct", field->getFieldName().c_str());
context->recover(); context->recover();
} }
} }
$$->push_back((*$2)[i]); $$.structure->push_back(field);
} }
} }
; ;
...@@ -1738,14 +1739,14 @@ struct_declaration ...@@ -1738,14 +1739,14 @@ struct_declaration
: type_specifier struct_declarator_list SEMICOLON { : type_specifier struct_declarator_list SEMICOLON {
$$ = $2; $$ = $2;
if (context->voidErrorCheck($1.line, (*$2)[0].type->getFieldName(), $1)) { if (context->voidErrorCheck($1.line, (*$2.structure)[0]->getFieldName(), $1)) {
context->recover(); context->recover();
} }
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$.structure->size(); ++i) {
// //
// Careful not to replace already known aspects of type, like array-ness // Careful not to replace already known aspects of type, like array-ness
// //
TType* type = (*$$)[i].type; TType* type = (*$$.structure)[i];
type->setBasicType($1.type); type->setBasicType($1.type);
type->setNominalSize($1.size); type->setNominalSize($1.size);
type->setMatrix($1.matrix); type->setMatrix($1.matrix);
...@@ -1772,11 +1773,11 @@ struct_declaration ...@@ -1772,11 +1773,11 @@ struct_declaration
struct_declarator_list struct_declarator_list
: struct_declarator { : struct_declarator {
$$ = NewPoolTTypeList(); $$.structure = NewPoolTTypeList();
$$->push_back($1); $$.structure->push_back($1);
} }
| struct_declarator_list COMMA struct_declarator { | struct_declarator_list COMMA struct_declarator {
$$->push_back($3); $$.structure->push_back($3);
} }
; ;
...@@ -1785,22 +1786,20 @@ struct_declarator ...@@ -1785,22 +1786,20 @@ struct_declarator
if (context->reservedErrorCheck($1.line, *$1.string)) if (context->reservedErrorCheck($1.line, *$1.string))
context->recover(); context->recover();
$$.type = new TType(EbtVoid, EbpUndefined); $$ = new TType(EbtVoid, EbpUndefined);
$$.line = $1.line; $$->setFieldName(*$1.string);
$$.type->setFieldName(*$1.string);
} }
| identifier LEFT_BRACKET constant_expression RIGHT_BRACKET { | identifier LEFT_BRACKET constant_expression RIGHT_BRACKET {
if (context->reservedErrorCheck($1.line, *$1.string)) if (context->reservedErrorCheck($1.line, *$1.string))
context->recover(); context->recover();
$$.type = new TType(EbtVoid, EbpUndefined); $$ = new TType(EbtVoid, EbpUndefined);
$$.line = $1.line; $$->setFieldName(*$1.string);
$$.type->setFieldName(*$1.string);
int size; int size;
if (context->arraySizeErrorCheck($2.line, $3, size)) if (context->arraySizeErrorCheck($2.line, $3, size))
context->recover(); context->recover();
$$.type->setArraySize(size); $$->setArraySize(size);
} }
; ;
......
/* A Bison parser, made by GNU Bison 2.5. */ /* A Bison parser, made by GNU Bison 2.4.2. */
/* Bison implementation for Yacc-like parsers in C /* Skeleton implementation for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
#define YYBISON 1 #define YYBISON 1
/* Bison version. */ /* Bison version. */
#define YYBISON_VERSION "2.5" #define YYBISON_VERSION "2.4.2"
/* Skeleton name. */ /* Skeleton name. */
#define YYSKELETON_NAME "yacc.c" #define YYSKELETON_NAME "yacc.c"
...@@ -249,8 +250,8 @@ typedef union YYSTYPE ...@@ -249,8 +250,8 @@ typedef union YYSTYPE
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
TTypeLine typeLine; TType* field;
TTypeList* typeList; TTypeList* structure;
}; };
} interm; } interm;
...@@ -394,11 +395,11 @@ YYID (yyi) ...@@ -394,11 +395,11 @@ YYID (yyi)
# define alloca _alloca # define alloca _alloca
# else # else
# define YYSTACK_ALLOC alloca # define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER) || defined __cplusplus || defined _MSC_VER)
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS # ifndef _STDLIB_H
# define EXIT_SUCCESS 0 # define _STDLIB_H 1
# endif # endif
# endif # endif
# endif # endif
...@@ -421,24 +422,24 @@ YYID (yyi) ...@@ -421,24 +422,24 @@ YYID (yyi)
# ifndef YYSTACK_ALLOC_MAXIMUM # ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif # endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \ # if (defined __cplusplus && ! defined _STDLIB_H \
&& ! ((defined YYMALLOC || defined malloc) \ && ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free))) && (defined YYFREE || defined free)))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS # ifndef _STDLIB_H
# define EXIT_SUCCESS 0 # define _STDLIB_H 1
# endif # endif
# endif # endif
# ifndef YYMALLOC # ifndef YYMALLOC
# define YYMALLOC malloc # define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER) || defined __cplusplus || defined _MSC_VER)
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif # endif
# endif # endif
# ifndef YYFREE # ifndef YYFREE
# define YYFREE free # define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER) || defined __cplusplus || defined _MSC_VER)
void free (void *); /* INFRINGES ON USER NAME SPACE */ void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif # endif
...@@ -467,7 +468,23 @@ union yyalloc ...@@ -467,7 +468,23 @@ union yyalloc
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM) + YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1 /* Copy COUNT objects from FROM to TO. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(To, From, Count) \
__builtin_memcpy (To, From, (Count) * sizeof (*(From)))
# else
# define YYCOPY(To, From, Count) \
do \
{ \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(To)[yyi] = (From)[yyi]; \
} \
while (YYID (0))
# endif
# endif
/* Relocate STACK from its old location to the new one. The /* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of local variables YYSIZE and YYSTACKSIZE give the old and new number of
...@@ -487,26 +504,6 @@ union yyalloc ...@@ -487,26 +504,6 @@ union yyalloc
#endif #endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from FROM to TO. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(To, From, Count) \
__builtin_memcpy (To, From, (Count) * sizeof (*(From)))
# else
# define YYCOPY(To, From, Count) \
do \
{ \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(To)[yyi] = (From)[yyi]; \
} \
while (YYID (0))
# endif
# endif
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
#define YYFINAL 74 #define YYFINAL 74
/* YYLAST -- Last index in YYTABLE. */ /* YYLAST -- Last index in YYTABLE. */
...@@ -676,13 +673,13 @@ static const yytype_uint16 yyrline[] = ...@@ -676,13 +673,13 @@ static const yytype_uint16 yyrline[] =
1520, 1530, 1537, 1540, 1543, 1549, 1552, 1567, 1571, 1575, 1520, 1530, 1537, 1540, 1543, 1549, 1552, 1567, 1571, 1575,
1579, 1588, 1593, 1598, 1603, 1608, 1613, 1618, 1623, 1628, 1579, 1588, 1593, 1598, 1603, 1608, 1613, 1618, 1623, 1628,
1633, 1639, 1645, 1651, 1656, 1661, 1670, 1679, 1684, 1697, 1633, 1639, 1645, 1651, 1656, 1661, 1670, 1679, 1684, 1697,
1697, 1711, 1711, 1720, 1723, 1738, 1774, 1778, 1784, 1792, 1697, 1711, 1711, 1720, 1723, 1739, 1775, 1779, 1785, 1792,
1808, 1812, 1816, 1817, 1823, 1824, 1825, 1826, 1827, 1831, 1807, 1811, 1815, 1816, 1822, 1823, 1824, 1825, 1826, 1830,
1832, 1832, 1832, 1842, 1843, 1847, 1847, 1848, 1848, 1853, 1831, 1831, 1831, 1841, 1842, 1846, 1846, 1847, 1847, 1852,
1856, 1866, 1869, 1875, 1876, 1880, 1888, 1892, 1902, 1907, 1855, 1865, 1868, 1874, 1875, 1879, 1887, 1891, 1901, 1906,
1924, 1924, 1929, 1929, 1936, 1936, 1944, 1947, 1953, 1956, 1923, 1923, 1928, 1928, 1935, 1935, 1943, 1946, 1952, 1955,
1962, 1966, 1973, 1980, 1987, 1994, 2005, 2014, 2018, 2025, 1961, 1965, 1972, 1979, 1986, 1993, 2004, 2013, 2017, 2024,
2028, 2034, 2034 2027, 2033, 2033
}; };
#endif #endif
...@@ -809,8 +806,8 @@ static const yytype_uint8 yyr2[] = ...@@ -809,8 +806,8 @@ static const yytype_uint8 yyr2[] =
1, 0, 3 1, 0, 3
}; };
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
Performed when YYTABLE doesn't specify something else to do. Zero STATE-NUM when YYTABLE doesn't specify something else to do. Zero
means the default is an error. */ means the default is an error. */
static const yytype_uint8 yydefact[] = static const yytype_uint8 yydefact[] =
{ {
...@@ -915,7 +912,8 @@ static const yytype_int16 yypgoto[] = ...@@ -915,7 +912,8 @@ static const yytype_int16 yypgoto[] =
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which positive, shift that token. If negative, reduce the rule which
number is the opposite. If YYTABLE_NINF, syntax error. */ number is the opposite. If zero, do what YYDEFACT says.
If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF -166 #define YYTABLE_NINF -166
static const yytype_int16 yytable[] = static const yytype_int16 yytable[] =
{ {
...@@ -1071,12 +1069,6 @@ static const yytype_int16 yytable[] = ...@@ -1071,12 +1069,6 @@ static const yytype_int16 yytable[] =
31 31
}; };
#define yypact_value_is_default(yystate) \
((yystate) == (-261))
#define yytable_value_is_error(yytable_value) \
YYID (0)
static const yytype_int16 yycheck[] = static const yytype_int16 yycheck[] =
{ {
0, 25, 89, 88, 96, 57, 162, 73, 153, 128, 0, 25, 89, 88, 96, 57, 162, 73, 153, 128,
...@@ -1301,6 +1293,7 @@ do \ ...@@ -1301,6 +1293,7 @@ do \
{ \ { \
yychar = (Token); \ yychar = (Token); \
yylval = (Value); \ yylval = (Value); \
yytoken = YYTRANSLATE (yychar); \
YYPOPSTACK (1); \ YYPOPSTACK (1); \
goto yybackup; \ goto yybackup; \
} \ } \
...@@ -1342,10 +1335,19 @@ while (YYID (0)) ...@@ -1342,10 +1335,19 @@ while (YYID (0))
#endif #endif
/* This macro is provided for backward compatibility. */ /* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */
#ifndef YY_LOCATION_PRINT #ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0) # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
# define YY_LOCATION_PRINT(File, Loc) \
fprintf (File, "%d.%d-%d.%d", \
(Loc).first_line, (Loc).first_column, \
(Loc).last_line, (Loc).last_column)
# else
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
# endif
#endif #endif
...@@ -1541,6 +1543,7 @@ int yydebug; ...@@ -1541,6 +1543,7 @@ int yydebug;
# define YYMAXDEPTH 10000 # define YYMAXDEPTH 10000
#endif #endif
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
...@@ -1643,142 +1646,115 @@ yytnamerr (char *yyres, const char *yystr) ...@@ -1643,142 +1646,115 @@ yytnamerr (char *yyres, const char *yystr)
} }
# endif # endif
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message /* Copy into YYRESULT an error message about the unexpected token
about the unexpected token YYTOKEN for the state stack whose top is YYCHAR while in state YYSTATE. Return the number of bytes copied,
YYSSP. including the terminating null byte. If YYRESULT is null, do not
copy anything; just return the number of bytes that would be
Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is copied. As a special case, return 0 if an ordinary "syntax error"
not large enough to hold the message. In that case, also set message will do. Return YYSIZE_MAXIMUM if overflow occurs during
*YYMSG_ALLOC to the required number of bytes. Return 2 if the size calculation. */
required number of bytes is too large to store. */ static YYSIZE_T
static int yysyntax_error (char *yyresult, int yystate, int yychar)
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yytype_int16 *yyssp, int yytoken)
{ {
YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); int yyn = yypact[yystate];
YYSIZE_T yysize = yysize0;
YYSIZE_T yysize1;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
const char *yyformat = 0;
/* Arguments of yyformat. */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Number of reported tokens (one for the "unexpected", one per
"expected"). */
int yycount = 0;
/* There are many possibilities here to consider:
- Assume YYFAIL is not used. It's too flawed to consider. See
<http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
for details. YYERROR is fine as it does not invoke this
function.
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yychar) is if
this state is a consistent state with a default action. Thus,
detecting the absence of a lookahead is sufficient to determine
that there is no unexpected or expected token to report. In that
case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state merging
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.
*/
if (yytoken != YYEMPTY)
{
int yyn = yypact[*yyssp];
yyarg[yycount++] = yytname[yytoken];
if (!yypact_value_is_default (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
break;
}
yyarg[yycount++] = yytname[yyx];
yysize1 = yysize + yytnamerr (0, yytname[yyx]);
if (! (yysize <= yysize1
&& yysize1 <= YYSTACK_ALLOC_MAXIMUM))
return 2;
yysize = yysize1;
}
}
}
switch (yycount) if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
return 0;
else
{ {
# define YYCASE_(N, S) \ int yytype = YYTRANSLATE (yychar);
case N: \ YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
yyformat = S; \ YYSIZE_T yysize = yysize0;
break YYSIZE_T yysize1;
YYCASE_(0, YY_("syntax error")); int yysize_overflow = 0;
YYCASE_(1, YY_("syntax error, unexpected %s")); enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); int yyx;
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); # if 0
# undef YYCASE_ /* This is so xgettext sees the translatable formats that are
} constructed on the fly. */
YY_("syntax error, unexpected %s");
YY_("syntax error, unexpected %s, expecting %s");
YY_("syntax error, unexpected %s, expecting %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s");
YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
# endif
char *yyfmt;
char const *yyf;
static char const yyunexpected[] = "syntax error, unexpected %s";
static char const yyexpecting[] = ", expecting %s";
static char const yyor[] = " or %s";
char yyformat[sizeof yyunexpected
+ sizeof yyexpecting - 1
+ ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
* (sizeof yyor - 1))];
char const *yyprefix = yyexpecting;
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yycount = 1;
yyarg[0] = yytname[yytype];
yyfmt = yystpcpy (yyformat, yyunexpected);
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
yyformat[sizeof yyunexpected - 1] = '\0';
break;
}
yyarg[yycount++] = yytname[yyx];
yysize1 = yysize + yytnamerr (0, yytname[yyx]);
yysize_overflow |= (yysize1 < yysize);
yysize = yysize1;
yyfmt = yystpcpy (yyfmt, yyprefix);
yyprefix = yyor;
}
yysize1 = yysize + yystrlen (yyformat); yyf = YY_(yyformat);
if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) yysize1 = yysize + yystrlen (yyf);
return 2; yysize_overflow |= (yysize1 < yysize);
yysize = yysize1; yysize = yysize1;
if (*yymsg_alloc < yysize) if (yysize_overflow)
{ return YYSIZE_MAXIMUM;
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return 1;
}
/* Avoid sprintf, as that infringes on the user's name space. if (yyresult)
Don't have undefined behavior even if the translation {
produced a string with the wrong number of "%s"s. */ /* Avoid sprintf, as that infringes on the user's name space.
{ Don't have undefined behavior even if the translation
char *yyp = *yymsg; produced a string with the wrong number of "%s"s. */
int yyi = 0; char *yyp = yyresult;
while ((*yyp = *yyformat) != '\0') int yyi = 0;
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) while ((*yyp = *yyf) != '\0')
{ {
yyp += yytnamerr (yyp, yyarg[yyi++]); if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
yyformat += 2; {
} yyp += yytnamerr (yyp, yyarg[yyi++]);
else yyf += 2;
{ }
yyp++; else
yyformat++; {
} yyp++;
} yyf++;
return 0; }
}
}
return yysize;
}
} }
#endif /* YYERROR_VERBOSE */ #endif /* YYERROR_VERBOSE */
/*-----------------------------------------------. /*-----------------------------------------------.
| Release the memory associated to this symbol. | | Release the memory associated to this symbol. |
...@@ -1813,7 +1789,6 @@ yydestruct (yymsg, yytype, yyvaluep, context) ...@@ -1813,7 +1789,6 @@ yydestruct (yymsg, yytype, yyvaluep, context)
} }
} }
/* Prevent warnings from -Wmissing-prototypes. */ /* Prevent warnings from -Wmissing-prototypes. */
#ifdef YYPARSE_PARAM #ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus #if defined __STDC__ || defined __cplusplus
...@@ -1830,9 +1805,12 @@ int yyparse (); ...@@ -1830,9 +1805,12 @@ int yyparse ();
#endif /* ! YYPARSE_PARAM */ #endif /* ! YYPARSE_PARAM */
/*----------.
| yyparse. |
`----------*/
/*-------------------------.
| yyparse or yypush_parse. |
`-------------------------*/
#ifdef YYPARSE_PARAM #ifdef YYPARSE_PARAM
#if (defined __STDC__ || defined __C99__FUNC__ \ #if (defined __STDC__ || defined __C99__FUNC__ \
...@@ -2019,7 +1997,7 @@ yybackup: ...@@ -2019,7 +1997,7 @@ yybackup:
/* First try to decide what to do without reference to lookahead token. */ /* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate]; yyn = yypact[yystate];
if (yypact_value_is_default (yyn)) if (yyn == YYPACT_NINF)
goto yydefault; goto yydefault;
/* Not known => get a lookahead token if don't already have one. */ /* Not known => get a lookahead token if don't already have one. */
...@@ -2050,8 +2028,8 @@ yybackup: ...@@ -2050,8 +2028,8 @@ yybackup:
yyn = yytable[yyn]; yyn = yytable[yyn];
if (yyn <= 0) if (yyn <= 0)
{ {
if (yytable_value_is_error (yyn)) if (yyn == 0 || yyn == YYTABLE_NINF)
goto yyerrlab; goto yyerrlab;
yyn = -yyn; yyn = -yyn;
goto yyreduce; goto yyreduce;
} }
...@@ -2351,7 +2329,7 @@ yyreduce: ...@@ -2351,7 +2329,7 @@ yyreduce:
} else { } else {
unsigned int i; unsigned int i;
for (i = 0; i < fields->size(); ++i) { for (i = 0; i < fields->size(); ++i) {
if ((*fields)[i].type->getFieldName() == *(yyvsp[(3) - (3)].lex).string) { if ((*fields)[i]->getFieldName() == *(yyvsp[(3) - (3)].lex).string) {
fieldFound = true; fieldFound = true;
break; break;
} }
...@@ -2364,7 +2342,7 @@ yyreduce: ...@@ -2364,7 +2342,7 @@ yyreduce:
(yyval.interm.intermTypedNode) = (yyvsp[(1) - (3)].interm.intermTypedNode); (yyval.interm.intermTypedNode) = (yyvsp[(1) - (3)].interm.intermTypedNode);
} }
else { else {
(yyval.interm.intermTypedNode)->setType(*(*fields)[i].type); (yyval.interm.intermTypedNode)->setType(*(*fields)[i]);
// change the qualifier of the return type, not of the structure field // change the qualifier of the return type, not of the structure field
// as the structure definition is shared between various structures. // as the structure definition is shared between various structures.
(yyval.interm.intermTypedNode)->getTypePointer()->setQualifier(EvqConst); (yyval.interm.intermTypedNode)->getTypePointer()->setQualifier(EvqConst);
...@@ -2372,9 +2350,9 @@ yyreduce: ...@@ -2372,9 +2350,9 @@ yyreduce:
} else { } else {
ConstantUnion *unionArray = new ConstantUnion[1]; ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setIConst(i); unionArray->setIConst(i);
TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, *(*fields)[i].type, (yyvsp[(3) - (3)].lex).line); TIntermTyped* index = context->intermediate.addConstantUnion(unionArray, *(*fields)[i], (yyvsp[(3) - (3)].lex).line);
(yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexDirectStruct, (yyvsp[(1) - (3)].interm.intermTypedNode), index, (yyvsp[(2) - (3)].lex).line); (yyval.interm.intermTypedNode) = context->intermediate.addIndex(EOpIndexDirectStruct, (yyvsp[(1) - (3)].interm.intermTypedNode), index, (yyvsp[(2) - (3)].lex).line);
(yyval.interm.intermTypedNode)->setType(*(*fields)[i].type); (yyval.interm.intermTypedNode)->setType(*(*fields)[i]);
} }
} else { } else {
context->error((yyvsp[(2) - (3)].lex).line, " no such field in structure", (yyvsp[(3) - (3)].lex).string->c_str()); context->error((yyvsp[(2) - (3)].lex).line, " no such field in structure", (yyvsp[(3) - (3)].lex).string->c_str());
...@@ -3952,7 +3930,7 @@ yyreduce: ...@@ -3952,7 +3930,7 @@ yyreduce:
if (context->reservedErrorCheck((yyvsp[(2) - (6)].lex).line, *(yyvsp[(2) - (6)].lex).string)) if (context->reservedErrorCheck((yyvsp[(2) - (6)].lex).line, *(yyvsp[(2) - (6)].lex).string))
context->recover(); context->recover();
TType* structure = new TType((yyvsp[(5) - (6)].interm.typeList), *(yyvsp[(2) - (6)].lex).string); TType* structure = new TType((yyvsp[(5) - (6)].interm).structure, *(yyvsp[(2) - (6)].lex).string);
TVariable* userTypeDef = new TVariable((yyvsp[(2) - (6)].lex).string, *structure, true); TVariable* userTypeDef = new TVariable((yyvsp[(2) - (6)].lex).string, *structure, true);
if (! context->symbolTable.insert(*userTypeDef)) { if (! context->symbolTable.insert(*userTypeDef)) {
context->error((yyvsp[(2) - (6)].lex).line, "redefinition", (yyvsp[(2) - (6)].lex).string->c_str(), "struct"); context->error((yyvsp[(2) - (6)].lex).line, "redefinition", (yyvsp[(2) - (6)].lex).string->c_str(), "struct");
...@@ -3972,7 +3950,7 @@ yyreduce: ...@@ -3972,7 +3950,7 @@ yyreduce:
case 142: case 142:
{ {
TType* structure = new TType((yyvsp[(4) - (5)].interm.typeList), TString("")); TType* structure = new TType((yyvsp[(4) - (5)].interm).structure, TString(""));
(yyval.interm.type).setBasic(EbtStruct, EvqTemporary, (yyvsp[(1) - (5)].lex).line); (yyval.interm.type).setBasic(EbtStruct, EvqTemporary, (yyvsp[(1) - (5)].lex).line);
(yyval.interm.type).userDef = structure; (yyval.interm.type).userDef = structure;
context->exitStructDeclaration(); context->exitStructDeclaration();
...@@ -3982,22 +3960,23 @@ yyreduce: ...@@ -3982,22 +3960,23 @@ yyreduce:
case 143: case 143:
{ {
(yyval.interm.typeList) = (yyvsp[(1) - (1)].interm.typeList); (yyval.interm) = (yyvsp[(1) - (1)].interm);
} }
break; break;
case 144: case 144:
{ {
(yyval.interm.typeList) = (yyvsp[(1) - (2)].interm.typeList); (yyval.interm) = (yyvsp[(1) - (2)].interm);
for (unsigned int i = 0; i < (yyvsp[(2) - (2)].interm.typeList)->size(); ++i) { for (size_t i = 0; i < (yyvsp[(2) - (2)].interm).structure->size(); ++i) {
for (unsigned int j = 0; j < (yyval.interm.typeList)->size(); ++j) { TType* field = (*(yyvsp[(2) - (2)].interm).structure)[i];
if ((*(yyval.interm.typeList))[j].type->getFieldName() == (*(yyvsp[(2) - (2)].interm.typeList))[i].type->getFieldName()) { for (size_t j = 0; j < (yyval.interm).structure->size(); ++j) {
context->error((*(yyvsp[(2) - (2)].interm.typeList))[i].line, "duplicate field name in structure:", "struct", (*(yyvsp[(2) - (2)].interm.typeList))[i].type->getFieldName().c_str()); if ((*(yyval.interm).structure)[j]->getFieldName() == field->getFieldName()) {
context->error((yyvsp[(2) - (2)].interm).line, "duplicate field name in structure:", "struct", field->getFieldName().c_str());
context->recover(); context->recover();
} }
} }
(yyval.interm.typeList)->push_back((*(yyvsp[(2) - (2)].interm.typeList))[i]); (yyval.interm).structure->push_back(field);
} }
} }
break; break;
...@@ -4005,16 +3984,16 @@ yyreduce: ...@@ -4005,16 +3984,16 @@ yyreduce:
case 145: case 145:
{ {
(yyval.interm.typeList) = (yyvsp[(2) - (3)].interm.typeList); (yyval.interm) = (yyvsp[(2) - (3)].interm);
if (context->voidErrorCheck((yyvsp[(1) - (3)].interm.type).line, (*(yyvsp[(2) - (3)].interm.typeList))[0].type->getFieldName(), (yyvsp[(1) - (3)].interm.type))) { if (context->voidErrorCheck((yyvsp[(1) - (3)].interm.type).line, (*(yyvsp[(2) - (3)].interm).structure)[0]->getFieldName(), (yyvsp[(1) - (3)].interm.type))) {
context->recover(); context->recover();
} }
for (unsigned int i = 0; i < (yyval.interm.typeList)->size(); ++i) { for (unsigned int i = 0; i < (yyval.interm).structure->size(); ++i) {
// //
// Careful not to replace already known aspects of type, like array-ness // Careful not to replace already known aspects of type, like array-ness
// //
TType* type = (*(yyval.interm.typeList))[i].type; TType* type = (*(yyval.interm).structure)[i];
type->setBasicType((yyvsp[(1) - (3)].interm.type).type); type->setBasicType((yyvsp[(1) - (3)].interm.type).type);
type->setNominalSize((yyvsp[(1) - (3)].interm.type).size); type->setNominalSize((yyvsp[(1) - (3)].interm.type).size);
type->setMatrix((yyvsp[(1) - (3)].interm.type).matrix); type->setMatrix((yyvsp[(1) - (3)].interm.type).matrix);
...@@ -4042,15 +4021,15 @@ yyreduce: ...@@ -4042,15 +4021,15 @@ yyreduce:
case 146: case 146:
{ {
(yyval.interm.typeList) = NewPoolTTypeList(); (yyval.interm).structure = NewPoolTTypeList();
(yyval.interm.typeList)->push_back((yyvsp[(1) - (1)].interm.typeLine)); (yyval.interm).structure->push_back((yyvsp[(1) - (1)].interm.field));
} }
break; break;
case 147: case 147:
{ {
(yyval.interm.typeList)->push_back((yyvsp[(3) - (3)].interm.typeLine)); (yyval.interm).structure->push_back((yyvsp[(3) - (3)].interm.field));
} }
break; break;
...@@ -4060,9 +4039,8 @@ yyreduce: ...@@ -4060,9 +4039,8 @@ yyreduce:
if (context->reservedErrorCheck((yyvsp[(1) - (1)].lex).line, *(yyvsp[(1) - (1)].lex).string)) if (context->reservedErrorCheck((yyvsp[(1) - (1)].lex).line, *(yyvsp[(1) - (1)].lex).string))
context->recover(); context->recover();
(yyval.interm.typeLine).type = new TType(EbtVoid, EbpUndefined); (yyval.interm.field) = new TType(EbtVoid, EbpUndefined);
(yyval.interm.typeLine).line = (yyvsp[(1) - (1)].lex).line; (yyval.interm.field)->setFieldName(*(yyvsp[(1) - (1)].lex).string);
(yyval.interm.typeLine).type->setFieldName(*(yyvsp[(1) - (1)].lex).string);
} }
break; break;
...@@ -4072,14 +4050,13 @@ yyreduce: ...@@ -4072,14 +4050,13 @@ yyreduce:
if (context->reservedErrorCheck((yyvsp[(1) - (4)].lex).line, *(yyvsp[(1) - (4)].lex).string)) if (context->reservedErrorCheck((yyvsp[(1) - (4)].lex).line, *(yyvsp[(1) - (4)].lex).string))
context->recover(); context->recover();
(yyval.interm.typeLine).type = new TType(EbtVoid, EbpUndefined); (yyval.interm.field) = new TType(EbtVoid, EbpUndefined);
(yyval.interm.typeLine).line = (yyvsp[(1) - (4)].lex).line; (yyval.interm.field)->setFieldName(*(yyvsp[(1) - (4)].lex).string);
(yyval.interm.typeLine).type->setFieldName(*(yyvsp[(1) - (4)].lex).string);
int size; int size;
if (context->arraySizeErrorCheck((yyvsp[(2) - (4)].lex).line, (yyvsp[(3) - (4)].interm.intermTypedNode), size)) if (context->arraySizeErrorCheck((yyvsp[(2) - (4)].lex).line, (yyvsp[(3) - (4)].interm.intermTypedNode), size))
context->recover(); context->recover();
(yyval.interm.typeLine).type->setArraySize(size); (yyval.interm.field)->setArraySize(size);
} }
break; break;
...@@ -4572,17 +4549,6 @@ yyreduce: ...@@ -4572,17 +4549,6 @@ yyreduce:
default: break; default: break;
} }
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action invokes
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
incorrect destructor might then be invoked immediately. In the
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
YYPOPSTACK (yylen); YYPOPSTACK (yylen);
...@@ -4610,10 +4576,6 @@ yyreduce: ...@@ -4610,10 +4576,6 @@ yyreduce:
| yyerrlab -- here on detecting error | | yyerrlab -- here on detecting error |
`------------------------------------*/ `------------------------------------*/
yyerrlab: yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */ /* If not already recovering from an error, report this error. */
if (!yyerrstatus) if (!yyerrstatus)
{ {
...@@ -4621,36 +4583,37 @@ yyerrlab: ...@@ -4621,36 +4583,37 @@ yyerrlab:
#if ! YYERROR_VERBOSE #if ! YYERROR_VERBOSE
yyerror (context, YY_("syntax error")); yyerror (context, YY_("syntax error"));
#else #else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
{ {
char const *yymsgp = YY_("syntax error"); YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
int yysyntax_error_status; if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
yysyntax_error_status = YYSYNTAX_ERROR; {
if (yysyntax_error_status == 0) YYSIZE_T yyalloc = 2 * yysize;
yymsgp = yymsg; if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
else if (yysyntax_error_status == 1) yyalloc = YYSTACK_ALLOC_MAXIMUM;
{ if (yymsg != yymsgbuf)
if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg);
YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yyalloc);
yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); if (yymsg)
if (!yymsg) yymsg_alloc = yyalloc;
{ else
yymsg = yymsgbuf; {
yymsg_alloc = sizeof yymsgbuf; yymsg = yymsgbuf;
yysyntax_error_status = 2; yymsg_alloc = sizeof yymsgbuf;
} }
else }
{
yysyntax_error_status = YYSYNTAX_ERROR; if (0 < yysize && yysize <= yymsg_alloc)
yymsgp = yymsg; {
} (void) yysyntax_error (yymsg, yystate, yychar);
} yyerror (context, yymsg);
yyerror (context, yymsgp); }
if (yysyntax_error_status == 2) else
goto yyexhaustedlab; {
yyerror (context, YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
}
} }
# undef YYSYNTAX_ERROR
#endif #endif
} }
...@@ -4709,7 +4672,7 @@ yyerrlab1: ...@@ -4709,7 +4672,7 @@ yyerrlab1:
for (;;) for (;;)
{ {
yyn = yypact[yystate]; yyn = yypact[yystate];
if (!yypact_value_is_default (yyn)) if (yyn != YYPACT_NINF)
{ {
yyn += YYTERROR; yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
...@@ -4768,13 +4731,8 @@ yyexhaustedlab: ...@@ -4768,13 +4731,8 @@ yyexhaustedlab:
yyreturn: yyreturn:
if (yychar != YYEMPTY) if (yychar != YYEMPTY)
{ yydestruct ("Cleanup: discarding lookahead",
/* Make sure we have latest lookahead translation. See comments at yytoken, &yylval, context);
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval, context);
}
/* Do not reclaim the symbols of the rule which action triggered /* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */ this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen); YYPOPSTACK (yylen);
......
/* A Bison parser, made by GNU Bison 2.5. */ /* A Bison parser, made by GNU Bison 2.4.2. */
/* Bison interface for Yacc-like parsers in C /* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -164,8 +165,8 @@ typedef union YYSTYPE ...@@ -164,8 +165,8 @@ typedef union YYSTYPE
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
TTypeLine typeLine; TType* field;
TTypeList* typeList; TTypeList* structure;
}; };
} interm; } interm;
......
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