// // This function returns the value of a particular field inside a constant structure from the symbol table. // If there is an embedded/nested struct, it appropriately calls addConstStructNested or addConstStructFromAggr // function and returns the parse-tree with the values of the embedded/nested struct. // TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* node, TSourceLoc line) { TTypeList* fields = node->getType().getStruct(); TIntermTyped *typedNode; int instanceSize = 0; unsigned int index = 0; TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion(); for ( index = 0; index < fields->size(); ++index) { if ((*fields)[index].type->getFieldName() == identifier) { break; } else { instanceSize += (*fields)[index].type->getObjectSize(); } } if (tempConstantNode) { constUnion* constArray = tempConstantNode->getUnionArrayPointer(); typedNode = intermediate.addConstantUnion(constArray+instanceSize, tempConstantNode->getType(), line); // type will be changed in the calling function } else { error(line, "Cannot offset into the structure", "Error", ""); recover(); return 0; } return typedNode; }
bool OutputSpecification(TIntermSpecification* node, TIntermTraverser* it) { TOutputTraverser* oit = static_cast<TOutputTraverser*>(it); TInfoSink& out = oit->infoSink; OutputExtensionText(out, node); OutputTreeText(out, node, oit->depth); TType* t = node->getType(); out.debug << "specify '" << t->getTypeName().c_str() << "' (" << t->getCompleteString() << ")\n"; return true; #if 0 TTypeList* tl = t->getStruct(); TTypeList::iterator iter = tl->begin(); for(; iter < tl->end(); iter++) { out.debug << FormatSourceRange(iter->line); for (i = 0; i < (oit->depth+1); ++i) out.debug << " "; out.debug << "'" << iter->type->getFieldName().c_str() << "' (" << iter->type->getCompleteString().c_str() << ")\n"; } #endif }
bool CompareStruct(const TType& leftNodeType, constUnion* rightUnionArray, constUnion* leftUnionArray) { TTypeList* fields = leftNodeType.getStruct(); size_t structSize = fields->size(); int index = 0; for (size_t j = 0; j < structSize; j++) { int size = (*fields)[j].type->getObjectSize(); for (int i = 0; i < size; i++) { if ((*fields)[j].type->getBasicType() == EbtStruct) { if (!CompareStructure(*(*fields)[j].type, &rightUnionArray[index], &leftUnionArray[index])) return false; } else { if (leftUnionArray[index] != rightUnionArray[index]) return false; index++; } } } return true; }