]> granicus.if.org Git - clang/commitdiff
- Add an ObjcIvarDecl AST node (a subclass of FieldDecl).
authorSteve Naroff <snaroff@apple.com>
Tue, 11 Sep 2007 21:17:26 +0000 (21:17 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 11 Sep 2007 21:17:26 +0000 (21:17 +0000)
- 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

Sema/Sema.h
Sema/SemaDecl.cpp
clang.xcodeproj/project.pbxproj
include/clang/AST/Decl.h
include/clang/Parse/Action.h

index f0a072eb9b8747083f71b2087637d08036d33085..2be727a4268742ab936b4d995c09280ccdcc0ea5 100644 (file)
@@ -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). 
index 71fc0b44710678ebb9366d9da5b7560a35fcc546..86e052b4df3218e0e1b61c54f7c48172851acf4a 100644 (file)
@@ -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;
index 0ca23958c7d4da21dd41f84d48841bdb04ff2f4c..f0f4c3f0b957f8f6ef2e463556fe10f832bf59b1 100644 (file)
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
                        projectDirPath = "";
index 644c0f7e43aa23fef1337cb71d7c4c7fc1bd4c96..d65ba6e4f45811b6556b423efa33df78b287bef1 100644 (file)
@@ -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.
index 1be6503a1130688b7a012061dceda743cfa91443..eb01d9bbe4fbff423820b6fd5158dbcc9c44f267 100644 (file)
@@ -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(