]> granicus.if.org Git - clang/commitdiff
Start rewriting ObjC interfaces. As a start, we comment out all the methods. This...
authorSteve Naroff <snaroff@apple.com>
Fri, 26 Oct 2007 20:53:56 +0000 (20:53 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 26 Oct 2007 20:53:56 +0000 (20:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43404 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
Parse/ParseObjc.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/DeclObjC.h
include/clang/Parse/Action.h
include/clang/Parse/Parser.h

index 95b05ba0f47113d97072d23b029bd16c5ec5dd54..6ccc23ae096fc04c53440a25300261135fb10c98 100644 (file)
@@ -58,6 +58,7 @@ namespace {
     void RewriteInclude(SourceLocation Loc);
     void RewriteTabs();
     void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
+    void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl);
     
     // Expression Rewriting.
     Stmt *RewriteFunctionBody(Stmt *S);
@@ -120,8 +121,9 @@ void RewriteTest::HandleTopLevelDecl(Decl *D) {
       GetClassFunctionDecl = FD;
     else if (strcmp(FD->getName(), "sel_getUid") == 0)
       SelGetUidFunctionDecl = FD;
+  } else if (ObjcInterfaceDecl *MD = dyn_cast<ObjcInterfaceDecl>(D)) {
+    RewriteInterfaceDecl(MD);
   }
-  
   // If we have a decl in the main file, see if we should rewrite it.
   if (SM->getDecomposedFileLoc(Loc).first == MainFileID)
     return HandleDeclInMainFile(D);
@@ -263,6 +265,31 @@ void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) {
                       typedefString.c_str(), typedefString.size());
 }
 
+void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
+  int nInstanceMethods = ClassDecl->getNumInstanceMethods();
+  ObjcMethodDecl **instanceMethods = ClassDecl->getInstanceMethods();
+  
+  for (int i = 0; i < nInstanceMethods; i++) {
+    ObjcMethodDecl *instanceMethod = instanceMethods[i];
+    SourceLocation Loc = instanceMethod->getLocStart();
+
+    Rewrite.ReplaceText(Loc, 0, "// ", 3);
+    
+    // FIXME: handle methods that are declared across multiple lines.
+  }
+  int nClassMethods = ClassDecl->getNumClassMethods();
+  ObjcMethodDecl **classMethods = ClassDecl->getClassMethods();
+  
+  for (int i = 0; i < nClassMethods; i++) {
+    ObjcMethodDecl *classMethod = classMethods[i];
+    SourceLocation Loc = classMethod->getLocStart();
+
+    Rewrite.ReplaceText(Loc, 0, "// ", 3);
+    
+    // FIXME: handle methods that are declared across multiple lines.
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Function Body / Expression rewriting
 //===----------------------------------------------------------------------===//
@@ -290,11 +317,11 @@ Stmt *RewriteTest::RewriteFunctionBody(Stmt *S) {
     messString += "// ";
     messString.append(startBuf, endBuf-startBuf+1);
     messString += "\n";
-    
+        
     // FIXME: Missing definition of Rewrite.InsertText(clang::SourceLocation, char const*, unsigned int).
     // Rewrite.InsertText(startLoc, messString.c_str(), messString.size());
     // Tried this, but it didn't work either...
-    // Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
+    Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
     return RewriteMessageExpr(MessExpr);
   }
   // Return this stmt unmodified.
index 2fd4446ae6d14689de1c9f1ea1739a96595eeb45..4abf8fd43dd5136f253ea6728315752234a570eb 100644 (file)
@@ -379,9 +379,9 @@ Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl,
   assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
 
   tok::TokenKind methodType = Tok.getKind();  
-  ConsumeToken();
+  SourceLocation mLoc = ConsumeToken();
   
-  DeclTy *MDecl = ParseObjCMethodDecl(methodType, MethodImplKind);
+  DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind);
   // Since this rule is used for both method declarations and definitions,
   // the caller is (optionally) responsible for consuming the ';'.
   return MDecl;
@@ -526,15 +526,16 @@ Parser::TypeTy *Parser::ParseObjCTypeName() {
 ///   objc-keyword-attributes:         [OBJC2]
 ///     __attribute__((unused))
 ///
-Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType, 
+Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
+                                            tok::TokenKind mType, 
                                            tok::ObjCKeywordKind MethodImplKind)
 {
   // Parse the return type.
   TypeTy *ReturnType = 0;
   if (Tok.is(tok::l_paren))
     ReturnType = ParseObjCTypeName();
-  SourceLocation mLoc;
-  IdentifierInfo *SelIdent = ParseObjCSelector(mLoc);
+  SourceLocation selLoc;
+  IdentifierInfo *SelIdent = ParseObjCSelector(selLoc);
   if (Tok.isNot(tok::colon)) {
     if (!SelIdent) {
       Diag(Tok, diag::err_expected_ident); // missing selector name.
@@ -548,7 +549,8 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType,
       MethodAttrs = ParseAttributes();
     
     Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
-    return Actions.ActOnMethodDeclaration(mLoc, mType, ReturnType, Sel, 
+    return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+                                          mType, ReturnType, Sel,
                                           0, 0, MethodAttrs, MethodImplKind);
   }
 
@@ -614,7 +616,8 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType,
   
   Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
                                                    &KeyIdents[0]);
-  return Actions.ActOnMethodDeclaration(mLoc, mType, ReturnType, Sel, 
+  return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+                                        mType, ReturnType, Sel, 
                                         &KeyTypes[0], &ArgNames[0],
                                         MethodAttrs, MethodImplKind);
 }
