std::string CppClass::getTextOfTemplateParamList(const ItemTextOptionFlags & options) const { if(! this->isTemplate()) { return ""; } string text; const TemplateDecl * templateDecl = dyn_cast<TemplateDecl>(this->getDecl()); const TemplateParameterList * templateParamList = templateDecl->getTemplateParameters(); for(TemplateParameterList::const_iterator it = templateParamList->begin(); it != templateParamList->end(); ++it) { if(! text.empty()) { text.append(", "); } const NamedDecl * namedDecl = *it; Decl::Kind kind = namedDecl->getKind(); string defaultValue; if(kind == Decl::TemplateTypeParm) { const TemplateTypeParmDecl * paramDecl = dyn_cast<TemplateTypeParmDecl>(namedDecl); if(options.has(itoWithArgType)) { text.append(paramDecl->wasDeclaredWithTypename() ? "typename " : "class "); } text.append(paramDecl->getNameAsString()); if(paramDecl->hasDefaultArgument()) { defaultValue = CppType(paramDecl->getDefaultArgument()).getQualifiedName(); } } else if(kind == Decl::NonTypeTemplateParm) { const NonTypeTemplateParmDecl * paramDecl = dyn_cast<NonTypeTemplateParmDecl>(namedDecl); if(options.has(itoWithArgType)) { text.append(CppType(paramDecl->getType()).getQualifiedName(paramDecl->getNameAsString())); } else { text.append(paramDecl->getNameAsString()); } if(paramDecl->hasDefaultArgument()) { defaultValue = exprToText(this->getASTContext(), paramDecl->getDefaultArgument()); } } else if(kind == Decl::TemplateTemplateParm) { const TemplateTemplateParmDecl * paramDecl = dyn_cast<TemplateTemplateParmDecl>(namedDecl); if(options.has(itoWithArgType)) { text.append(declToText(this->getASTContext(), paramDecl)); } else { text.append(paramDecl->getNameAsString()); } if(paramDecl->hasDefaultArgument()) { defaultValue = getTemplateArgumentName(this->getASTContext(), paramDecl->getDefaultArgument().getArgument()); } } if(! defaultValue.empty() && options.has(itoWithDefaultValue)) { text.append(" = " + defaultValue); } } return text; }
std::string getTemplateSpecializationName(const TemplateSpecializationType * type) { string qualifiedName; qualifiedName = type->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString(); qualifiedName += "<"; for(unsigned int i = 0; i < type->getNumArgs(); ++i) { if(i > 0) { qualifiedName += ", "; } qualifiedName += getTemplateArgumentName(type->getArg(i)); } qualifiedName += " >"; return qualifiedName; }