diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -447,7 +447,9 @@ return Actions.incrementMSManglingNumber(); } - Decl *getObjCDeclContext() const { return Actions.getObjCDeclContext(); } + ObjCContainerDecl *getObjCDeclContext() const { + return Actions.getObjCDeclContext(); + } // Type forwarding. All of these are statically 'void*', but they may all be // different actual classes based on the actions in place. @@ -1001,18 +1003,18 @@ /// back. class ObjCDeclContextSwitch { Parser &P; - Decl *DC; + ObjCContainerDecl *DC; SaveAndRestore WithinObjCContainer; public: explicit ObjCDeclContextSwitch(Parser &p) : P(p), DC(p.getObjCDeclContext()), WithinObjCContainer(P.ParsingInObjCContainer, DC != nullptr) { if (DC) - P.Actions.ActOnObjCTemporaryExitContainerContext(cast(DC)); + P.Actions.ActOnObjCTemporaryExitContainerContext(DC); } ~ObjCDeclContextSwitch() { if (DC) - P.Actions.ActOnObjCReenterContainerContext(cast(DC)); + P.Actions.ActOnObjCReenterContainerContext(DC); } }; @@ -1614,11 +1616,12 @@ SmallVectorImpl &protocolIdents, SourceLocation &rAngleLoc, bool mayBeProtocolList = true); - void HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, + void HelperActionsForIvarDeclarations(ObjCContainerDecl *interfaceDecl, + SourceLocation atLoc, BalancedDelimiterTracker &T, SmallVectorImpl &AllIvarDecls, bool RBraceMissing); - void ParseObjCClassInstanceVariables(Decl *interfaceDecl, + void ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl, tok::ObjCKeywordKind visibility, SourceLocation atLoc); bool ParseObjCProtocolReferences(SmallVectorImpl &P, diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3285,7 +3285,7 @@ /// Invoked when we enter a tag definition that we're skipping. SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); - Decl *ActOnObjCContainerStartDefinition(Decl *IDecl); + void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a /// C++ record definition's base-specifiers clause and are starting its @@ -3309,8 +3309,8 @@ /// scope for parsing/looking-up C constructs. /// /// Must be followed by a call to \see ActOnObjCReenterContainerContext - void ActOnObjCTemporaryExitContainerContext(DeclContext *DC); - void ActOnObjCReenterContainerContext(DeclContext *DC); + void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); + void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); /// ActOnTagDefinitionError - Invoked when there was an unrecoverable /// error parsing the definition of a tag. @@ -9738,7 +9738,7 @@ SourceLocation rAngleLoc); void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); - Decl *ActOnStartClassInterface( + ObjCInterfaceDecl *ActOnStartClassInterface( Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, IdentifierInfo *SuperName, SourceLocation SuperLoc, @@ -9772,13 +9772,13 @@ SourceLocation &PLoc, SourceLocation PrevLoc, const ObjCList &PList); - Decl *ActOnStartProtocolInterface( + ObjCProtocolDecl *ActOnStartProtocolInterface( SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, unsigned NumProtoRefs, const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList); - Decl *ActOnStartCategoryInterface( + ObjCCategoryDecl *ActOnStartCategoryInterface( SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, IdentifierInfo *CategoryName, SourceLocation CategoryLoc, @@ -9786,19 +9786,15 @@ const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList); - Decl *ActOnStartClassImplementation(SourceLocation AtClassImplLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *SuperClassname, - SourceLocation SuperClassLoc, - const ParsedAttributesView &AttrList); + ObjCImplementationDecl *ActOnStartClassImplementation( + SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, + SourceLocation ClassLoc, IdentifierInfo *SuperClassname, + SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); - Decl *ActOnStartCategoryImplementation(SourceLocation AtCatImplLoc, - IdentifierInfo *ClassName, - SourceLocation ClassLoc, - IdentifierInfo *CatName, - SourceLocation CatLoc, - const ParsedAttributesView &AttrList); + ObjCCategoryImplDecl *ActOnStartCategoryImplementation( + SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, + SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, + const ParsedAttributesView &AttrList); DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, ArrayRef Decls); @@ -13147,7 +13143,7 @@ IdentifierInfo *getSuperIdentifier() const; IdentifierInfo *getFloat128Identifier() const; - Decl *getObjCDeclContext() const; + ObjCContainerDecl *getObjCDeclContext() const; DeclContext *getCurLexicalContext() const { return OriginalLexicalContext ? OriginalLexicalContext : CurContext; diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -283,7 +283,7 @@ /*consumeLastToken=*/true)) return nullptr; - Decl *CategoryType = Actions.ActOnStartCategoryInterface( + ObjCCategoryDecl *CategoryType = Actions.ActOnStartCategoryInterface( AtLoc, nameId, nameLoc, typeParameterList, categoryId, categoryLoc, ProtocolRefs.data(), ProtocolRefs.size(), ProtocolLocs.data(), EndProtoLoc, attrs); @@ -353,7 +353,7 @@ Actions.ActOnTypedefedProtocols(protocols, protocolLocs, superClassId, superClassLoc); - Decl *ClsType = Actions.ActOnStartClassInterface( + ObjCInterfaceDecl *ClsType = Actions.ActOnStartClassInterface( getCurScope(), AtLoc, nameId, nameLoc, typeParameterList, superClassId, superClassLoc, typeArgs, SourceRange(typeArgsLAngleLoc, typeArgsRAngleLoc), protocols.data(), @@ -1864,10 +1864,10 @@ protocolRAngleLoc); } -void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, - BalancedDelimiterTracker &T, - SmallVectorImpl &AllIvarDecls, - bool RBraceMissing) { +void Parser::HelperActionsForIvarDeclarations( + ObjCContainerDecl *interfaceDecl, SourceLocation atLoc, + BalancedDelimiterTracker &T, SmallVectorImpl &AllIvarDecls, + bool RBraceMissing) { if (!RBraceMissing) T.consumeClose(); @@ -1902,7 +1902,7 @@ /// objc-instance-variable-decl: /// struct-declaration /// -void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, +void Parser::ParseObjCClassInstanceVariables(ObjCContainerDecl *interfaceDecl, tok::ObjCKeywordKind visibility, SourceLocation atLoc) { assert(Tok.is(tok::l_brace) && "expected {"); @@ -2120,7 +2120,7 @@ // We have a class or category name - consume it. IdentifierInfo *nameId = Tok.getIdentifierInfo(); SourceLocation nameLoc = ConsumeToken(); // consume class or category name - Decl *ObjCImpDecl = nullptr; + ObjCImplDecl *ObjCImpDecl = nullptr; // Neither a type parameter list nor a list of protocol references is // permitted here. Parse and diagnose them. diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -16980,14 +16980,10 @@ return true; } -Decl *Sema::ActOnObjCContainerStartDefinition(Decl *IDecl) { - assert(isa(IDecl) && - "ActOnObjCContainerStartDefinition - Not ObjCContainerDecl"); - DeclContext *OCD = cast(IDecl); - assert(OCD->getLexicalParent() == CurContext && +void Sema::ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl) { + assert(IDecl->getLexicalParent() == CurContext && "The next DeclContext should be lexically contained in the current one."); - CurContext = OCD; - return IDecl; + CurContext = IDecl; } void Sema::ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagD, @@ -17095,14 +17091,14 @@ PopDeclContext(); } -void Sema::ActOnObjCTemporaryExitContainerContext(DeclContext *DC) { - assert(DC == CurContext && "Mismatch of container contexts"); - OriginalLexicalContext = DC; +void Sema::ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx) { + assert(ObjCCtx == CurContext && "Mismatch of container contexts"); + OriginalLexicalContext = ObjCCtx; ActOnObjCContainerFinishDefinition(); } -void Sema::ActOnObjCReenterContainerContext(DeclContext *DC) { - ActOnObjCContainerStartDefinition(cast(DC)); +void Sema::ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx) { + ActOnObjCContainerStartDefinition(ObjCCtx); OriginalLexicalContext = nullptr; } @@ -19028,7 +19024,7 @@ } } -Decl *Sema::getObjCDeclContext() const { +ObjCContainerDecl *Sema::getObjCDeclContext() const { return (dyn_cast_or_null(CurContext)); } diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -971,7 +971,7 @@ return false; } -Decl *Sema::ActOnStartClassInterface( +ObjCInterfaceDecl *Sema::ActOnStartClassInterface( Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, IdentifierInfo *SuperName, SourceLocation SuperLoc, @@ -1100,7 +1100,8 @@ } CheckObjCDeclScope(IDecl); - return ActOnObjCContainerStartDefinition(IDecl); + ActOnObjCContainerStartDefinition(IDecl); + return IDecl; } /// ActOnTypedefedProtocols - this action finds protocol list as part of the @@ -1208,7 +1209,7 @@ return res; } -Decl *Sema::ActOnStartProtocolInterface( +ObjCProtocolDecl *Sema::ActOnStartProtocolInterface( SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, Decl *const *ProtoRefs, unsigned NumProtoRefs, const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, @@ -1272,7 +1273,8 @@ } CheckObjCDeclScope(PDecl); - return ActOnObjCContainerStartDefinition(PDecl); + ActOnObjCContainerStartDefinition(PDecl); + return PDecl; } static bool NestedProtocolHasNoDefinition(ObjCProtocolDecl *PDecl, @@ -1799,7 +1801,7 @@ return BuildDeclaratorGroup(DeclsInGroup); } -Decl *Sema::ActOnStartCategoryInterface( +ObjCCategoryDecl *Sema::ActOnStartCategoryInterface( SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, IdentifierInfo *CategoryName, SourceLocation CategoryLoc, @@ -1826,7 +1828,8 @@ if (!IDecl) Diag(ClassLoc, diag::err_undef_interface) << ClassName; - return ActOnObjCContainerStartDefinition(CDecl); + ActOnObjCContainerStartDefinition(CDecl); + return CDecl; } if (!CategoryName && IDecl->getImplementation()) { @@ -1889,17 +1892,17 @@ } CheckObjCDeclScope(CDecl); - return ActOnObjCContainerStartDefinition(CDecl); + ActOnObjCContainerStartDefinition(CDecl); + return CDecl; } /// ActOnStartCategoryImplementation - Perform semantic checks on the /// category implementation declaration and build an ObjCCategoryImplDecl /// object. -Decl *Sema::ActOnStartCategoryImplementation( - SourceLocation AtCatImplLoc, - IdentifierInfo *ClassName, SourceLocation ClassLoc, - IdentifierInfo *CatName, SourceLocation CatLoc, - const ParsedAttributesView &Attrs) { +ObjCCategoryImplDecl *Sema::ActOnStartCategoryImplementation( + SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, + SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, + const ParsedAttributesView &Attrs) { ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc, true); ObjCCategoryDecl *CatIDecl = nullptr; if (IDecl && IDecl->hasDefinition()) { @@ -1958,15 +1961,14 @@ } CheckObjCDeclScope(CDecl); - return ActOnObjCContainerStartDefinition(CDecl); + ActOnObjCContainerStartDefinition(CDecl); + return CDecl; } -Decl *Sema::ActOnStartClassImplementation( - SourceLocation AtClassImplLoc, - IdentifierInfo *ClassName, SourceLocation ClassLoc, - IdentifierInfo *SuperClassname, - SourceLocation SuperClassLoc, - const ParsedAttributesView &Attrs) { +ObjCImplementationDecl *Sema::ActOnStartClassImplementation( + SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, + SourceLocation ClassLoc, IdentifierInfo *SuperClassname, + SourceLocation SuperClassLoc, const ParsedAttributesView &Attrs) { ObjCInterfaceDecl *IDecl = nullptr; // Check for another declaration kind with the same name. NamedDecl *PrevDecl @@ -2063,8 +2065,10 @@ ProcessDeclAttributeList(TUScope, IMPDecl, Attrs); AddPragmaAttributes(TUScope, IMPDecl); - if (CheckObjCDeclScope(IMPDecl)) - return ActOnObjCContainerStartDefinition(IMPDecl); + if (CheckObjCDeclScope(IMPDecl)) { + ActOnObjCContainerStartDefinition(IMPDecl); + return IMPDecl; + } // Check that there is no duplicate implementation of this class. if (IDecl->getImplementation()) { @@ -2090,7 +2094,8 @@ << IDecl->getSuperClass()->getDeclName(); } - return ActOnObjCContainerStartDefinition(IMPDecl); + ActOnObjCContainerStartDefinition(IMPDecl); + return IMPDecl; } Sema::DeclGroupPtrTy