[cfe-commits] r48404 - in /cfe/trunk: clang.xcodeproj/project.pbxproj lib/AST/Decl.cpp lib/AST/DeclObjC.cpp

Chris Lattner sabre at nondot.org
Sat Mar 15 17:19:01 PDT 2008


Author: lattner
Date: Sat Mar 15 19:19:01 2008
New Revision: 48404

URL: http://llvm.org/viewvc/llvm-project?rev=48404&view=rev
Log:
Split objc decl implementation out into DeclObjC.cpp

Added:
    cfe/trunk/lib/AST/DeclObjC.cpp
Modified:
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/lib/AST/Decl.cpp

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

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Sat Mar 15 19:19:01 2008
@@ -63,6 +63,7 @@
 		DE3464220B03040900DBC861 /* Type.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3464210B03040900DBC861 /* Type.h */; };
 		DE38CD500D794D0100A273B6 /* CGObjCGNU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE38CD4F0D794D0100A273B6 /* CGObjCGNU.cpp */; };
 		DE38CF160D8C9DE000A273B6 /* DiagChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE38CF150D8C9DE000A273B6 /* DiagChecker.cpp */; };
+		DE38CF270D8C9E6C00A273B6 /* DeclObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE38CF260D8C9E6C00A273B6 /* DeclObjC.cpp */; };
 		DE3985790CB8ADC800223765 /* ASTConsumers.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3985780CB8ADC800223765 /* ASTConsumers.h */; };
 		DE39857B0CB8ADCB00223765 /* ASTConsumers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE39857A0CB8ADCB00223765 /* ASTConsumers.cpp */; };
 		DE3986F00CB8D4B300223765 /* IdentifierTable.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE3986EF0CB8D4B300223765 /* IdentifierTable.h */; };
@@ -313,6 +314,7 @@
 		DE38CD4E0D794CF900A273B6 /* CGObjCRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGObjCRuntime.h; path = lib/CodeGen/CGObjCRuntime.h; sourceTree = "<group>"; };
 		DE38CD4F0D794D0100A273B6 /* CGObjCGNU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGObjCGNU.cpp; path = lib/CodeGen/CGObjCGNU.cpp; sourceTree = "<group>"; };
 		DE38CF150D8C9DE000A273B6 /* DiagChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DiagChecker.cpp; path = Driver/DiagChecker.cpp; sourceTree = "<group>"; };
+		DE38CF260D8C9E6C00A273B6 /* DeclObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DeclObjC.cpp; path = lib/AST/DeclObjC.cpp; sourceTree = "<group>"; };
 		DE3985780CB8ADC800223765 /* ASTConsumers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTConsumers.h; path = Driver/ASTConsumers.h; sourceTree = "<group>"; };
 		DE39857A0CB8ADCB00223765 /* ASTConsumers.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTConsumers.cpp; path = Driver/ASTConsumers.cpp; sourceTree = "<group>"; };
 		DE3986EF0CB8D4B300223765 /* IdentifierTable.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IdentifierTable.h; sourceTree = "<group>"; };
@@ -727,6 +729,7 @@
 				DED677C80B6C854100AAD4A3 /* Builtins.cpp */,
 				DEC63B190C7B940200DBF169 /* CFG.cpp */,
 				DED62ABA0AE2EDF1001E80A4 /* Decl.cpp */,
+				DE38CF260D8C9E6C00A273B6 /* DeclObjC.cpp */,
 				3513185F0CD14468006B66F7 /* DeclSerialization.cpp */,
 				DE0FCB330A9C21F100248FD5 /* Expr.cpp */,
 				35260CA40C7F75C000D66CE9 /* ExprCXX.cpp */,
@@ -997,6 +1000,7 @@
 				DE85CDB00D838C390070E26E /* PPDirectives.cpp in Sources */,
 				DE85CDB60D839BAE0070E26E /* PPLexerChange.cpp in Sources */,
 				DE38CF160D8C9DE000A273B6 /* DiagChecker.cpp in Sources */,
