diff options
author | Steve Naroff <snaroff@apple.com> | 2007-10-10 17:32:04 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2007-10-10 17:32:04 +0000 |
commit | e440eb8158e71deb1e4ab11618ae3d680aac6da1 (patch) | |
tree | 87e73a5f37a8b809bbdf6d01a1fd9144ff70f483 | |
parent | f1af947276efe378dbf1f6b0ec24cb46802a124a (diff) |
Remove Scope argument from ObjC actions that either don't need it or can now use TUScope.
Also improve a recently added comment.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42826 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Parse/MinimalAction.cpp | 6 | ||||
-rw-r--r-- | Parse/ParseDecl.cpp | 3 | ||||
-rw-r--r-- | Parse/ParseObjc.cpp | 14 | ||||
-rw-r--r-- | Sema/Sema.h | 23 | ||||
-rw-r--r-- | Sema/SemaDecl.cpp | 29 | ||||
-rw-r--r-- | include/clang/Parse/Action.h | 22 |
6 files changed, 45 insertions, 52 deletions
diff --git a/Parse/MinimalAction.cpp b/Parse/MinimalAction.cpp index 05b91dafc2..932f8ff29e 100644 --- a/Parse/MinimalAction.cpp +++ b/Parse/MinimalAction.cpp @@ -68,7 +68,7 @@ MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) { } 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 @@ MinimalAction::ActOnStartClassInterface(Scope* S, SourceLocation AtInterafceLoc, /// 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 @@ MinimalAction::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc, 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; } diff --git a/Parse/ParseDecl.cpp b/Parse/ParseDecl.cpp index dcbbd89e65..00e441412f 100644 --- a/Parse/ParseDecl.cpp +++ b/Parse/ParseDecl.cpp @@ -409,8 +409,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { if (Tok.is(tok::less)) { llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; ParseObjCProtocolReferences(ProtocolRefs); - Actions.ActOnFindProtocolDeclaration(CurScope, - Loc, + Actions.ActOnFindProtocolDeclaration(Loc, &ProtocolRefs[0], ProtocolRefs.size()); } diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index e3c5f727d4..464fad2e40 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -80,7 +80,7 @@ Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { 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 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( 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 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( 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 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { 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 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { return 0; } - DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(CurScope, AtLoc, + DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, &ProtocolRefs[0], ProtocolRefs.size()); @@ -867,7 +867,7 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( return 0; } rparenLoc = ConsumeParen(); - DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation(CurScope, + DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( atLoc, nameId, nameLoc, categoryId, categoryLoc); return ImplCatType; @@ -885,7 +885,7 @@ Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( superClassId = Tok.getIdentifierInfo(); superClassLoc = ConsumeToken(); // Consume super class name } - DeclTy *ImplClsType = Actions.ActOnStartClassImplementation(CurScope, + DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( atLoc, nameId, nameLoc, superClassId, superClassLoc); diff --git a/Sema/Sema.h b/Sema/Sema.h index 6c2b41e3ce..b1f1dcde8d 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -113,8 +113,9 @@ class Sema : public Action { /// 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 @@ public: 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); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index ba6c7d0175..4fc6f78fbe 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -881,7 +881,7 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, 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 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S, // 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 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S, 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 @@ Sema::DeclTy *Sema::ActOnStartClassInterface(Scope* S, 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 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface(Scope* S, /// 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 @@ Sema::ActOnFindProtocolDeclaration(Scope *S, } /// 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 @@ Sema::ActOnForwardProtocolDeclaration(Scope *S, SourceLocation AtProtocolLoc, &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 @@ Sema::DeclTy *Sema::ActOnStartCategoryInterface(Scope* S, /// 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 @@ Sema::DeclTy *Sema::ActOnStartCategoryImplementation(Scope* S, return CDecl; } -Sema::DeclTy *Sema::ActOnStartClassImplementation(Scope *S, +Sema::DeclTy *Sema::ActOnStartClassImplementation( SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, IdentifierInfo *SuperClassname, @@ -1093,7 +1091,7 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation(Scope *S, 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 @@ Sema::DeclTy *Sema::ActOnStartClassImplementation(Scope *S, 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 @@ void Sema::ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl, } /// 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 @@ Sema::ActOnForwardClassDeclaration(Scope *S, SourceLocation AtClassLoc, 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); diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index af8170fe90..89ed0c6e99 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -445,7 +445,6 @@ public: // 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 @@ public: // 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 @@ public: // 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 @@ public: // 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 @@ public: // 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 @@ public: 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 @@ public: /// 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 @@ public: /// 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 @@ public: /// 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, |