зеркало из https://github.com/microsoft/clang-1.git
Allow Objective-C entities to be declared within a transparent context
nested in the translation unit. This fixes <rdar://problem/6476070>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61832 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
5b034ad3ec
Коммит
ce35607c28
|
@ -425,6 +425,12 @@ public:
|
|||
/// 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
|
||||
|
|
|
@ -567,6 +567,13 @@ DeclContext::lookup(ASTContext &Context, DeclarationName Name) const {
|
|||
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) {
|
||||
|
|
|
@ -60,8 +60,7 @@ DeclContext *IdentifierResolver::LookupContext::getContext(Decl *D) {
|
|||
else
|
||||
return TUCtx();
|
||||
|
||||
while (Ctx->isTransparentContext())
|
||||
Ctx = Ctx->getParent();
|
||||
Ctx = Ctx->getLookupContext();
|
||||
|
||||
if (isa<TranslationUnitDecl>(Ctx))
|
||||
return TUCtx();
|
||||
|
@ -132,8 +131,7 @@ IdentifierResolver::~IdentifierResolver() {
|
|||
/// 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.
|
||||
|
|
|
@ -156,9 +156,7 @@ void Sema::PushOnScopeChains(NamedDecl *D, Scope *S) {
|
|||
// 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*/),
|
||||
|
|
|
@ -1647,7 +1647,7 @@ Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
// RUN: clang -fsyntax-only -verify %s
|
||||
extern "C" {
|
||||
@class Protocol;
|
||||
}
|
Загрузка…
Ссылка в новой задаче