]> granicus.if.org Git - clang/commitdiff
Removed use of hash table for class decls and do a name look up directly.
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 29 Sep 2007 00:54:24 +0000 (00:54 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 29 Sep 2007 00:54:24 +0000 (00:54 +0000)
There is still an issue if doing ScopedLookup is an overkill and we can
just access the decl using the identifier.

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

Parse/ParseDecl.cpp
Parse/ParseObjc.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/ASTContext.h
include/clang/Parse/Action.h

index 7fbab64d11e3fcf22f1f0e5f37119f896bdf5c40..db568df26e1aeb9410e86e468ad8494dc632ef46 100644 (file)
@@ -757,7 +757,8 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
   
   MatchRHSPunctuation(tok::r_brace, LBraceLoc);
   
-  Actions.ActOnFields(RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
+  Actions.ActOnFields(CurScope,
+                     RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
   
   AttributeList *AttrList = 0;
   // If attributes exist after struct contents, parse them.
index be0e026157b294d049295f9e0eb5ec81144dce52..e367834f70c0777a8ebd28ff37f25b2db3d12e93 100644 (file)
@@ -154,7 +154,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
     if (attrList) // categories don't support attributes.
       Diag(Tok, diag::err_objc_no_attributes_on_category);
     
-    DeclTy *CategoryType = Actions.ObjcStartCatInterface(atLoc, 
+    DeclTy *CategoryType = Actions.ObjcStartCatInterface(CurScope, atLoc, 
                                      nameId, nameLoc,
                                      categoryId, categoryLoc,
                                      &ProtocolRefs[0],
@@ -268,7 +268,8 @@ void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl,
     }
   }
   /// Insert collected methods declarations into the @interface object.
-  Actions.ObjcAddMethodsToClass(interfaceDecl,&allMethods[0],allMethods.size());
+  Actions.ObjcAddMethodsToClass(CurScope,
+                               interfaceDecl,&allMethods[0],allMethods.size());
   return;
 }
 
@@ -801,7 +802,7 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
     }
   }
   if (AllIvarDecls.size()) {  // Check for {} - no ivars in braces
-    Actions.ActOnFields(LBraceLoc, interfaceDecl, 
+    Actions.ActOnFields(CurScope, LBraceLoc, interfaceDecl, 
                         &AllIvarDecls[0], AllIvarDecls.size(),
                         &AllVisibilities[0]);
   }
@@ -968,7 +969,7 @@ Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) {
     // @implementation not to have been parsed to completion and ObjcImpDecl 
     // could be 0.
     /// Insert collected methods declarations into the @interface object.
-    Actions.ObjcAddMethodsToClass(ObjcImpDecl,
+    Actions.ObjcAddMethodsToClass(CurScope, ObjcImpDecl,
                                   &AllImplMethods[0],AllImplMethods.size());
     ObjcImpDecl = 0;
     AllImplMethods.clear();
index d9a1cc4fe2487b12c23dbb8c3c5c7e5aba6419e9..2c753f3aa5264649bfa1b6a49389988e697e19ed 100644 (file)
@@ -46,6 +46,7 @@ namespace clang {
   class SwitchStmt;
   class OCUVectorType;
   class TypedefDecl;
+  class ObjcInterfaceDecl;
 
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema : public Action {
@@ -121,7 +122,7 @@ public:
   bool Diag(SourceLocation Loc, unsigned DiagID, 
             const std::string &Msg1, const std::string &Msg2, 
             SourceRange R1, SourceRange R2);
-
+  
   virtual void DeleteExpr(ExprTy *E);
   virtual void DeleteStmt(StmtTy *S);
 
@@ -157,7 +158,8 @@ private:
                              Declarator &D, ExprTy *BitfieldWidth);
                                       
   // This is used for both record definitions and ObjC interface declarations.
-  virtual void ActOnFields(SourceLocation RecLoc, DeclTy *TagDecl,
+  virtual void ActOnFields(Scope* S,
+                                SourceLocation RecLoc, DeclTy *TagDecl,
                                  DeclTy **Fields, unsigned NumFields,
                                  tok::ObjCKeywordKind *visibility = 0);
   virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@@ -181,6 +183,8 @@ private:
                                     Scope *FnBodyScope);
   ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, 
                                SourceLocation IdLoc, Scope *S);  
+  ObjcInterfaceDecl *getObjCInterfaceDecl(Scope *S, 
+                      IdentifierInfo *Id, SourceLocation IdLoc);
   ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
   ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
                                  Scope *S);
@@ -364,7 +368,8 @@ public:
                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
   
-  virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+  virtual DeclTy *ObjcStartCatInterface(Scope* S,
+                   SourceLocation AtInterfaceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
@@ -384,7 +389,7 @@ public:
                                                  IdentifierInfo **IdentList,
                                                  unsigned NumElts);
 
-  virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl, 
+  virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl, 
                                     DeclTy **allMethods, unsigned allNum);
   
   virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl,
