]> granicus.if.org Git - clang/commitdiff
Eliminate Sema::ObjCAliasDecls. This is based on Steve's fix, but also
authorDouglas Gregor <dgregor@apple.com>
Fri, 24 Apr 2009 02:57:34 +0000 (02:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 24 Apr 2009 02:57:34 +0000 (02:57 +0000)
updates name lookup so that we see through @compatibility_alias
declarations to their underlying interfaces.

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

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaLookup.cpp

index d87d93105dd837f13f7c90b13a54a4bf5a6fe1c4..3544324ae562b62408c50770269f0262c86fc192 100644 (file)
@@ -172,14 +172,6 @@ public:
   /// we can check for duplicates and find local method declarations.
   llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
   
-  /// ObjCAliasDecls - Keep track of all class declarations declared
-  /// with @compatibility_alias, so that we can emit errors on duplicates and
-  /// find the declarations when needed. This construct is ancient and will
-  /// likely never be seen. Nevertheless, it is here for compatibility.
-  typedef llvm::DenseMap<const IdentifierInfo*, 
-                         ObjCCompatibleAliasDecl*> ObjCAliasTy;
-  ObjCAliasTy ObjCAliasDecls;
-
   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
   llvm::OwningPtr<CXXFieldCollector> FieldCollector;
 
index e81e8832724323bbe393458d19145103a642f34a..63b006277c01d4ddc2508f31283b4659b78ca45e 100644 (file)
@@ -299,6 +299,18 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) {
       S->RemoveDecl(DeclPtrTy::make(*Redecl));
       IdResolver.RemoveDecl(*Redecl);
     }
+  } else if (isa<ObjCInterfaceDecl>(D)) {
+    // We're pushing an Objective-C interface into the current
+    // context. If there is already an alias declaration, remove it first.
+    for (IdentifierResolver::iterator 
+           I = IdResolver.begin(D->getDeclName()), IEnd = IdResolver.end();
+         I != IEnd; ++I) {
+      if (isa<ObjCCompatibleAliasDecl>(*I)) {
+        S->RemoveDecl(DeclPtrTy::make(*I));
+        IdResolver.RemoveDecl(*I);
+        break;
+      }
+    }
   }
 
   IdResolver.AddDecl(D);
index c30a7b26e1438950ebed1a7463c239b2d433cd00..f4014d1f25d50a30c44852605b28fe3e8c6da717 100644 (file)
@@ -201,12 +201,8 @@ Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
   ObjCCompatibleAliasDecl *AliasDecl = 
     ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl);
   
-  ObjCAliasDecls[AliasName] = AliasDecl;
-
-  // FIXME: PushOnScopeChains?
-  CurContext->addDecl(Context, AliasDecl);
   if (!CheckObjCDeclScope(AliasDecl))
-    TUScope->AddDecl(DeclPtrTy::make(AliasDecl));
+    PushOnScopeChains(AliasDecl, TUScope);
 
   return DeclPtrTy::make(AliasDecl);
 }
index df869d9a6b804b529d9f0a5ff91d246f907a41da..b1643bb50ba1aa8942fd39cce449a4778427e51f 100644 (file)
@@ -311,6 +311,10 @@ getIdentifierNamespacesFromLookupNameKind(Sema::LookupNameKind NameKind,
 
 Sema::LookupResult
 Sema::LookupResult::CreateLookupResult(ASTContext &Context, NamedDecl *D) {
+  if (ObjCCompatibleAliasDecl *Alias 
+        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
+    D = Alias->getClassInterface();
+
   LookupResult Result;
   Result.StoredKind = (D && isa<OverloadedFunctionDecl>(D))?
     OverloadedDeclSingleDecl : SingleDecl;
@@ -338,9 +342,14 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context,
       return Result;
     }
   } 
+
+  Decl *D = *F;
+  if (ObjCCompatibleAliasDecl *Alias 
+        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
+    D = Alias->getClassInterface();
     
   Result.StoredKind = SingleDecl;
-  Result.First = reinterpret_cast<uintptr_t>(*F);
+  Result.First = reinterpret_cast<uintptr_t>(D);
   Result.Last = 0;
   return Result;
 }
@@ -362,9 +371,14 @@ Sema::LookupResult::CreateLookupResult(ASTContext &Context,
       return Result;
     }
   }
+
+  Decl *D = *F;
+  if (ObjCCompatibleAliasDecl *Alias 
+        = dyn_cast_or_null<ObjCCompatibleAliasDecl>(D))
+    D = Alias->getClassInterface();
   
   Result.StoredKind = SingleDecl;
-  Result.First = reinterpret_cast<uintptr_t>(*F);
+  Result.First = reinterpret_cast<uintptr_t>(D);
   Result.Last = 0;
   return Result;
 }
@@ -930,16 +944,6 @@ Sema::LookupName(Scope *S, DeclarationName Name, LookupNameKind NameKind,
                                                 S, RedeclarationOnly, Loc));
       }
     }
-    if (getLangOptions().ObjC1 && II) {
-      // @interface and @compatibility_alias introduce typedef-like names.
-      // Unlike typedef's, they can only be introduced at file-scope (and are 
-      // therefore not scoped decls). They can, however, be shadowed by
-      // other names in IDNS_Ordinary.
-      ObjCAliasTy::iterator I = ObjCAliasDecls.find(II);
-      if (I != ObjCAliasDecls.end())
-        return LookupResult::CreateLookupResult(Context, 
-                                                I->second->getClassInterface());
-    }
   }
   return LookupResult::CreateLookupResult(Context, 0);
 }