From a2ba66a7fee863daf4a28aeebb7184e3255df3ed Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 19 Jun 2015 23:18:00 +0000 Subject: Handle 'instancetype' in ParseDeclarationSpecifiers. ...instead of as a special case in ParseObjCTypeName with lots of duplicated logic. Besides being a nice refactoring, this also allows "- (instancetype __nonnull)self" in addition to "- (nonnull instancetype)self". rdar://problem/19924646 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240188 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseObjc.cpp | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'lib/Parse/ParseObjc.cpp') diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index de347181bf..e4f7911138 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1005,11 +1005,14 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, ParseObjCTypeQualifierList(DS, context); ParsedType Ty; - if (isTypeSpecifierQualifier()) { + if (isTypeSpecifierQualifier() || isObjCInstancetype()) { // Parse an abstract declarator. DeclSpec declSpec(AttrFactory); declSpec.setObjCQualifiers(&DS); - ParseSpecifierQualifierList(declSpec); + DeclSpecContext dsContext = DSC_normal; + if (context == Declarator::ObjCResultContext) + dsContext = DSC_objc_method_result; + ParseSpecifierQualifierList(declSpec, AS_none, dsContext); declSpec.SetRangeEnd(Tok.getLocation()); Declarator declarator(declSpec, context); ParseDeclarator(declarator); @@ -1033,38 +1036,6 @@ ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, if (context == Declarator::ObjCParameterContext) takeDeclAttributes(*paramAttrs, declarator); } - } else if (context == Declarator::ObjCResultContext && - Tok.is(tok::identifier)) { - if (!Ident_instancetype) - Ident_instancetype = PP.getIdentifierInfo("instancetype"); - - if (Tok.getIdentifierInfo() == Ident_instancetype) { - SourceLocation loc = ConsumeToken(); - Ty = Actions.ActOnObjCInstanceType(loc); - - // Synthesize an abstract declarator so we can use Sema::ActOnTypeName. - bool addedToDeclSpec = false; - const char *prevSpec; - unsigned diagID; - DeclSpec declSpec(AttrFactory); - declSpec.setObjCQualifiers(&DS); - declSpec.SetTypeSpecType(DeclSpec::TST_typename, loc, prevSpec, diagID, - Ty, - Actions.getASTContext().getPrintingPolicy()); - declSpec.SetRangeEnd(loc); - Declarator declarator(declSpec, context); - - // Map a nullability specifier to a context-sensitive keyword attribute. - if (DS.getObjCDeclQualifier() & ObjCDeclSpec::DQ_CSNullability) - addContextSensitiveTypeNullability(*this, declarator, - DS.getNullability(), - DS.getNullabilityLoc(), - addedToDeclSpec); - - TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator); - if (!type.isInvalid()) - Ty = type.get(); - } } if (Tok.is(tok::r_paren)) -- cgit v1.2.3