From: Kadir Cetinkaya Date: Fri, 12 Apr 2019 10:09:14 +0000 (+0000) Subject: [clangd] Print template arguments helper X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=64771d94b8235e03a970d4e12e3e8adfe38f9645;p=clang [clangd] Print template arguments helper Summary: Prepares ground for printing template arguments as written in the source code, part of re-landing rC356541 with D59599 applied. Reviewers: ioeric, ilya-biryukov Subscribers: mgorny, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59639 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@358272 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index ebcc01aa46..82a2fa09c7 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -1632,6 +1632,19 @@ static const TemplateArgument &getArgument(const TemplateArgumentLoc &A) { 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) { + const TemplateArgument::ArgKind &Kind = A.getArgument().getKind(); + if (Kind == TemplateArgument::ArgKind::Type) + return A.getTypeSourceInfo()->getType().print(OS, PP); + return A.getArgument().print(PP, OS); +} + template static void printTo(raw_ostream &OS, ArrayRef Args, const PrintingPolicy &Policy, bool SkipBrackets) { @@ -1653,7 +1666,8 @@ static void printTo(raw_ostream &OS, ArrayRef Args, } else { if (!FirstArg) OS << Comma; - Argument.print(Policy, ArgOS); + // Tries to print the argument with location info if exists. + printArgument(Arg, Policy, ArgOS); } StringRef ArgString = ArgOS.str();