[cfe-commits] r59933 - in /cfe/trunk: Driver/ docs/ include/clang/AST/ include/clang/Basic/ lib/AST/ lib/Analysis/ lib/Basic/ lib/CodeGen/ lib/Sema/

Chris Lattner sabre at nondot.org
Sun Nov 23 19:33:14 PST 2008


Author: lattner
Date: Sun Nov 23 21:33:13 2008
New Revision: 59933

URL: http://llvm.org/viewvc/llvm-project?rev=59933&view=rev
Log:
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.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/AnalysisConsumer.cpp
    cfe/trunk/Driver/RewriteBlocks.cpp
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/docs/InternalsManual.html
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/include/clang/Basic/IdentifierTable.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/AST/DeclarationName.cpp
    cfe/trunk/lib/AST/StmtDumper.cpp
    cfe/trunk/lib/AST/StmtPrinter.cpp
    cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
    cfe/trunk/lib/Basic/IdentifierTable.cpp
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sun Nov 23 21:33:13 2008
@@ -198,7 +198,7 @@
   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 @@
       
   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 @@
       } else if (isa<FileScopeAsmDecl>(D)) {
         Out << "Read file scope asm decl\n";
       } else if (ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(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?

Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Sun Nov 23 21:33:13 2008
@@ -246,7 +246,7 @@
         llvm::cerr << "ANALYZE (ObjC Method): "
         << getContext().getSourceManager().getSourceName(MD->getLocation())
         << " '"
-        << MD->getSelector().getName() << "'\n";
+        << MD->getSelector().getAsString() << "'\n";
       }
     }
   };
@@ -281,7 +281,7 @@
     case Decl::ObjCMethod: {
       ObjCMethodDecl* MD = cast<ObjCMethodDecl>(D);
       
-      if (FName.size() > 0 && FName != MD->getSelector().getName())
+      if (FName.size() > 0 && FName != MD->getSelector().getAsString())
         return;
       
       Stmt* Body = MD->getBody();

Modified: cfe/trunk/Driver/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteBlocks.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Sun Nov 23 21:33:13 2008
@@ -625,7 +625,7 @@
 
 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 @@
   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)

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Sun Nov 23 21:33:13 2008
@@ -749,10 +749,8 @@
     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 @@
   // Create a call to sel_registerName("selName").
   llvm::SmallVector<Expr*, 8> 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 @@
   // Create a call to sel_registerName("selName"), it will be the 2nd argument.
   llvm::SmallVector<Expr*, 8> 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 @@
   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 @@
   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 @@
           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 @@
           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 @@
   //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 @@
   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)

Modified: cfe/trunk/docs/InternalsManual.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/InternalsManual.html?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/docs/InternalsManual.html (original)
+++ cfe/trunk/docs/InternalsManual.html Sun Nov 23 21:33:13 2008
@@ -297,6 +297,20 @@
 	abort, as will a failure to match the argument against any
 	expression.</p></td></tr>
 
+<tr><td colspan="2"><b>"objcclass" format</b></td></tr>
+<tr><td>Example:</td><td><tt>"method %objcclass0 not found"</tt></td></tr>
+<tr><td>Class:</td><td>DeclarationName</td></tr>
+<tr><td>Description:</td><td><p>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 '+'.</p></td></tr>
+
+<tr><td colspan="2"><b>"objcinstance" format</b></td></tr>
+<tr><td>Example:</td><td><tt>"method %objcinstance0 not found"</tt></td></tr>
+<tr><td>Class:</td><td>DeclarationName</td></tr>
+<tr><td>Description:</td><td><p>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 '-'.</p></td></tr>
+
 </table>
 
 <p>It is really easy to add format specifiers to the Clang diagnostics system,

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun Nov 23 21:33:13 2008
@@ -101,6 +101,7 @@
   /// 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;

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Nov 23 21:33:13 2008
@@ -489,9 +489,9 @@
 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 @@
      "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,

Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Basic/IdentifierTable.h Sun Nov 23 21:33:13 2008
@@ -281,9 +281,9 @@
   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));

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sun Nov 23 21:33:13 2008
@@ -1577,12 +1577,12 @@
 
   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) {

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Nov 23 21:33:13 2008
@@ -763,7 +763,7 @@
   if (ObjCCategoryImplDecl *CID = 
       dyn_cast<ObjCCategoryImplDecl>(MethodContext))
     length += strlen(CID->getIdentifierName()) +1;
-  length += getSelector().getName().size(); // selector name
+  length += getSelector().getAsString().size(); // selector name
   return length; 
 }
 

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Sun Nov 23 21:33:13 2008
@@ -120,7 +120,7 @@
   case ObjCZeroArgSelector:
   case ObjCOneArgSelector:
   case ObjCMultiArgSelector:
