From: Fariborz Jahanian Date: Thu, 25 Aug 2011 17:47:31 +0000 (+0000) Subject: objc -arse: Use DeclGroup for forward class declarations; X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8e987bee9d39f9131e9be319483265fd894c108;p=clang objc -arse: Use DeclGroup for forward class declarations; as in @class foo, bar. More cleanup to follow. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138567 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 1215e2daa7..dc57268d7b 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -1060,8 +1060,8 @@ private: ExprResult ParseAsmStringLiteral(); // Objective-C External Declarations - Decl *ParseObjCAtDirectives(); - Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc); + Parser::DeclGroupPtrTy ParseObjCAtDirectives(); + Parser::DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc); Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, ParsedAttributes &prefixAttrs); void ParseObjCClassInstanceVariables(Decl *interfaceDecl, diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 07bbd18bee..40d570df05 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -5001,7 +5001,7 @@ public: IdentifierInfo *CatName, SourceLocation CatLoc); - Decl *ActOnForwardClassDeclaration(SourceLocation Loc, + DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, IdentifierInfo **IdentList, SourceLocation *IdentLocs, unsigned NumElts); diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 684d8edf89..17c962e2b5 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -29,47 +29,59 @@ using namespace clang; /// [OBJC] objc-protocol-definition /// [OBJC] objc-method-definition /// [OBJC] '@' 'end' -Decl *Parser::ParseObjCAtDirectives() { +Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { SourceLocation AtLoc = ConsumeToken(); // the "@" if (Tok.is(tok::code_completion)) { Actions.CodeCompleteObjCAtDirective(getCurScope()); ConsumeCodeCompletionToken(); } - + + Decl *SingleDecl = 0; switch (Tok.getObjCKeywordID()) { case tok::objc_class: return ParseObjCAtClassDeclaration(AtLoc); + break; case tok::objc_interface: { ParsedAttributes attrs(AttrFactory); - return ParseObjCAtInterfaceDeclaration(AtLoc, attrs); + SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, attrs); + break; } case tok::objc_protocol: { ParsedAttributes attrs(AttrFactory); - return ParseObjCAtProtocolDeclaration(AtLoc, attrs); + SingleDecl = ParseObjCAtProtocolDeclaration(AtLoc, attrs); + break; } case tok::objc_implementation: - return ParseObjCAtImplementationDeclaration(AtLoc); + SingleDecl = ParseObjCAtImplementationDeclaration(AtLoc); + break; case tok::objc_end: - return ParseObjCAtEndDeclaration(AtLoc); + SingleDecl = ParseObjCAtEndDeclaration(AtLoc); + break; case tok::objc_compatibility_alias: - return ParseObjCAtAliasDeclaration(AtLoc); + SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); + break; case tok::objc_synthesize: - return ParseObjCPropertySynthesize(AtLoc); + SingleDecl = ParseObjCPropertySynthesize(AtLoc); + break; case tok::objc_dynamic: - return ParseObjCPropertyDynamic(AtLoc); + SingleDecl = ParseObjCPropertyDynamic(AtLoc); + break; default: Diag(AtLoc, diag::err_unexpected_at); SkipUntil(tok::semi); - return 0; + SingleDecl = 0; + break; } + return Actions.ConvertDeclToDeclGroup(SingleDecl); } /// /// objc-class-declaration: /// '@' 'class' identifier-list ';' /// -Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { +Parser::DeclGroupPtrTy +Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { ConsumeToken(); // the identifier "class" SmallVector ClassNames; SmallVector ClassLocs; @@ -79,7 +91,7 @@ Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { if (Tok.isNot(tok::identifier)) { Diag(Tok, diag::err_expected_ident); SkipUntil(tok::semi); - return 0; + return Actions.ConvertDeclToDeclGroup(0); } ClassNames.push_back(Tok.getIdentifierInfo()); ClassLocs.push_back(Tok.getLocation()); @@ -93,7 +105,7 @@ Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { // Consume the ';'. if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) - return 0; + return Actions.ConvertDeclToDeclGroup(0); return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), ClassLocs.data(), diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 0da2b4302c..e57b898d52 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -593,10 +593,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs, break; } case tok::at: - // @ is not a legal token unless objc is enabled, no need to check for ObjC. - /// FIXME: ParseObjCAtDirectives should return a DeclGroup for things like - /// @class foo, bar; - SingleDecl = ParseObjCAtDirectives(); + return ParseObjCAtDirectives(); break; case tok::minus: case tok::plus: diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 7a9d6d5072..0aea739222 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1654,14 +1654,14 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, } /// ActOnForwardClassDeclaration - -Decl * +Sema::DeclGroupPtrTy Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, IdentifierInfo **IdentList, SourceLocation *IdentLocs, unsigned NumElts) { - SmallVector Interfaces; - + SmallVector DeclsInGroup; for (unsigned i = 0; i != NumElts; ++i) { + SmallVector Interfaces; // Check for another declaration kind with the same name. NamedDecl *PrevDecl = LookupSingleName(TUScope, IdentList[i], IdentLocs[i], @@ -1707,15 +1707,15 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, } Interfaces.push_back(IDecl); + ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc, + Interfaces.data(), IdentLocs, + 1); + CurContext->addDecl(CDecl); + CheckObjCDeclScope(CDecl); + DeclsInGroup.push_back(CDecl); } - - assert(Interfaces.size() == NumElts); - ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc, - Interfaces.data(), IdentLocs, - Interfaces.size()); - CurContext->addDecl(CDecl); - CheckObjCDeclScope(CDecl); - return CDecl; + + return BuildDeclaratorGroup(DeclsInGroup.data(), 1, false); } static bool tryMatchRecordTypes(ASTContext &Context,