diff options
author | Douglas Gregor <dgregor@apple.com> | 2015-06-19 23:18:00 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2015-06-19 23:18:00 +0000 |
commit | a2ba66a7fee863daf4a28aeebb7184e3255df3ed (patch) | |
tree | a722c94da1f67eb951aadda5d9482e1e2962a688 /lib/Parse/ParseObjc.cpp | |
parent | 5c5a8ceac8e2b0477814f0dfcc4d33bcb079eb67 (diff) |
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
Diffstat (limited to 'lib/Parse/ParseObjc.cpp')
-rw-r--r-- | lib/Parse/ParseObjc.cpp | 39 |
1 files changed, 5 insertions, 34 deletions
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)) |