+				DE38CF270D8C9E6C00A273B6 /* DeclObjC.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Mar 15 19:19:01 2008
@@ -12,7 +12,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/AST/Decl.h"
-#include "clang/AST/DeclObjC.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -303,7 +302,7 @@
 
 void Decl::addAttr(Attr *NewAttr) {
   if (!DeclAttrs)
-    DeclAttrs = new llvm::DenseMap<const Decl*, Attr*>();
+    DeclAttrs = new DeclAttrMapTy();
   
   Attr *&ExistingAttr = (*DeclAttrs)[this];
 
@@ -372,298 +371,3 @@
   }
   return 0;
 }
-
-//===----------------------------------------------------------------------===//
-// Objective-C Decl Implementation
-//===----------------------------------------------------------------------===//
-
-void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
-                                     unsigned NumParams) {
-  assert(ParamInfo == 0 && "Already has param info!");
-
-  // Zero params -> null pointer.
-  if (NumParams) {
-    ParamInfo = new ParmVarDecl*[NumParams];
-    memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
-    NumMethodParams = NumParams;
-  }
-}
-
-ObjCMethodDecl::~ObjCMethodDecl() {
-  delete[] ParamInfo;
-}
-
-/// ObjCAddInstanceVariablesToClass - Inserts instance variables
-/// into ObjCInterfaceDecl's fields.
-///
-void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
-                                                    unsigned numIvars,
-                                                    SourceLocation RBrac) {
-  NumIvars = numIvars;
-  if (numIvars) {
-    Ivars = new ObjCIvarDecl*[numIvars];
-    memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
-  }
-  setLocEnd(RBrac);
-}
-
-/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance 
-/// Variables (Ivars) relative to what declared in @implementation;s class. 
-/// Ivars into ObjCImplementationDecl's fields.
-///
-void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl(
-                               ObjCIvarDecl **ivars, unsigned numIvars) {
-  NumIvars = numIvars;
-  if (numIvars) {
-    Ivars = new ObjCIvarDecl*[numIvars];
-    memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
-  }
-}
-
-/// addMethods - Insert instance and methods declarations into
-/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
-///
-void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods, 
-                                   unsigned numInsMembers,
-                                   ObjCMethodDecl **clsMethods,
-                                   unsigned numClsMembers,
-                                   SourceLocation endLoc) {
-  NumInstanceMethods = numInsMembers;
-  if (numInsMembers) {
-    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
-    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
-  }
-  NumClassMethods = numClsMembers;
-  if (numClsMembers) {
-    ClassMethods = new ObjCMethodDecl*[numClsMembers];
-    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
-  }
-  AtEndLoc = endLoc;
-}
-
-/// addMethods - Insert instance and methods declarations into
-/// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
-///
-void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods, 
-                                  unsigned numInsMembers,
-                                  ObjCMethodDecl **clsMethods,
-                                  unsigned numClsMembers,
-                                  SourceLocation endLoc) {
-  NumInstanceMethods = numInsMembers;
-  if (numInsMembers) {
-    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
-    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
-  }
-  NumClassMethods = numClsMembers;
-  if (numClsMembers) {
-    ClassMethods = new ObjCMethodDecl*[numClsMembers];
-    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
-  }
-  AtEndLoc = endLoc;
-}
-
-/// addMethods - Insert instance and methods declarations into
-/// ObjCCategoryDecl's CatInsMethods and CatClsMethods fields.
-///
-void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods, 
-                                  unsigned numInsMembers,
-                                  ObjCMethodDecl **clsMethods,
-                                  unsigned numClsMembers,
-                                  SourceLocation endLoc) {
-  NumInstanceMethods = numInsMembers;
-  if (numInsMembers) {
-    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
-    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
-  }
-  NumClassMethods = numClsMembers;
-  if (numClsMembers) {
-    ClassMethods = new ObjCMethodDecl*[numClsMembers];
-    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
-  }
-  AtEndLoc = endLoc;
-}
-
-ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
-  IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
-  ObjCInterfaceDecl* ClassDecl = this;
-  while (ClassDecl != NULL) {
-    for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
-         I != E; ++I) {
-      if ((*I)->getIdentifier() == ID) {
-        clsDeclared = ClassDecl;
-        return *I;
-      }
-    }
-    ClassDecl = ClassDecl->getSuperClass();
-  }
-  return NULL;
-}
-
-/// lookupInstanceMethod - This method returns an instance method by looking in
-/// the class, its categories, and its super classes (using a linear search).
-ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
-  ObjCInterfaceDecl* ClassDecl = this;
-  ObjCMethodDecl *MethodDecl = 0;
-  
-  while (ClassDecl != NULL) {
-    if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
-      return MethodDecl;
-      
-    // Didn't find one yet - look through protocols.
-    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
-    int numProtocols = ClassDecl->getNumIntfRefProtocols();
-    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
-      if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
-        return MethodDecl;
-    }
-    // Didn't find one yet - now look through categories.
-    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
-    while (CatDecl) {
-      if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
-        return MethodDecl;
-      CatDecl = CatDecl->getNextClassCategory();
-    }
-    ClassDecl = ClassDecl->getSuperClass();
-  }
-  return NULL;
-}
-
-// lookupClassMethod - This method returns a class method by looking in the
-// class, its categories, and its super classes (using a linear search).
-ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
-  ObjCInterfaceDecl* ClassDecl = this;
-  ObjCMethodDecl *MethodDecl = 0;
-
-  while (ClassDecl != NULL) {
-    if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
-      return MethodDecl;
-
-    // Didn't find one yet - look through protocols.
-    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
-    int numProtocols = ClassDecl->getNumIntfRefProtocols();
-    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
-      if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
-        return MethodDecl;
-    }
-    // Didn't find one yet - now look through categories.
-    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
-    while (CatDecl) {
-      if ((MethodDecl = CatDecl->getClassMethod(Sel)))
-        return MethodDecl;
-      CatDecl = CatDecl->getNextClassCategory();
-    }
-    ClassDecl = ClassDecl->getSuperClass();
-  }
-  return NULL;
-}
-
-/// lookupInstanceMethod - This method returns an instance method by looking in
-/// the class implementation. Unlike interfaces, we don't look outside the
-/// implementation.
-ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) {
-  for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
-    if ((*I)->getSelector() == Sel)
-      return *I;
-  return NULL;
-}
-
-/// lookupClassMethod - This method returns a class method by looking in
-/// the class implementation. Unlike interfaces, we don't look outside the
-/// implementation.
-ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) {
-  for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
-       I != E; ++I)
-    if ((*I)->getSelector() == Sel)
-      return *I;
-  return NULL;
-}
-
-// lookupInstanceMethod - This method returns an instance method by looking in
-// the class implementation. Unlike interfaces, we don't look outside the
-// implementation.
-ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) {
-  for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
-    if ((*I)->getSelector() == Sel)
-      return *I;
-  return NULL;
-}
-
-// lookupClassMethod - This method returns an instance method by looking in
-// the class implementation. Unlike interfaces, we don't look outside the
-// implementation.
-ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) {
-  for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
-       I != E; ++I)
-    if ((*I)->getSelector() == Sel)
-      return *I;
-  return NULL;
-}
-
-// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
-// it inherited.
-ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
-  ObjCMethodDecl *MethodDecl = NULL;
-  
-  if ((MethodDecl = getInstanceMethod(Sel)))
-    return MethodDecl;
-    
-  if (getNumReferencedProtocols() > 0) {
-    ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
-    
-    for (unsigned i = 0; i < getNumReferencedProtocols(); i++) {
-      if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
-        return MethodDecl;
-    }
-  }
-  return NULL;
-}
-
-// lookupInstanceMethod - Lookup a class method in the protocol and protocols
-// it inherited.
-ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
-  ObjCMethodDecl *MethodDecl = NULL;
-
-  if ((MethodDecl = getClassMethod(Sel)))
-    return MethodDecl;
-    
-  if (getNumReferencedProtocols() > 0) {
-    ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
-    
-    for(unsigned i = 0; i < getNumReferencedProtocols(); i++) {
-      if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
-        return MethodDecl;
-    }
-  }
-  return NULL;
-}
-
-/// getSynthesizedMethodSize - Compute size of synthesized method name
-/// as done be the rewrite.
-///
-unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
-  // syntesized method name is a concatenation of -/+[class-name selector]
-  // Get length of this name.
-  unsigned length = 3;  // _I_ or _C_
-  length += strlen(getClassInterface()->getName()) +1; // extra for _
-  NamedDecl *MethodContext = getMethodContext();
-  if (ObjCCategoryImplDecl *CID = 
-      dyn_cast<ObjCCategoryImplDecl>(MethodContext))
-    length += strlen(CID->getName()) +1;
-  length += getSelector().getName().size(); // selector name
-  return length; 
-}
-
-ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
-  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
-    return ID;
-  if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(MethodContext))
-    return CD->getClassInterface();
-  if (ObjCImplementationDecl *IMD = 
-      dyn_cast<ObjCImplementationDecl>(MethodContext))
-    return IMD->getClassInterface();
-  if (ObjCCategoryImplDecl *CID = 
-      dyn_cast<ObjCCategoryImplDecl>(MethodContext))
-    return CID->getClassInterface();
-  assert(false && "unknown method context");
-  return 0;
-}

Added: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=48404&view=auto

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (added)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sat Mar 15 19:19:01 2008
@@ -0,0 +1,312 @@
+//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Objective-C related Decl classes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/ASTContext.h"
+using namespace clang;
+
+
+//===----------------------------------------------------------------------===//
+// Objective-C Decl Implementation
+//===----------------------------------------------------------------------===//
+
+void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
+                                     unsigned NumParams) {
+  assert(ParamInfo == 0 && "Already has param info!");
+
+  // Zero params -> null pointer.
+  if (NumParams) {
+    ParamInfo = new ParmVarDecl*[NumParams];
+    memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
+    NumMethodParams = NumParams;
+  }
+}
+
+ObjCMethodDecl::~ObjCMethodDecl() {
+  delete[] ParamInfo;
+}
+
+/// ObjCAddInstanceVariablesToClass - Inserts instance variables
+/// into ObjCInterfaceDecl's fields.
+///
+void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
+                                                    unsigned numIvars,
+                                                    SourceLocation RBrac) {
+  NumIvars = numIvars;
+  if (numIvars) {
+    Ivars = new ObjCIvarDecl*[numIvars];
+    memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
+  }
+  setLocEnd(RBrac);
+}
+
+/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance 
+/// Variables (Ivars) relative to what declared in @implementation;s class. 
+/// Ivars into ObjCImplementationDecl's fields.
+///
+void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl(
+                               ObjCIvarDecl **ivars, unsigned numIvars) {
+  NumIvars = numIvars;
+  if (numIvars) {
+    Ivars = new ObjCIvarDecl*[numIvars];
+    memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
+  }
+}
+
+/// addMethods - Insert instance and methods declarations into
+/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
+///
+void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods, 
+                                   unsigned numInsMembers,
+                                   ObjCMethodDecl **clsMethods,
+                                   unsigned numClsMembers,
+                                   SourceLocation endLoc) {
+  NumInstanceMethods = numInsMembers;
+  if (numInsMembers) {
+    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
+    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
+  }
+  NumClassMethods = numClsMembers;
+  if (numClsMembers) {
+    ClassMethods = new ObjCMethodDecl*[numClsMembers];
+    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
+  }
+  AtEndLoc = endLoc;
+}
+
+/// addMethods - Insert instance and methods declarations into
+/// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
+///
+void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods, 
+                                  unsigned numInsMembers,
+                                  ObjCMethodDecl **clsMethods,
+                                  unsigned numClsMembers,
+                                  SourceLocation endLoc) {
+  NumInstanceMethods = numInsMembers;
+  if (numInsMembers) {
+    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
+    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
+  }
+  NumClassMethods = numClsMembers;
+  if (numClsMembers) {
+    ClassMethods = new ObjCMethodDecl*[numClsMembers];
+    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
+  }
+  AtEndLoc = endLoc;
+}
+
+/// addMethods - Insert instance and methods declarations into
+/// ObjCCategoryDecl's CatInsMethods and CatClsMethods fields.
+///
+void ObjCCategoryDecl::addMethods(ObjCMethodDecl **insMethods, 
+                                  unsigned numInsMembers,
+                                  ObjCMethodDecl **clsMethods,
+                                  unsigned numClsMembers,
+                                  SourceLocation endLoc) {
+  NumInstanceMethods = numInsMembers;
+  if (numInsMembers) {
+    InstanceMethods = new ObjCMethodDecl*[numInsMembers];
+    memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjCMethodDecl*));
+  }
+  NumClassMethods = numClsMembers;
+  if (numClsMembers) {
+    ClassMethods = new ObjCMethodDecl*[numClsMembers];
+    memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjCMethodDecl*));
+  }
+  AtEndLoc = endLoc;
+}
+
+ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
+  IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
+  ObjCInterfaceDecl* ClassDecl = this;
+  while (ClassDecl != NULL) {
+    for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
+         I != E; ++I) {
+      if ((*I)->getIdentifier() == ID) {
+        clsDeclared = ClassDecl;
+        return *I;
+      }
+    }
+    ClassDecl = ClassDecl->getSuperClass();
+  }
+  return NULL;
+}
+
+/// lookupInstanceMethod - This method returns an instance method by looking in
+/// the class, its categories, and its super classes (using a linear search).
+ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
+  ObjCInterfaceDecl* ClassDecl = this;
+  ObjCMethodDecl *MethodDecl = 0;
+  
+  while (ClassDecl != NULL) {
+    if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
+      return MethodDecl;
+      
+    // Didn't find one yet - look through protocols.
+    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
+    int numProtocols = ClassDecl->getNumIntfRefProtocols();
+    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
+      if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
+        return MethodDecl;
+    }
+    // Didn't find one yet - now look through categories.
+    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
+    while (CatDecl) {
+      if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
+        return MethodDecl;
+      CatDecl = CatDecl->getNextClassCategory();
+    }
+    ClassDecl = ClassDecl->getSuperClass();
+  }
+  return NULL;
+}
+
+// lookupClassMethod - This method returns a class method by looking in the
+// class, its categories, and its super classes (using a linear search).
+ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
+  ObjCInterfaceDecl* ClassDecl = this;
+  ObjCMethodDecl *MethodDecl = 0;
+
+  while (ClassDecl != NULL) {
+    if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
+      return MethodDecl;
+
+    // Didn't find one yet - look through protocols.
+    ObjCProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
+    int numProtocols = ClassDecl->getNumIntfRefProtocols();
+    for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
+      if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
+        return MethodDecl;
+    }
+    // Didn't find one yet - now look through categories.
+    ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
+    while (CatDecl) {
+      if ((MethodDecl = CatDecl->getClassMethod(Sel)))
+        return MethodDecl;
+      CatDecl = CatDecl->getNextClassCategory();
+    }
+    ClassDecl = ClassDecl->getSuperClass();
+  }
+  return NULL;
+}
+
+/// lookupInstanceMethod - This method returns an instance method by looking in
+/// the class implementation. Unlike interfaces, we don't look outside the
+/// implementation.
+ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) {
+  for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
+    if ((*I)->getSelector() == Sel)
+      return *I;
+  return NULL;
+}
+
+/// lookupClassMethod - This method returns a class method by looking in
+/// the class implementation. Unlike interfaces, we don't look outside the
+/// implementation.
+ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) {
+  for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
+       I != E; ++I)
+    if ((*I)->getSelector() == Sel)
+      return *I;
+  return NULL;
+}
+
+// lookupInstanceMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) {
+  for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
+    if ((*I)->getSelector() == Sel)
+      return *I;
+  return NULL;
+}
+
+// lookupClassMethod - This method returns an instance method by looking in
+// the class implementation. Unlike interfaces, we don't look outside the
+// implementation.
+ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) {
+  for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
+       I != E; ++I)
+    if ((*I)->getSelector() == Sel)
+      return *I;
+  return NULL;
+}
+
+// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
+// it inherited.
+ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
+  ObjCMethodDecl *MethodDecl = NULL;
+  
+  if ((MethodDecl = getInstanceMethod(Sel)))
+    return MethodDecl;
+    
+  if (getNumReferencedProtocols() > 0) {
+    ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
+    
+    for (unsigned i = 0; i < getNumReferencedProtocols(); i++) {
+      if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
+        return MethodDecl;
+    }
+  }
+  return NULL;
+}
+
+// lookupInstanceMethod - Lookup a class method in the protocol and protocols
+// it inherited.
+ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
+  ObjCMethodDecl *MethodDecl = NULL;
+
+  if ((MethodDecl = getClassMethod(Sel)))
+    return MethodDecl;
+    
+  if (getNumReferencedProtocols() > 0) {
+    ObjCProtocolDecl **RefPDecl = getReferencedProtocols();
+    
+    for(unsigned i = 0; i < getNumReferencedProtocols(); i++) {
+      if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
+        return MethodDecl;
+    }
+  }
+  return NULL;
+}
+
+/// getSynthesizedMethodSize - Compute size of synthesized method name
+/// as done be the rewrite.
+///
+unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
+  // syntesized method name is a concatenation of -/+[class-name selector]
+  // Get length of this name.
+  unsigned length = 3;  // _I_ or _C_
+  length += strlen(getClassInterface()->getName()) +1; // extra for _
+  NamedDecl *MethodContext = getMethodContext();
+  if (ObjCCategoryImplDecl *CID = 
+      dyn_cast<ObjCCategoryImplDecl>(MethodContext))
+    length += strlen(CID->getName()) +1;
+  length += getSelector().getName().size(); // selector name
+  return length; 
+}
+
+ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const {
+  if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(MethodContext))
+    return ID;
+  if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(MethodContext))
+    return CD->getClassInterface();
+  if (ObjCImplementationDecl *IMD = 
+      dyn_cast<ObjCImplementationDecl>(MethodContext))
+    return IMD->getClassInterface();
+  if (ObjCCategoryImplDecl *CID = 
+      dyn_cast<ObjCCategoryImplDecl>(MethodContext))
+    return CID->getClassInterface();
+  assert(false && "unknown method context");
+  return 0;
+}





More information about the cfe-commits mailing list