index 596173dda2d41c78ebccaef9d1020e91009aee8f..70d2f55ff87044ae8439447e54dae60397bad33a 100644 (file)
@@ -516,7 +516,9 @@ public:
   virtual void ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl, 
                                         DeclTy **allMethods, unsigned allNum);
   
-  virtual DeclTy *ActOnMethodDeclaration(SourceLocation MethodLoc, 
+  virtual DeclTy *ActOnMethodDeclaration(
+    SourceLocation BeginLoc, // location of the + or -.
+    SourceLocation EndLoc,   // location of the ; or {.
     tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().
@@ -528,7 +530,7 @@ public:
   // is obtained from Sel.getNumArgs().
   virtual ExprResult ActOnClassMessage(
     IdentifierInfo *receivingClassName, Selector Sel,
-     SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
+    SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
 
   // ActOnInstanceMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
index b2845978bf402622774f3be708882c366861bc03..12efd458b22ddad75d577c7925aa5a62302a2ba3 100644 (file)
@@ -1941,7 +1941,8 @@ void Sema::ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *classDecl,
   }
 }
 
-Sema::DeclTy *Sema::ActOnMethodDeclaration(SourceLocation MethodLoc, 
+Sema::DeclTy *Sema::ActOnMethodDeclaration(
+    SourceLocation MethodLoc, SourceLocation EndLoc,
     tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().
@@ -1968,7 +1969,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(SourceLocation MethodLoc,
   else // get the type for "id".
     resultDeclType = GetObjcIdType(MethodLoc);
 
-  ObjcMethodDecl* ObjcMethod =  new ObjcMethodDecl(MethodLoc, Sel,
+  ObjcMethodDecl* ObjcMethod =  new ObjcMethodDecl(MethodLoc, EndLoc, Sel,
                                       resultDeclType, 0, -1, AttrList, 
                                       MethodType == tok::minus,
                                       MethodDeclKind == tok::objc_optional ? 
index fe4cf8d85be8296188b8454e3723b21a50eb5906..de41b4628d0c47ae944965792f26798c623eb63f 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index 40a2d9643ce9313ab42bdd2e7142dad1782e2b53..6157187405725366d9e20d83878826e7ea9e101f 100644 (file)
@@ -219,19 +219,25 @@ private:
   /// List of attributes for this method declaration.
   AttributeList *MethodAttrs;
   
+  SourceLocation EndLoc; // the location of the ';' or '{'.
 public:
-  ObjcMethodDecl(SourceLocation L, Selector SelInfo, QualType T,
+  ObjcMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
+                 Selector SelInfo, QualType T,
                  ParmVarDecl **paramInfo = 0, int numParams=-1,
                  AttributeList *M = 0, bool isInstance = true,
                  ImplementationControl impControl = None,
                  Decl *PrevDecl = 0)
-    : Decl(ObjcMethod, L),
+    : Decl(ObjcMethod, beginLoc),
       IsInstance(isInstance), DeclImplementation(impControl),
       SelName(SelInfo), MethodDeclType(T), 
       ParamInfo(paramInfo), NumMethodParams(numParams),
-      MethodAttrs(M) {}
+      MethodAttrs(M), EndLoc(endLoc) {}
   virtual ~ObjcMethodDecl();
   
+  // Location information, modeled after the Stmt API.
+  SourceLocation getLocStart() const { return getLocation(); }
+  SourceLocation getLocEnd() const { return EndLoc; }
+  
   Selector getSelector() const { return SelName; }
   QualType getResultType() const { return MethodDeclType; }
 
index e8c943d62468bb8372bff5db3e3ea71fd52ccd7f..24b47c660f77a83b9522a003a716cb51a6f52717 100644 (file)
@@ -519,7 +519,8 @@ public:
   }  
   // ActOnMethodDeclaration - called for all method declarations. 
   virtual DeclTy *ActOnMethodDeclaration(
-    SourceLocation MethodLoc, 
+    SourceLocation BeginLoc,   // location of the + or -.
+    SourceLocation EndLoc,     // location of the ; or {.
     tok::TokenKind MethodType, // tok::minus for instance, tok::plus for class.
     TypeTy *ReturnType,        // the method return type.
     Selector Sel,              // a unique name for the method.
index 8c0b8e47bf2237c54e0ac50bcccf8ccc81713ef8..a41d357215be53949c4e0e4c50cd332483eb6cf1 100644 (file)
@@ -295,7 +295,7 @@ private:
   void ParseObjCMethodRequirement();
   DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat,
            tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
-  DeclTy *ParseObjCMethodDecl(tok::TokenKind mType,
+  DeclTy *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
             tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
   void ParseObjCPropertyAttribute(DeclTy *interfaceDecl);
   void ParseObjCPropertyDecl(DeclTy *interfaceDecl);