From 077bf5e2f48acfa9e7d69429b6e4ba86ea14896d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 24 Nov 2008 03:33:13 +0000 Subject: [PATCH] Rename Selector::getName() to Selector::getAsString(), and add a new NamedDecl::getAsString() method. Change uses of Selector::getName() to just pass in a Selector where possible (e.g. to diagnostics) instead of going through an std::string. This also adds new formatters for objcinstance and objcclass as described in the dox. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59933 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/ASTConsumers.cpp | 8 +++--- Driver/AnalysisConsumer.cpp | 4 +-- Driver/RewriteBlocks.cpp | 4 +-- Driver/RewriteObjC.cpp | 28 ++++++++++----------- docs/InternalsManual.html | 14 +++++++++++ include/clang/AST/Decl.h | 1 + include/clang/Basic/DiagnosticKinds.def | 12 +++++---- include/clang/Basic/IdentifierTable.h | 6 ++--- lib/AST/ASTContext.cpp | 4 +-- lib/AST/DeclObjC.cpp | 2 +- lib/AST/DeclarationName.cpp | 2 +- lib/AST/StmtDumper.cpp | 11 ++++---- lib/AST/StmtPrinter.cpp | 2 +- lib/Analysis/BasicObjCFoundationChecks.cpp | 4 +-- lib/Analysis/CFRefCount.cpp | 4 +-- lib/Analysis/CheckObjCInstMethSignature.cpp | 2 +- lib/Basic/IdentifierTable.cpp | 2 +- lib/CodeGen/CGCXX.cpp | 13 ++++------ lib/CodeGen/CGObjCGNU.cpp | 17 +++++++------ lib/CodeGen/CGObjCMac.cpp | 17 ++++++------- lib/Sema/Sema.cpp | 17 ++++++++++--- lib/Sema/Sema.h | 2 +- lib/Sema/SemaDeclObjC.cpp | 11 ++++---- lib/Sema/SemaExprObjC.cpp | 26 ++++++++++--------- 24 files changed, 118 insertions(+), 95 deletions(-) diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 3536ee8d9f..55a7d0273f 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -198,7 +198,7 @@ void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) { if (!OMD->getResultType().isNull()) Out << '(' << OMD->getResultType().getAsString() << ")"; - std::string name = OMD->getSelector().getName(); + std::string name = OMD->getSelector().getAsString(); std::string::size_type pos, lastPos = 0; for (unsigned i = 0, e = OMD->getNumParams(); i != e; ++i) { ParmVarDecl *PDecl = OMD->getParamDecl(i); @@ -363,12 +363,12 @@ void DeclPrinter::PrintObjCPropertyDecl(ObjCPropertyDecl *PDecl) { if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { Out << (first ? ' ' : ',') << "getter = " - << PDecl->getGetterName().getName(); + << PDecl->getGetterName().getAsString(); first = false; } if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { Out << (first ? ' ' : ',') << "setter = " - << PDecl->getSetterName().getName(); + << PDecl->getSetterName().getAsString(); first = false; } @@ -477,7 +477,7 @@ namespace { } else if (isa(D)) { Out << "Read file scope asm decl\n"; } else if (ObjCMethodDecl* MD = dyn_cast(D)) { - Out << "Read objc method decl: '" << MD->getSelector().getName() + Out << "Read objc method decl: '" << MD->getSelector().getAsString() << "'\n"; if (MD->getBody()) { // FIXME: convert dumper to use std::ostream? diff --git a/Driver/AnalysisConsumer.cpp b/Driver/AnalysisConsumer.cpp index 503ad38345..5d9f896173 100644 --- a/Driver/AnalysisConsumer.cpp +++ b/Driver/AnalysisConsumer.cpp @@ -246,7 +246,7 @@ case PD_##NAME: C.PD.reset(CREATEFN(C.HTMLDir, C.PP, C.PPF)); break; llvm::cerr << "ANALYZE (ObjC Method): " << getContext().getSourceManager().getSourceName(MD->getLocation()) << " '" - << MD->getSelector().getName() << "'\n"; + << MD->getSelector().getAsString() << "'\n"; } } }; @@ -281,7 +281,7 @@ void AnalysisConsumer::HandleTopLevelDecl(Decl *D) { case Decl::ObjCMethod: { ObjCMethodDecl* MD = cast(D); - if (FName.size() > 0 && FName != MD->getSelector().getName()) + if (FName.size() > 0 && FName != MD->getSelector().getAsString()) return; Stmt* Body = MD->getBody(); diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp index 535915344c..11d7e36e6c 100644 --- a/Driver/RewriteBlocks.cpp +++ b/Driver/RewriteBlocks.cpp @@ -625,7 +625,7 @@ void RewriteBlocks::InsertBlockLiteralsWithinFunction(FunctionDecl *FD) { void RewriteBlocks::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { SourceLocation FunLocStart = MD->getLocStart(); - std::string FuncName = std::string(MD->getSelector().getName()); + std::string FuncName = MD->getSelector().getAsString(); // Convert colons to underscores. std::string::size_type loc = 0; while ((loc = FuncName.find(":", loc)) != std::string::npos) @@ -920,7 +920,7 @@ std::string RewriteBlocks::SynthesizeBlockInitExpr(BlockExpr *Exp, VarDecl *VD) if (CurFunctionDef) FuncName = std::string(CurFunctionDef->getName()); else if (CurMethodDef) { - FuncName = std::string(CurMethodDef->getSelector().getName()); + FuncName = CurMethodDef->getSelector().getAsString(); // Convert colons to underscores. std::string::size_type loc = 0; while ((loc = FuncName.find(":", loc)) != std::string::npos) diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index a3ce8a8c56..3acb6dd94e 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -749,10 +749,8 @@ void RewriteObjC::RewriteObjCMethodDecl(ObjCMethodDecl *OMD, NameStr += "_"; } // Append selector names, replacing ':' with '_' - if (OMD->getSelector().getName().find(':') == std::string::npos) - NameStr += OMD->getSelector().getName(); - else { - std::string selString = OMD->getSelector().getName(); + { + std::string selString = OMD->getSelector().getAsString(); int len = selString.size(); for (int i = 0; i < len; i++) if (selString[i] == ':') @@ -1498,8 +1496,8 @@ Stmt *RewriteObjC::RewriteAtSelector(ObjCSelectorExpr *Exp) { // Create a call to sel_registerName("selName"). llvm::SmallVector SelExprs; QualType argType = Context->getPointerType(Context->CharTy); - SelExprs.push_back(new StringLiteral(Exp->getSelector().getName().c_str(), - Exp->getSelector().getName().size(), + SelExprs.push_back(new StringLiteral(Exp->getSelector().getAsString().c_str(), + Exp->getSelector().getAsString().size(), false, argType, SourceLocation(), SourceLocation())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, @@ -2146,8 +2144,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) { // Create a call to sel_registerName("selName"), it will be the 2nd argument. llvm::SmallVector SelExprs; QualType argType = Context->getPointerType(Context->CharTy); - SelExprs.push_back(new StringLiteral(Exp->getSelector().getName().c_str(), - Exp->getSelector().getName().size(), + SelExprs.push_back(new StringLiteral(Exp->getSelector().getAsString().c_str(), + Exp->getSelector().getAsString().size(), false, argType, SourceLocation(), SourceLocation())); CallExpr *SelExp = SynthesizeCallToFunctionDecl(SelGetUidFunctionDecl, @@ -2532,7 +2530,7 @@ void RewriteObjC::RewriteObjCMethodsMetaData(instmeth_iterator MethodBegin, Result += "{\n\t0, " + utostr(MethodEnd-MethodBegin) + "\n"; Result += "\t,{{(SEL)\""; - Result += (*MethodBegin)->getSelector().getName().c_str(); + Result += (*MethodBegin)->getSelector().getAsString().c_str(); std::string MethodTypeString; Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString); Result += "\", \""; @@ -2542,7 +2540,7 @@ void RewriteObjC::RewriteObjCMethodsMetaData(instmeth_iterator MethodBegin, Result += "}\n"; for (++MethodBegin; MethodBegin != MethodEnd; ++MethodBegin) { Result += "\t ,{(SEL)\""; - Result += (*MethodBegin)->getSelector().getName().c_str(); + Result += (*MethodBegin)->getSelector().getAsString().c_str(); std::string MethodTypeString; Context->getObjCEncodingForMethodDecl(*MethodBegin, MethodTypeString); Result += "\", \""; @@ -2606,7 +2604,7 @@ RewriteObjCProtocolsMetaData(const ObjCList &Protocols, Result += "\t ,{{(SEL)\""; else Result += "\t ,{(SEL)\""; - Result += (*I)->getSelector().getName().c_str(); + Result += (*I)->getSelector().getAsString().c_str(); std::string MethodTypeString; Context->getObjCEncodingForMethodDecl((*I), MethodTypeString); Result += "\", \""; @@ -2642,7 +2640,7 @@ RewriteObjCProtocolsMetaData(const ObjCList &Protocols, Result += "\t ,{{(SEL)\""; else Result += "\t ,{(SEL)\""; - Result += (*I)->getSelector().getName().c_str(); + Result += (*I)->getSelector().getAsString().c_str(); std::string MethodTypeString; Context->getObjCEncodingForMethodDecl((*I), MethodTypeString); Result += "\", \""; @@ -3451,7 +3449,7 @@ void RewriteObjC::InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD) { //SourceLocation FunLocStart = MD->getLocStart(); // FIXME: This hack works around a bug in Rewrite.InsertText(). SourceLocation FunLocStart = MD->getLocStart().getFileLocWithOffset(-1); - std::string FuncName = std::string(MD->getSelector().getName()); + std::string FuncName = MD->getSelector().getAsString(); // Convert colons to underscores. std::string::size_type loc = 0; while ((loc = FuncName.find(":", loc)) != std::string::npos) @@ -3767,9 +3765,9 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp) { std::string FuncName; if (CurFunctionDef) - FuncName = std::string(CurFunctionDef->getName()); + FuncName = CurFunctionDef->getNameAsString(); else if (CurMethodDef) { - FuncName = std::string(CurMethodDef->getSelector().getName()); + FuncName = CurMethodDef->getSelector().getAsString(); // Convert colons to underscores. std::string::size_type loc = 0; while ((loc = FuncName.find(":", loc)) != std::string::npos) diff --git a/docs/InternalsManual.html b/docs/InternalsManual.html index 91a12a93b9..9e8a21e708 100644 --- a/docs/InternalsManual.html +++ b/docs/InternalsManual.html @@ -297,6 +297,20 @@ Clang:

abort, as will a failure to match the argument against any expression.

+"objcclass" format +Example:"method %objcclass0 not found" +Class:DeclarationName +Description:

This is a simple formatter that indicates the + DeclarationName corresponds to an Objective-C class method selector. As + such, it prints the selector with a leading '+'.

+ +"objcinstance" format +Example:"method %objcinstance0 not found" +Class:DeclarationName +Description:

This is a simple formatter that indicates the + DeclarationName corresponds to an Objective-C instance method selector. As + such, it prints the selector with a leading '-'.

+

It is really easy to add format specifiers to the Clang diagnostics system, diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 8e688fec5d..46cbe7ab54 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -101,6 +101,7 @@ public: /// absolutely critical. For simple declarations, @c /// getIdentifierName() should suffice. std::string getName() const { return Name.getAsString(); } + std::string getNameAsString() const { return Name.getAsString(); } static bool classof(const Decl *D) { return D->getKind() >= NamedFirst && D->getKind() <= NamedLast; diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 13894aef86..249b92e608 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -489,9 +489,9 @@ DIAG(warn_undef_method_impl, WARNING, DIAG(warn_incomplete_impl, WARNING, "incomplete implementation") DIAG(warn_multiple_method_decl, WARNING, - "multiple methods named '%0' found") + "multiple methods named %0 found") DIAG(err_duplicate_method_decl, ERROR, - "duplicate declaration of method '%0'") + "duplicate declaration of method %0") DIAG(err_undeclared_protocol, ERROR, "cannot find protocol declaration for %0") DIAG(err_missing_sel_definition, ERROR, @@ -508,10 +508,12 @@ DIAG(err_conflicting_aliasing_type, ERROR, "conflicting types for alias %0") DIAG(err_statically_allocated_object, ERROR, "statically allocated Objective-C object %0") -DIAG(warn_method_not_found, WARNING, - "method '%0%1' not found (return type defaults to 'id')") +DIAG(warn_class_method_not_found, WARNING, + "method %objcclass0 not found (return type defaults to 'id')") +DIAG(warn_inst_method_not_found, WARNING, + "method %objcinstance0 not found (return type defaults to 'id')") DIAG(warn_method_not_found_in_protocol, WARNING, - "method '%0%1' not found in protocol (return type defaults to 'id')") + "method %objcinstance0 not found in protocol (return type defaults to 'id')") DIAG(err_collection_expr_type, ERROR, "collection expression type ('%0') is not a valid object") DIAG(err_selector_element_type, ERROR, diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 348ef1477f..a0fac27657 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -281,9 +281,9 @@ public: unsigned getNumArgs() const; IdentifierInfo *getIdentifierInfoForSlot(unsigned argIndex) const; - /// getName - Derive the full selector name (e.g. "foo:bar:") and return it. - /// - std::string getName() const; + /// getAsString - Derive the full selector name (e.g. "foo:bar:") and return + /// it as an std::string. + std::string getAsString() const; static Selector getEmptyMarker() { return Selector(uintptr_t(-1)); diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 7bfdf71339..61e8c99aa4 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1577,12 +1577,12 @@ void ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) { S += ",G"; - S += PD->getGetterName().getName(); + S += PD->getGetterName().getAsString(); } if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) { S += ",S"; - S += PD->getSetterName().getName(); + S += PD->getSetterName().getAsString(); } if (SynthesizePID) { diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 558156c4a0..e69526e241 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -763,7 +763,7 @@ unsigned ObjCMethodDecl::getSynthesizedMethodSize() const { if (ObjCCategoryImplDecl *CID = dyn_cast(MethodContext)) length += strlen(CID->getIdentifierName()) +1; - length += getSelector().getName().size(); // selector name + length += getSelector().getAsString().size(); // selector name return length; } diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 3a9e7c84e3..ed4b7c6105 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -120,7 +120,7 @@ std::string DeclarationName::getAsString() const { case ObjCZeroArgSelector: case ObjCOneArgSelector: case ObjCMultiArgSelector: - return getObjCSelector().getName(); + return getObjCSelector().getAsString(); case CXXConstructorName: { QualType ClassType = getCXXNameType(); diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp index 04ae2cdb19..f7330c2a9d 100644 --- a/lib/AST/StmtDumper.cpp +++ b/lib/AST/StmtDumper.cpp @@ -376,7 +376,7 @@ void StmtDumper::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) { void StmtDumper::VisitMemberExpr(MemberExpr *Node) { DumpExpr(Node); fprintf(F, " %s%s %p", Node->isArrow() ? "->" : ".", - Node->getMemberDecl()->getName().c_str(), + Node->getMemberDecl()->getNameAsString().c_str(), (void*)Node->getMemberDecl()); } void StmtDumper::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { @@ -441,7 +441,7 @@ void StmtDumper::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { void StmtDumper::VisitObjCMessageExpr(ObjCMessageExpr* Node) { DumpExpr(Node); - fprintf(F, " selector=%s", Node->getSelector().getName().c_str()); + fprintf(F, " selector=%s", Node->getSelector().getAsString().c_str()); IdentifierInfo* clsName = Node->getClassName(); if (clsName) fprintf(F, " class=%s", clsName->getName()); } @@ -457,8 +457,7 @@ void StmtDumper::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { DumpExpr(Node); fprintf(F, " "); - Selector selector = Node->getSelector(); - fprintf(F, "%s", selector.getName().c_str()); + fprintf(F, "%s", Node->getSelector().getAsString().c_str()); } void StmtDumper::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { @@ -481,8 +480,8 @@ void StmtDumper::VisitObjCKVCRefExpr(ObjCKVCRefExpr *Node) { ObjCMethodDecl *Getter = Node->getGetterMethod(); ObjCMethodDecl *Setter = Node->getSetterMethod(); fprintf(F, " Kind=MethodRef Getter=\"%s\" Setter=\"%s\"", - Getter->getSelector().getName().c_str(), - Setter ? Setter->getSelector().getName().c_str() : "(null)"); + Getter->getSelector().getAsString().c_str(), + Setter ? Setter->getSelector().getAsString().c_str() : "(null)"); } void StmtDumper::VisitObjCSuperExpr(ObjCSuperExpr *Node) { diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 94cfae9d4c..8a7d3eb650 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -988,7 +988,7 @@ void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { } void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { - OS << "@selector(" << Node->getSelector().getName() << ")"; + OS << "@selector(" << Node->getSelector().getAsString() << ")"; } void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp index 033dc02cd7..d81b3343c9 100644 --- a/lib/Analysis/BasicObjCFoundationChecks.cpp +++ b/lib/Analysis/BasicObjCFoundationChecks.cpp @@ -91,7 +91,7 @@ public: std::ostringstream os; os << "Argument to '" << GetReceiverNameType(ME) << "' method '" - << ME->getSelector().getName() << "' cannot be nil."; + << ME->getSelector().getAsString() << "' cannot be nil."; Msg = os.str(); s = Msg.c_str(); @@ -243,7 +243,7 @@ bool BasicObjCFoundationChecks::AuditNSString(NodeTy* N, // FIXME: This is going to be really slow doing these checks with // lexical comparisons. - std::string name = S.getName(); + std::string name = S.getAsString(); assert (!name.empty()); const char* cstr = &name[0]; unsigned len = name.size(); diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 8c16c9fd6b..56f5ab6234 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1887,7 +1887,7 @@ CFRefCount::HandleSymbolDeath(GRStateManager& VMgr, if (V.isReturnedOwned() && V.getCount() == 0) if (const ObjCMethodDecl* MD = dyn_cast(CD)) { - std::string s = MD->getSelector().getName(); + std::string s = MD->getSelector().getAsString(); if (!followsReturnRule(s.c_str())) { hasLeak = true; state = state.set(sid, V ^ RefVal::ErrorLeakReturned); @@ -2635,7 +2635,7 @@ PathDiagnosticPiece* CFRefReport::getEndPath(BugReporter& br, if (RV->getKind() == RefVal::ErrorLeakReturned) { ObjCMethodDecl& MD = cast(BR.getGraph().getCodeDecl()); os << " is returned from a method whose name ('" - << MD.getSelector().getName() + << MD.getSelector().getAsString() << "') does not contain 'create' or 'copy' or otherwise starts with" " 'new' or 'alloc'. This violates the naming convention rules given" " in the Memory Management Guide for Cocoa (object leaked)."; diff --git a/lib/Analysis/CheckObjCInstMethSignature.cpp b/lib/Analysis/CheckObjCInstMethSignature.cpp index ffaef42b23..00dbe9f2b2 100644 --- a/lib/Analysis/CheckObjCInstMethSignature.cpp +++ b/lib/Analysis/CheckObjCInstMethSignature.cpp @@ -53,7 +53,7 @@ static void CompareReturnTypes(ObjCMethodDecl* MethDerived, << "', which is derived from class '" << MethAncestor->getClassInterface()->getName() << "', defines the instance method '" - << MethDerived->getSelector().getName() + << MethDerived->getSelector().getAsString() << "' whose return type is '" << ResDerived.getAsString() << "'. A method with the same name (same selector) is also defined in " diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp index 1bef76688c..048abf8b2e 100644 --- a/lib/Basic/IdentifierTable.cpp +++ b/lib/Basic/IdentifierTable.cpp @@ -342,7 +342,7 @@ std::string MultiKeywordSelector::getName() const { return Result; } -std::string Selector::getName() const { +std::string Selector::getAsString() const { if (IdentifierInfo *II = getAsIdentifierInfo()) { if (getNumArgs() == 0) return II->getName(); diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 70eeb942b7..d55d0f81bc 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -19,12 +19,9 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" #include "llvm/ADT/StringExtras.h" - using namespace clang; using namespace CodeGen; -using llvm::utostr; - // FIXME: Name mangling should be moved to a separate class. @@ -35,7 +32,7 @@ static void mangleDeclContextInternal(const DeclContext *D, std::string &S) "Only one level of decl context mangling is currently supported!"); if (const FunctionDecl* FD = dyn_cast(D)) { - S += utostr(FD->getIdentifier()->getLength()); + S += llvm::utostr(FD->getIdentifier()->getLength()); S += FD->getIdentifier()->getName(); if (FD->param_size() == 0) @@ -48,11 +45,11 @@ static void mangleDeclContextInternal(const DeclContext *D, std::string &S) std::string Name; Name += MD->isInstance() ? '-' : '+'; Name += '['; - Name += MD->getClassInterface()->getName(); + Name += MD->getClassInterface()->getNameAsString(); Name += ' '; - Name += MD->getSelector().getName(); + Name += MD->getSelector().getAsString(); Name += ']'; - S += utostr(Name.length()); + S += llvm::utostr(Name.length()); S += Name; } else assert(0 && "Unsupported decl type!"); @@ -64,7 +61,7 @@ static void mangleVarDeclInternal(const VarDecl &D, std::string &S) mangleDeclContextInternal(D.getDeclContext(), S); S += 'E'; - S += utostr(D.getIdentifier()->getLength()); + S += llvm::utostr(D.getIdentifier()->getLength()); S += D.getIdentifier()->getName(); } diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 25e3915049..9bcd816c6d 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -205,7 +205,7 @@ llvm::Value *CGObjCGNU::GetClass(CGBuilderTy &Builder, /// GetSelector - Return the pointer to the unique'd string for this selector. llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, Selector Sel) { // FIXME: uniquing on the string is wasteful, unique on Sel instead! - llvm::GlobalAlias *&US = UntypedSelectors[Sel.getName()]; + llvm::GlobalAlias *&US = UntypedSelectors[Sel.getAsString()]; if (US == 0) US = new llvm::GlobalAlias(llvm::PointerType::getUnqual(SelectorTy), llvm::GlobalValue::InternalLinkage, @@ -370,13 +370,14 @@ llvm::Constant *CGObjCGNU::GenerateMethodList(const std::string &ClassName, std::vector Elements; for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) { Elements.clear(); - llvm::Constant *C = CGM.GetAddrOfConstantCString(MethodSels[i].getName()); + llvm::Constant *C = + CGM.GetAddrOfConstantCString(MethodSels[i].getAsString()); Elements.push_back(llvm::ConstantExpr::getGetElementPtr(C, Zeros, 2)); Elements.push_back( llvm::ConstantExpr::getGetElementPtr(MethodTypes[i], Zeros, 2)); llvm::Constant *Method = TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName, - MethodSels[i].getName(), + MethodSels[i].getAsString(), isClassMethodList)); Method = llvm::ConstantExpr::getBitCast(Method, llvm::PointerType::getUnqual(IMPTy)); @@ -581,7 +582,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { std::string TypeStr; Context.getObjCEncodingForMethodDecl(*iter, TypeStr); InstanceMethodNames.push_back( - CGM.GetAddrOfConstantCString((*iter)->getSelector().getName())); + CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString())); InstanceMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr)); } // Collect information about class methods: @@ -592,7 +593,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { std::string TypeStr; Context.getObjCEncodingForMethodDecl((*iter),TypeStr); ClassMethodNames.push_back( - CGM.GetAddrOfConstantCString((*iter)->getSelector().getName())); + CGM.GetAddrOfConstantCString((*iter)->getSelector().getAsString())); ClassMethodTypes.push_back(CGM.GetAddrOfConstantCString(TypeStr)); } @@ -932,9 +933,9 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD) { const ObjCCategoryImplDecl *OCD = dyn_cast(OMD->getMethodContext()); - const std::string &CategoryName = OCD ? OCD->getName() : ""; - const std::string &ClassName = OMD->getClassInterface()->getName(); - const std::string &MethodName = OMD->getSelector().getName(); + std::string CategoryName = OCD ? OCD->getNameAsString() : ""; + std::string ClassName = OMD->getClassInterface()->getNameAsString(); + std::string MethodName = OMD->getSelector().getAsString(); bool isClassMethod = !OMD->isInstance(); const llvm::FunctionType *MethodTy = diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 8eb81a4b4b..f9a4d77925 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2065,7 +2065,8 @@ llvm::Constant *CGObjCMac::GetMethodVarName(Selector Sel) { llvm::GlobalVariable *&Entry = MethodVarNames[Sel]; if (!Entry) { - llvm::Constant *C = llvm::ConstantArray::get(Sel.getName()); + // FIXME: Avoid std::string copying. + llvm::Constant *C = llvm::ConstantArray::get(Sel.getAsString()); Entry = new llvm::GlobalVariable(C->getType(), false, llvm::GlobalValue::InternalLinkage, @@ -2143,14 +2144,12 @@ llvm::Constant *CGObjCMac::GetPropertyTypeString(const ObjCPropertyDecl *PD, void CGObjCMac::GetNameForMethod(const ObjCMethodDecl *D, std::string &NameOut) { // FIXME: Find the mangling GCC uses. - std::stringstream s; - s << (D->isInstance() ? "-" : "+"); - s << "["; - s << D->getClassInterface()->getName(); - s << " "; - s << D->getSelector().getName(); - s << "]"; - NameOut = s.str(); + NameOut = (D->isInstance() ? "-" : "+"); + NameOut += '['; + NameOut += D->getClassInterface()->getName(); + NameOut += ' '; + NameOut += D->getSelector().getAsString(); + NameOut += ']'; } void CGObjCMac::FinishModule() { diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index be21c36073..6b913fb215 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -23,22 +23,33 @@ using namespace clang; /// ConvertQualTypeToStringFn - This function is used to pretty print the /// specified QualType as a string in diagnostics. static void ConvertArgToStringFn(Diagnostic::ArgumentKind Kind, intptr_t Val, - const char *Modifier, unsigned ML, + const char *Modifier, unsigned ModLen, const char *Argument, unsigned ArgLen, llvm::SmallVectorImpl &Output) { - assert(ML == 0 && ArgLen == 0 && "Invalid modifier for QualType argument"); std::string S; if (Kind == Diagnostic::ak_qualtype) { QualType Ty(QualType::getFromOpaquePtr(reinterpret_cast(Val))); - + // FIXME: Playing with std::string is really slow. S = Ty.getAsString(); + + assert(ModLen == 0 && ArgLen == 0 && + "Invalid modifier for QualType argument"); + } else { assert(Kind == Diagnostic::ak_declarationname); DeclarationName N = DeclarationName::getFromOpaqueInteger(Val); S = N.getAsString(); + + if (ModLen == 9 && !memcmp(Modifier, "objcclass", 9) && ArgLen == 0) + S = '+' + S; + else if (ModLen == 12 && !memcmp(Modifier, "objcinstance", 12) && ArgLen==0) + S = '-' + S; + else + assert(ModLen == 0 && ArgLen == 0 && + "Invalid modifier for DeclarationName argument"); } Output.append(S.begin(), S.end()); } diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 410c25486b..de588c58fb 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1317,7 +1317,7 @@ public: /// \param [out] ReturnType - The return type of the send. /// \return true iff there were any incompatible types. bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, - ObjCMethodDecl *Method, const char *PrefixStr, + ObjCMethodDecl *Method, bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, QualType &ReturnType); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index cc54e890cf..64fd6c515d 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -805,8 +805,7 @@ void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { if (!match) { // We have a new signature for an existing method - add it. // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". - struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next); - FirstMethod.Next = OMI; + FirstMethod.Next = new ObjCMethodList(Method, FirstMethod.Next);; } } } @@ -824,7 +823,7 @@ ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, issueWarning = true; } if (issueWarning && (MethList.Method && MethList.Next)) { - Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel.getName() << R; + Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R; Diag(MethList.Method->getLocStart(), diag::note_using_decl) << MethList.Method->getSourceRange(); for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) @@ -905,7 +904,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, if (isInterfaceDeclKind && PrevMethod && !match || checkIdenticalMethods && match) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) - << Method->getSelector().getName(); + << Method->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } else { insMethods.push_back(Method); @@ -922,7 +921,7 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, if (isInterfaceDeclKind && PrevMethod && !match || checkIdenticalMethods && match) { Diag(Method->getLocation(), diag::err_duplicate_method_decl) - << Method->getSelector().getName(); + << Method->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } else { clsMethods.push_back(Method); @@ -1115,7 +1114,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( if (PrevMethod) { // You can never have two method definitions with the same name. Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) - << ObjCMethod->getSelector().getName(); + << ObjCMethod->getDeclName(); Diag(PrevMethod->getLocation(), diag::note_previous_declaration); } return ObjCMethod; diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index f587dd6ae2..2225d6758f 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -109,7 +109,7 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId, bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel, ObjCMethodDecl *Method, - const char *PrefixStr, + bool isClassMessage, SourceLocation lbrac, SourceLocation rbrac, QualType &ReturnType) { if (!Method) { @@ -117,13 +117,15 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, for (unsigned i = 0; i != NumArgs; i++) DefaultArgumentPromotion(Args[i]); - Diag(lbrac, diag::warn_method_not_found) - << PrefixStr << Sel.getName() << SourceRange(lbrac, rbrac); + unsigned DiagID = isClassMessage ? diag::warn_class_method_not_found : + diag::warn_inst_method_not_found; + Diag(lbrac, DiagID) + << Sel << isClassMessage << SourceRange(lbrac, rbrac); ReturnType = Context.getObjCIdType(); return false; - } else { - ReturnType = Method->getResultType(); } + + ReturnType = Method->getResultType(); unsigned NumNamedArgs = Sel.getNumArgs(); assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!"); @@ -261,7 +263,7 @@ Sema::ExprResult Sema::ActOnClassMessage( if (!Method) Method = ClassDecl->lookupInstanceMethod(Sel); - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "+", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, true, lbrac, rbrac, returnType)) return true; @@ -304,7 +306,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass()) Method = SuperDecl->lookupInstanceMethod(Sel); } - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -318,7 +320,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Sel, SourceRange(lbrac,rbrac)); if (!Method) Method = FactoryMethodPool[Sel].Method; - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -340,7 +342,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method) Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, @@ -361,7 +363,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, } if (!Method) Diag(lbrac, diag::warn_method_not_found_in_protocol) - << "-" << Sel.getName() << RExpr->getSourceRange(); + << Sel << RExpr->getSourceRange(); } else if (const ObjCInterfaceType *OCIReceiver = ReceiverCType->getAsPointerToObjCInterfaceType()) { // We allow sending a message to a pointer to an interface (an object). @@ -383,7 +385,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, if (!Method && !OCIReceiver->qual_empty()) Diag(lbrac, diag::warn_method_not_found_in_protocol) - << "-" << Sel.getName() << SourceRange(lbrac, rbrac); + << Sel << SourceRange(lbrac, rbrac); } else { Diag(lbrac, diag::error_bad_receiver_type) << RExpr->getType().getAsString() << RExpr->getSourceRange(); @@ -403,7 +405,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel, Method = LookupInstanceMethodInGlobalPool( Sel, SourceRange(lbrac,rbrac)); } - if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", + if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, false, lbrac, rbrac, returnType)) return true; return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, -- 2.40.0