[cfe-commits] r41864 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/AST/Decl.h include/clang/Parse/Action.h

Steve Naroff snaroff at apple.com
Tue Sep 11 14:17:26 PDT 2007


Author: snaroff
Date: Tue Sep 11 16:17:26 2007
New Revision: 41864

URL: http://llvm.org/viewvc/llvm-project?rev=41864&view=rev
Log:

- 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.


Modified:
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41864&r1=41863&r2=41864&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Sep 11 16:17:26 2007
@@ -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). 

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41864&r1=41863&r2=41864&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Sep 11 16:17:26 2007
@@ -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;

Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41864&r1=41863&r2=41864&view=diff

==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Sep 11 16:17:26 2007
@@ -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 = "";

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=41864&r1=41863&r2=41864&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Sep 11 16:17:26 2007
@@ -38,7 +38,7 @@
     // 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 @@
 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 @@
   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.

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=41864&r1=41863&r2=41864&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Sep 11 16:17:26 2007
@@ -174,9 +174,6 @@
   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 @@
                                        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(





More information about the cfe-commits mailing list