-    return getObjCSelector().getName();
+    return getObjCSelector().getAsString();
 
   case CXXConstructorName: {
     QualType ClassType = getCXXNameType();

Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Sun Nov 23 21:33:13 2008
@@ -376,7 +376,7 @@
 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::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 @@
   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 @@
   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) {

Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Sun Nov 23 21:33:13 2008
@@ -988,7 +988,7 @@
 }
 
 void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) {
-  OS << "@selector(" << Node->getSelector().getName() << ")";
+  OS << "@selector(" << Node->getSelector().getAsString() << ")";
 }
 
 void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) {

Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Sun Nov 23 21:33:13 2008
@@ -91,7 +91,7 @@
       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 @@
   // 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();

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Sun Nov 23 21:33:13 2008
@@ -1887,7 +1887,7 @@
 
   if (V.isReturnedOwned() && V.getCount() == 0)
     if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(CD)) {
-      std::string s = MD->getSelector().getName();
+      std::string s = MD->getSelector().getAsString();
       if (!followsReturnRule(s.c_str())) {
         hasLeak = true;
         state = state.set<RefBindings>(sid, V ^ RefVal::ErrorLeakReturned);
@@ -2635,7 +2635,7 @@
   if (RV->getKind() == RefVal::ErrorLeakReturned) {
     ObjCMethodDecl& MD = cast<ObjCMethodDecl>(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).";

Modified: cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp Sun Nov 23 21:33:13 2008
@@ -53,7 +53,7 @@
        << "', 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 "

Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)
+++ cfe/trunk/lib/Basic/IdentifierTable.cpp Sun Nov 23 21:33:13 2008
@@ -342,7 +342,7 @@
   return Result;
 }
 
-std::string Selector::getName() const {
+std::string Selector::getAsString() const {
   if (IdentifierInfo *II = getAsIdentifierInfo()) {
     if (getNumArgs() == 0)
       return II->getName();

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun Nov 23 21:33:13 2008
@@ -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 @@
          "Only one level of decl context mangling is currently supported!");
   
   if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(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 @@
     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 @@
   mangleDeclContextInternal(D.getDeclContext(), S);
   S += 'E';
   
-  S += utostr(D.getIdentifier()->getLength());
+  S += llvm::utostr(D.getIdentifier()->getLength());
   S += D.getIdentifier()->getName();
 }
 

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Nov 23 21:33:13 2008
@@ -205,7 +205,7 @@
 /// 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 @@
   std::vector<llvm::Constant*> 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 @@
     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 @@
     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::GenerateMethod(const ObjCMethodDecl *OMD) {  
   const ObjCCategoryImplDecl *OCD = 
     dyn_cast<ObjCCategoryImplDecl>(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 = 

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun Nov 23 21:33:13 2008
@@ -2065,7 +2065,8 @@
   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 @@
 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() {

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sun Nov 23 21:33:13 2008
@@ -23,22 +23,33 @@
 /// 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<char> &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<void*>(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());
 }

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Nov 23 21:33:13 2008
@@ -1317,7 +1317,7 @@
   /// \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);  
 

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Nov 23 21:33:13 2008
@@ -805,8 +805,7 @@
     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 @@
         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 @@
       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 @@
       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 @@
   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;

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=59933&r1=59932&r2=59933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Nov 23 21:33:13 2008
@@ -109,7 +109,7 @@
 
 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 @@
     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 @@
   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 @@
         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 @@
                                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 @@
     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 @@
     }
     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 @@
     
     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 @@
           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, 





More information about the cfe-commits mailing list