Use of DeclContext for objc's ivars. No functionality

change. More to follow.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72951 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2009-06-05 18:16:35 +00:00
Родитель f5dba388e7
Коммит 496b5a894c
7 изменённых файлов: 47 добавлений и 15 удалений

Просмотреть файл

@ -330,6 +330,7 @@ public:
// Get the local instance/class method declared in this interface.
ObjCMethodDecl *getInstanceMethod(ASTContext &Context, Selector Sel) const;
ObjCMethodDecl *getClassMethod(ASTContext &Context, Selector Sel) const;
ObjCIvarDecl *getIvarDecl(ASTContext &Context, IdentifierInfo *Id) const;
ObjCMethodDecl *
getMethod(ASTContext &Context, Selector Sel, bool isInstance) const {

Просмотреть файл

@ -417,6 +417,7 @@ public:
}
virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
DeclPtrTy IntfDecl,
Declarator &D, ExprTy *BitfieldWidth,
tok::ObjCKeywordKind visibility) {
return DeclPtrTy();

Просмотреть файл

@ -42,6 +42,19 @@ void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
// ObjCInterfaceDecl
//===----------------------------------------------------------------------===//
/// getIvarDecl - This method looks up an ivar in this ContextDecl.
///
ObjCIvarDecl *
ObjCContainerDecl::getIvarDecl(ASTContext &Context, IdentifierInfo *Id) const {
lookup_const_iterator Ivar, IvarEnd;
for (llvm::tie(Ivar, IvarEnd) = lookup(Context, Id);
Ivar != IvarEnd; ++Ivar) {
if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
return ivar;
}
return 0;
}
// Get the local instance method declared in this interface.
ObjCMethodDecl *
ObjCContainerDecl::getInstanceMethod(ASTContext &Context, Selector Sel) const {
@ -139,12 +152,9 @@ ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
ASTContext &Context, IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
ObjCInterfaceDecl* ClassDecl = this;
while (ClassDecl != NULL) {
for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
I != E; ++I) {
if ((*I)->getIdentifier() == ID) {
clsDeclared = ClassDecl;
return *I;
}
if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(Context, ID)) {
clsDeclared = ClassDecl;
return I;
}
// look into properties.
for (ObjCInterfaceDecl::prop_iterator I = ClassDecl->prop_begin(Context),

Просмотреть файл

@ -220,6 +220,7 @@ namespace {
}
virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
DeclPtrTy IntfDecl,
Declarator &D, ExprTy *BitfieldWidth,
tok::ObjCKeywordKind visibility) {
Out << __FUNCTION__ << "\n";

Просмотреть файл

@ -891,6 +891,7 @@ void Parser::ParseObjCClassInstanceVariables(DeclPtrTy interfaceDecl,
// Install the declarator into interfaceDecl.
DeclPtrTy Field = Actions.ActOnIvar(CurScope,
DS.getSourceRange().getBegin(),
interfaceDecl,
FD.D, FD.BitfieldSize, visibility);
AllIvarDecls.push_back(Field);
}

Просмотреть файл

@ -472,6 +472,7 @@ public:
Declarator *D = 0);
virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
DeclPtrTy IntfDecl,
Declarator &D, ExprTy *BitfieldWidth,
tok::ObjCKeywordKind visibility);

Просмотреть файл

@ -3914,6 +3914,7 @@ TranslateIvarVisibility(tok::ObjCKeywordKind ivarVisibility) {
/// in order to create an IvarDecl object for it.
Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
SourceLocation DeclStart,
DeclPtrTy IntfDecl,
Declarator &D, ExprTy *BitfieldWidth,
tok::ObjCKeywordKind Visibility) {
@ -3952,14 +3953,28 @@ Sema::DeclPtrTy Sema::ActOnIvar(Scope *S,
ObjCIvarDecl::AccessControl ac =
Visibility != tok::objc_not_keyword ? TranslateIvarVisibility(Visibility)
: ObjCIvarDecl::None;
// Must set ivar's DeclContext to its enclosing interface.
Decl *EnclosingDecl = IntfDecl.getAs<Decl>();
DeclContext *EnclosingContext;
if (ObjCImplementationDecl *IMPDecl =
dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
// Case of ivar declared in an implementation. Context is that of its class.
ObjCInterfaceDecl* IDecl = IMPDecl->getClassInterface();
assert(IDecl && "No class- ActOnIvar");
EnclosingContext = cast_or_null<DeclContext>(IDecl);
}
else
EnclosingContext = dyn_cast<DeclContext>(EnclosingDecl);
assert(EnclosingContext && "null DeclContext for ivar - ActOnIvar");
// Construct the decl.
ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context, CurContext, Loc, II, T,ac,
ObjCIvarDecl *NewID = ObjCIvarDecl::Create(Context,
EnclosingContext, Loc, II, T,ac,
(Expr *)BitfieldWidth);
if (II) {
NamedDecl *PrevDecl = LookupName(S, II, LookupMemberName, true);
if (PrevDecl && isDeclInScope(PrevDecl, CurContext, S)
if (PrevDecl && isDeclInScope(PrevDecl, EnclosingContext, S)
&& !isa<TagDecl>(PrevDecl)) {
Diag(Loc, diag::err_duplicate_member) << II;
Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
@ -4100,7 +4115,11 @@ void Sema::ActOnFields(Scope* S,
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
ID->setIVarList(ClsFields, RecFields.size(), Context);
ID->setLocEnd(RBrac);
// Add ivar's to class's DeclContext.
for (unsigned i = 0, e = RecFields.size(); i != e; ++i) {
ClsFields[i]->setLexicalDeclContext(ID);
ID->addDecl(Context, ClsFields[i]);
}
// Must enforce the rule that ivars in the base classes may not be
// duplicates.
if (ID->getSuperClass()) {
@ -4121,12 +4140,10 @@ void Sema::ActOnFields(Scope* S,
} else if (ObjCImplementationDecl *IMPDecl =
dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl");
for (unsigned I = 0, N = RecFields.size(); I != N; ++I) {
// FIXME: Set the DeclContext correctly when we build the
// declarations.
for (unsigned I = 0, N = RecFields.size(); I != N; ++I)
// Ivar declared in @implementation never belongs to the implementation.
// Only it is in implementation's lexical context.
ClsFields[I]->setLexicalDeclContext(IMPDecl);
IMPDecl->addDecl(Context, ClsFields[I]);
}
CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
}
}