From 920a9ab81f56465d0a69c899432251ef73e8b66e Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Mon, 25 May 2015 12:20:37 -0400 Subject: [PATCH] ahh, I git added in the tests directory and thus missed the entire ASTTransformation. Sigh. --- src/ASTTransformation.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index 17e9b14..8f24658 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -1023,8 +1023,21 @@ void ASTTransformation::unifyType(NodeTree *syntaxType, Type type, std:: // b) instantiated with a template type type (i.e. vector) // this will be a bit of a pain too // 4) This is a pointer type, go down a pointer level + // 5) This is a function type, unify on parameter types and return type auto children = syntaxType->getChildren(); + + if (children.back()->getDataRef()->getName() == "function_type") { + if (!type.returnType) + return; + auto childrenTypes = getNodes("type", children.back()->getChildren()); + // unify params + for (int i = 0; i < childrenTypes.size()-1; i++) + unifyType(childrenTypes[i], *type.parameterTypes[i], templateTypeMap); + unifyType(childrenTypes.back(), *type.returnType, templateTypeMap); + return; + } + if (children.size() == 1) { (*templateTypeMap)[concatSymbolTree(children.back())] = type; } else { @@ -1437,22 +1450,24 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec // have the actual instantiation part. If do have the instantiation part, then we'll use that. // 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) { // templateFunctionLookup adds the actual types to templateActualTypes if it's currently empty templateDefinition = templateFunctionLookup(scope, functionName, &templateActualTypes, types); + for (auto instType : templateActualTypes) + instTypeString += (instTypeString == "" ? instType->toString() : "," + instType->toString()); } else { auto unsliced = children[1]->getChildren(); std::vector*> templateParamInstantiationNodes = slice(unsliced, 1 , -2, 2);//skip <, >, and commas - std::string instTypeString = ""; for (int i = 0; i < templateParamInstantiationNodes.size(); i++) { Type* instType = typeFromTypeNode(templateParamInstantiationNodes[i],scope, templateTypeReplacements); instTypeString += (instTypeString == "" ? instType->toString() : "," + instType->toString()); templateActualTypes.push_back(instType); } std::cout << "Size: " << templateParamInstantiationNodes.size() << std::endl; - fullyInstantiatedName = functionName + "<" + instTypeString + ">"; - std::cout << "Looking for " << fullyInstantiatedName << std::endl; } + fullyInstantiatedName = functionName + "<" + instTypeString + ">"; + std::cout << "Looking for " << fullyInstantiatedName << std::endl; std::cout << "Types are : "; for (auto i : types) std::cout << " " << i.toString();