some bug fixes, templated operator method overloading
This commit is contained in:
@@ -852,8 +852,12 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
||||
NodeTree<ASTData>* operatorMethod = NULL;
|
||||
|
||||
// make sure this isn't a pointer, also. Silly vector<string> bug
|
||||
if (nodes[0]->getDataRef()->valueType && !nodes[0]->getDataRef()->valueType->getIndirection() && nodes[0]->getDataRef()->valueType->typeDefinition)
|
||||
if (nodes[0]->getDataRef()->valueType && !nodes[0]->getDataRef()->valueType->getIndirection() && nodes[0]->getDataRef()->valueType->typeDefinition) {
|
||||
operatorMethod = functionLookup(nodes[0]->getDataRef()->valueType->typeDefinition, lookupOp, mapNodesToTypes(slice(nodes,1,-1)));
|
||||
// we're also gonna check to see if this is an operator template method
|
||||
if (!operatorMethod)
|
||||
operatorMethod = tryToFindOrInstantiateFunctionTemplate(lookupOp, nodes[0]->getDataRef()->valueType->typeDefinition, mapNodesToTypes(slice(nodes,1,-1)), templateTypeReplacements);
|
||||
}
|
||||
if (operatorMethod) {
|
||||
//Ok, so we construct
|
||||
std::cout << "Early method level operator was found" << std::endl;
|
||||
@@ -1634,10 +1638,26 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<A
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// So we want to be able to call this with either the children which is one name and one template thingy (func<a>), or just the name (func), or even with just
|
||||
// a string as the name if, for example, we're generating the name from an operator overload (which we do) (operator+)
|
||||
NodeTree<ASTData>* ASTTransformation::tryToFindOrInstantiateFunctionTemplate(std::string functionName, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements) {
|
||||
try {
|
||||
return findOrInstantiateFunctionTemplate(functionName, std::vector<NodeTree<Symbol>*>(), scope, types, templateTypeReplacements);
|
||||
} catch (const char *ex) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::vector<NodeTree<Symbol>*> children, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements) {
|
||||
return findOrInstantiateFunctionTemplate("", children, scope, types, templateTypeReplacements);
|
||||
}
|
||||
NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::string functionName, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements) {
|
||||
return findOrInstantiateFunctionTemplate(functionName, std::vector<NodeTree<Symbol>*>(), scope, types, templateTypeReplacements);
|
||||
}
|
||||
NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::string functionName, std::vector<NodeTree<Symbol>*> children, NodeTree<ASTData>* scope, std::vector<Type> types, std::map<std::string, Type*> templateTypeReplacements) {
|
||||
//First look to see if we can find this already instantiated
|
||||
std::cout << "\n\nFinding or instantiating templated function\n\n" << std::endl;
|
||||
std::string functionName = concatSymbolTree(children[0]);
|
||||
if (children.size())
|
||||
functionName = concatSymbolTree(children[0]);
|
||||
std::string fullyInstantiatedName;
|
||||
std::string scopelessFullyInstantiatedName;
|
||||
std::vector<Type*> templateActualTypes;
|
||||
@@ -1659,7 +1679,7 @@ NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec
|
||||
// Note that as a part o finferring the instantiation we already find the template, so we make that
|
||||
// condtitional too (templateDefinition)
|
||||
std::string instTypeString = "";
|
||||
if (children.size() == 1) {
|
||||
if (children.size() <= 1) {
|
||||
// templateFunctionLookup adds the actual types to templateActualTypes if it's currently empty
|
||||
templateDefinition = templateFunctionLookup(scope, functionName, &templateActualTypes, types, scopeTypeMap);
|
||||
for (auto instType : templateActualTypes)
|
||||
|
||||
@@ -287,17 +287,8 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
return CCodeTriple("/* never reached import? */\n");
|
||||
case identifier:
|
||||
{
|
||||
//but first, if we're this, we should just emit. (assuming enclosing object) (note that technically this would fall through, but for errors)
|
||||
if (data.symbol.getName() == "this") {
|
||||
if (enclosingObject)
|
||||
return CCodeTriple("this");
|
||||
std::cerr << "Error: this used in non-object scope" << std::endl;
|
||||
throw "Error: this used in non-object scope";
|
||||
}
|
||||
//If we're in an object method, and our enclosing scope is that object, we're a member of the object and should use the this reference.
|
||||
std::string preName;
|
||||
std::string postName;
|
||||
//std::string preName = "/*ident*/";
|
||||
std::string preName = "";
|
||||
std::string postName = "";
|
||||
// check for this being a closed over variable
|
||||
// first, get declaring function, if it exists
|
||||
if (enclosingFunction) {
|
||||
@@ -309,6 +300,15 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
||||
}
|
||||
}
|
||||
}
|
||||
// enclosing function comes first now, we might have a double closure that both close over the this pointer of an object
|
||||
//but first, if we're this, we should just emit. (assuming enclosing object) (note that technically this would fall through, but for errors)
|
||||
if (data.symbol.getName() == "this") {
|
||||
if (enclosingObject || enclosingFunction)
|
||||
return CCodeTriple(preName + "this" + postName);
|
||||
std::cerr << "Error: this used in non-object scope" << std::endl;
|
||||
throw "Error: this used in non-object scope";
|
||||
}
|
||||
//If we're in an object method, and our enclosing scope is that object, we're a member of the object and should use the this reference.
|
||||
if (enclosingObject && enclosingObject->getDataRef()->scope.find(data.symbol.getName()) != enclosingObject->getDataRef()->scope.end())
|
||||
preName += "this->";
|
||||
// dereference references, but only if inside a function
|
||||
|
||||
Reference in New Issue
Block a user