Make ADT functions be name-decorated correctly, including replaceing some name-decoration iteration over parameters with iterating over parameter types from the function type
This commit is contained in:
@@ -210,6 +210,16 @@ void ASTTransformation::secondPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* par
|
|||||||
addToScope("operator!=", inequalityFunc, adtDef);
|
addToScope("operator!=", inequalityFunc, adtDef);
|
||||||
addToScope("~enclosing_scope", adtDef, inequalityFunc);
|
addToScope("~enclosing_scope", adtDef, inequalityFunc);
|
||||||
|
|
||||||
|
NodeTree<ASTData>* copy_constructFunc = new NodeTree<ASTData>("function", ASTData(function, Symbol("copy_construct", true), new Type(std::vector<Type*>{thisADTType->withIncreasedIndirectionPtr()}, new Type(void_type))));
|
||||||
|
adtDef->addChild(copy_constructFunc);
|
||||||
|
addToScope("copy_construct", copy_constructFunc, adtDef);
|
||||||
|
addToScope("~enclosing_scope", adtDef, copy_constructFunc);
|
||||||
|
|
||||||
|
NodeTree<ASTData>* destructFunc = new NodeTree<ASTData>("function", ASTData(function, Symbol("destruct", true), new Type(std::vector<Type*>(), new Type(void_type))));
|
||||||
|
adtDef->addChild(destructFunc);
|
||||||
|
addToScope("destruct", destructFunc, adtDef);
|
||||||
|
addToScope("~enclosing_scope", adtDef, destructFunc);
|
||||||
|
|
||||||
for (NodeTree<Symbol>* j : getNodes("adt_option", i)) {
|
for (NodeTree<Symbol>* j : getNodes("adt_option", i)) {
|
||||||
std::string ident_name = concatSymbolTree(getNode("identifier", j));
|
std::string ident_name = concatSymbolTree(getNode("identifier", j));
|
||||||
std::cout << "add ing " << ident_name << " to " << name << " for ADT" << std::endl;
|
std::cout << "add ing " << ident_name << " to " << name << " for ADT" << std::endl;
|
||||||
|
|||||||
@@ -301,17 +301,20 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
|||||||
for (auto child : decChildren) {
|
for (auto child : decChildren) {
|
||||||
if (child->getName() == "function") {
|
if (child->getName() == "function") {
|
||||||
std::string orig_fun_name = child->getDataRef()->symbol.getName();
|
std::string orig_fun_name = child->getDataRef()->symbol.getName();
|
||||||
std::string fun_name = "fun_" + declarationData.symbol.getName() + "__" + CifyName(orig_fun_name);
|
std::string nameDecoration;
|
||||||
|
for (Type *paramType : child->getDataRef()->valueType->parameterTypes)
|
||||||
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(paramType);
|
||||||
|
std::string fun_name = "fun_" + declarationData.symbol.getName() + "__" + CifyName(orig_fun_name + nameDecoration);
|
||||||
std::string first_param;
|
std::string first_param;
|
||||||
if (orig_fun_name == "operator==" || orig_fun_name == "operator!=") {
|
if (orig_fun_name == "operator==" || orig_fun_name == "operator!=" || orig_fun_name == "copy_construct" || orig_fun_name == "destruct") {
|
||||||
//fun_name = "fun_" + declarationData.symbol.getName() + "__" + CifyName(orig_fun_name);
|
first_param = ValueTypeToCType(declarationData.valueType->withIncreasedIndirectionPtr(), "this");
|
||||||
first_param = ValueTypeToCType(child->getDataRef()->valueType->parameterTypes[0]->withIncreasedIndirectionPtr(), "this") + ", ";
|
//first_param = ValueTypeToCType(child->getDataRef()->valueType->parameterTypes[0]->withIncreasedIndirectionPtr(), "this");
|
||||||
} else {
|
//if (orig_fun_name == "operator==" || orig_fun_name == "operator!=" || orig_fun_name == "copy_construct")
|
||||||
//fun_name = "fun_" + orig_fun_name;
|
//first_param += ", ";
|
||||||
}
|
}
|
||||||
bool has_param = child->getDataRef()->valueType->parameterTypes.size();
|
bool has_param = child->getDataRef()->valueType->parameterTypes.size();
|
||||||
std::string first_part = "\n" + ValueTypeToCType(child->getDataRef()->valueType->returnType, fun_name) + "(" + first_param +
|
std::string first_part = "\n" + ValueTypeToCType(child->getDataRef()->valueType->returnType, fun_name) + "(" + first_param +
|
||||||
(has_param ? ValueTypeToCType(child->getDataRef()->valueType->parameterTypes[0], "in") : "") + ")";
|
(has_param ? (first_param != "" ? ", " : "") + ValueTypeToCType(child->getDataRef()->valueType->parameterTypes[0], "in") : "") + ")";
|
||||||
functionPrototypes += first_part + "; /*adt func*/\n";
|
functionPrototypes += first_part + "; /*adt func*/\n";
|
||||||
functionDefinitions += first_part + "{ /*adt func*/\n";
|
functionDefinitions += first_part + "{ /*adt func*/\n";
|
||||||
if (orig_fun_name == "operator==") {
|
if (orig_fun_name == "operator==") {
|
||||||
@@ -336,7 +339,12 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
|||||||
functionDefinitions += " return true;\n";
|
functionDefinitions += " return true;\n";
|
||||||
} else if (orig_fun_name == "operator!=") {
|
} else if (orig_fun_name == "operator!=") {
|
||||||
functionDefinitions += " /* inequality woop woop */\n";
|
functionDefinitions += " /* inequality woop woop */\n";
|
||||||
functionDefinitions += " return !fun_" + declarationData.symbol.getName() + "__" + CifyName("operator==") + "(this, in);\n";
|
std::string adtName = declarationData.symbol.getName();
|
||||||
|
functionDefinitions += " return !fun_" + adtName + "__" + CifyName("operator==") + "_" + adtName+ "(this, in);\n";
|
||||||
|
} else if (orig_fun_name == "copy_construct") {
|
||||||
|
functionDefinitions += " /* copy_construct woop woop */\n";
|
||||||
|
} else if (orig_fun_name == "destruct") {
|
||||||
|
functionDefinitions += " /* destruct woop woop */\n";
|
||||||
} else {
|
} else {
|
||||||
// ok, is a constructor function
|
// ok, is a constructor function
|
||||||
functionDefinitions += " /* constructor woop woop */\n";
|
functionDefinitions += " /* constructor woop woop */\n";
|
||||||
@@ -434,10 +442,12 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
if (j > 0 || data.closedVariables.size())
|
if (j > 0 || data.closedVariables.size())
|
||||||
parameters += ", ";
|
parameters += ", ";
|
||||||
parameters += ValueTypeToCType(children[j]->getData().valueType, generate(children[j], enclosingObject, justFuncName, enclosingFunction).oneString());
|
parameters += ValueTypeToCType(children[j]->getData().valueType, generate(children[j], enclosingObject, justFuncName, enclosingFunction).oneString());
|
||||||
nameDecoration += "_" + ValueTypeToCTypeDecoration(children[j]->getData().valueType);
|
//nameDecoration += "_" + ValueTypeToCTypeDecoration(children[j]->getData().valueType);
|
||||||
// add parameters to distructDoubleStack so that their destructors will be called at return (if they exist)
|
// add parameters to distructDoubleStack so that their destructors will be called at return (if they exist)
|
||||||
distructDoubleStack.back().push_back(children[j]);
|
distructDoubleStack.back().push_back(children[j]);
|
||||||
}
|
}
|
||||||
|
for (Type *paramType : from->getDataRef()->valueType->parameterTypes)
|
||||||
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(paramType);
|
||||||
// this is for using functions as values
|
// this is for using functions as values
|
||||||
if (justFuncName) {
|
if (justFuncName) {
|
||||||
std::string funcName;
|
std::string funcName;
|
||||||
@@ -818,10 +828,13 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
NodeTree<ASTData>* unaliasedTypeDef = getMethodsObjectType(possibleObjectType, functionName);
|
NodeTree<ASTData>* unaliasedTypeDef = getMethodsObjectType(possibleObjectType, functionName);
|
||||||
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.
|
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::string nameDecoration;
|
std::string nameDecoration;
|
||||||
std::vector<NodeTree<ASTData>*> functionDefChildren = children[2]->getChildren(); //The function def is the rhs of the access operation
|
NodeTree<ASTData>* functionDef = children[2]; //The function def is the rhs of the access operation
|
||||||
|
//std::vector<NodeTree<ASTData>*> functionDefChildren = children[2]->getChildren(); //The function def is the rhs of the access operation
|
||||||
//std::cout << "Decorating (in access-should be object) " << name << " " << functionDefChildren.size() << std::endl;
|
//std::cout << "Decorating (in access-should be object) " << name << " " << functionDefChildren.size() << std::endl;
|
||||||
for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
for (Type *paramType : functionDef->getDataRef()->valueType->parameterTypes)
|
||||||
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(paramType);
|
||||||
|
//for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
||||||
|
//nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
||||||
// Note that we only add scoping to the object, as this specifies our member function too
|
// Note that we only add scoping to the object, as this specifies our member function too
|
||||||
/*HERE*/ return function_header + prefixIfNeeded(scopePrefix(unaliasedTypeDef), CifyName(unaliasedTypeDef->getDataRef()->symbol.getName())) +"__" +
|
/*HERE*/ return function_header + prefixIfNeeded(scopePrefix(unaliasedTypeDef), CifyName(unaliasedTypeDef->getDataRef()->symbol.getName())) +"__" +
|
||||||
CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject, true, enclosingFunction) + ",";
|
CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject, true, enclosingFunction) + ",";
|
||||||
@@ -849,8 +862,10 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
std::vector<NodeTree<ASTData>*> functionDefChildren = children[0]->getChildren();
|
std::vector<NodeTree<ASTData>*> functionDefChildren = children[0]->getChildren();
|
||||||
//std::cout << "Decorating (none-special)" << name << " " << functionDefChildren.size() << std::endl;
|
//std::cout << "Decorating (none-special)" << name << " " << functionDefChildren.size() << std::endl;
|
||||||
std::string nameDecoration;
|
std::string nameDecoration;
|
||||||
for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
for (Type *paramType : children[0]->getDataRef()->valueType->parameterTypes)
|
||||||
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(paramType);
|
||||||
|
//for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++)
|
||||||
|
//nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
||||||
// it is possible that this is an object method from inside a closure
|
// it is possible that this is an object method from inside a closure
|
||||||
// in which case, recover the enclosing object from this
|
// in which case, recover the enclosing object from this
|
||||||
bool addClosedOver = false;
|
bool addClosedOver = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user