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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits