From: Aaron Ballman Date: Fri, 3 Jan 2014 17:59:55 +0000 (+0000) Subject: Fixed a FIXME; created a print method for Selectors that accepts a raw_ostream, and... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b190f974c9c0312fa8a6b5a1979722569c27dca8;p=platform%2Fupstream%2Fllvm.git Fixed a FIXME; created a print method for Selectors that accepts a raw_ostream, and started using it in places it made sense. No functional changes intended, just API cleanliness. llvm-svn: 198428 --- diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h index 304ff36..abf5b93 100644 --- a/clang/include/clang/Basic/IdentifierTable.h +++ b/clang/include/clang/Basic/IdentifierTable.h @@ -697,9 +697,11 @@ public: /// \brief Derive the full selector name (e.g. "foo:bar:") and return /// it as an std::string. - // FIXME: Add a print method that uses a raw_ostream. std::string getAsString() const; + /// \brief Prints the full selector name (e.g. "foo:bar:"). + void print(llvm::raw_ostream &OS) const; + /// \brief Derive the conventional family of this method. ObjCMethodFamily getMethodFamily() const { return getMethodFamilyImpl(*this); diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index 2f40255..a5591a9 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -1838,7 +1838,8 @@ void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) { void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) { VisitExpr(Node); - OS << " selector=" << Node->getSelector().getAsString(); + OS << " selector="; + Node->getSelector().print(OS); switch (Node->getReceiverKind()) { case ObjCMessageExpr::Instance: break; @@ -1860,7 +1861,8 @@ void ASTDumper::VisitObjCMessageExpr(const ObjCMessageExpr *Node) { void ASTDumper::VisitObjCBoxedExpr(const ObjCBoxedExpr *Node) { VisitExpr(Node); - OS << " selector=" << Node->getBoxingMethod()->getSelector().getAsString(); + OS << " selector="; + Node->getBoxingMethod()->getSelector().print(OS); } void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { @@ -1879,7 +1881,8 @@ void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) { void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) { VisitExpr(Node); - OS << " " << Node->getSelector().getAsString(); + OS << " "; + Node->getSelector().print(OS); } void ASTDumper::VisitObjCProtocolExpr(const ObjCProtocolExpr *Node) { @@ -1893,13 +1896,13 @@ void ASTDumper::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *Node) { if (Node->isImplicitProperty()) { OS << " Kind=MethodRef Getter=\""; if (Node->getImplicitPropertyGetter()) - OS << Node->getImplicitPropertyGetter()->getSelector().getAsString(); + Node->getImplicitPropertyGetter()->getSelector().print(OS); else OS << "(null)"; OS << "\" Setter=\""; if (ObjCMethodDecl *Setter = Node->getImplicitPropertySetter()) - OS << Setter->getSelector().getAsString(); + Setter->getSelector().print(OS); else OS << "(null)"; OS << "\""; @@ -1926,7 +1929,7 @@ void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) { else OS << " Kind=DictionarySubscript GetterForDictionary=\""; if (Node->getAtIndexMethodDecl()) - OS << Node->getAtIndexMethodDecl()->getSelector().getAsString(); + Node->getAtIndexMethodDecl()->getSelector().print(OS); else OS << "(null)"; @@ -1935,7 +1938,7 @@ void ASTDumper::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *Node) { else OS << "\" SetterForDictionary=\""; if (Node->setAtIndexMethodDecl()) - OS << Node->setAtIndexMethodDecl()->getSelector().getAsString(); + Node->setAtIndexMethodDecl()->getSelector().print(OS); else OS << "(null)"; } diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 26e2cda..61c693c 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -1078,13 +1078,13 @@ void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { } if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { - Out << (first ? ' ' : ',') << "getter = " - << PDecl->getGetterName().getAsString(); + Out << (first ? ' ' : ',') << "getter = "; + PDecl->getGetterName().print(Out); first = false; } if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { - Out << (first ? ' ' : ',') << "setter = " - << PDecl->getSetterName().getAsString(); + Out << (first ? ' ' : ',') << "setter = "; + PDecl->getSetterName().print(Out); first = false; } diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp index e064e23..56b7574 100644 --- a/clang/lib/AST/DeclarationName.cpp +++ b/clang/lib/AST/DeclarationName.cpp @@ -143,7 +143,8 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) { case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: - return OS << N.getObjCSelector().getAsString(); + N.getObjCSelector().print(OS); + return OS; case DeclarationName::CXXConstructorName: { QualType ClassType = N.getCXXNameType(); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index cf7beb3..aff0a12 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -627,7 +627,7 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) { Out << '(' << *CID << ')'; Out << ' '; - Out << MD->getSelector().getAsString(); + MD->getSelector().print(Out); Out << ']'; Out.flush(); diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index 231ef03..24b9d52 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -246,7 +246,9 @@ void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD, OS << (MD->isInstanceMethod() ? '-' : '+') << '[' << CD->getName(); if (const ObjCCategoryImplDecl *CID = dyn_cast(CD)) OS << '(' << *CID << ')'; - OS << ' ' << MD->getSelector().getAsString() << ']'; + OS << ' '; + MD->getSelector().print(OS); + OS << ']'; Out << OS.str().size() << OS.str(); } diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index b5a96c1..d15dfd1 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -722,7 +722,7 @@ void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { } if (Node->isImplicitProperty()) - OS << Node->getImplicitPropertyGetter()->getSelector().getAsString(); + Node->getImplicitPropertyGetter()->getSelector().print(OS); else OS << Node->getExplicitProperty()->getName(); } @@ -1815,7 +1815,9 @@ void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { } void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { - OS << "@selector(" << Node->getSelector().getAsString() << ')'; + OS << "@selector("; + Node->getSelector().print(OS); + OS << ')'; } void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index 500e732..1e2bab7 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -398,6 +398,10 @@ std::string Selector::getAsString() const { return getMultiKeywordSelector()->getName(); } +void Selector::print(llvm::raw_ostream &OS) const { + OS << getAsString(); +} + /// Interpreting the given string using the normal CamelCase /// conventions, determine whether the given string starts with the /// given "word", which is assumed to end in a lowercase letter. diff --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp index 6b8c56f..3384d4b 100644 --- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp @@ -170,10 +170,13 @@ void NilArgChecker::warnIfNilArg(CheckerContext &C, assert(Arg == 1); os << "Key argument "; } - os << "to '" << msg.getSelector().getAsString() << "' cannot be nil"; + os << "to '"; + msg.getSelector().print(os); + os << "' cannot be nil"; } else { - os << "Argument to '" << GetReceiverInterfaceName(msg) << "' method '" - << msg.getSelector().getAsString() << "' cannot be nil"; + os << "Argument to '" << GetReceiverInterfaceName(msg) << "' method '"; + msg.getSelector().print(os); + os << "' cannot be nil"; } } @@ -620,7 +623,9 @@ void ClassReleaseChecker::checkPreObjCMessage(const ObjCMethodCall &msg, SmallString<200> buf; llvm::raw_svector_ostream os(buf); - os << "The '" << S.getAsString() << "' message should be sent to instances " + os << "The '"; + S.print(os); + os << "' message should be sent to instances " "of class '" << Class->getName() << "' and not the class directly"; @@ -771,8 +776,8 @@ void VariadicMethodTypeChecker::checkPreObjCMessage(const ObjCMethodCall &msg, else os << "Argument to method '"; - os << msg.getSelector().getAsString() - << "' should be an Objective-C pointer type, not '"; + msg.getSelector().print(os); + os << "' should be an Objective-C pointer type, not '"; ArgTy.print(os, C.getLangOpts()); os << "'"; diff --git a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp index fefcbe7..8918cd1 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp @@ -426,8 +426,9 @@ void CallAndMessageChecker::emitNilReceiverBug(CheckerContext &C, SmallString<200> buf; llvm::raw_svector_ostream os(buf); - os << "The receiver of message '" << ME->getSelector().getAsString() - << "' is nil"; + os << "The receiver of message '"; + ME->getSelector().print(os); + os << "' is nil"; if (ResTy->isReferenceType()) { os << ", which results in forming a null reference"; } else { diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp index 9cb1d2d..cf2d6cc 100644 --- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp @@ -53,9 +53,9 @@ static void CompareReturnTypes(const ObjCMethodDecl *MethDerived, << *MethDerived->getClassInterface() << "', which is derived from class '" << *MethAncestor->getClassInterface() - << "', defines the instance method '" - << MethDerived->getSelector().getAsString() - << "' whose return type is '" + << "', defines the instance method '"; + MethDerived->getSelector().print(os); + os << "' whose return type is '" << ResDerived.getAsString() << "'. A method with the same name (same selector) is also defined in " "class '" diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 3702977..8697bad 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -909,7 +909,7 @@ bool MallocChecker::printAllocDeallocName(raw_ostream &os, CheckerContext &C, os << "-"; else os << "+"; - os << Msg->getSelector().getAsString(); + Msg->getSelector().print(os); return true; } diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 7ee87f5..6ce57fe 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -1087,7 +1087,9 @@ PathDiagnosticPiece *NilReceiverBRVisitor::VisitNode(const ExplodedNode *N, llvm::raw_svector_ostream OS(Buf); if (const ObjCMessageExpr *ME = dyn_cast(S)) { - OS << "'" << ME->getSelector().getAsString() << "' not called"; + OS << "'"; + ME->getSelector().print(OS); + OS << "' not called"; } else { OS << "No method is called";