More complicated inference working, now just have to round out the edges
This commit is contained in:
@@ -1026,6 +1026,24 @@ void ASTTransformation::unifyType(NodeTree<Symbol> *syntaxType, Type type, std::
|
|||||||
if (children.size() == 1) {
|
if (children.size() == 1) {
|
||||||
(*templateTypeMap)[concatSymbolTree(children.back())] = type;
|
(*templateTypeMap)[concatSymbolTree(children.back())] = type;
|
||||||
} else {
|
} else {
|
||||||
|
if (type.typeDefinition) {
|
||||||
|
// ok, what happens here is that we get the origional type from our type. This is
|
||||||
|
// the same as the type we have now but it still has extra data from when it was instantiated
|
||||||
|
// like the templateTypeReplacement map, which we'll use.
|
||||||
|
// We get the <T, int, ...> etc part from the template we're matching against and unify it with the
|
||||||
|
// actual types the type we're unifying with used by passing it's <A, B, ...> through the templateTypeReplacement
|
||||||
|
// to get the type it was instantiated with.
|
||||||
|
auto origionalType = type.typeDefinition->getDataRef()->valueType;
|
||||||
|
auto typeTemplateDefinition = origionalType->templateDefinition;
|
||||||
|
if (typeTemplateDefinition && concatSymbolTree(getNode("scoped_identifier", children)) == concatSymbolTree(getNode("identifier", typeTemplateDefinition->getChildren()))) {
|
||||||
|
std::vector<NodeTree<Symbol>*> uninTypeInstTypes = getNodes("type", getNode("template_inst", children));
|
||||||
|
std::vector<NodeTree<Symbol>*> typeInstTypes = getNodes("template_param", getNode("template_dec", typeTemplateDefinition->getChildren()));
|
||||||
|
for (int i = 0; i < uninTypeInstTypes.size(); i++)
|
||||||
|
unifyType(uninTypeInstTypes[i], *origionalType->templateTypeReplacement[concatSymbolTree(typeInstTypes[i])], templateTypeMap);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
throw "the inference just isn't good enough";
|
throw "the inference just isn't good enough";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1333,10 +1351,6 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<A
|
|||||||
std::cout << "Did not find already instantiated template of " << templateLookupName << " at second check" << std::endl;
|
std::cout << "Did not find already instantiated template of " << templateLookupName << " at second check" << std::endl;
|
||||||
//Look up this template's plain definition. It's type has the syntax tree that we need to parse
|
//Look up this template's plain definition. It's type has the syntax tree that we need to parse
|
||||||
NodeTree<ASTData>* templateDefinition = templateClassLookup(scope, concatSymbolTree(typeNode->getChildren()[0]), templateParamInstantiationTypes);
|
NodeTree<ASTData>* templateDefinition = templateClassLookup(scope, concatSymbolTree(typeNode->getChildren()[0]), templateParamInstantiationTypes);
|
||||||
if (templateDefinition == NULL)
|
|
||||||
std::cout << "Template definition is null!" << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << "Template definition is not null!" << std::endl;
|
|
||||||
|
|
||||||
std::string fullyInstantiatedName = templateDefinition->getDataRef()->symbol.getName() + "<" + instTypeString + ">";
|
std::string fullyInstantiatedName = templateDefinition->getDataRef()->symbol.getName() + "<" + instTypeString + ">";
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ fun main():int {
|
|||||||
var fromTemplateFun = id(11)
|
var fromTemplateFun = id(11)
|
||||||
var aVec.construct(): vector<int>
|
var aVec.construct(): vector<int>
|
||||||
aVec.addEnd(12)
|
aVec.addEnd(12)
|
||||||
//var fromTemplateFun = id<int>(11);
|
|
||||||
println(fromTemplateFun)
|
println(fromTemplateFun)
|
||||||
println(idVec(aVec))
|
println(idVec(aVec))
|
||||||
//println(idVec<int>(aVec))
|
//println(idVec<int>(aVec))
|
||||||
|
|||||||
Reference in New Issue
Block a user