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
int index = 0;
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++) {
if ((*fields)[j].type->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j].type, &rightUnionArray[index], &leftUnionArray[index]))
if ((*fields)[j]->getBasicType() == EbtStruct) {
if (!CompareStructure(*(*fields)[j], &rightUnionArray[index], &leftUnionArray[index]))
return false;
} else {
if (leftUnionArray[index] != rightUnionArray[index])
......
......@@ -87,7 +87,7 @@ void TOutputGLSLBase::writeVariableType(const TType& type)
ASSERT(structure != NULL);
for (size_t i = 0; i < structure->size(); ++i)
{
const TType* fieldType = (*structure)[i].type;
const TType* fieldType = (*structure)[i];
ASSERT(fieldType != NULL);
if (writeVariablePrecision(fieldType->getPrecision()))
out << " ";
......@@ -143,7 +143,7 @@ const ConstantUnion* TOutputGLSLBase::writeConstantUnion(const TType& type,
ASSERT(structure != NULL);
for (size_t i = 0; i < structure->size(); ++i)
{
const TType* fieldType = (*structure)[i].type;
const TType* fieldType = (*structure)[i];
ASSERT(fieldType != NULL);
pConstUnion = writeConstantUnion(*fieldType, pConstUnion);
if (i != structure->size() - 1) out << ", ";
......
......@@ -1025,7 +1025,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
for (size_t i = 0; i < fields->size(); i++)
{
const TType *fieldType = (*fields)[i].type;
const TType *fieldType = (*fields)[i];
node->getLeft()->traverse(this);
out << "." + decorateField(fieldType->getFieldName(), node->getLeft()->getType()) + " == ";
......@@ -2226,7 +2226,7 @@ TString OutputHLSL::typeString(const TType &type)
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";
}
......@@ -2351,7 +2351,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
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";
}
......@@ -2365,7 +2365,7 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
for (unsigned int i = 0; i < fields.size(); i++)
{
ctorParameters.push_back(*fields[i].type);
ctorParameters.push_back(*fields[i]);
}
}
else if (parameters)
......@@ -2540,7 +2540,7 @@ const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const Con
for (size_t i = 0; i < structure->size(); i++)
{
const TType *fieldType = (*structure)[i].type;
const TType *fieldType = (*structure)[i];
constUnion = writeConstantUnion(*fieldType, constUnion);
......
......@@ -659,7 +659,7 @@ bool TParseContext::containsSampler(TType& type)
if (type.getBasicType() == EbtStruct) {
TTypeList& structure = *type.getStruct();
for (unsigned int i = 0; i < structure.size(); ++i) {
if (containsSampler(*structure[i].type))
if (containsSampler(*structure[i]))
return true;
}
}
......@@ -1139,7 +1139,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
if (type->isArray())
newNode = constructStruct(node, &elementType, 1, node->getLine(), false);
else if (op == EOpConstructStruct)
newNode = constructStruct(node, (*memberTypes).type, 1, node->getLine(), false);
newNode = constructStruct(node, *memberTypes, 1, node->getLine(), false);
else
newNode = constructBuiltIn(type, op, node, node->getLine(), false);
......@@ -1170,7 +1170,7 @@ TIntermTyped* TParseContext::addConstructor(TIntermNode* node, const TType* type
if (type->isArray())
newNode = constructStruct(*p, &elementType, paramCount+1, node->getLine(), true);
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
newNode = constructBuiltIn(type, op, *p, node->getLine(), true);
......@@ -1430,10 +1430,10 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
for ( index = 0; index < fields->size(); ++index) {
if ((*fields)[index].type->getFieldName() == identifier) {
if ((*fields)[index]->getFieldName() == identifier) {
break;
} else {
instanceSize += (*fields)[index].type->getObjectSize();
instanceSize += (*fields)[index]->getObjectSize();
}
}
......
......@@ -52,7 +52,7 @@ void TType::buildMangledName(TString& mangledName)
{// support MSVC++6.0
for (unsigned int i = 0; i < structure->size(); ++i) {
mangledName += '-';
(*structure)[i].type->buildMangledName(mangledName);
(*structure)[i]->buildMangledName(mangledName);
}
}
default:
......@@ -78,7 +78,7 @@ int TType::getStructSize() const
if (structureSize == 0)
for (TTypeList::const_iterator tl = getStruct()->begin(); tl != getStruct()->end(); tl++)
structureSize += ((*tl).type)->getObjectSize();
structureSize += (*tl)->getObjectSize();
return structureSize;
}
......@@ -91,7 +91,7 @@ void TType::computeDeepestStructNesting()
int maxNesting = 0;
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;
......@@ -106,8 +106,8 @@ bool TType::isStructureContainingArrays() const
for (TTypeList::const_iterator member = structure->begin(); member != structure->end(); member++)
{
if (member->type->isArray() ||
member->type->isStructureContainingArrays())
if ((*member)->isArray() ||
(*member)->isStructureContainingArrays())
{
return true;
}
......
......@@ -14,14 +14,7 @@
class TType;
struct TPublicType;
//
// 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;
typedef TVector<TType*> TTypeList;
inline TTypeList* NewPoolTTypeList()
{
......
......@@ -133,7 +133,7 @@ void getUserDefinedVariableInfo(const TType& type,
const TTypeList* structure = type.getStruct();
for (size_t i = 0; i < structure->size(); ++i) {
const TType* fieldType = (*structure)[i].type;
const TType* fieldType = (*structure)[i];
getVariableInfo(*fieldType,
name + "." + fieldType->getFieldName(),
mappedName + "." + TIntermTraverser::hash(fieldType->getFieldName(), hashFunction),
......
......@@ -74,8 +74,8 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
TQualifier qualifier;
TFunction* function;
TParameter param;
TTypeLine typeLine;
TTypeList* typeList;
TType* field;
TTypeList* structure;
};
} interm;
}
......@@ -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_specifier_no_prec type_specifier_nonarray
%type <interm.type> struct_specifier
%type <interm.typeLine> struct_declarator
%type <interm.typeList> struct_declarator_list struct_declaration struct_declaration_list
%type <interm.field> struct_declarator
%type <interm> struct_declarator_list struct_declaration struct_declaration_list
%type <interm.function> function_header function_declarator function_identifier
%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
......@@ -384,7 +384,7 @@ postfix_expression
} else {
unsigned int i;
for (i = 0; i < fields->size(); ++i) {
if ((*fields)[i].type->getFieldName() == *$3.string) {
if ((*fields)[i]->getFieldName() == *$3.string) {
fieldFound = true;
break;
}
......@@ -397,7 +397,7 @@ postfix_expression
$$ = $1;
}
else {
$$->setType(*(*fields)[i].type);
$$->setType(*(*fields)[i]);
// change the qualifier of the return type, not of the structure field
// as the structure definition is shared between various structures.
$$->getTypePointer()->setQualifier(EvqConst);
......@@ -405,9 +405,9 @@ postfix_expression
} else {
ConstantUnion *unionArray = new ConstantUnion[1];
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);
$$->setType(*(*fields)[i].type);
$$->setType(*(*fields)[i]);
}
} else {
context->error($2.line, " no such field in structure", $3.string->c_str());
......@@ -1698,7 +1698,7 @@ struct_specifier
if (context->reservedErrorCheck($2.line, *$2.string))
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);
if (! context->symbolTable.insert(*userTypeDef)) {
context->error($2.line, "redefinition", $2.string->c_str(), "struct");
......@@ -1709,7 +1709,7 @@ struct_specifier
context->exitStructDeclaration();
}
| 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);
$$.userDef = structure;
context->exitStructDeclaration();
......@@ -1722,14 +1722,15 @@ struct_declaration_list
}
| struct_declaration_list struct_declaration {
$$ = $1;
for (unsigned int i = 0; i < $2->size(); ++i) {
for (unsigned int j = 0; j < $$->size(); ++j) {
if ((*$$)[j].type->getFieldName() == (*$2)[i].type->getFieldName()) {
context->error((*$2)[i].line, "duplicate field name in structure:", "struct", (*$2)[i].type->getFieldName().c_str());
for (size_t i = 0; i < $2.structure->size(); ++i) {
TType* field = (*$2.structure)[i];
for (size_t j = 0; j < $$.structure->size(); ++j) {
if ((*$$.structure)[j]->getFieldName() == field->getFieldName()) {
context->error($2.line, "duplicate field name in structure:", "struct", field->getFieldName().c_str());
context->recover();
}
}
$$->push_back((*$2)[i]);
$$.structure->push_back(field);
}
}
;
......@@ -1738,14 +1739,14 @@ struct_declaration
: type_specifier struct_declarator_list SEMICOLON {
$$ = $2;
if (context->voidErrorCheck($1.line, (*$2)[0].type->getFieldName(), $1)) {
if (context->voidErrorCheck($1.line, (*$2.structure)[0]->getFieldName(), $1)) {
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
//
TType* type = (*$$)[i].type;
TType* type = (*$$.structure)[i];
type->setBasicType($1.type);
type->setNominalSize($1.size);
type->setMatrix($1.matrix);
......@@ -1772,11 +1773,11 @@ struct_declaration
struct_declarator_list
: struct_declarator {
$$ = NewPoolTTypeList();
$$->push_back($1);
$$.structure = NewPoolTTypeList();
$$.structure->push_back($1);
}
| struct_declarator_list COMMA struct_declarator {
$$->push_back($3);
$$.structure->push_back($3);
}
;
......@@ -1785,22 +1786,20 @@ struct_declarator
if (context->reservedErrorCheck($1.line, *$1.string))
context->recover();
$$.type = new TType(EbtVoid, EbpUndefined);
$$.line = $1.line;
$$.type->setFieldName(*$1.string);
$$ = new TType(EbtVoid, EbpUndefined);
$$->setFieldName(*$1.string);
}
| identifier LEFT_BRACKET constant_expression RIGHT_BRACKET {
if (context->reservedErrorCheck($1.line, *$1.string))
context->recover();
$$.type = new TType(EbtVoid, EbpUndefined);
$$.line = $1.line;
$$.type->setFieldName(*$1.string);
$$ = new TType(EbtVoid, EbpUndefined);
$$->setFieldName(*$1.string);
int size;
if (context->arraySizeErrorCheck($2.line, $3, size))
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 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
it under the terms of the GNU General Public License as published by
......@@ -164,8 +165,8 @@ typedef union YYSTYPE
TQualifier qualifier;
TFunction* function;
TParameter param;
TTypeLine typeLine;
TTypeList* typeList;
TType* field;
TTypeList* structure;
};
} 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