[PATCH] D67825: [AST] Extrat Decl::printQualifier helper from Decl::printQualifiedName.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 04:21:07 PDT 2019


ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added a subscriber: usaxena95.
Herald added a project: clang.

To be used in clangd, e.g. in D66647 <https://reviews.llvm.org/D66647>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67825

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp


Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1558,6 +1558,18 @@
 
 void NamedDecl::printQualifiedName(raw_ostream &OS,
                                    const PrintingPolicy &P) const {
+  printQualifier(OS, P);
+  if (getDeclName() || isa<DecompositionDecl>(this))
+    OS << *this;
+  else
+    OS << "(anonymous)";
+}
+
+void NamedDecl::printQualifier(raw_ostream &OS) const {
+  printQualifier(OS, getASTContext().getPrintingPolicy());
+}
+
+void NamedDecl::printQualifier(raw_ostream &OS, const PrintingPolicy &P) const {
   const DeclContext *Ctx = getDeclContext();
 
   // For ObjC methods and properties, look through categories and use the
@@ -1571,10 +1583,8 @@
         Ctx = ID;
   }
 
-  if (Ctx->isFunctionOrMethod()) {
-    printName(OS);
+  if (Ctx->isFunctionOrMethod())
     return;
-  }
 
   using ContextsTy = SmallVector<const DeclContext *, 8>;
   ContextsTy Contexts;
@@ -1644,11 +1654,6 @@
     }
     OS << "::";
   }
-
-  if (getDeclName() || isa<DecompositionDecl>(this))
-    OS << *this;
-  else
-    OS << "(anonymous)";
 }
 
 void NamedDecl::getNameForDiagnostic(raw_ostream &OS,
Index: clang/include/clang/AST/Decl.h
===================================================================
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -310,6 +310,13 @@
   void printQualifiedName(raw_ostream &OS) const;
   void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
 
+  /// Returns only qualifier from printQualifiedName, including the :: at the
+  /// end. E.g.
+  ///    when `printQualifiedName(D) == "A::B::i`,
+  ///    this function returns "A::B::".
+  void printQualifier(raw_ostream &OS) const;
+  void printQualifier(raw_ostream &OS, const PrintingPolicy &Policy) const;
+
   // FIXME: Remove string version.
   std::string getQualifiedNameAsString() const;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67825.220998.patch
Type: text/x-patch
Size: 1959 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190920/34d93237/attachment.bin>


More information about the cfe-commits mailing list