Fixed the remaining problems\! All the tests pass now.
This commit is contained in:
@@ -23,10 +23,10 @@ class CGenerator {
|
|||||||
static std::string ValueTypeToCTypeDecoration(Type *type);
|
static std::string ValueTypeToCTypeDecoration(Type *type);
|
||||||
static std::string CifyName(std::string name);
|
static std::string CifyName(std::string name);
|
||||||
std::string generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from);
|
std::string generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from);
|
||||||
|
NodeTree<ASTData>* getMethodsObjectType(NodeTree<ASTData>* scope, std::string functionName);
|
||||||
std::string generatorString;
|
std::string generatorString;
|
||||||
private:
|
private:
|
||||||
std::string tabs();
|
std::string tabs();
|
||||||
int tabLevel;
|
int tabLevel;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ void ASTTransformation::secondPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* par
|
|||||||
Type* aliasedType = typeFromTypeNode(typedefChildren[1], ast, std::map<std::string, Type*>(), false); //No templates, we're in the traslation unit
|
Type* aliasedType = typeFromTypeNode(typedefChildren[1], ast, std::map<std::string, Type*>(), false); //No templates, we're in the traslation unit
|
||||||
typeDef->getDataRef()->valueType = aliasedType;
|
typeDef->getDataRef()->valueType = aliasedType;
|
||||||
typeDef->getDataRef()->scope["~enclosing_scope"][0] = aliasedType->typeDefinition; //So that object lookups find the right member. Note that this overrides translation_unit as a parent scope
|
typeDef->getDataRef()->scope["~enclosing_scope"][0] = aliasedType->typeDefinition; //So that object lookups find the right member. Note that this overrides translation_unit as a parent scope
|
||||||
std::cout << name << " alias's to " << aliasedType->typeDefinition << std::endl;
|
// std::cout << name << " alias's to " << aliasedType->typeDefinition << std::endl;
|
||||||
std::cout << "that is " << aliasedType->typeDefinition->getDataRef()->toString() << std::endl;
|
// std::cout << "that is " << aliasedType->typeDefinition->getDataRef()->toString() << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//Do the inside of classes here
|
//Do the inside of classes here
|
||||||
|
|||||||
@@ -64,9 +64,12 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
//In case there are pointer dependencies. If the typedef has no children, then it is a simple renaming and we don't need to predeclare the class (maybe?)
|
//In case there are pointer dependencies. If the typedef has no children, then it is a simple renaming and we don't need to predeclare the class (maybe?)
|
||||||
if (classChildren.size())
|
if (classChildren.size())
|
||||||
output += "struct " + CifyName(children[i]->getDataRef()->symbol.getName()) + ";\n";
|
output += "struct " + CifyName(children[i]->getDataRef()->symbol.getName()) + ";\n";
|
||||||
else if (children[i]->getDataRef()->valueType->typeDefinition != children[i] && !children[i]->getDataRef()->valueType->templateDefinition) //Isn't uninstantiated template or 0 parameter class, so must be alias
|
else {
|
||||||
typedefPoset.addRelationship(children[i], children[i]->getDataRef()->valueType->typeDefinition); //An alias typedef depends on the type it aliases being declared before it
|
Type *aliasType = children[i]->getDataRef()->valueType;
|
||||||
}
|
if (aliasType->typeDefinition && aliasType->typeDefinition != children[i] && !aliasType->templateDefinition) //Isn't uninstantiated template or 0 parameter class, so must be alias. if typeDefinition isn't null, then it's an alias of a custom, not a primitive, type.
|
||||||
|
typedefPoset.addRelationship(children[i], children[i]->getDataRef()->valueType->typeDefinition); //An alias typedef depends on the type it aliases being declared before it
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Now generate the typedef's in the correct, topological order
|
//Now generate the typedef's in the correct, topological order
|
||||||
for (NodeTree<ASTData>* i : typedefPoset.getTopoSort())
|
for (NodeTree<ASTData>* i : typedefPoset.getTopoSort())
|
||||||
@@ -249,18 +252,24 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
std::string functionName = children[2]->getDataRef()->symbol.getName();
|
std::string functionName = children[2]->getDataRef()->symbol.getName();
|
||||||
NodeTree<ASTData>* possibleObjectType = children[1]->getDataRef()->valueType->typeDefinition;
|
NodeTree<ASTData>* possibleObjectType = children[1]->getDataRef()->valueType->typeDefinition;
|
||||||
//If is an object method, generate it like one. Needs extension/modification for inheritence
|
//If is an object method, generate it like one. Needs extension/modification for inheritence
|
||||||
if (possibleObjectType && possibleObjectType->getDataRef()->scope.find(functionName) != possibleObjectType->getDataRef()->scope.end()) {
|
if (possibleObjectType) {
|
||||||
std::string nameDecoration;
|
NodeTree<ASTData>* unaliasedTypeDef = getMethodsObjectType(possibleObjectType, functionName);
|
||||||
std::vector<NodeTree<ASTData>*> functionDefChildren = children[2]->getChildren(); //The function def is the rhs of the access operation
|
if (unaliasedTypeDef) { //Test to see if the function's a member of this type_def, or if this is an alias, of the original type. Get this original type if it exists.
|
||||||
std::cout << "Decorating (in access-should be object) " << name << " " << functionDefChildren.size() << std::endl;
|
std::string nameDecoration;
|
||||||
for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
std::vector<NodeTree<ASTData>*> functionDefChildren = children[2]->getChildren(); //The function def is the rhs of the access operation
|
||||||
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
std::cout << "Decorating (in access-should be object) " << name << " " << functionDefChildren.size() << std::endl;
|
||||||
/*HERE*/ return CifyName(possibleObjectType->getDataRef()->symbol.getName()) +"__" + CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject) + ",";
|
for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
||||||
//The comma lets the upper function call know we already started the param list
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
||||||
//Note that we got here from a function call. We just pass up this special case and let them finish with the perentheses
|
/*HERE*/ return CifyName(unaliasedTypeDef->getDataRef()->symbol.getName()) +"__" + CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject) + ",";
|
||||||
} else {
|
//The comma lets the upper function call know we already started the param list
|
||||||
std::cout << "Is not in scope or not type" << std::endl;
|
//Note that we got here from a function call. We just pass up this special case and let them finish with the perentheses
|
||||||
return "((" + generate(children[1], enclosingObject) + ")" + name + functionName + ")";
|
} else {
|
||||||
|
std::cout << "Is not in scope or not type" << std::endl;
|
||||||
|
return "((" + generate(children[1], enclosingObject) + ")" + name + functionName + ")";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << "Is not in scope or not type" << std::endl;
|
||||||
|
return "((" + generate(children[1], enclosingObject) + ")" + name + functionName + ")";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//return "((" + generate(children[1], enclosingObject) + ")" + name + generate(children[2], enclosingObject) + ")";
|
//return "((" + generate(children[1], enclosingObject) + ")" + name + generate(children[2], enclosingObject) + ")";
|
||||||
@@ -309,7 +318,12 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
NodeTree<ASTData>* CGenerator::getMethodsObjectType(NodeTree<ASTData>* scope, std::string functionName) {
|
||||||
|
//check the thing
|
||||||
|
while (scope != scope->getDataRef()->valueType->typeDefinition) //type is an alias, follow it to the definition
|
||||||
|
scope = scope->getDataRef()->valueType->typeDefinition;
|
||||||
|
return (scope->getDataRef()->scope.find(functionName) != scope->getDataRef()->scope.end()) ? scope : NULL;
|
||||||
|
}
|
||||||
std::string CGenerator::generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from) {
|
std::string CGenerator::generateObjectMethod(NodeTree<ASTData>* enclosingObject, NodeTree<ASTData>* from) {
|
||||||
std::string output;
|
std::string output;
|
||||||
ASTData data = from->getData();
|
ASTData data = from->getData();
|
||||||
|
|||||||
Reference in New Issue
Block a user