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

Fariborz Jahanian fjahanian at apple.com
Fri Sep 28 17:54:24 PDT 2007


Author: fjahanian
Date: Fri Sep 28 19:54:24 2007
New Revision: 42463

URL: http://llvm.org/viewvc/llvm-project?rev=42463&view=rev
Log:
Removed use of hash table for class decls and do a name look up directly.
There is still an issue if doing ScopedLookup is an overkill and we can
just access the decl using the identifier.

Modified:
    cfe/trunk/Parse/ParseDecl.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/ASTContext.h
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=42463&r1=42462&r2=42463&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Fri Sep 28 19:54:24 2007
@@ -757,7 +757,8 @@
   
   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.

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

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Sep 28 19:54:24 2007
@@ -154,7 +154,7 @@
     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 @@
     }
   }
   /// 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 @@
     }
   }
   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 @@
     // @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();

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Sep 28 19:54:24 2007
@@ -46,6 +46,7 @@
   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 @@
   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 @@
                              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 @@
                                     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 @@
                     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 @@
                                                  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,

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Sep 28 19:54:24 2007
@@ -78,6 +78,18 @@
   }
 }
 
+/// 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 @@
     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 @@
     }
     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 @@
     IDecl->setIntfRefProtocols((int)i, RefPDecl);
   }
   
-  
-  Context.setObjCInterfaceDecl(ClassName, IDecl);
-    
   return IDecl;
 }
 
@@ -1003,12 +1011,13 @@
   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 @@
   }
   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 @@
       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 @@
 
   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 @@
   }
 }
 
-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 @@
 	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::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 @@
                                                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);
   }

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

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Fri Sep 28 19:54:24 2007
@@ -733,6 +733,7 @@
 		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/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=42463&r1=42462&r2=42463&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Sep 28 19:54:24 2007
@@ -39,7 +39,6 @@
   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 @@
   /// 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,

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Sep 28 19:54:24 2007
@@ -174,7 +174,8 @@
                              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 @@
                     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 @@
                     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) {





More information about the cfe-commits mailing list