diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 32 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 7 | ||||
-rw-r--r-- | clang/lib/AST/Expr.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenTypes.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTConsumers.cpp | 3 |
5 files changed, 36 insertions, 13 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index d2a9f84cd4f..5e8d1307897 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1173,10 +1173,24 @@ std::string NamedDecl::getQualifiedNameAsString() const { } std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { + std::string QualName; + llvm::raw_string_ostream OS(QualName); + printQualifiedName(OS, P); + return OS.str(); +} + +void NamedDecl::printQualifiedName(raw_ostream &OS) const { + printQualifiedName(OS, getASTContext().getPrintingPolicy()); +} + +void NamedDecl::printQualifiedName(raw_ostream &OS, + const PrintingPolicy &P) const { const DeclContext *Ctx = getDeclContext(); - if (Ctx->isFunctionOrMethod()) - return getNameAsString(); + if (Ctx->isFunctionOrMethod()) { + printName(OS); + return; + } typedef SmallVector<const DeclContext *, 8> ContextsTy; ContextsTy Contexts; @@ -1185,10 +1199,7 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { while (Ctx && isa<NamedDecl>(Ctx)) { Contexts.push_back(Ctx); Ctx = Ctx->getParent(); - }; - - std::string QualName; - llvm::raw_string_ostream OS(QualName); + } for (ContextsTy::reverse_iterator I = Contexts.rbegin(), E = Contexts.rend(); I != E; ++I) { @@ -1241,8 +1252,15 @@ std::string NamedDecl::getQualifiedNameAsString(const PrintingPolicy &P) const { OS << *this; else OS << "<anonymous>"; +} - return OS.str(); +void NamedDecl::getNameForDiagnostic(raw_ostream &OS, + const PrintingPolicy &Policy, + bool Qualified) const { + if (Qualified) + printQualifiedName(OS, Policy); + else + printName(OS); } bool NamedDecl::declarationReplaces(NamedDecl *OldD) const { diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index cdf150595c3..0db520e7d63 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -190,8 +190,11 @@ void PrettyStackTraceDecl::print(raw_ostream &OS) const { OS << Message; - if (const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) - OS << " '" << DN->getQualifiedNameAsString() << '\''; + if (const NamedDecl *DN = dyn_cast_or_null<NamedDecl>(TheDecl)) { + OS << " '"; + DN->printQualifiedName(OS); + OS << '\''; + } OS << '\n'; } diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 66980a9cd12..b97f4d1d3a9 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -477,8 +477,9 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { } PrintingPolicy Policy(Context.getLangOpts()); - std::string Proto = FD->getQualifiedNameAsString(Policy); + std::string Proto; llvm::raw_string_ostream POut(Proto); + FD->printQualifiedName(POut, Policy); const FunctionDecl *Decl = FD; if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern()) diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index c82e1d829df..259d10673d8 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -61,14 +61,14 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, // FIXME: We should not have to check for a null decl context here. // Right now we do it because the implicit Obj-C decls don't have one. if (RD->getDeclContext()) - OS << RD->getQualifiedNameAsString(); + RD->printQualifiedName(OS); else RD->printName(OS); } else if (const TypedefNameDecl *TDD = RD->getTypedefNameForAnonDecl()) { // FIXME: We should not have to check for a null decl context here. // Right now we do it because the implicit Obj-C decls don't have one. if (TDD->getDeclContext()) - OS << TDD->getQualifiedNameAsString(); + TDD->printQualifiedName(OS); else TDD->printName(OS); } else diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp index 687fc00c6c9..936bd2f8a4e 100644 --- a/clang/lib/Frontend/ASTConsumers.cpp +++ b/clang/lib/Frontend/ASTConsumers.cpp @@ -104,7 +104,8 @@ namespace { bool shouldWalkTypesOfTypeLocs() const { return false; } virtual bool VisitNamedDecl(NamedDecl *D) { - Out << D->getQualifiedNameAsString() << "\n"; + D->printQualifiedName(Out); + Out << '\n'; return true; } |