index 28682cc0e53350dcaa141e1f2db9f38e09f4a08c..2b0e1452f6e114d4261a492c2142f9b1930be447 100644 (file)
@@ -78,6 +78,18 @@ void Sema::PopScope(SourceLocation Loc, Scope *S) {
   }
 }
 
+/// ObjcInterfaceDecl - Look up a for a class declaration in the scope.
+/// return 0 if one not found.
+ObjcInterfaceDecl *Sema::getObjCInterfaceDecl(Scope *S,
+                                                     IdentifierInfo *Id, 
+                                             SourceLocation IdLoc) {
+  ScopedDecl *IdDecl = LookupScopedDecl(Id, Decl::IDNS_Ordinary, 
+                                       IdLoc, S);
+  if (IdDecl && !isa<ObjcInterfaceDecl>(IdDecl))
+    IdDecl = 0;
+  return cast_or_null<ObjcInterfaceDecl>(static_cast<Decl*>(IdDecl));
+}
+
 /// LookupScopedDecl - Look up the inner-most declaration in the specified
 /// namespace.
 ScopedDecl *Sema::LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
@@ -880,8 +892,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
     Diag(PrevDecl->getLocation(), diag::err_previous_definition);
   }
   
-  ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName);
-  
+  ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
   if (IDecl) {
     // Class already seen. Is it a forward declaration?
     if (!IDecl->getIsForwardDecl())
@@ -912,7 +923,7 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
     }
     else {
       // Check that super class is previously defined
-      SuperClassEntry = Context.getObjCInterfaceDecl(SuperName);
+      SuperClassEntry = getObjCInterfaceDecl(S, SuperName, SuperLoc); 
                               
       if (!SuperClassEntry || SuperClassEntry->getIsForwardDecl()) {
         Diag(AtInterfaceLoc, diag::err_undef_superclass, SuperName->getName(),
@@ -932,9 +943,6 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(Scope* S,
     IDecl->setIntfRefProtocols((int)i, RefPDecl);
   }
   
-  
-  Context.setObjCInterfaceDecl(ClassName, IDecl);
-    
   return IDecl;
 }
 
@@ -1003,12 +1011,13 @@ Sema::ObjcForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
   return FDecl;
 }
 
-Sema::DeclTy *Sema::ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+Sema::DeclTy *Sema::ObjcStartCatInterface(Scope* S,
+                     SourceLocation AtInterfaceLoc,
                       IdentifierInfo *ClassName, SourceLocation ClassLoc,
                       IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
                       IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
   ObjcCategoryDecl *CDecl;
-  ObjcInterfaceDecl* IDecl = Context.getObjCInterfaceDecl(ClassName);
+  ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc);
   CDecl = new ObjcCategoryDecl(AtInterfaceLoc, NumProtoRefs, ClassName);
   if (IDecl) {
     assert (ClassName->getFETokenInfo<ScopedDecl>() && "Missing @interface decl");
@@ -1071,7 +1080,7 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
   }
   else {
     // Is there an interface declaration of this class; if not, warn!
-    IDecl = Context.getObjCInterfaceDecl(ClassName);
+    IDecl = getObjCInterfaceDecl(S, ClassName, ClassLoc); 
     if (!IDecl)
       Diag(ClassLoc, diag::warn_undef_interface, ClassName->getName());
   }
@@ -1089,7 +1098,7 @@ Sema::DeclTy *Sema::ObjcStartClassImplementation(Scope *S,
       Diag(PrevDecl->getLocation(), diag::err_previous_definition);
     }
     else {
-      SDecl = Context.getObjCInterfaceDecl(SuperClassname);
+      SDecl = getObjCInterfaceDecl(S, SuperClassname, SuperClassLoc); 
       if (!SDecl)
         Diag(SuperClassLoc, diag::err_undef_superclass, 
              SuperClassname->getName(), ClassName->getName());
@@ -1256,13 +1265,12 @@ Sema::ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
 
   for (unsigned i = 0; i != NumElts; ++i) {
     ObjcInterfaceDecl *IDecl;
-    IDecl = Context.getObjCInterfaceDecl(IdentList[i]);
+    IDecl = getObjCInterfaceDecl(S, IdentList[i], AtClassLoc); 
     if (!IDecl)  {// Already seen?
       IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
       // Chain & install the interface decl into the identifier.
       IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
       IdentList[i]->setFETokenInfo(IDecl);
-      Context.setObjCInterfaceDecl(IdentList[i], IDecl);
     }
     // Remember that this needs to be removed when the scope is popped.
     S->AddDecl(IdentList[i]);
@@ -1452,7 +1460,8 @@ static void ObjcSetIvarVisibility(ObjcIvarDecl *OIvar,
   }
 }
 
-void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
+void Sema::ActOnFields(Scope* S,
+                      SourceLocation RecLoc, DeclTy *RecDecl,
                        DeclTy **Fields, unsigned NumFields,
                        tok::ObjCKeywordKind *visibility) {
   Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
@@ -1589,8 +1598,8 @@ void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
        cast<ObjcImplementationDecl>(static_cast<Decl*>(RecDecl));
       assert(IMPDecl && "ActOnFields - missing ObjcImplementationDecl");
       IMPDecl->ObjcAddInstanceVariablesToClassImpl(ClsFields, RecFields.size());
-      ObjcInterfaceDecl* IDecl = 
-        Context.getObjCInterfaceDecl(IMPDecl->getIdentifier());
+      ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, 
+                                  IMPDecl->getIdentifier(), RecLoc);
       if (IDecl)
         ActOnImpleIvarVsClassIvars(static_cast<DeclTy*>(IDecl), 
           reinterpret_cast<DeclTy**>(&RecFields[0]), RecFields.size());
@@ -1598,7 +1607,7 @@ void Sema::ActOnFields(SourceLocation RecLoc, DeclTy *RecDecl,
   }
 }
 
-void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
+void Sema::ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
                                  DeclTy **allMethods, unsigned allNum) {
   // FIXME: Fix this when we can handle methods declared in protocols.
   // See Parser::ParseObjCAtProtocolDeclaration
@@ -1639,8 +1648,8 @@ void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
                                                static_cast<Decl*>(ClassDecl));
     ImplClass->ObjcAddImplMethods(&insMethods[0], insMethods.size(),
                                  &clsMethods[0], clsMethods.size());
