A kinda ugly/hacky addition, but overloading () as operator() works now!

This commit is contained in:
Nathan Braswell
2015-05-16 00:09:50 -04:00
parent 795f8715ff
commit aafb52d108
4 changed files with 38 additions and 4 deletions

View File

@@ -376,8 +376,24 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
newNode = functionLookup(scope, lookupName, types);
if (newNode == NULL) {
std::cout << "scope lookup failed! Could not find " << lookupName << " in identifier (functionLookup)" << std::endl;
std::cout << "(maybe this is supposted to happen because the function is a template and we're infrencing)" << std::endl;
//throw "LOOKUP ERROR: " + lookupName;
std::cout << "(maybe this is supposted to happen because the function is a template and we're infrencing), or this is a operator() call" << std::endl;
// Ok, now we try the case where the lookupName is an object, and we'll try to look for operator()
// in its scope
for (auto possibleObj : scopeLookup(scope, lookupName)) {
NodeTree<ASTData> *typeDefinition = possibleObj->getDataRef()->valueType->typeDefinition;
if (typeDefinition) {
// ugly for now, it's just operator because the ( and ) have been removed by a removal
// pass
NodeTree<ASTData>* perenOp = functionLookup(typeDefinition, "operator", types);
if (perenOp) {
NodeTree<ASTData>* dotFunctionCall = new NodeTree<ASTData>(".", ASTData(function_call, Symbol(".", true)));
dotFunctionCall->addChild(languageLevelOperators["."][0]); //function definition
dotFunctionCall->addChild(possibleObj); // The object whose method we're calling
dotFunctionCall->addChild(perenOp); //The method we're calling
return dotFunctionCall;
}
}
}
return nullptr;
}
} else {
@@ -536,7 +552,6 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
throw "LOOKUP ERROR: " + functionCallName;
}
return newNode;
//skipChildren.insert(1);
}
if (children.size() == 1) {
newNode = transform(children[0], scope, types, templateTypeReplacements); //Just a promoted child, so do it instead