[PATCH] D59354: [clangd] Print arguments in template specializations
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 14 04:01:48 PDT 2019
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D59354
Files:
clang-tools-extra/clangd/AST.cpp
clang/lib/AST/TypePrinter.cpp
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1632,6 +1632,18 @@
return A.getArgument();
}
+static void printArgument(const TemplateArgument &A,
+ const PrintingPolicy &PP,
+ llvm::raw_ostream &OS) {
+ A.print(PP, OS);
+}
+
+static void printArgument(const TemplateArgumentLoc &A,
+ const PrintingPolicy &PP,
+ llvm::raw_ostream &OS) {
+ A.getTypeSourceInfo()->getType().print(OS, PP);
+}
+
template<typename TA>
static void printTo(raw_ostream &OS, ArrayRef<TA> Args,
const PrintingPolicy &Policy, bool SkipBrackets) {
@@ -1653,7 +1665,7 @@
} else {
if (!FirstArg)
OS << Comma;
- Argument.print(Policy, ArgOS);
+ printArgument(Arg, Policy, ArgOS);
}
StringRef ArgString = ArgOS.str();
Index: clang-tools-extra/clangd/AST.cpp
===================================================================
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -50,6 +50,17 @@
return SM.getSpellingLoc(D->getLocation());
}
+static llvm::Optional<llvm::ArrayRef<TemplateArgumentLoc>>
+getTemplateSpecializationArgLocs(const NamedDecl &ND) {
+ if (auto *Func = llvm::dyn_cast<FunctionDecl>(&ND))
+ return Func->getTemplateSpecializationArgsAsWritten()->arguments();
+ if (auto *Cls = llvm::dyn_cast<ClassTemplatePartialSpecializationDecl>(&ND))
+ return Cls->getTemplateArgsAsWritten()->arguments();
+ if (auto *Var = llvm::dyn_cast<VarTemplateSpecializationDecl>(&ND))
+ return Var->getTemplateArgsInfo().arguments();
+ return llvm::None;
+}
+
std::string printQualifiedName(const NamedDecl &ND) {
std::string QName;
llvm::raw_string_ostream OS(QName);
@@ -60,6 +71,10 @@
// namespaces to query: the preamble doesn't have a dedicated list.
Policy.SuppressUnwrittenScope = true;
ND.printQualifiedName(OS, Policy);
+ if (auto Args = getTemplateSpecializationArgLocs(ND))
+ printTemplateArgumentList(OS, *Args, Policy);
+ else if (auto *Cls = llvm::dyn_cast<ClassTemplateSpecializationDecl>(&ND))
+ printTemplateArgumentList(OS, Cls->getTemplateArgs().asArray(), Policy);
OS.flush();
assert(!StringRef(QName).startswith("::"));
return QName;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59354.190591.patch
Type: text/x-patch
Size: 2429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190314/9543e91b/attachment-0001.bin>
More information about the cfe-commits
mailing list