resolve template arguments
This commit is contained in:
parent
0f69db00fb
commit
7cd4b1d857
|
|
@ -255,6 +255,27 @@ final class FirstPass : ASTVisitor
|
|||
// TODO: remove this cast. See the note on structFieldTypes
|
||||
structFieldTypes.insert(cast() dec.type);
|
||||
}
|
||||
if (dec.type.type2 && dec.type.type2.typeIdentifierPart)
|
||||
{
|
||||
auto typeIdentifierPart = dec.type.type2.typeIdentifierPart;
|
||||
if (typeIdentifierPart && typeIdentifierPart.identifierOrTemplateInstance &&
|
||||
typeIdentifierPart.identifierOrTemplateInstance.templateInstance)
|
||||
{
|
||||
auto templateInstance = typeIdentifierPart.identifierOrTemplateInstance.templateInstance;
|
||||
if (templateInstance.templateArguments.templateArgumentList)
|
||||
{
|
||||
foreach(i, targ; templateInstance.templateArguments.templateArgumentList.items)
|
||||
{
|
||||
// TODO: support template with multiple arguments
|
||||
}
|
||||
}
|
||||
else if (typeIdentifierPart.identifierOrTemplateInstance.templateInstance.templateArguments.templateSingleArgument)
|
||||
{
|
||||
auto singleArg = typeIdentifierPart.identifierOrTemplateInstance.templateInstance.templateArguments.templateSingleArgument;
|
||||
symbol.acSymbol.tmplArgNames.insert(istring(singleArg.token.text));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dec.autoDeclaration !is null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ void secondPass(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCac
|
|||
resolveType(currentSymbol.acSymbol, currentSymbol.typeLookups,
|
||||
moduleScope, cache);
|
||||
}
|
||||
|
||||
if (currentSymbol.acSymbol.tmplArgNames.length > 0 && currentSymbol.acSymbol.type)
|
||||
{
|
||||
auto type = currentSymbol.acSymbol.type;
|
||||
if (type.kind == structName || type.kind == className)
|
||||
resolveTemplate(currentSymbol.acSymbol, type, moduleScope, cache);
|
||||
}
|
||||
break;
|
||||
case importSymbol:
|
||||
if (currentSymbol.acSymbol.type is null)
|
||||
|
|
@ -99,6 +106,48 @@ void secondPass(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCac
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve template arguments
|
||||
*/
|
||||
void resolveTemplate(DSymbol* sym, DSymbol* type, Scope* moduleScope, ref ModuleCache cache)
|
||||
{
|
||||
if (sym.tmplArgNames.length > 1) return;
|
||||
auto argName = sym.tmplArgNames.back;
|
||||
auto result = moduleScope.getSymbolsAtGlobalScope(argName);
|
||||
if (result.length > 0)
|
||||
{
|
||||
auto argSymbol = result[0];
|
||||
DSymbol* newType = GCAllocator.instance.make!DSymbol(type.name, type.kind, null);
|
||||
newType.qualifier = type.qualifier;
|
||||
newType.protection = type.protection;
|
||||
newType.symbolFile = type.symbolFile;
|
||||
newType.doc = type.doc;
|
||||
newType.callTip = type.callTip;
|
||||
foreach(part; type.opSlice())
|
||||
{
|
||||
if (part.kind == typeTmpParam)
|
||||
{ }
|
||||
else if (part.type && part.type.kind == typeTmpParam)
|
||||
{
|
||||
DSymbol* newPart = GCAllocator.instance.make!DSymbol(part.name, part.kind, argSymbol);
|
||||
newPart.qualifier = part.qualifier;
|
||||
newPart.protection = part.protection;
|
||||
newPart.symbolFile = part.symbolFile;
|
||||
newPart.doc = part.doc;
|
||||
newPart.callTip = part.callTip;
|
||||
newType.addChild(newPart, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
newType.addChild(part, false);
|
||||
}
|
||||
}
|
||||
|
||||
sym.type = newType;
|
||||
sym.ownType = true;
|
||||
}
|
||||
}
|
||||
|
||||
void resolveImport(DSymbol* acSymbol, ref TypeLookups typeLookups,
|
||||
ref ModuleCache cache)
|
||||
in
|
||||
|
|
|
|||
|
|
@ -381,6 +381,11 @@ struct DSymbol
|
|||
// TODO: remove since we have function arguments
|
||||
UnrolledList!(istring) argNames;
|
||||
|
||||
/**
|
||||
* Names of template arguments
|
||||
*/
|
||||
UnrolledList!(istring) tmplArgNames;
|
||||
|
||||
/**
|
||||
* Function parameter symbols
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue