diff options
Diffstat (limited to 'lib/AST/DeclarationName.cpp')
-rw-r--r-- | lib/AST/DeclarationName.cpp | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index b2f27275f49c7..2a988e1d22d03 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" -#include "clang/AST/Decl.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclarationName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" @@ -133,36 +133,45 @@ int DeclarationName::compare(DeclarationName LHS, DeclarationName RHS) { llvm_unreachable("Invalid DeclarationName Kind!"); } -raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { +static void printCXXConstructorDestructorName(QualType ClassType, + raw_ostream &OS, + PrintingPolicy Policy) { + // We know we're printing C++ here. Ensure we print types properly. + Policy.adjustForCPlusPlus(); + + if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) { + OS << *ClassRec->getDecl(); + return; + } + if (Policy.SuppressTemplateArgsInCXXConstructors) { + if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) { + OS << *InjTy->getDecl(); + return; + } + } + ClassType.print(OS, Policy); +} + +void DeclarationName::print(raw_ostream &OS, const PrintingPolicy &Policy) { + DeclarationName &N = *this; switch (N.getNameKind()) { case DeclarationName::Identifier: if (const IdentifierInfo *II = N.getAsIdentifierInfo()) OS << II->getName(); - return OS; + return; case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: N.getObjCSelector().print(OS); - return OS; - - case DeclarationName::CXXConstructorName: { - QualType ClassType = N.getCXXNameType(); - if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) - return OS << *ClassRec->getDecl(); - LangOptions LO; - LO.CPlusPlus = true; - return OS << ClassType.getAsString(PrintingPolicy(LO)); - } + return; + + case DeclarationName::CXXConstructorName: + return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); case DeclarationName::CXXDestructorName: { OS << '~'; - QualType Type = N.getCXXNameType(); - if (const RecordType *Rec = Type->getAs<RecordType>()) - return OS << *Rec->getDecl(); - LangOptions LO; - LO.CPlusPlus = true; - return OS << Type.getAsString(PrintingPolicy(LO)); + return printCXXConstructorDestructorName(N.getCXXNameType(), OS, Policy); } case DeclarationName::CXXOperatorName: { @@ -178,29 +187,41 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { OS << "operator"; if (OpName[0] >= 'a' && OpName[0] <= 'z') OS << ' '; - return OS << OpName; + OS << OpName; + return; } case DeclarationName::CXXLiteralOperatorName: - return OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); + OS << "operator\"\"" << N.getCXXLiteralIdentifier()->getName(); + return; case DeclarationName::CXXConversionFunctionName: { OS << "operator "; QualType Type = N.getCXXNameType(); - if (const RecordType *Rec = Type->getAs<RecordType>()) - return OS << *Rec->getDecl(); - LangOptions LO; - LO.CPlusPlus = true; - LO.Bool = true; - return OS << Type.getAsString(PrintingPolicy(LO)); + if (const RecordType *Rec = Type->getAs<RecordType>()) { + OS << *Rec->getDecl(); + return; + } + // We know we're printing C++ here, ensure we print 'bool' properly. + PrintingPolicy CXXPolicy = Policy; + CXXPolicy.adjustForCPlusPlus(); + Type.print(OS, CXXPolicy); + return; } case DeclarationName::CXXUsingDirective: - return OS << "<using-directive>"; + OS << "<using-directive>"; + return; } llvm_unreachable("Unexpected declaration name kind"); } +raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { + LangOptions LO; + N.print(OS, PrintingPolicy(LO)); + return OS; +} + } // end namespace clang DeclarationName::NameKind DeclarationName::getNameKind() const { @@ -333,7 +354,7 @@ DeclarationName DeclarationName::getUsingDirectiveName() { return DeclarationName(Ptr); } -void DeclarationName::dump() const { +LLVM_DUMP_METHOD void DeclarationName::dump() const { llvm::errs() << *this << '\n'; } |