-    ObjcInterfaceDecl* IDecl = 
-       Context.getObjCInterfaceDecl(ImplClass->getIdentifier());
+    ObjcInterfaceDecl* IDecl = getObjCInterfaceDecl(S, 
+                                ImplClass->getIdentifier(), SourceLocation());
     if (IDecl)
       ImplMethodsVsClassMethods(this, ImplClass, IDecl);
   }
index 04dad73923642fe8370e14e246e86154e9d98bb5..fca0464b4752d414dd76727fe5bf5bd18bc2ddca 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 86051eaa3c7c0cac55c4ca5c81dab4b8f1dd9cfe..59b1387eda8536f3df65ff4ccf6cc35027cc2d94 100644 (file)
@@ -39,7 +39,6 @@ class ASTContext {
   llvm::FoldingSet<FunctionTypeNoProto> FunctionTypeNoProtos;
   llvm::FoldingSet<FunctionTypeProto> FunctionTypeProtos;
   llvm::DenseMap<const RecordDecl*, const RecordLayout*> RecordLayoutInfo;
-  llvm::DenseMap<const IdentifierInfo*, ObjcInterfaceDecl*> ClassNameInfo;
   llvm::DenseMap<const IdentifierInfo*, ObjcProtocolDecl*> ProtocolNameInfo;
   llvm::SmallVector<ObjcImplementationDecl*, 8> ImplementationClassInfo;
   RecordDecl *CFConstantStringTypeDecl;
@@ -166,12 +165,6 @@ public:
   /// position information.
   const RecordLayout &getRecordLayout(const RecordDecl *D, SourceLocation L);
   
-  ObjcInterfaceDecl* getObjCInterfaceDecl(const IdentifierInfo* ClassName) 
-                       { return ClassNameInfo[ClassName]; }
-  void setObjCInterfaceDecl(const IdentifierInfo* ClassName,
-                            ObjcInterfaceDecl* InterfaceDecl)
-  { ClassNameInfo[ClassName] = InterfaceDecl; }
-  
   ObjcProtocolDecl* getObjCProtocolDecl(const IdentifierInfo* ProtocolName) 
   { return ProtocolNameInfo[ProtocolName]; }
   void setObjCProtocolDecl(const IdentifierInfo* ProtocolName,
index 9ef27de47dcd170660028952562e7a682453c171..34561f7a2e41df1716cf3480d868d68056e73bc1 100644 (file)
@@ -174,7 +174,8 @@ public:
                              Declarator &D, ExprTy *BitfieldWidth) {
     return 0;
   }
-  virtual void ActOnFields(SourceLocation RecLoc, DeclTy *TagDecl,
+  virtual void ActOnFields(Scope* S,
+                                SourceLocation RecLoc, DeclTy *TagDecl,
                                  DeclTy **Fields, unsigned NumFields,
                                  tok::ObjCKeywordKind *visibility = 0) {}
   virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
@@ -443,7 +444,7 @@ public:
                     AttributeList *AttrList) {
     return 0;
   }
-  virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
+  virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
                                     DeclTy **allMethods, unsigned allNum) {
     return;
   }
@@ -457,7 +458,8 @@ public:
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
     return 0;
   }
-  virtual DeclTy *ObjcStartCatInterface(SourceLocation AtInterfaceLoc,
+  virtual DeclTy *ObjcStartCatInterface(Scope* S,
+                   SourceLocation AtInterfaceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {