[cfe-commits] r61832 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/Sema/IdentifierResolver.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp test/SemaObjCXX/linkage-spec.mm

Douglas Gregor dgregor at apple.com
Tue Jan 6 15:51:29 PST 2009


Author: dgregor
Date: Tue Jan  6 17:51:29 2009
New Revision: 61832

URL: http://llvm.org/viewvc/llvm-project?rev=61832&view=rev
Log:
Allow Objective-C entities to be declared within a transparent context
nested in the translation unit. This fixes <rdar://problem/6476070>.


Added:
    cfe/trunk/test/SemaObjCXX/linkage-spec.mm
Modified:
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/IdentifierResolver.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=61832&r1=61831&r2=61832&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Jan  6 17:51:29 2009
@@ -425,6 +425,12 @@
   /// information needed to perform name lookup into this context.
   DeclContext *getPrimaryContext(ASTContext &Context);
 
+  /// getLookupContext - Retrieve the innermost non-transparent
+  /// context of this context, which corresponds to the innermost
+  /// location from which name lookup can find the entities in this
+  /// context.
+  DeclContext *getLookupContext();
+
   /// getNextContext - If this is a DeclContext that may have other
   /// DeclContexts that are semantically connected but syntactically
   /// different, such as C++ namespaces, this routine retrieves the

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

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jan  6 17:51:29 2009
@@ -567,6 +567,13 @@
   return const_cast<DeclContext*>(this)->lookup(Context, Name);
 }
 
+DeclContext *DeclContext::getLookupContext() {
+  DeclContext *Ctx = this;
+  while (Ctx->isTransparentContext())
+    Ctx = Ctx->getParent();
+  return Ctx;
+}
+
 void DeclContext::insert(ASTContext &Context, ScopedDecl *D) {
   DeclContext *PrimaryContext = getPrimaryContext(Context);
   if (PrimaryContext != this) {

Modified: cfe/trunk/lib/Sema/IdentifierResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/IdentifierResolver.cpp?rev=61832&r1=61831&r2=61832&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/IdentifierResolver.cpp (original)
+++ cfe/trunk/lib/Sema/IdentifierResolver.cpp Tue Jan  6 17:51:29 2009
@@ -60,8 +60,7 @@
   else
     return TUCtx();
 
-  while (Ctx->isTransparentContext())
-    Ctx = Ctx->getParent();
+  Ctx = Ctx->getLookupContext();
 
   if (isa<TranslationUnitDecl>(Ctx))
     return TUCtx();
@@ -132,8 +131,7 @@
 /// true if 'D' belongs to the given declaration context.
 bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx,
                                        ASTContext &Context, Scope *S) const {
-  while (Ctx->isTransparentContext())
-    Ctx = Ctx->getParent();
+  Ctx = Ctx->getLookupContext();
 
   if (Ctx->isFunctionOrMethod()) {
     // Ignore the scopes associated within transparent declaration contexts.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan  6 17:51:29 2009
@@ -156,9 +156,7 @@
     // We are pushing the name of a function, which might be an
     // overloaded name.
     FunctionDecl *FD = cast<FunctionDecl>(D);
-    DeclContext *DC = FD->getDeclContext();                                     
-    while (DC->isTransparentContext())
-      DC = DC->getParent(); 
+    DeclContext *DC = FD->getDeclContext()->getLookupContext();
     IdentifierResolver::iterator Redecl
       = std::find_if(IdResolver.begin(FD->getDeclName(), DC, 
                                       false/*LookInParentCtx*/),

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=61832&r1=61831&r2=61832&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Jan  6 17:51:29 2009
@@ -1647,7 +1647,7 @@
 }
 
 bool Sema::CheckObjCDeclScope(Decl *D) {
-  if (isa<TranslationUnitDecl>(CurContext))
+  if (isa<TranslationUnitDecl>(CurContext->getLookupContext()))
     return false;
   
   Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);

Added: cfe/trunk/test/SemaObjCXX/linkage-spec.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/linkage-spec.mm?rev=61832&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjCXX/linkage-spec.mm (added)
+++ cfe/trunk/test/SemaObjCXX/linkage-spec.mm Tue Jan  6 17:51:29 2009
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only -verify %s
+extern "C" {
+ at class Protocol;
+}





More information about the cfe-commits mailing list