Author: Sam McCall Date: 2019-11-15T19:19:41+01:00 New Revision: 575e09d9f82f3bd0894dc10d1fa5873e97a7e70f
URL: https://github.com/llvm/llvm-project/commit/575e09d9f82f3bd0894dc10d1fa5873e97a7e70f DIFF: https://github.com/llvm/llvm-project/commit/575e09d9f82f3bd0894dc10d1fa5873e97a7e70f.diff LOG: [AST] Let DeclarationNameInfo printing use PrintingPolicy, and fix const-correctness Added: Modified: clang/include/clang/AST/DeclarationName.h clang/lib/AST/DeclPrinter.cpp clang/lib/AST/DeclarationName.cpp clang/lib/AST/StmtPrinter.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/DeclarationName.h b/clang/include/clang/AST/DeclarationName.h index 90449147637d..82f6868e3a7e 100644 --- a/clang/include/clang/AST/DeclarationName.h +++ b/clang/include/clang/AST/DeclarationName.h @@ -528,7 +528,7 @@ class DeclarationName { static int compare(DeclarationName LHS, DeclarationName RHS); - void print(raw_ostream &OS, const PrintingPolicy &Policy); + void print(raw_ostream &OS, const PrintingPolicy &Policy) const; void dump() const; }; @@ -792,7 +792,7 @@ struct DeclarationNameInfo { std::string getAsString() const; /// printName - Print the human-readable name to a stream. - void printName(raw_ostream &OS) const; + void printName(raw_ostream &OS, PrintingPolicy Policy) const; /// getBeginLoc - Retrieve the location of the first token. SourceLocation getBeginLoc() const { return NameLoc; } @@ -829,11 +829,7 @@ inline const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, return PD; } -inline raw_ostream &operator<<(raw_ostream &OS, - DeclarationNameInfo DNInfo) { - DNInfo.printName(OS); - return OS; -} +raw_ostream &operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo); } // namespace clang diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 2c0077eca9d1..a11c87604658 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -625,13 +625,13 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (Policy.FullyQualifiedName) { Proto += D->getQualifiedNameAsString(); } else { + llvm::raw_string_ostream OS(Proto); if (!Policy.SuppressScope) { if (const NestedNameSpecifier *NS = D->getQualifier()) { - llvm::raw_string_ostream OS(Proto); NS->print(OS, Policy); } } - Proto += D->getNameInfo().getAsString(); + D->getNameInfo().printName(OS, Policy); } if (GuideDecl) diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp index fe69c71aa3dd..4eb11bc57e52 100644 --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -134,7 +134,8 @@ static void printCXXConstructorDestructorName(QualType ClassType, ClassType.print(OS, Policy); } -void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) { +void DeclarationName::print(raw_ostream &OS, + const PrintingPolicy &Policy) const { switch (getNameKind()) { case DeclarationName::Identifier: if (const IdentifierInfo *II = getAsIdentifierInfo()) @@ -447,11 +448,17 @@ bool DeclarationNameInfo::isInstantiationDependent() const { std::string DeclarationNameInfo::getAsString() const { std::string Result; llvm::raw_string_ostream OS(Result); - printName(OS); + OS << *this; return OS.str(); } -void DeclarationNameInfo::printName(raw_ostream &OS) const { +raw_ostream &clang::operator<<(raw_ostream &OS, DeclarationNameInfo DNInfo) { + LangOptions LO; + DNInfo.printName(OS, PrintingPolicy(LangOptions())); + return OS; +} + +void DeclarationNameInfo::printName(raw_ostream &OS, PrintingPolicy Policy) const { switch (Name.getNameKind()) { case DeclarationName::Identifier: case DeclarationName::ObjCZeroArgSelector: @@ -461,7 +468,7 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const { case DeclarationName::CXXLiteralOperatorName: case DeclarationName::CXXUsingDirective: case DeclarationName::CXXDeductionGuideName: - OS << Name; + Name.print(OS, Policy); return; case DeclarationName::CXXConstructorName: @@ -473,13 +480,11 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const { else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName) OS << "operator "; LangOptions LO; - LO.CPlusPlus = true; - LO.Bool = true; - PrintingPolicy PP(LO); - PP.SuppressScope = true; - OS << TInfo->getType().getAsString(PP); + Policy.adjustForCPlusPlus(); + Policy.SuppressScope = true; + OS << TInfo->getType().getAsString(Policy); } else - OS << Name; + Name.print(OS, Policy); return; } llvm_unreachable("Unexpected declaration name kind"); diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 603ae5f9c48d..1602ef567605 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -697,7 +697,7 @@ void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) { Indent() << "#pragma omp critical"; if (Node->getDirectiveName().getName()) { OS << " ("; - Node->getDirectiveName().printName(OS); + Node->getDirectiveName().printName(OS, Policy); OS << ")"; } PrintOMPExecutableDirective(Node); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits