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 | 5c0870ac51175309a8dc98ca056d499d5eeeca48 (patch) | |
tree | 06826fdae357909853051512d49df508e29cf57f /clang/lib/Parse/ParseObjc.cpp | |
parent | 227fe4bc032cdd791f684a3a8f17826f42cb73a8 (diff) | |
download | bcm5719-llvm-5c0870ac51175309a8dc98ca056d499d5eeeca48.tar.gz bcm5719-llvm-5c0870ac51175309a8dc98ca056d499d5eeeca48.zip |
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
llvm-svn: 240188
Diffstat (limited to 'clang/lib/Parse/ParseObjc.cpp')
-rw-r--r-- | clang/lib/Parse/ParseObjc.cpp | 39 |
1 files changed, 5 insertions, 34 deletions
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index de347181bf3..e4f7911138d 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/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)) |