Print NamedDecls directly to a raw_ostream where possible.

llvm-svn: 149982
This commit is contained in:
Benjamin Kramer 2012-02-07 11:57:57 +00:00
parent 2f56992964
commit db0fc5131d
10 changed files with 18 additions and 19 deletions

View File

@ -335,8 +335,7 @@ void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
}
void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Out << "using " << D->getNameAsString() << " = "
<< D->getUnderlyingType().getAsString(Policy);
Out << "using " << *D << " = " << D->getUnderlyingType().getAsString(Policy);
}
void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
@ -600,7 +599,7 @@ void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
}
void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
Out << D->getNameAsString() << ":";
Out << *D << ":";
}
@ -761,7 +760,7 @@ void DeclPrinter::PrintTemplateParameters(
if (TTP->isParameterPack())
Out << "... ";
Out << TTP->getNameAsString();
Out << *TTP;
if (Args) {
Out << " = ";

View File

@ -287,7 +287,7 @@ void StmtDumper::DumpDeclarator(Decl *D) {
PrintingPolicy(UD->getASTContext().getLangOptions()));
OS << ";\"";
} else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
OS << "label " << LD->getNameAsString();
OS << "label " << *LD;
} else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
OS << "\"static_assert(\n";
DumpSubTree(SAD->getAssertExpr());

View File

@ -1608,12 +1608,12 @@ void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) {
}
void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
OS << "sizeof...(" << E->getPack()->getNameAsString() << ")";
OS << "sizeof...(" << *E->getPack() << ")";
}
void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr(
SubstNonTypeTemplateParmPackExpr *Node) {
OS << Node->getParameterPack()->getNameAsString();
OS << *Node->getParameterPack();
}
void StmtPrinter::VisitSubstNonTypeTemplateParmExpr(

View File

@ -326,7 +326,7 @@ void TemplateArgument::print(const PrintingPolicy &Policy,
if (NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getAsDecl())) {
if (ND->getDeclName()) {
Unnamed = false;
Out << ND->getNameAsString();
Out << *ND;
}
}

View File

@ -149,7 +149,7 @@ TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy,
subst->getReplacement().print(OS, Policy, SuppressNNS);
} else if (SubstTemplateTemplateParmPackStorage *SubstPack
= getAsSubstTemplateTemplateParmPack())
OS << SubstPack->getParameterPack()->getNameAsString();
OS << *SubstPack->getParameterPack();
else {
OverloadedTemplateStorage *OTS = getAsOverloadedTemplate();
(*OTS->begin())->printName(OS);

View File

@ -76,7 +76,7 @@ public:
virtual void DeclRead(serialization::DeclID ID, const Decl *D) {
llvm::outs() << "PCH DECL: " << D->getDeclKindName();
if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
llvm::outs() << " - " << ND->getNameAsString();
llvm::outs() << " - " << *ND;
llvm::outs() << "\n";
DelegatingDeserializationListener::DeclRead(ID, D);

View File

@ -2205,7 +2205,7 @@ CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
else {
const FunctionDecl *FD = cast<FunctionDecl>(D);
os << " is returned from a function whose name ('"
<< FD->getNameAsString()
<< *FD
<< "') does not contain 'Copy' or 'Create'. This violates the naming"
" convention rules given in the Memory Management Guide for Core"
" Foundation";

View File

@ -165,18 +165,18 @@ void WalkAST::ReportVirtualCall(const CallExpr *CE, bool isPure) {
os << "Call Path : ";
// Name of current visiting CallExpr.
os << CE->getDirectCallee()->getNameAsString();
os << *CE->getDirectCallee();
// Name of the CallExpr whose body is current walking.
if (visitingCallExpr)
os << " <-- " << visitingCallExpr->getDirectCallee()->getNameAsString();
os << " <-- " << *visitingCallExpr->getDirectCallee();
// Names of FunctionDecls in worklist with state PostVisited.
for (SmallVectorImpl<const CallExpr *>::iterator I = WList.end(),
E = WList.begin(); I != E; --I) {
const FunctionDecl *FD = (*(I-1))->getDirectCallee();
assert(FD);
if (VisitedFunctions[FD] == PostVisited)
os << " <-- " << FD->getNameAsString();
os << " <-- " << *FD;
}
PathDiagnosticLocation CELoc =

View File

@ -757,7 +757,7 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N,
if (isa<BlockDecl>(callee))
Out << "Entering call to block";
else if (const NamedDecl *ND = dyn_cast<NamedDecl>(callee))
Out << "Entering call to '" << ND->getNameAsString() << "'";
Out << "Entering call to '" << *ND << "'";
StringRef msg = Out.str();
if (msg.empty())
return 0;
@ -767,7 +767,7 @@ CallEnterExitBRVisitor::VisitNode(const ExplodedNode *N,
const Decl *caller = CExit->getLocationContext()->getParent()->getDecl();
pos = getLastStmtLoc(PrevN, BRC.getSourceManager());
if (const NamedDecl *ND = dyn_cast<NamedDecl>(caller))
Out << "Returning to '" << ND->getNameAsString() << "'";
Out << "Returning to '" << *ND << "'";
else
Out << "Returning to caller";
return new PathDiagnosticCallExitPiece(pos, Out.str());

View File

@ -3042,7 +3042,7 @@ CXString clang_getCursorDisplayName(CXCursor C) {
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
llvm::SmallString<64> Str;
llvm::raw_svector_ostream OS(Str);
OS << Function->getNameAsString();
OS << *Function;
if (Function->getPrimaryTemplate())
OS << "<>";
OS << "(";
@ -3064,7 +3064,7 @@ CXString clang_getCursorDisplayName(CXCursor C) {
if (ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) {
llvm::SmallString<64> Str;
llvm::raw_svector_ostream OS(Str);
OS << ClassTemplate->getNameAsString();
OS << *ClassTemplate;
OS << "<";
TemplateParameterList *Params = ClassTemplate->getTemplateParameters();
for (unsigned I = 0, N = Params->size(); I != N; ++I) {
@ -3100,7 +3100,7 @@ CXString clang_getCursorDisplayName(CXCursor C) {
llvm::SmallString<64> Str;
llvm::raw_svector_ostream OS(Str);
OS << ClassSpec->getNameAsString();
OS << *ClassSpec;
OS << TemplateSpecializationType::PrintTemplateArgumentList(
ClassSpec->getTemplateArgs().data(),
ClassSpec->getTemplateArgs().size(),