aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-09-11 21:17:26 +0000
committerSteve Naroff <snaroff@apple.com>2007-09-11 21:17:26 +0000
commit4473921b663539cc489435d6eae5c14df1bc4a96 (patch)
tree2b8b3622f102f6bb8ae5ae43889fa568f47c07f5
parent8a4010d40c7ba61a92c728814639674726888e8f (diff)
- 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
-rw-r--r--Sema/Sema.h7
-rw-r--r--Sema/SemaDecl.cpp40
-rw-r--r--clang.xcodeproj/project.pbxproj1
-rw-r--r--include/clang/AST/Decl.h22
-rw-r--r--include/clang/Parse/Action.h7
5 files changed, 66 insertions, 11 deletions
diff --git a/Sema/Sema.h b/Sema/Sema.h
index f0a072eb9b..2be727a426 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -156,8 +156,6 @@ private:
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 @@ public:
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 71fc0b4471..86e052b4df 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -855,6 +855,35 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(SourceLocation AtInterfaceLoc,
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 @@ Sema::DeclTy *Sema::ParseField(Scope *S, DeclTy *TagDecl,
Declarator &D, ExprTy *BitfieldWidth) {
IdentifierInfo *II = D.getIdentifier();
Expr *BitWidth = (Expr*)BitfieldWidth;
-
SourceLocation Loc = DeclStart;
if (II) Loc = D.getIdentifierLoc();
@@ -1023,7 +1051,15 @@ Sema::DeclTy *Sema::ParseField(Scope *S, DeclTy *TagDecl,
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;
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj
index 0ca23958c7..f0f4c3f0b9 100644
--- a/clang.xcodeproj/project.pbxproj
+++ b/clang.xcodeproj/project.pbxproj
@@ -671,7 +671,6 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 644c0f7e43..d65ba6e4f4 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -38,7 +38,7 @@ public:
// Concrete sub-classes of TypeDecl
Typedef, Struct, Union, Class, Enum, ObjcInterface, ObjcClass, ObjcMethod,
// Concrete sub-class of Decl
- Field
+ Field, ObjcIvar
};
/// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
@@ -306,6 +306,8 @@ class FieldDecl : public Decl {
public:
FieldDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
: Decl(Field, L, Id, PrevDecl), DeclType(T) {}
+ FieldDecl(Kind DK, SourceLocation L, IdentifierInfo *Id, QualType T,
+ Decl *PrevDecl) : Decl(DK, L, Id, PrevDecl), DeclType(T) {}
QualType getType() const { return DeclType; }
QualType getCanonicalType() const { return DeclType.getCanonicalType(); }
@@ -536,6 +538,24 @@ public:
static bool classof(const ObjcInterfaceDecl *D) { return true; }
};
+class ObjcIvarDecl : public FieldDecl {
+public:
+ ObjcIvarDecl(SourceLocation L, IdentifierInfo *Id, QualType T, Decl *PrevDecl)
+ : FieldDecl(ObjcIvar, L, Id, T, PrevDecl) {}
+
+ enum AccessControl {
+ None, Private, Protected, Public, Package
+ };
+ void setAccessControl(AccessControl ac) { DeclAccess = ac; }
+ AccessControl getAccessControl() const { return DeclAccess; }
+
+ // Implement isa/cast/dyncast/etc.
+ static bool classof(const Decl *D) { return D->getKind() == ObjcIvar; }
+ static bool classof(const ObjcIvarDecl *D) { return true; }
+private:
+ AccessControl DeclAccess : 3;
+};
+
class ObjcClassDecl : public TypeDecl {
ObjcInterfaceDecl **ForwardDecls; // Null if not defined.
int NumForwardDecls; // -1 if not defined.
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h
index 1be6503a11..eb01d9bbe4 100644
--- a/include/clang/Parse/Action.h
+++ b/include/clang/Parse/Action.h
@@ -174,9 +174,6 @@ public:
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,
@@ -447,8 +444,8 @@ public:
tok::ObjCKeywordKind visibility) {
return;
}
- virtual void ObjcAddMethod(DeclTy *ClassDec, DeclTy *Meth,
- AttributeList *AttrList) {
+ virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
+ DeclTy **allMethods, unsigned allNum) {
return;
}
virtual DeclTy *ObjcBuildMethodDeclaration(