]> granicus.if.org Git - clang/commitdiff
Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument.
authorSteve Naroff <snaroff@apple.com>
Fri, 14 Sep 2007 23:09:53 +0000 (23:09 +0000)
committerSteve Naroff <snaroff@apple.com>
Fri, 14 Sep 2007 23:09:53 +0000 (23:09 +0000)
Remove Action::ObjcAddVisibilityToIvars(). No need for an extra API when it is trivial to add this info to the previous hook.

In general, I want to start migrating away from having Actions prefixed with "Parse" (which is confusing, since the Action API doesn't do any parsing, per se).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41973 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseDecl.cpp
Parse/ParseObjc.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/Parse/Action.h

index be3711106b88f17c074a1c357dbfa41c2f17d8cb..9dd0d95d7908fed8914036a86508feb4d206e98e 100644 (file)
@@ -757,7 +757,7 @@ void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
   
   MatchRHSPunctuation(tok::r_brace, LBraceLoc);
   
-  Actions.ParseRecordBody(RecordLoc, TagDecl, &FieldDecls[0],FieldDecls.size());
+  Actions.ProcessFieldDecls(RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
   
   AttributeList *AttrList = 0;
   // If attributes exist after struct contents, parse them.
index 29f8001c13527f50b43bf6141dc2faaa76188fa9..791057b627adbb74fa93732a029c3c109102b635 100644 (file)
@@ -659,10 +659,9 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) {
     }
   }
   if (AllIvarDecls.size()) {  // Check for {} - no ivars in braces
-    Actions.ObjcAddVisibilityToIvars(interfaceDecl, 
-             &AllIvarDecls[0], AllIvarDecls.size(), &AllVisibilities[0]);
-    Actions.ParseRecordBody(LBraceLoc, interfaceDecl, 
-                           &AllIvarDecls[0], AllIvarDecls.size());
+    Actions.ProcessFieldDecls(LBraceLoc, interfaceDecl, 
+                             &AllIvarDecls[0], AllIvarDecls.size(),
+                              &AllVisibilities[0]);
   }
   MatchRHSPunctuation(tok::r_brace, LBraceLoc);
   return;
index 2b50f5e354f7759669a099e6166378a149adc8d7..a9e33f423a23e6424792476650179d06b2250204 100644 (file)
@@ -155,8 +155,11 @@ private:
                            SourceLocation NameLoc, AttributeList *Attr);
   virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
                              Declarator &D, ExprTy *BitfieldWidth);
-  virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl,
-                               DeclTy **Fields, unsigned NumFields);
+                                      
+  // This is used for both record definitions and ObjC interface declarations.
+  virtual void ProcessFieldDecls(SourceLocation RecLoc, DeclTy *TagDecl,
+                                 DeclTy **Fields, unsigned NumFields,
+                                 tok::ObjCKeywordKind *visibility = 0);
   virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
                                     DeclTy *LastEnumConstant,
                                     SourceLocation IdLoc, IdentifierInfo *Id,
@@ -368,10 +371,6 @@ public:
   virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc, 
                    tok::TokenKind MethodType, TypeTy *ReturnType,
                    IdentifierInfo *SelectorName, AttributeList *AttrList);
-                                      
-  virtual void ObjcAddVisibilityToIvars(DeclTy *ClassDec, DeclTy **Ivar,
-                                       unsigned numIvars,
-                                        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 260a450dd43be0b0278af7a74a416d8b1e6c2532..b0a3a1266acacbb0a208f9921cf90210ce7abee8 100644 (file)
@@ -877,40 +877,6 @@ Sema::DeclTy *Sema::ObjcStartClassInterface(SourceLocation AtInterfaceLoc,
   return IDecl;
 }
 
-void Sema::ObjcAddVisibilityToIvars(DeclTy *ClassDecl, DeclTy **Ivar,
-                                   unsigned numIvars,
-                                    tok::ObjCKeywordKind *visibility) {
-  assert((ClassDecl && numIvars) && "missing class or instance variable");
-  ObjcInterfaceDecl *OInterface = dyn_cast<ObjcInterfaceDecl>(
-                                    static_cast<Decl *>(ClassDecl));
-  assert (OInterface && "mistyped class");
-  for (unsigned i = 0; i != numIvars; ++i) {
-    ObjcIvarDecl *OIvar = dyn_cast<ObjcIvarDecl>(static_cast<Decl *>(Ivar[i]));
-    tok::ObjCKeywordKind ivarVisibility = visibility[i];
-  
-    assert(OIvar && "mistyped instance variable");
-  
-    switch (ivarVisibility) {
-    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 *
@@ -1092,10 +1058,31 @@ Sema::DeclTy *Sema::ParseField(Scope *S, DeclTy *TagDecl,
   return NewFD;
 }
 
-// FIXME: Change ParseRecordBody name to something more generic as 
-// it also used for ivar semantics check.
-void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,
-                           DeclTy **Fields, unsigned NumFields) {
+static void ObjcSetIvarVisibility(ObjcIvarDecl *OIvar,
+                                  tok::ObjCKeywordKind ivarVisibility) {
+  assert(OIvar && "missing instance variable");
+  switch (ivarVisibility) {
+  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;
+  }
+}
+
+void Sema::ProcessFieldDecls(SourceLocation RecLoc, DeclTy *RecDecl,
+                             DeclTy **Fields, unsigned NumFields,
+                             tok::ObjCKeywordKind *visibility) {
   Decl *EnclosingDecl = static_cast<Decl*>(RecDecl);
   assert(EnclosingDecl && "missing record or interface decl");
   RecordDecl *Record = dyn_cast<RecordDecl>(EnclosingDecl);
@@ -1127,6 +1114,10 @@ void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,
     // Get the type for the field.
     Type *FDTy = FD->getType().getTypePtr();
     
+    // If we have visibility info, make sure the AST is set accordingly.
+    if (visibility)
+      ObjcSetIvarVisibility(dyn_cast<ObjcIvarDecl>(FD), visibility[i]);
+      
     // C99 6.7.2.1p2 - A field may not be a function type.
     if (FDTy->isFunctionType()) {
       Diag(FD->getLocation(), diag::err_field_declared_as_function, 
index 770187a930d6125bffa226efd479b80d33e91790..141261b7cd2f26061e968014ea9d49d8d78e32a5 100644 (file)
@@ -180,9 +180,9 @@ public:
                              Declarator &D, ExprTy *BitfieldWidth) {
     return 0;
   }
-  virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl,
-                               DeclTy **Fields, unsigned NumFields) {}
-
+  virtual void ProcessFieldDecls(SourceLocation RecLoc, DeclTy *TagDecl,
+                                 DeclTy **Fields, unsigned NumFields,
+                                 tok::ObjCKeywordKind *visibility = 0) {}
   virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
                                     DeclTy *LastEnumConstant,
                                     SourceLocation IdLoc, IdentifierInfo *Id,
@@ -449,11 +449,6 @@ public:
                     AttributeList *AttrList) {
     return 0;
   }
-  virtual void ObjcAddVisibilityToIvars(DeclTy *ClassDec, DeclTy **Ivars, 
-                                       unsigned numIvars, 
-                                        tok::ObjCKeywordKind *visibility) {
-    return;
-  }
   virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
                                     DeclTy **allMethods, unsigned allNum) {
     return;