- Add an ObjcIvarDecl AST node (a subclass of FieldDecl).
- Instantiate the node in Sema::ParseField(), based on the type of the TagDecl.
- Add Sema::ObjcAddInstanceVariable(), responsible for adorning/adding the ObjcIvarDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41864 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.h b/Sema/Sema.h
index f0a072e..2be727a 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -156,8 +156,6 @@
Declarator &D, ExprTy *BitfieldWidth);
virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl,
DeclTy **Fields, unsigned NumFields);
- virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
- DeclTy **allMethods, unsigned allNum);
virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
DeclTy *LastEnumConstant,
SourceLocation IdLoc, IdentifierInfo *Id,
@@ -360,6 +358,11 @@
IdentifierInfo **IdentList,
unsigned NumElts);
+ virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
+ DeclTy **allMethods, unsigned allNum);
+
+ virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivars,
+ tok::ObjCKeywordKind visibility);
private:
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
// functions and arrays to their respective pointers (C99 6.3.2.1).
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 71fc0b4..86e052b 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -855,6 +855,35 @@
return IDecl;
}
+void Sema::ObjcAddInstanceVariable(DeclTy *ClassDecl, DeclTy *Ivar,
+ tok::ObjCKeywordKind visibility) {
+ assert((ClassDecl && Ivar) && "missing class or instance variable");
+ ObjcInterfaceDecl *OInterface = dyn_cast<ObjcInterfaceDecl>(
+ static_cast<Decl *>(ClassDecl));
+ ObjcIvarDecl *OIvar = dyn_cast<ObjcIvarDecl>(static_cast<Decl *>(Ivar));
+
+ assert((OInterface && OIvar) && "mistyped class or instance variable");
+
+ switch (visibility) {
+ case tok::objc_private:
+ OIvar->setAccessControl(ObjcIvarDecl::Private);
+ break;
+ case tok::objc_public:
+ OIvar->setAccessControl(ObjcIvarDecl::Public);
+ break;
+ case tok::objc_protected:
+ OIvar->setAccessControl(ObjcIvarDecl::Protected);
+ break;
+ case tok::objc_package:
+ OIvar->setAccessControl(ObjcIvarDecl::Package);
+ break;
+ default:
+ OIvar->setAccessControl(ObjcIvarDecl::None);
+ break;
+ }
+ // FIXME: add to the class...
+}
+
/// ObjcClassDeclaration -
/// Scope will always be top level file scope.
Action::DeclTy *
@@ -989,7 +1018,6 @@
Declarator &D, ExprTy *BitfieldWidth) {
IdentifierInfo *II = D.getIdentifier();
Expr *BitWidth = (Expr*)BitfieldWidth;
-
SourceLocation Loc = DeclStart;
if (II) Loc = D.getIdentifierLoc();
@@ -1023,7 +1051,15 @@
InvalidDecl = true;
}
// FIXME: Chain fielddecls together.
- FieldDecl *NewFD = new FieldDecl(Loc, II, T, 0);
+ FieldDecl *NewFD;
+
+ if (isa<RecordDecl>(static_cast<Decl *>(TagDecl)))
+ NewFD = new FieldDecl(Loc, II, T, 0);
+ else if (isa<ObjcInterfaceDecl>(static_cast<Decl *>(TagDecl)))
+ NewFD = new ObjcIvarDecl(Loc, II, T, 0);
+ else
+ assert(0 && "Sema::ParseField(): Unknown TagDecl");
+
if (D.getInvalidType() || InvalidDecl)
NewFD->setInvalidDecl();
return NewFD;