[cfe-commits] r42826 - in /cfe/trunk: Parse/MinimalAction.cpp Parse/ParseDecl.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Parse/Action.h

Steve Naroff snaroff at apple.com
Wed Oct 10 10:32:04 PDT 2007


Author: snaroff
Date: Wed Oct 10 12:32:04 2007
New Revision: 42826

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

Remove Scope argument from ObjC actions that either don't need it or can now use TUScope.
Also improve a recently added comment.


Modified:
    cfe/trunk/Parse/MinimalAction.cpp
    cfe/trunk/Parse/ParseDecl.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/MinimalAction.cpp?rev=42826&r1=42825&r2=42826&view=diff

==============================================================================
--- cfe/trunk/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/Parse/MinimalAction.cpp Wed Oct 10 12:32:04 2007
@@ -68,7 +68,7 @@
 }
 
 Action::DeclTy *
-MinimalAction::ActOnStartClassInterface(Scope* S, SourceLocation AtInterafceLoc,
+MinimalAction::ActOnStartClassInterface(SourceLocation AtInterafceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperName, SourceLocation SuperLoc,
                     IdentifierInfo **ProtocolNames, unsigned NumProtocols,
@@ -83,7 +83,7 @@
 /// ActOnForwardClassDeclaration - 
 /// Scope will always be top level file scope. 
 Action::DeclTy *
-MinimalAction::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc,
+MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
                                 IdentifierInfo **IdentList, unsigned NumElts) {
   for (unsigned i = 0; i != NumElts; ++i) {
     TypeNameInfo *TI =
@@ -92,7 +92,7 @@
     IdentList[i]->setFETokenInfo(TI);
   
     // Remember that this needs to be removed when the scope is popped.
-    S->AddDecl(IdentList[i]);
+    TUScope->AddDecl(IdentList[i]);
   }
   return 0;
 }

Modified: cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseDecl.cpp?rev=42826&r1=42825&r2=42826&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/Parse/ParseDecl.cpp Wed Oct 10 12:32:04 2007
@@ -409,8 +409,7 @@
             if (Tok.is(tok::less)) {
               llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
               ParseObjCProtocolReferences(ProtocolRefs);
-              Actions.ActOnFindProtocolDeclaration(CurScope,
-                                                   Loc,
+              Actions.ActOnFindProtocolDeclaration(Loc,
                                                    &ProtocolRefs[0],
                                                    ProtocolRefs.size());
             }

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=42826&r1=42825&r2=42826&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Oct 10 12:32:04 2007
@@ -80,7 +80,7 @@
   if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
     return 0;
   
-  return Actions.ActOnForwardClassDeclaration(CurScope, atLoc,
+  return Actions.ActOnForwardClassDeclaration(atLoc,
                                       &ClassNames[0], ClassNames.size());
 }
 
@@ -154,7 +154,7 @@
     if (attrList) // categories don't support attributes.
       Diag(Tok, diag::err_objc_no_attributes_on_category);
     
-    DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(CurScope, atLoc, 
+    DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, 
                                      nameId, nameLoc, categoryId, categoryLoc,
                                      &ProtocolRefs[0], ProtocolRefs.size());
     
@@ -187,7 +187,7 @@
     if (ParseObjCProtocolReferences(ProtocolRefs))
       return 0;
   }
-  DeclTy *ClsType = Actions.ActOnStartClassInterface(CurScope,
+  DeclTy *ClsType = Actions.ActOnStartClassInterface(
 		      atLoc, nameId, nameLoc, 
                       superClassId, superClassLoc, &ProtocolRefs[0], 
                       ProtocolRefs.size(), attrList);
@@ -799,7 +799,7 @@
       return 0;
   }
   if (ProtocolRefs.size() > 0)
-    return Actions.ActOnForwardProtocolDeclaration(CurScope, AtLoc,
+    return Actions.ActOnForwardProtocolDeclaration(AtLoc,
                                                    &ProtocolRefs[0], 
                                                    ProtocolRefs.size());
   // Last, and definitely not least, parse a protocol declaration.
@@ -808,7 +808,7 @@
       return 0;
   }
   
-  DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(CurScope, AtLoc, 
+  DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, 
                                 protocolName, nameLoc,
                                 &ProtocolRefs[0],
                                 ProtocolRefs.size());
@@ -867,7 +867,7 @@
       return 0;
     }
     rparenLoc = ConsumeParen();
