Exemplo n.º 1
0
//
// 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;
}
Exemplo n.º 2
0
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;
}