[cfe-commits] r44015 - in /cfe/trunk: AST/Decl.cpp Driver/ASTConsumers.cpp Driver/RewriteTest.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/DeclObjC.h

Steve Naroff snaroff at apple.com
Mon Nov 12 05:56:43 PST 2007


Author: snaroff
Date: Mon Nov 12 07:56:41 2007
New Revision: 44015

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

- Minor cleanup to yesterday's changes to Sema::ObjcActOnStartOfMethodDef();
- Add Sema::CurMethodDecl, in preparation for adding ObjcIvarRefExpr.
- Add ObjcInterfaceDecl::lookupInstanceVariable(), in prep for adding ivars.
- A couple renames in ObjcInterfaceDecl, while I was in the vicinity:-)


Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=44015&r1=44014&r2=44015&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Mon Nov 12 07:56:41 2007
@@ -408,6 +408,23 @@
   }
 }
 
+ObjcIvarDecl *ObjcInterfaceDecl::lookupInstanceVariable(
+  IdentifierInfo *ID, ObjcInterfaceDecl *&clsDeclared) {
+  ObjcInterfaceDecl* ClassDecl = this;
+  while (ClassDecl != NULL) {
+    ObjcIvarDecl **ivars = ClassDecl->getInstanceVariables();
+    int ivarCount = ClassDecl->getNumInstanceVariables();
+    for (int i = 0; i < ivarCount; ++i) {
+      if (ivars[i]->getIdentifier() == ID) {
+        clsDeclared = ClassDecl;
+        return ivars[i];
+      }
+    }
+    ClassDecl = ClassDecl->getSuperClass();
+  }
+  return NULL;
+}
+
 // lookupInstanceMethod - This method returns an instance method by looking in
 // the class, it's categories, and it's super classes (using a linear search).
 ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {

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

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Mon Nov 12 07:56:41 2007
@@ -147,9 +147,9 @@
   else
     fprintf(stderr, "\n");
   
-  int NumIvars = OID->getIntfDeclNumIvars();
+  int NumIvars = OID->getNumInstanceVariables();
   if (NumIvars > 0) {
-    ObjcIvarDecl **Ivars = OID->getIntfDeclIvars();
+    ObjcIvarDecl **Ivars = OID->getInstanceVariables();
     fprintf(stderr,"{");
     for (int i = 0; i < NumIvars; i++) {
       fprintf(stderr, "\t%s %s;\n", Ivars[i]->getType().getAsString().c_str(),

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

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Mon Nov 12 07:56:41 2007
@@ -981,7 +981,7 @@
     SynthesizeObjcInternalStruct(RCDecl, Result);
   }
   
-  int NumIvars = CDecl->getIntfDeclNumIvars();
+  int NumIvars = CDecl->getNumInstanceVariables();
   // If no ivars and no root or if its root, directly or indirectly,
   // have no ivars (thus not synthesized) then no need to synthesize this class.
   if (NumIvars <= 0 && (!RCDecl || !ObjcSynthesizedStructs.count(RCDecl)))
@@ -1391,7 +1391,7 @@
   // Build _objc_ivar_list metadata for classes ivars if needed
   int NumIvars = IDecl->getImplDeclNumIvars() > 0 
                    ? IDecl->getImplDeclNumIvars() 
-                   : (CDecl ? CDecl->getIntfDeclNumIvars() : 0);
+                   : (CDecl ? CDecl->getNumInstanceVariables() : 0);
   
   SynthesizeObjcInternalStruct(CDecl, Result);
   
@@ -1430,7 +1430,7 @@
           
     ObjcIvarDecl **Ivars = IDecl->getImplDeclIVars() 
                              ? IDecl->getImplDeclIVars() 
-                             : CDecl->getIntfDeclIvars();
+                             : CDecl->getInstanceVariables();
     Result += "\t,{{\"";
     Result += Ivars[0]->getName();
     Result += "\", \"";

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Mon Nov 12 07:56:41 2007
@@ -64,6 +64,10 @@
   /// CurFunctionDecl - If inside of a function body, this contains a pointer to
   /// the function decl for the function being parsed.
   FunctionDecl *CurFunctionDecl;
+
+  /// CurMethodDecl - If inside of a method body, this contains a pointer to
+  /// the method decl for the method being parsed.
+  ObjcMethodDecl *CurMethodDecl;
   
   /// LastInGroupList - This vector is populated when there are multiple
   /// declarators in a single decl group (e.g. "int A, B, C").  In this case,

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Nov 12 07:56:41 2007
@@ -912,7 +912,9 @@
     assert(FD == CurFunctionDecl && "Function parsing confused");
   } else if (ObjcMethodDecl *MD = dyn_cast<ObjcMethodDecl>(dcl)) {
     MD->setBody((Stmt*)Body);
+    CurMethodDecl = 0;
   }
+  // This is unconditional, since methods have a corresponding function decl.
   CurFunctionDecl = 0;
   
   // Verify and clean out per-function state.
@@ -943,9 +945,8 @@
 /// ObjcActOnStartOfMethodDef - This routine sets up parameters; invisible
 /// and user declared, in the method definition's AST.
 void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
-  assert(CurFunctionDecl == 0 && "Function parsing confused");
+  assert(CurFunctionDecl == 0 && "Method parsing confused");
   ObjcMethodDecl *MDecl = dyn_cast<ObjcMethodDecl>(static_cast<Decl *>(D));
-  
   assert(MDecl != 0 && "Not a method declarator!");
   
   Scope *GlobalScope = FnBodyScope->getParent();
@@ -957,10 +958,10 @@
   Name += MDecl->getSelector().getName();
   Name += "]";
   IdentifierInfo *II = &Context.Idents.get(Name);
-  assert (II && "ObjcActOnMethodDefinition - selector name is missing");
+  assert (II && "ObjcActOnStartOfMethodDef - selector name is missing");
   
   QualType R = ObjcGetTypeForMethodDefinition(MDecl, GlobalScope);
-  assert(!R.isNull() && "ObjcGetTypeForMethodDefinition() returned null type");
+  assert(!R.isNull() && "ObjcActOnStartOfMethodDef() returned null type");
     
   FunctionDecl *NewFD = new FunctionDecl(MDecl->getLocation(), II, R, 
                                          FunctionDecl::Static, false, 0);
@@ -968,34 +969,34 @@
   II->setFETokenInfo(NewFD);
   GlobalScope->AddDecl(NewFD);
   AddTopLevelDecl(NewFD, 0);
+  
+  // Allow all of Sema to see that we are entering a method definition.
+  CurMethodDecl = MDecl;
   CurFunctionDecl = NewFD;
 
   // Create Decl objects for each parameter, adding them to the FunctionDecl.
   llvm::SmallVector<ParmVarDecl*, 16> Params;
   struct DeclaratorChunk::ParamInfo PI;
 
+  // Insert the invisible arguments, self and _cmd!
   PI.Ident = &Context.Idents.get("self");
-  PI.IdentLoc = SourceLocation(/*FIXME*/);
-  
-  // Insert the invisible arguments!
+  PI.IdentLoc = SourceLocation(); // synthesized vars have a null location.
   if (MDecl->isInstance()) {
     QualType selfTy = Context.getObjcInterfaceType(MDecl->getClassInterface());
     selfTy = Context.getPointerType(selfTy);
     PI.TypeInfo = selfTy.getAsOpaquePtr();
   } else
     PI.TypeInfo = Context.getObjcIdType().getAsOpaquePtr();
-    
   Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
   
   PI.Ident = &Context.Idents.get("_cmd");
-  PI.IdentLoc = SourceLocation(/*FIXME*/);
   PI.TypeInfo = Context.getObjcSelType().getAsOpaquePtr();
   Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
   
   for (int i = 0; i <  MDecl->getNumParams(); i++) {
     ParmVarDecl *PDecl = MDecl->getParamDecl(i);
     PI.Ident = PDecl->getIdentifier();
-    PI.IdentLoc = PDecl->getLocation();
+    PI.IdentLoc = PDecl->getLocation(); // user vars have a real location.
     PI.TypeInfo = PDecl->getType().getAsOpaquePtr();
     Params.push_back(ParseParamDeclarator(PI, FnBodyScope));
   }
@@ -1406,8 +1407,8 @@
   // Check interface's Ivar list against those in the implementation.
   // names and types must match.
   //
-  ObjcIvarDecl** IntfIvars = IDecl->getIntfDeclIvars();
-  int IntfNumIvars = IDecl->getIntfDeclNumIvars();
+  ObjcIvarDecl** IntfIvars = IDecl->getInstanceVariables();
+  int IntfNumIvars = IDecl->getNumInstanceVariables();
   unsigned j = 0;
   bool err = false;
   while (numIvars > 0 && IntfNumIvars > 0) {

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Nov 12 07:56:41 2007
@@ -111,8 +111,8 @@
   }
   int getNumIntfRefProtocols() const { return NumReferencedProtocols; }
   
-  ObjcIvarDecl **getIntfDeclIvars() const { return Ivars; }
-  int getIntfDeclNumIvars() const { return NumIvars; }
+  ObjcIvarDecl **getInstanceVariables() const { return Ivars; }
+  int getNumInstanceVariables() const { return NumIvars; }
   
   ObjcMethodDecl** getInstanceMethods() const { return InstanceMethods; }
   int getNumInstanceMethods() const { return NumInstanceMethods; }
@@ -142,6 +142,8 @@
   void setCategoryList(ObjcCategoryDecl *category) { 
          CategoryList = category; 
   }
+  ObjcIvarDecl *lookupInstanceVariable(IdentifierInfo *ivarName,
+                                       ObjcInterfaceDecl *&clsDeclared);
   ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
   ObjcMethodDecl *lookupClassMethod(Selector &Sel);
 





More information about the cfe-commits mailing list