[cfe-commits] r43404 - in /cfe/trunk: 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

Steve Naroff snaroff at apple.com
Fri Oct 26 13:53:56 PDT 2007


Author: snaroff
Date: Fri Oct 26 15:53:56 2007
New Revision: 43404

URL: http://llvm.org/viewvc/llvm-project?rev=43404&view=rev
Log:

Start rewriting ObjC interfaces. As a start, we comment out all the methods. This involved refining how the parser/AST passes/manages SourceLocations for ObjcMethodDecl's. 


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

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Fri Oct 26 15:53:56 2007
@@ -58,6 +58,7 @@
     void RewriteInclude(SourceLocation Loc);
     void RewriteTabs();
     void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
+    void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl);
     
     // Expression Rewriting.
     Stmt *RewriteFunctionBody(Stmt *S);
@@ -120,8 +121,9 @@
       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 @@
                       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 @@
     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.

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Oct 26 15:53:56 2007
@@ -379,9 +379,9 @@
   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 @@
 ///   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 @@
       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 @@
   
   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);
 }

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Oct 26 15:53:56 2007
@@ -516,7 +516,9 @@
   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 @@
   // 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

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct 26 15:53:56 2007
@@ -1941,7 +1941,8 @@
   }
 }
 
-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 @@
   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 ? 

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Oct 26 15:53:56 2007
@@ -756,7 +756,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Oct 26 15:53:56 2007
@@ -219,19 +219,25 @@
   /// 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; }
 

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Oct 26 15:53:56 2007
@@ -519,7 +519,8 @@
   }  
   // 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.

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=43404&r1=43403&r2=43404&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Oct 26 15:53:56 2007
@@ -295,7 +295,7 @@
   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);





More information about the cfe-commits mailing list