diff --git a/dsymbol/src/dsymbol/conversion/first.d b/dsymbol/src/dsymbol/conversion/first.d index e488566..e1713c4 100644 --- a/dsymbol/src/dsymbol/conversion/first.d +++ b/dsymbol/src/dsymbol/conversion/first.d @@ -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) { diff --git a/dsymbol/src/dsymbol/conversion/second.d b/dsymbol/src/dsymbol/conversion/second.d index 433cd66..f39f1cb 100644 --- a/dsymbol/src/dsymbol/conversion/second.d +++ b/dsymbol/src/dsymbol/conversion/second.d @@ -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 diff --git a/dsymbol/src/dsymbol/symbol.d b/dsymbol/src/dsymbol/symbol.d index f6d2abb..ad61b5c 100644 --- a/dsymbol/src/dsymbol/symbol.d +++ b/dsymbol/src/dsymbol/symbol.d @@ -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 */