-    DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(CurScope,
+    DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(
                                     atLoc, nameId, nameLoc, categoryId, 
                                     categoryLoc);
     return ImplCatType;
@@ -885,7 +885,7 @@
     superClassId = Tok.getIdentifierInfo();
     superClassLoc = ConsumeToken(); // Consume super class name
   }
-  DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(CurScope,
+  DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(
 				  atLoc, nameId, nameLoc,
                                   superClassId, superClassLoc);
   

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Oct 10 12:32:04 2007
@@ -113,8 +113,9 @@
   /// This list is populated upon the creation of a Sema object.    
   IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
   
-  /// Translation Unit Scope - useful to many Objective-C actions that need
-  /// to lookup file scope declarations (like classes, protocols, etc.).
+  /// Translation Unit Scope - useful to Objective-C actions that need
+  /// to lookup file scope declarations in the "ordinary" C decl namespace.
+  /// For example, user-defined classes, built-in "id" type, etc.
   Scope *TUScope;
 public:
   Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
@@ -403,48 +404,46 @@
                                                SourceLocation RParenLoc);
   
   // Objective-C declarations.
-  virtual DeclTy *ActOnStartClassInterface(Scope* S,
+  virtual DeclTy *ActOnStartClassInterface(
 		    SourceLocation AtInterafceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperName, SourceLocation SuperLoc,
                     IdentifierInfo **ProtocolNames, unsigned NumProtocols,
                     AttributeList *AttrList);
                     
-  virtual DeclTy *ActOnStartProtocolInterface(Scope* S,
+  virtual DeclTy *ActOnStartProtocolInterface(
 		    SourceLocation AtProtoInterfaceLoc,
                     IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
   
-  virtual DeclTy *ActOnStartCategoryInterface(Scope* S,
+  virtual DeclTy *ActOnStartCategoryInterface(
 		    SourceLocation AtInterfaceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
                     IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
   
-  virtual DeclTy *ActOnStartClassImplementation(Scope* S,
+  virtual DeclTy *ActOnStartClassImplementation(
 		    SourceLocation AtClassImplLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperClassname, 
                     SourceLocation SuperClassLoc);
   
-  virtual DeclTy *ActOnStartCategoryImplementation(Scope* S,
+  virtual DeclTy *ActOnStartCategoryImplementation(
                                                   SourceLocation AtCatImplLoc,
                                                   IdentifierInfo *ClassName, 
                                                   SourceLocation ClassLoc,
                                                   IdentifierInfo *CatName,
                                                   SourceLocation CatLoc);
   
-  virtual DeclTy *ActOnForwardClassDeclaration(Scope *S, SourceLocation Loc,
+  virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
                                                IdentifierInfo **IdentList,
                                                unsigned NumElts);
   
-  virtual DeclTy *ActOnForwardProtocolDeclaration(Scope *S, 
-                                                  SourceLocation AtProtocolLoc,
+  virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
                                                   IdentifierInfo **IdentList,
                                                   unsigned NumElts);
   
-  virtual DeclTy **ActOnFindProtocolDeclaration(Scope *S,
-                                                SourceLocation TypeLoc,
+  virtual DeclTy **ActOnFindProtocolDeclaration(SourceLocation TypeLoc,
                                                 IdentifierInfo **ProtocolId,
                                                 unsigned NumProtocols);
 

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Oct 10 12:32:04 2007
@@ -881,7 +881,7 @@
   return NewTD;
 }
 
-Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S,
+Sema::DeclTy *Sema::ActOnStartClassInterface(
                     SourceLocation AtInterfaceLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperName, SourceLocation SuperLoc,
@@ -891,7 +891,7 @@
   
   // Check for another declaration kind with the same name.
   ScopedDecl *PrevDecl = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
-                                          ClassLoc, S);
+                                          ClassLoc, TUScope);
   if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind,
          ClassName->getName());
@@ -920,7 +920,7 @@
     ObjcInterfaceDecl* SuperClassEntry = 0;
     // Check if a different kind of symbol declared in this scope.
     PrevDecl = LookupScopedDecl(SuperName, Decl::IDNS_Ordinary,
-                                SuperLoc, S);
+                                SuperLoc, TUScope);
     if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
       Diag(SuperLoc, diag::err_redefinition_different_kind,
            SuperName->getName());
@@ -951,7 +951,7 @@
   return IDecl;
 }
 
-Sema::DeclTy *Sema::ActOnStartProtocolInterface(Scope* S,
+Sema::DeclTy *Sema::ActOnStartProtocolInterface(
                 SourceLocation AtProtoInterfaceLoc,
                 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
                 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
@@ -990,8 +990,7 @@
 /// declared protocol and returns it. If not found, issues diagnostic.
 /// Will build a list of previously protocol declarations found in the list.
 Action::DeclTy **
-Sema::ActOnFindProtocolDeclaration(Scope *S,
-                                   SourceLocation TypeLoc,
+Sema::ActOnFindProtocolDeclaration(SourceLocation TypeLoc,
                                    IdentifierInfo **ProtocolId,
                                    unsigned NumProtocols) {
   for (unsigned i = 0; i != NumProtocols; ++i) {
@@ -1004,9 +1003,8 @@
 }
 
 /// ActOnForwardProtocolDeclaration - 
-/// Scope will always be top level file scope. 
 Action::DeclTy *
-Sema::ActOnForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc,
+Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
         IdentifierInfo **IdentList, unsigned NumElts) {
   llvm::SmallVector<ObjcProtocolDecl*, 32> Protocols;
   
@@ -1025,7 +1023,7 @@
                                      &Protocols[0], Protocols.size());
 }
 
-Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S,
+Sema::DeclTy *Sema::ActOnStartCategoryInterface(
                       SourceLocation AtInterfaceLoc,
                       IdentifierInfo *ClassName, SourceLocation ClassLoc,
                       IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
@@ -1070,7 +1068,7 @@
 /// ActOnStartCategoryImplementation - Perform semantic checks on the
 /// category implementation declaration and build an ObjcCategoryImplDecl
 /// object.
-Sema::DeclTy *Sema::ActOnStartCategoryImplementation(Scope* S,
+Sema::DeclTy *Sema::ActOnStartCategoryImplementation(
                       SourceLocation AtCatImplLoc,
                       IdentifierInfo *ClassName, SourceLocation ClassLoc,
                       IdentifierInfo *CatName, SourceLocation CatLoc) {
@@ -1085,7 +1083,7 @@
   return CDecl;
 }
 
-Sema::DeclTy *Sema::ActOnStartClassImplementation(Scope *S,
+Sema::DeclTy *Sema::ActOnStartClassImplementation(
                       SourceLocation AtClassImplLoc,
                       IdentifierInfo *ClassName, SourceLocation ClassLoc,
                       IdentifierInfo *SuperClassname, 
@@ -1093,7 +1091,7 @@
   ObjcInterfaceDecl* IDecl = 0;
   // Check for another declaration kind with the same name.
   ScopedDecl *PrevDecl = LookupScopedDecl(ClassName, Decl::IDNS_Ordinary,
-                                          ClassLoc, S);
+                                          ClassLoc, TUScope);
   if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
     Diag(ClassLoc, diag::err_redefinition_different_kind,
          ClassName->getName());
@@ -1111,7 +1109,7 @@
   if (SuperClassname) {
     // Check if a different kind of symbol declared in this scope.
     PrevDecl = LookupScopedDecl(SuperClassname, Decl::IDNS_Ordinary,
-                                SuperClassLoc, S);
+                                SuperClassLoc, TUScope);
     if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
       Diag(SuperClassLoc, diag::err_redefinition_different_kind,
            SuperClassname->getName());
@@ -1317,9 +1315,8 @@
 }
 
 /// ActOnForwardClassDeclaration - 
-/// Scope will always be top level file scope. 
 Action::DeclTy *
-Sema::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc,
+Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
                                    IdentifierInfo **IdentList, unsigned NumElts) 
 {
   llvm::SmallVector<ObjcInterfaceDecl*, 32> Interfaces;
@@ -1333,7 +1330,7 @@
       IdentList[i]->setFETokenInfo(IDecl);
 
       // Remember that this needs to be removed when the scope is popped.
-      S->AddDecl(IDecl);
+      TUScope->AddDecl(IDecl);
     }
 
     Interfaces.push_back(IDecl);

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Oct 10 12:32:04 2007
@@ -445,7 +445,6 @@
   // the prologue for a class interface (before parsing the instance 
   // variables). Instance variables are processed by ActOnFields().
   virtual DeclTy *ActOnStartClassInterface(
-    Scope* S, 
     SourceLocation AtInterafceLoc,
     IdentifierInfo *ClassName, 
     SourceLocation ClassLoc,
@@ -459,7 +458,6 @@
   // ActOnStartProtocolInterface - this action is called immdiately after
   // parsing the prologue for a protocol interface.
   virtual DeclTy *ActOnStartProtocolInterface(
-    Scope* S,
     SourceLocation AtProtoInterfaceLoc,
     IdentifierInfo *ProtocolName, 
     SourceLocation ProtocolLoc,
@@ -470,7 +468,6 @@
   // ActOnStartCategoryInterface - this action is called immdiately after
   // parsing the prologue for a category interface.
   virtual DeclTy *ActOnStartCategoryInterface(
-    Scope* S,
     SourceLocation AtInterfaceLoc,
     IdentifierInfo *ClassName, 
     SourceLocation ClassLoc,
@@ -484,7 +481,6 @@
   // parsing the prologue for a class implementation. Instance variables are 
   // processed by ActOnFields().
   virtual DeclTy *ActOnStartClassImplementation(
-    Scope* S,
     SourceLocation AtClassImplLoc,
     IdentifierInfo *ClassName, 
     SourceLocation ClassLoc,
@@ -495,7 +491,6 @@
   // ActOnStartCategoryImplementation - this action is called immdiately after
   // parsing the prologue for a category implementation.
   virtual DeclTy *ActOnStartCategoryImplementation(
-    Scope* S,
     SourceLocation AtCatImplLoc,
     IdentifierInfo *ClassName, 
     SourceLocation ClassLoc,
@@ -545,14 +540,12 @@
     return 0;
   }
   virtual DeclTy *ActOnForwardClassDeclaration(
-    Scope *S,
     SourceLocation AtClassLoc,
     IdentifierInfo **IdentList,
     unsigned NumElts) {
     return 0;
   }
   virtual DeclTy *ActOnForwardProtocolDeclaration(
-    Scope *S, 
     SourceLocation AtProtocolLoc,
     IdentifierInfo **IdentList,
     unsigned NumElts) {
@@ -562,8 +555,7 @@
   /// ActOnFindProtocolDeclaration - This routine looks for a previously
   /// declared protocol and returns it. If not found, issues diagnostic.
   /// Will build a list of previously protocol declarations found in the list.
-  virtual DeclTy **ActOnFindProtocolDeclaration(Scope *S,
-                                                SourceLocation TypeLoc,
+  virtual DeclTy **ActOnFindProtocolDeclaration(SourceLocation TypeLoc,
                                                 IdentifierInfo **ProtocolId,
                                                 unsigned NumProtocols) {
     return 0;
@@ -591,6 +583,10 @@
 /// the parser doesn't have to build complex data structures and thus runs more
 /// quickly.
 class MinimalAction : public Action {
+  /// Translation Unit Scope - useful to Objective-C actions that need
+  /// to lookup file scope declarations in the "ordinary" C decl namespace.
+  /// For example, user-defined classes, built-in "id" type, etc.
+  Scope *TUScope;
 public:
   /// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
   /// determine whether the name is a typedef or not in this scope.
@@ -604,13 +600,15 @@
   /// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
   /// they are removed from the IdentifierInfo::FETokenInfo field.
   virtual void PopScope(SourceLocation Loc, Scope *S);
+  virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
+    TUScope = S;
+  }
   
-  virtual DeclTy *ActOnForwardClassDeclaration(Scope *S, 
-                                               SourceLocation AtClassLoc,
+  virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
                                                IdentifierInfo **IdentList,
                                                unsigned NumElts);
   
-  virtual DeclTy *ActOnStartClassInterface(Scope* S, SourceLocation interLoc,
+  virtual DeclTy *ActOnStartClassInterface(SourceLocation interLoc,
                     IdentifierInfo *ClassName, SourceLocation ClassLoc,
                     IdentifierInfo *SuperName, SourceLocation SuperLoc,
                     IdentifierInfo **ProtocolNames, unsigned NumProtocols,





More information about the cfe-commits mailing list