]> granicus.if.org Git - clang/commitdiff
- Minor cleanup to yesterday's changes to Sema::ObjcActOnStartOfMethodDef();
authorSteve Naroff <snaroff@apple.com>
Mon, 12 Nov 2007 13:56:41 +0000 (13:56 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 12 Nov 2007 13:56:41 +0000 (13:56 +0000)
- 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:-)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44015 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Decl.cpp
Driver/ASTConsumers.cpp
Driver/RewriteTest.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/AST/DeclObjC.h

index 584fbf5a6301bc22b1ada017b6ebfd7235b7fe78..b09960eab1f80808d1e1dabe005208624a5685d5 100644 (file)
@@ -408,6 +408,23 @@ void ObjcCategoryImplDecl::addMethods(ObjcMethodDecl **insMethods,
   }
 }
 
+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) {
index 8b68f2489ba857fb9e6abfc077987fda63605682..e47946b9165adc3168818114a98faec8bfeb5a25 100644 (file)
@@ -147,9 +147,9 @@ static void PrintObjcInterfaceDecl(ObjcInterfaceDecl *OID) {
   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(),
index a0a11470dc502f9125c8f88abf704e4ef0e40325..66f8aa8fc3bf9567e50adbf50e47ba28ff994b08 100644 (file)
@@ -981,7 +981,7 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl,
     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 @@ void RewriteTest::RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl,
   // 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 @@ void RewriteTest::RewriteObjcClassMetaData(ObjcImplementationDecl *IDecl,
           
     ObjcIvarDecl **Ivars = IDecl->getImplDeclIVars() 
                              ? IDecl->getImplDeclIVars() 
-                             : CDecl->getIntfDeclIvars();
+                             : CDecl->getInstanceVariables();
     Result += "\t,{{\"";
     Result += Ivars[0]->getName();
     Result += "\", \"";
index 395adbc312850904abaf2237c2812971a8f78193..4c66e10301a84dd60aaf4254660d036b80f87a99 100644 (file)
@@ -64,6 +64,10 @@ class Sema : public Action {
   /// 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,
index 05a9f6130d2e1c856036180c0e978587c50c1b2c..62089141cbc03dca51306908c893a506925e3d82 100644 (file)
@@ -912,7 +912,9 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
     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 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
 /// 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 @@ void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
   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 @@ void Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
   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 @@ void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl,
   // 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) {
index 48cdce363e148df483920a95a5b4444113fb2335..db40ba904b8fc87c76383c883df48265272e1f3e 100644 (file)
@@ -111,8 +111,8 @@ public:
   }
   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 @@ public:
   void setCategoryList(ObjcCategoryDecl *category) { 
          CategoryList = category; 
   }
+  ObjcIvarDecl *lookupInstanceVariable(IdentifierInfo *ivarName,
+                                       ObjcInterfaceDecl *&clsDeclared);
   ObjcMethodDecl *lookupInstanceMethod(Selector &Sel);
   ObjcMethodDecl *lookupClassMethod(Selector &Sel);