Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1 | //===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C portions of the Parser interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 14 | #include "clang/Parse/Parser.h" |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 16 | #include "clang/Basic/CharInfo.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 18 | #include "clang/Sema/DeclSpec.h" |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 19 | #include "clang/Sema/PrettyDeclStackTrace.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallVector.h" |
Fariborz Jahanian | f4ffdf3 | 2012-09-17 19:15:26 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 25 | /// Skips attributes after an Objective-C @ directive. Emits a diagnostic. |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 26 | void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) { |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 27 | ParsedAttributes attrs(AttrFactory); |
| 28 | if (Tok.is(tok::kw___attribute)) { |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 29 | if (Kind == tok::objc_interface || Kind == tok::objc_protocol) |
| 30 | Diag(Tok, diag::err_objc_postfix_attribute_hint) |
| 31 | << (Kind == tok::objc_protocol); |
| 32 | else |
| 33 | Diag(Tok, diag::err_objc_postfix_attribute); |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 34 | ParseGNUAttributes(attrs); |
| 35 | } |
| 36 | } |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 37 | |
Chris Lattner | 3a90716 | 2008-12-08 21:53:24 +0000 | [diff] [blame] | 38 | /// ParseObjCAtDirectives - Handle parts of the external-declaration production: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 39 | /// external-declaration: [C99 6.9] |
| 40 | /// [OBJC] objc-class-definition |
Steve Naroff | e093339 | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 41 | /// [OBJC] objc-class-declaration |
| 42 | /// [OBJC] objc-alias-declaration |
| 43 | /// [OBJC] objc-protocol-definition |
| 44 | /// [OBJC] objc-method-definition |
| 45 | /// [OBJC] '@' 'end' |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 46 | Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 47 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 49 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 50 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 51 | cutOffParsing(); |
| 52 | return DeclGroupPtrTy(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 53 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 54 | |
| 55 | Decl *SingleDecl = nullptr; |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 56 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 57 | case tok::objc_class: |
| 58 | return ParseObjCAtClassDeclaration(AtLoc); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 59 | case tok::objc_interface: { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 60 | ParsedAttributes attrs(AttrFactory); |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 61 | SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, attrs); |
| 62 | break; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 63 | } |
| 64 | case tok::objc_protocol: { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 65 | ParsedAttributes attrs(AttrFactory); |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 66 | return ParseObjCAtProtocolDeclaration(AtLoc, attrs); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 67 | } |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 68 | case tok::objc_implementation: |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 69 | return ParseObjCAtImplementationDeclaration(AtLoc); |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 70 | case tok::objc_end: |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 71 | return ParseObjCAtEndDeclaration(AtLoc); |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 72 | case tok::objc_compatibility_alias: |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 73 | SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); |
| 74 | break; |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 75 | case tok::objc_synthesize: |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 76 | SingleDecl = ParseObjCPropertySynthesize(AtLoc); |
| 77 | break; |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 78 | case tok::objc_dynamic: |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 79 | SingleDecl = ParseObjCPropertyDynamic(AtLoc); |
| 80 | break; |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 81 | case tok::objc_import: |
Sean Callanan | 8759649 | 2014-12-09 23:47:56 +0000 | [diff] [blame^] | 82 | if (getLangOpts().Modules || getLangOpts().DebuggerSupport) |
Douglas Gregor | 0bf886d | 2012-01-03 18:24:14 +0000 | [diff] [blame] | 83 | return ParseModuleImport(AtLoc); |
Fariborz Jahanian | a773d08 | 2014-03-26 22:02:43 +0000 | [diff] [blame] | 84 | Diag(AtLoc, diag::err_atimport); |
| 85 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 86 | return Actions.ConvertDeclToDeclGroup(nullptr); |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 87 | default: |
| 88 | Diag(AtLoc, diag::err_unexpected_at); |
| 89 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 90 | SingleDecl = nullptr; |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 91 | break; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 92 | } |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 93 | return Actions.ConvertDeclToDeclGroup(SingleDecl); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | /// objc-class-declaration: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 98 | /// '@' 'class' identifier-list ';' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 99 | /// |
Fariborz Jahanian | 3a039e3 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 100 | Parser::DeclGroupPtrTy |
| 101 | Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 102 | ConsumeToken(); // the identifier "class" |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 103 | SmallVector<IdentifierInfo *, 8> ClassNames; |
| 104 | SmallVector<SourceLocation, 8> ClassLocs; |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 105 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 107 | while (1) { |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 108 | MaybeSkipAttributes(tok::objc_class); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 109 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 110 | Diag(Tok, diag::err_expected) << tok::identifier; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 111 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 112 | return Actions.ConvertDeclToDeclGroup(nullptr); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 113 | } |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 114 | ClassNames.push_back(Tok.getIdentifierInfo()); |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 115 | ClassLocs.push_back(Tok.getLocation()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 116 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 118 | if (!TryConsumeToken(tok::comma)) |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 119 | break; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 120 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 122 | // Consume the ';'. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 123 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@class")) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 124 | return Actions.ConvertDeclToDeclGroup(nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 126 | return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), |
| 127 | ClassLocs.data(), |
| 128 | ClassNames.size()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 131 | void Parser::CheckNestedObjCContexts(SourceLocation AtLoc) |
| 132 | { |
| 133 | Sema::ObjCContainerKind ock = Actions.getObjCContainerKind(); |
| 134 | if (ock == Sema::OCK_None) |
| 135 | return; |
| 136 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 137 | Decl *Decl = Actions.getObjCDeclContext(); |
| 138 | if (CurParsedObjCImpl) { |
| 139 | CurParsedObjCImpl->finish(AtLoc); |
| 140 | } else { |
| 141 | Actions.ActOnAtEnd(getCurScope(), AtLoc); |
| 142 | } |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 143 | Diag(AtLoc, diag::err_objc_missing_end) |
| 144 | << FixItHint::CreateInsertion(AtLoc, "@end\n"); |
| 145 | if (Decl) |
| 146 | Diag(Decl->getLocStart(), diag::note_objc_container_start) |
| 147 | << (int) ock; |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 150 | /// |
| 151 | /// objc-interface: |
| 152 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 153 | /// objc-category-interface |
| 154 | /// |
| 155 | /// objc-class-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 156 | /// '@' 'interface' identifier objc-superclass[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 157 | /// objc-protocol-refs[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 158 | /// objc-class-instance-variables[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 159 | /// objc-interface-decl-list |
| 160 | /// @end |
| 161 | /// |
| 162 | /// objc-category-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 164 | /// objc-protocol-refs[opt] |
| 165 | /// objc-interface-decl-list |
| 166 | /// @end |
| 167 | /// |
| 168 | /// objc-superclass: |
| 169 | /// ':' identifier |
| 170 | /// |
| 171 | /// objc-class-interface-attributes: |
| 172 | /// __attribute__((visibility("default"))) |
| 173 | /// __attribute__((visibility("hidden"))) |
| 174 | /// __attribute__((deprecated)) |
| 175 | /// __attribute__((unavailable)) |
| 176 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
Patrick Beard | acfbe9e | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 177 | /// __attribute__((objc_root_class)) |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 178 | /// |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 179 | Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 180 | ParsedAttributes &attrs) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 181 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 182 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 183 | CheckNestedObjCContexts(AtLoc); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 184 | ConsumeToken(); // the "interface" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 186 | // Code completion after '@interface'. |
| 187 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 188 | Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 189 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 190 | return nullptr; |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 193 | MaybeSkipAttributes(tok::objc_interface); |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 194 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 195 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 196 | Diag(Tok, diag::err_expected) |
| 197 | << tok::identifier; // missing class or category name. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 198 | return nullptr; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 199 | } |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 200 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 201 | // We have a class or category name - consume it. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 202 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 203 | SourceLocation nameLoc = ConsumeToken(); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 204 | if (Tok.is(tok::l_paren) && |
| 205 | !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 206 | |
| 207 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 208 | T.consumeOpen(); |
| 209 | |
| 210 | SourceLocation categoryLoc; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 211 | IdentifierInfo *categoryId = nullptr; |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 212 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 213 | Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 214 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 215 | return nullptr; |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Steve Naroff | 4e1f80d | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 218 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 219 | if (Tok.is(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 220 | categoryId = Tok.getIdentifierInfo(); |
| 221 | categoryLoc = ConsumeToken(); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 222 | } |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 223 | else if (!getLangOpts().ObjC2) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 224 | Diag(Tok, diag::err_expected) |
| 225 | << tok::identifier; // missing category name. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 226 | return nullptr; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 227 | } |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 228 | |
| 229 | T.consumeClose(); |
| 230 | if (T.getCloseLocation().isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 231 | return nullptr; |
| 232 | |
Douglas Gregor | 0c254a0 | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 233 | if (!attrs.empty()) { // categories don't support attributes. |
| 234 | Diag(nameLoc, diag::err_objc_no_attributes_on_category); |
| 235 | attrs.clear(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 236 | } |
Douglas Gregor | 0c254a0 | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 237 | |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 238 | // Next, we need to check for any protocol references. |
| 239 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 240 | SmallVector<Decl *, 8> ProtocolRefs; |
| 241 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 242 | if (Tok.is(tok::less) && |
| 243 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 244 | LAngleLoc, EndProtoLoc)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 245 | return nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 246 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 247 | Decl *CategoryType = |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 248 | Actions.ActOnStartCategoryInterface(AtLoc, |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 249 | nameId, nameLoc, |
| 250 | categoryId, categoryLoc, |
| 251 | ProtocolRefs.data(), |
| 252 | ProtocolRefs.size(), |
| 253 | ProtocolLocs.data(), |
| 254 | EndProtoLoc); |
Fariborz Jahanian | 9a3b269 | 2011-08-19 18:02:47 +0000 | [diff] [blame] | 255 | |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 256 | if (Tok.is(tok::l_brace)) |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 257 | ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, AtLoc); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 258 | |
Fariborz Jahanian | b66de9f | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 259 | ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 260 | return CategoryType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 261 | } |
| 262 | // Parse a class interface. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 263 | IdentifierInfo *superClassId = nullptr; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 264 | SourceLocation superClassLoc; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 265 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 266 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 267 | ConsumeToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 268 | |
| 269 | // Code completion of superclass names. |
| 270 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 271 | Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 272 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 273 | return nullptr; |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 276 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 277 | Diag(Tok, diag::err_expected) |
| 278 | << tok::identifier; // missing super class name. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 279 | return nullptr; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 280 | } |
| 281 | superClassId = Tok.getIdentifierInfo(); |
| 282 | superClassLoc = ConsumeToken(); |
| 283 | } |
| 284 | // Next, we need to check for any protocol references. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 285 | SmallVector<Decl *, 8> ProtocolRefs; |
| 286 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 287 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 288 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 289 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
| 290 | LAngleLoc, EndProtoLoc)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 291 | return nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 292 | |
Fariborz Jahanian | b7c5f74 | 2013-09-25 19:36:32 +0000 | [diff] [blame] | 293 | if (Tok.isNot(tok::less)) |
| 294 | Actions.ActOnTypedefedProtocols(ProtocolRefs, superClassId, superClassLoc); |
| 295 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 296 | Decl *ClsType = |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 297 | Actions.ActOnStartClassInterface(AtLoc, nameId, nameLoc, |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 298 | superClassId, superClassLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 299 | ProtocolRefs.data(), ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 300 | ProtocolLocs.data(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 301 | EndProtoLoc, attrs.getList()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 302 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 303 | if (Tok.is(tok::l_brace)) |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 304 | ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, AtLoc); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 305 | |
Fariborz Jahanian | b66de9f | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 306 | ParseObjCInterfaceDeclList(tok::objc_interface, ClsType); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 307 | return ClsType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /// objc-interface-decl-list: |
| 311 | /// empty |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 312 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 313 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 314 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 315 | /// objc-interface-decl-list declaration |
| 316 | /// objc-interface-decl-list ';' |
| 317 | /// |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 318 | /// objc-method-requirement: [OBJC2] |
| 319 | /// @required |
| 320 | /// @optional |
| 321 | /// |
Fariborz Jahanian | b66de9f | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 322 | void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, |
| 323 | Decl *CDecl) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 324 | SmallVector<Decl *, 32> allMethods; |
| 325 | SmallVector<Decl *, 16> allProperties; |
| 326 | SmallVector<DeclGroupPtrTy, 8> allTUVariables; |
Fariborz Jahanian | 0c74e9d | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 327 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 328 | |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 329 | SourceRange AtEnd; |
Fariborz Jahanian | b66de9f | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 330 | |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 331 | while (1) { |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 332 | // If this is a method prototype, parse it. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 333 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
Fariborz Jahanian | a5fc75f | 2012-07-26 17:32:28 +0000 | [diff] [blame] | 334 | if (Decl *methodPrototype = |
| 335 | ParseObjCMethodPrototype(MethodImplKind, false)) |
| 336 | allMethods.push_back(methodPrototype); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 337 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 338 | // method definitions. |
Argyrios Kyrtzidis | e1ee623 | 2011-12-17 04:13:22 +0000 | [diff] [blame] | 339 | if (ExpectAndConsumeSemi(diag::err_expected_semi_after_method_proto)) { |
| 340 | // We didn't find a semi and we error'ed out. Skip until a ';' or '@'. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 341 | SkipUntil(tok::at, StopAtSemi | StopBeforeMatch); |
Argyrios Kyrtzidis | e1ee623 | 2011-12-17 04:13:22 +0000 | [diff] [blame] | 342 | if (Tok.is(tok::semi)) |
| 343 | ConsumeToken(); |
| 344 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 345 | continue; |
| 346 | } |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 347 | if (Tok.is(tok::l_paren)) { |
| 348 | Diag(Tok, diag::err_expected_minus_or_plus); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 349 | ParseObjCMethodDecl(Tok.getLocation(), |
| 350 | tok::minus, |
Fariborz Jahanian | c677f69 | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 351 | MethodImplKind, false); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 352 | continue; |
| 353 | } |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 354 | // Ignore excess semicolons. |
| 355 | if (Tok.is(tok::semi)) { |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 356 | ConsumeToken(); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 357 | continue; |
| 358 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 360 | // If we got to the end of the file, exit the loop. |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 361 | if (isEofOrEom()) |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 362 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 364 | // Code completion within an Objective-C interface. |
| 365 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 366 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 367 | CurParsedObjCImpl? Sema::PCC_ObjCImplementation |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 368 | : Sema::PCC_ObjCInterface); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 369 | return cutOffParsing(); |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 370 | } |
| 371 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 372 | // If we don't have an @ directive, parse it as a function definition. |
| 373 | if (Tok.isNot(tok::at)) { |
Chris Lattner | c7c9ab7 | 2009-01-09 04:34:13 +0000 | [diff] [blame] | 374 | // The code below does not consume '}'s because it is afraid of eating the |
| 375 | // end of a namespace. Because of the way this code is structured, an |
| 376 | // erroneous r_brace would cause an infinite loop if not handled here. |
| 377 | if (Tok.is(tok::r_brace)) |
| 378 | break; |
Alexis Hunt | 6aa9bee | 2012-06-23 05:07:58 +0000 | [diff] [blame] | 379 | ParsedAttributesWithRange attrs(AttrFactory); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 380 | allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 381 | continue; |
| 382 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 384 | // Otherwise, we have an @ directive, eat the @. |
| 385 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 386 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 387 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 388 | return cutOffParsing(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 391 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 392 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 393 | if (DirectiveKind == tok::objc_end) { // @end -> terminate list |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 394 | AtEnd.setBegin(AtLoc); |
| 395 | AtEnd.setEnd(Tok.getLocation()); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 396 | break; |
Douglas Gregor | 00a0cf7 | 2010-03-16 06:04:47 +0000 | [diff] [blame] | 397 | } else if (DirectiveKind == tok::objc_not_keyword) { |
| 398 | Diag(Tok, diag::err_objc_unknown_at); |
| 399 | SkipUntil(tok::semi); |
| 400 | continue; |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 401 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 402 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 403 | // Eat the identifier. |
| 404 | ConsumeToken(); |
| 405 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 406 | switch (DirectiveKind) { |
| 407 | default: |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 408 | // FIXME: If someone forgets an @end on a protocol, this loop will |
| 409 | // continue to eat up tons of stuff and spew lots of nonsense errors. It |
| 410 | // would probably be better to bail out if we saw an @class or @interface |
| 411 | // or something like that. |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 412 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 413 | // Skip until we see an '@' or '}' or ';'. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 414 | SkipUntil(tok::r_brace, tok::at, StopAtSemi); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 415 | break; |
Fariborz Jahanian | d4c5348 | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 416 | |
| 417 | case tok::objc_implementation: |
Fariborz Jahanian | dbee986 | 2010-11-09 20:38:00 +0000 | [diff] [blame] | 418 | case tok::objc_interface: |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 419 | Diag(AtLoc, diag::err_objc_missing_end) |
| 420 | << FixItHint::CreateInsertion(AtLoc, "@end\n"); |
| 421 | Diag(CDecl->getLocStart(), diag::note_objc_container_start) |
| 422 | << (int) Actions.getObjCContainerKind(); |
Fariborz Jahanian | d4c5348 | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 423 | ConsumeToken(); |
| 424 | break; |
| 425 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 426 | case tok::objc_required: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 427 | case tok::objc_optional: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 428 | // This is only valid on protocols. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 429 | // FIXME: Should this check for ObjC2 being enabled? |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 430 | if (contextKey != tok::objc_protocol) |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 431 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 432 | else |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 433 | MethodImplKind = DirectiveKind; |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 434 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 436 | case tok::objc_property: |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 437 | if (!getLangOpts().ObjC2) |
Chris Lattner | 4da4e25 | 2010-12-17 05:40:22 +0000 | [diff] [blame] | 438 | Diag(AtLoc, diag::err_objc_properties_require_objc2); |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 439 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 440 | ObjCDeclSpec OCDS; |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 441 | SourceLocation LParenLoc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | // Parse property attribute list, if any. |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 443 | if (Tok.is(tok::l_paren)) { |
| 444 | LParenLoc = Tok.getLocation(); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 445 | ParseObjCPropertyAttribute(OCDS); |
Fariborz Jahanian | 86c2f5c | 2012-02-29 22:18:55 +0000 | [diff] [blame] | 446 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | |
Benjamin Kramer | a39beb9 | 2014-09-03 11:06:10 +0000 | [diff] [blame] | 448 | auto ObjCPropertyCallback = [&](ParsingFieldDeclarator &FD) { |
| 449 | if (FD.D.getIdentifier() == nullptr) { |
| 450 | Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 451 | << FD.D.getSourceRange(); |
| 452 | return; |
| 453 | } |
| 454 | if (FD.BitfieldSize) { |
| 455 | Diag(AtLoc, diag::err_objc_property_bitfield) |
| 456 | << FD.D.getSourceRange(); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | // Install the property declarator into interfaceDecl. |
| 461 | IdentifierInfo *SelName = |
| 462 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 463 | |
| 464 | Selector GetterSel = PP.getSelectorTable().getNullarySelector(SelName); |
| 465 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 466 | Selector SetterSel; |
| 467 | if (SetterName) |
| 468 | SetterSel = PP.getSelectorTable().getSelector(1, &SetterName); |
| 469 | else |
| 470 | SetterSel = SelectorTable::constructSetterSelector( |
| 471 | PP.getIdentifierTable(), PP.getSelectorTable(), |
| 472 | FD.D.getIdentifier()); |
| 473 | bool isOverridingProperty = false; |
| 474 | Decl *Property = Actions.ActOnProperty( |
| 475 | getCurScope(), AtLoc, LParenLoc, FD, OCDS, GetterSel, SetterSel, |
| 476 | &isOverridingProperty, MethodImplKind); |
| 477 | if (!isOverridingProperty) |
| 478 | allProperties.push_back(Property); |
| 479 | |
| 480 | FD.complete(Property); |
| 481 | }; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 482 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 483 | // Parse all the comma separated declarators. |
Eli Friedman | 89b1f2c | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 484 | ParsingDeclSpec DS(*this); |
Benjamin Kramer | a39beb9 | 2014-09-03 11:06:10 +0000 | [diff] [blame] | 485 | ParseStructDeclaration(DS, ObjCPropertyCallback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
John McCall | 405988b | 2011-03-26 01:53:26 +0000 | [diff] [blame] | 487 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 488 | break; |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 489 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 490 | } |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 491 | |
| 492 | // We break out of the big loop in two cases: when we see @end or when we see |
| 493 | // EOF. In the former case, eat the @end. In the later case, emit an error. |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 494 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 495 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 496 | return cutOffParsing(); |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 497 | } else if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 498 | ConsumeToken(); // the "end" identifier |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 499 | } else { |
| 500 | Diag(Tok, diag::err_objc_missing_end) |
| 501 | << FixItHint::CreateInsertion(Tok.getLocation(), "\n@end\n"); |
| 502 | Diag(CDecl->getLocStart(), diag::note_objc_container_start) |
| 503 | << (int) Actions.getObjCContainerKind(); |
| 504 | AtEnd.setBegin(Tok.getLocation()); |
| 505 | AtEnd.setEnd(Tok.getLocation()); |
| 506 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 507 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 508 | // Insert collected methods declarations into the @interface object. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 509 | // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. |
Fariborz Jahanian | 0080fb5 | 2013-07-16 15:33:19 +0000 | [diff] [blame] | 510 | Actions.ActOnAtEnd(getCurScope(), AtEnd, allMethods, allTUVariables); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 513 | /// Parse property attribute declarations. |
| 514 | /// |
| 515 | /// property-attr-decl: '(' property-attrlist ')' |
| 516 | /// property-attrlist: |
| 517 | /// property-attribute |
| 518 | /// property-attrlist ',' property-attribute |
| 519 | /// property-attribute: |
| 520 | /// getter '=' identifier |
| 521 | /// setter '=' identifier ':' |
| 522 | /// readonly |
| 523 | /// readwrite |
| 524 | /// assign |
| 525 | /// retain |
| 526 | /// copy |
| 527 | /// nonatomic |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 528 | /// atomic |
| 529 | /// strong |
| 530 | /// weak |
| 531 | /// unsafe_unretained |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 532 | /// |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 533 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 534 | assert(Tok.getKind() == tok::l_paren); |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 535 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 536 | T.consumeOpen(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 538 | while (1) { |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 539 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 540 | Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 541 | return cutOffParsing(); |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 542 | } |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 543 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 545 | // If this is not an identifier at all, bail out early. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 546 | if (!II) { |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 547 | T.consumeClose(); |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 548 | return; |
| 549 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 551 | SourceLocation AttrName = ConsumeToken(); // consume last attribute name |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 553 | if (II->isStr("readonly")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 554 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 555 | else if (II->isStr("assign")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 556 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 557 | else if (II->isStr("unsafe_unretained")) |
| 558 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 559 | else if (II->isStr("readwrite")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 560 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 561 | else if (II->isStr("retain")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 562 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 563 | else if (II->isStr("strong")) |
| 564 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 565 | else if (II->isStr("copy")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 566 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 567 | else if (II->isStr("nonatomic")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 568 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Fariborz Jahanian | c3bcde0 | 2011-06-11 00:45:12 +0000 | [diff] [blame] | 569 | else if (II->isStr("atomic")) |
| 570 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 571 | else if (II->isStr("weak")) |
| 572 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 573 | else if (II->isStr("getter") || II->isStr("setter")) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 574 | bool IsSetter = II->getNameStart()[0] == 's'; |
| 575 | |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 576 | // getter/setter require extra treatment. |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 577 | unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : |
| 578 | diag::err_objc_expected_equal_for_getter; |
| 579 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 580 | if (ExpectAndConsume(tok::equal, DiagID)) { |
| 581 | SkipUntil(tok::r_paren, StopAtSemi); |
Chris Lattner | 43c76c3 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 582 | return; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 583 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 584 | |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 585 | if (Tok.is(tok::code_completion)) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 586 | if (IsSetter) |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 587 | Actions.CodeCompleteObjCPropertySetter(getCurScope()); |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 588 | else |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 589 | Actions.CodeCompleteObjCPropertyGetter(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 590 | return cutOffParsing(); |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 593 | |
| 594 | SourceLocation SelLoc; |
| 595 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); |
| 596 | |
| 597 | if (!SelIdent) { |
| 598 | Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) |
| 599 | << IsSetter; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 600 | SkipUntil(tok::r_paren, StopAtSemi); |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 601 | return; |
| 602 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 604 | if (IsSetter) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 605 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 606 | DS.setSetterName(SelIdent); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 608 | if (ExpectAndConsume(tok::colon, |
| 609 | diag::err_expected_colon_after_setter_name)) { |
| 610 | SkipUntil(tok::r_paren, StopAtSemi); |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 611 | return; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 612 | } |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 613 | } else { |
| 614 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 615 | DS.setGetterName(SelIdent); |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 616 | } |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 617 | } else { |
Chris Lattner | 406c096 | 2008-11-19 07:49:38 +0000 | [diff] [blame] | 618 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 619 | SkipUntil(tok::r_paren, StopAtSemi); |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 620 | return; |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 621 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 622 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 623 | if (Tok.isNot(tok::comma)) |
| 624 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 626 | ConsumeToken(); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 627 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 629 | T.consumeClose(); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 632 | /// objc-method-proto: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 634 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 635 | /// |
| 636 | /// objc-instance-method: '-' |
| 637 | /// objc-class-method: '+' |
| 638 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 639 | /// objc-method-attributes: [OBJC2] |
| 640 | /// __attribute__((deprecated)) |
| 641 | /// |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 642 | Decl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind, |
Fariborz Jahanian | c677f69 | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 643 | bool MethodDefinition) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 644 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 645 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 646 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 647 | SourceLocation mLoc = ConsumeToken(); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 648 | Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind, |
Fariborz Jahanian | c677f69 | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 649 | MethodDefinition); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 650 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | acb1e74 | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 651 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 652 | return MDecl; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /// objc-selector: |
| 656 | /// identifier |
| 657 | /// one of |
| 658 | /// enum struct union if else while do for switch case default |
| 659 | /// break continue return goto asm sizeof typeof __alignof |
| 660 | /// unsigned long const short volatile signed restrict _Complex |
| 661 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 662 | /// |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 663 | IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { |
Fariborz Jahanian | 0389df4a | 2010-09-03 01:26:16 +0000 | [diff] [blame] | 664 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 665 | switch (Tok.getKind()) { |
| 666 | default: |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 667 | return nullptr; |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 668 | case tok::ampamp: |
| 669 | case tok::ampequal: |
| 670 | case tok::amp: |
| 671 | case tok::pipe: |
| 672 | case tok::tilde: |
| 673 | case tok::exclaim: |
| 674 | case tok::exclaimequal: |
| 675 | case tok::pipepipe: |
| 676 | case tok::pipeequal: |
| 677 | case tok::caret: |
| 678 | case tok::caretequal: { |
Fariborz Jahanian | dadfc1c | 2010-09-03 18:01:09 +0000 | [diff] [blame] | 679 | std::string ThisTok(PP.getSpelling(Tok)); |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 680 | if (isLetter(ThisTok[0])) { |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 681 | IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); |
| 682 | Tok.setKind(tok::identifier); |
| 683 | SelectorLoc = ConsumeToken(); |
| 684 | return II; |
| 685 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 686 | return nullptr; |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 689 | case tok::identifier: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 690 | case tok::kw_asm: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 691 | case tok::kw_auto: |
Chris Lattner | bb31a42 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 692 | case tok::kw_bool: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 693 | case tok::kw_break: |
| 694 | case tok::kw_case: |
| 695 | case tok::kw_catch: |
| 696 | case tok::kw_char: |
| 697 | case tok::kw_class: |
| 698 | case tok::kw_const: |
| 699 | case tok::kw_const_cast: |
| 700 | case tok::kw_continue: |
| 701 | case tok::kw_default: |
| 702 | case tok::kw_delete: |
| 703 | case tok::kw_do: |
| 704 | case tok::kw_double: |
| 705 | case tok::kw_dynamic_cast: |
| 706 | case tok::kw_else: |
| 707 | case tok::kw_enum: |
| 708 | case tok::kw_explicit: |
| 709 | case tok::kw_export: |
| 710 | case tok::kw_extern: |
| 711 | case tok::kw_false: |
| 712 | case tok::kw_float: |
| 713 | case tok::kw_for: |
| 714 | case tok::kw_friend: |
| 715 | case tok::kw_goto: |
| 716 | case tok::kw_if: |
| 717 | case tok::kw_inline: |
| 718 | case tok::kw_int: |
| 719 | case tok::kw_long: |
| 720 | case tok::kw_mutable: |
| 721 | case tok::kw_namespace: |
| 722 | case tok::kw_new: |
| 723 | case tok::kw_operator: |
| 724 | case tok::kw_private: |
| 725 | case tok::kw_protected: |
| 726 | case tok::kw_public: |
| 727 | case tok::kw_register: |
| 728 | case tok::kw_reinterpret_cast: |
| 729 | case tok::kw_restrict: |
| 730 | case tok::kw_return: |
| 731 | case tok::kw_short: |
| 732 | case tok::kw_signed: |
| 733 | case tok::kw_sizeof: |
| 734 | case tok::kw_static: |
| 735 | case tok::kw_static_cast: |
| 736 | case tok::kw_struct: |
| 737 | case tok::kw_switch: |
| 738 | case tok::kw_template: |
| 739 | case tok::kw_this: |
| 740 | case tok::kw_throw: |
| 741 | case tok::kw_true: |
| 742 | case tok::kw_try: |
| 743 | case tok::kw_typedef: |
| 744 | case tok::kw_typeid: |
| 745 | case tok::kw_typename: |
| 746 | case tok::kw_typeof: |
| 747 | case tok::kw_union: |
| 748 | case tok::kw_unsigned: |
| 749 | case tok::kw_using: |
| 750 | case tok::kw_virtual: |
| 751 | case tok::kw_void: |
| 752 | case tok::kw_volatile: |
| 753 | case tok::kw_wchar_t: |
| 754 | case tok::kw_while: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 755 | case tok::kw__Bool: |
| 756 | case tok::kw__Complex: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 757 | case tok::kw___alignof: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 758 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 759 | SelectorLoc = ConsumeToken(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 760 | return II; |
Fariborz Jahanian | fa80e80 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 761 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 764 | /// objc-for-collection-in: 'in' |
| 765 | /// |
Fariborz Jahanian | 3622e59 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 766 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 732b8c2 | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 767 | // FIXME: May have to do additional look-ahead to only allow for |
| 768 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 769 | // '[' etc. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 770 | return (getLangOpts().ObjC2 && Tok.is(tok::identifier) && |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 771 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 774 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 775 | /// qualifier list and builds their bitmask representation in the input |
| 776 | /// argument. |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 777 | /// |
| 778 | /// objc-type-qualifiers: |
| 779 | /// objc-type-qualifier |
| 780 | /// objc-type-qualifiers objc-type-qualifier |
| 781 | /// |
Douglas Gregor | 95d3e37 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 782 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 783 | Declarator::TheContext Context) { |
| 784 | assert(Context == Declarator::ObjCParameterContext || |
| 785 | Context == Declarator::ObjCResultContext); |
| 786 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 787 | while (1) { |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 788 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 95d3e37 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 789 | Actions.CodeCompleteObjCPassingType(getCurScope(), DS, |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 790 | Context == Declarator::ObjCParameterContext); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 791 | return cutOffParsing(); |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 794 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 795 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 797 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 798 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 799 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 800 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 802 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 803 | switch (i) { |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 804 | default: llvm_unreachable("Unknown decl qualifier"); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 805 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 806 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 807 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 808 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 809 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 810 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 811 | } |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 812 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 813 | ConsumeToken(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 814 | II = nullptr; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 815 | break; |
| 816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 817 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 818 | // If this wasn't a recognized qualifier, bail out. |
| 819 | if (II) return; |
| 820 | } |
| 821 | } |
| 822 | |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 823 | /// Take all the decl attributes out of the given list and add |
| 824 | /// them to the given attribute set. |
| 825 | static void takeDeclAttributes(ParsedAttributes &attrs, |
| 826 | AttributeList *list) { |
| 827 | while (list) { |
| 828 | AttributeList *cur = list; |
| 829 | list = cur->getNext(); |
| 830 | |
| 831 | if (!cur->isUsedAsTypeAttr()) { |
| 832 | // Clear out the next pointer. We're really completely |
| 833 | // destroying the internal invariants of the declarator here, |
| 834 | // but it doesn't matter because we're done with it. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 835 | cur->setNext(nullptr); |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 836 | attrs.add(cur); |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | /// takeDeclAttributes - Take all the decl attributes from the given |
| 842 | /// declarator and add them to the given list. |
| 843 | static void takeDeclAttributes(ParsedAttributes &attrs, |
| 844 | Declarator &D) { |
| 845 | // First, take ownership of all attributes. |
| 846 | attrs.getPool().takeAllFrom(D.getAttributePool()); |
| 847 | attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool()); |
| 848 | |
| 849 | // Now actually move the attributes over. |
| 850 | takeDeclAttributes(attrs, D.getDeclSpec().getAttributes().getList()); |
| 851 | takeDeclAttributes(attrs, D.getAttributes()); |
| 852 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) |
| 853 | takeDeclAttributes(attrs, |
| 854 | const_cast<AttributeList*>(D.getTypeObject(i).getAttrs())); |
| 855 | } |
| 856 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 857 | /// objc-type-name: |
| 858 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 859 | /// '(' objc-type-qualifiers[opt] ')' |
| 860 | /// |
Douglas Gregor | 95d3e37 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 861 | ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 862 | Declarator::TheContext context, |
| 863 | ParsedAttributes *paramAttrs) { |
| 864 | assert(context == Declarator::ObjCParameterContext || |
| 865 | context == Declarator::ObjCResultContext); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 866 | assert((paramAttrs != nullptr) == |
| 867 | (context == Declarator::ObjCParameterContext)); |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 868 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 869 | assert(Tok.is(tok::l_paren) && "expected ("); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 870 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 871 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 872 | T.consumeOpen(); |
| 873 | |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 874 | SourceLocation TypeStartLoc = Tok.getLocation(); |
Fariborz Jahanian | 4bf8262 | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 875 | ObjCDeclContextSwitch ObjCDC(*this); |
| 876 | |
Fariborz Jahanian | d822d68 | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 877 | // Parse type qualifiers, in, inout, etc. |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 878 | ParseObjCTypeQualifierList(DS, context); |
Steve Naroff | 7e901fd | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 879 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 880 | ParsedType Ty; |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 881 | if (isTypeSpecifierQualifier()) { |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 882 | // Parse an abstract declarator. |
| 883 | DeclSpec declSpec(AttrFactory); |
| 884 | declSpec.setObjCQualifiers(&DS); |
| 885 | ParseSpecifierQualifierList(declSpec); |
Fariborz Jahanian | b6499eb | 2012-05-29 21:52:45 +0000 | [diff] [blame] | 886 | declSpec.SetRangeEnd(Tok.getLocation()); |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 887 | Declarator declarator(declSpec, context); |
| 888 | ParseDeclarator(declarator); |
| 889 | |
| 890 | // If that's not invalid, extract a type. |
| 891 | if (!declarator.isInvalidType()) { |
| 892 | TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator); |
| 893 | if (!type.isInvalid()) |
| 894 | Ty = type.get(); |
| 895 | |
| 896 | // If we're parsing a parameter, steal all the decl attributes |
| 897 | // and add them to the decl spec. |
| 898 | if (context == Declarator::ObjCParameterContext) |
| 899 | takeDeclAttributes(*paramAttrs, declarator); |
| 900 | } |
| 901 | } else if (context == Declarator::ObjCResultContext && |
| 902 | Tok.is(tok::identifier)) { |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 903 | if (!Ident_instancetype) |
| 904 | Ident_instancetype = PP.getIdentifierInfo("instancetype"); |
| 905 | |
| 906 | if (Tok.getIdentifierInfo() == Ident_instancetype) { |
| 907 | Ty = Actions.ActOnObjCInstanceType(Tok.getLocation()); |
| 908 | ConsumeToken(); |
| 909 | } |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 910 | } |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 911 | |
Steve Naroff | 90255b4 | 2008-10-21 14:15:04 +0000 | [diff] [blame] | 912 | if (Tok.is(tok::r_paren)) |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 913 | T.consumeClose(); |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 914 | else if (Tok.getLocation() == TypeStartLoc) { |
| 915 | // If we didn't eat any tokens, then this isn't a type. |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 916 | Diag(Tok, diag::err_expected_type); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 917 | SkipUntil(tok::r_paren, StopAtSemi); |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 918 | } else { |
| 919 | // Otherwise, we found *something*, but didn't get a ')' in the right |
| 920 | // place. Emit an error then return what we have as the type. |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 921 | T.consumeClose(); |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 922 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 923 | return Ty; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /// objc-method-decl: |
| 927 | /// objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 928 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 929 | /// objc-type-name objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 930 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 931 | /// |
| 932 | /// objc-keyword-selector: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 933 | /// objc-keyword-decl |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 934 | /// objc-keyword-selector objc-keyword-decl |
| 935 | /// |
| 936 | /// objc-keyword-decl: |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 937 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 938 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 939 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 940 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 941 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 942 | /// objc-parmlist: |
| 943 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 944 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 945 | /// objc-parms: |
| 946 | /// objc-parms , parameter-declaration |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 947 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 948 | /// objc-ellipsis: |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 949 | /// , ... |
| 950 | /// |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 951 | /// objc-keyword-attributes: [OBJC2] |
| 952 | /// __attribute__((unused)) |
| 953 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 954 | Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Douglas Gregor | c49f5b2 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 955 | tok::TokenKind mType, |
Fariborz Jahanian | c677f69 | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 956 | tok::ObjCKeywordKind MethodImplKind, |
| 957 | bool MethodDefinition) { |
John McCall | 2ec8537 | 2012-05-07 06:16:41 +0000 | [diff] [blame] | 958 | ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 959 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 960 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 961 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 962 | /*ReturnType=*/ ParsedType()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 963 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 964 | return nullptr; |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 967 | // Parse the return type if present. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 968 | ParsedType ReturnType; |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 969 | ObjCDeclSpec DSRet; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 970 | if (Tok.is(tok::l_paren)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 971 | ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, |
| 972 | nullptr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 974 | // If attributes exist before the method, parse them. |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 975 | ParsedAttributes methodAttrs(AttrFactory); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 976 | if (getLangOpts().ObjC2) |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 977 | MaybeParseGNUAttributes(methodAttrs); |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 978 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 979 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 980 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 981 | ReturnType); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 982 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 983 | return nullptr; |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 986 | // Now parse the selector. |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 987 | SourceLocation selLoc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 988 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 989 | |
Steve Naroff | 7a54c0d | 2009-02-11 20:43:13 +0000 | [diff] [blame] | 990 | // An unnamed colon is valid. |
| 991 | if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 992 | Diag(Tok, diag::err_expected_selector_for_method) |
| 993 | << SourceRange(mLoc, Tok.getLocation()); |
Fariborz Jahanian | a5fc75f | 2012-07-26 17:32:28 +0000 | [diff] [blame] | 994 | // Skip until we get a ; or @. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 995 | SkipUntil(tok::at, StopAtSemi | StopBeforeMatch); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 996 | return nullptr; |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 997 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 998 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 999 | SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1000 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1001 | // If attributes exist after the method, parse them. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1002 | if (getLangOpts().ObjC2) |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1003 | MaybeParseGNUAttributes(methodAttrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1005 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1006 | Decl *Result |
Fariborz Jahanian | ca3566f | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1007 | = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1008 | mType, DSRet, ReturnType, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1009 | selLoc, Sel, nullptr, |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1010 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1011 | methodAttrs.getList(), MethodImplKind, |
| 1012 | false, MethodDefinition); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1013 | PD.complete(Result); |
| 1014 | return Result; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1015 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 1016 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1017 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Argyrios Kyrtzidis | dfd6570 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1018 | SmallVector<SourceLocation, 12> KeyLocs; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1019 | SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; |
Richard Smith | e233fbf | 2013-01-28 22:42:45 +0000 | [diff] [blame] | 1020 | ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | |
| 1021 | Scope::FunctionDeclarationScope | Scope::DeclScope); |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1022 | |
| 1023 | AttributePool allParamAttrs(AttrFactory); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1024 | while (1) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1025 | ParsedAttributes paramAttrs(AttrFactory); |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1026 | Sema::ObjCArgInfo ArgInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1028 | // Each iteration parses a single keyword argument. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1029 | if (ExpectAndConsume(tok::colon)) |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1030 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1031 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1032 | ArgInfo.Type = ParsedType(); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1033 | if (Tok.is(tok::l_paren)) // Parse the argument type if present. |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1034 | ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, |
| 1035 | Declarator::ObjCParameterContext, |
| 1036 | ¶mAttrs); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1037 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1038 | // If attributes exist before the argument name, parse them. |
John McCall | a55902b | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 1039 | // Regardless, collect all the attributes we've parsed so far. |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1040 | ArgInfo.ArgAttrs = nullptr; |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1041 | if (getLangOpts().ObjC2) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1042 | MaybeParseGNUAttributes(paramAttrs); |
| 1043 | ArgInfo.ArgAttrs = paramAttrs.getList(); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1044 | } |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1045 | |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1046 | // Code completion for the next piece of the selector. |
| 1047 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1048 | KeyIdents.push_back(SelIdent); |
| 1049 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1050 | mType == tok::minus, |
| 1051 | /*AtParameterName=*/true, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 1052 | ReturnType, KeyIdents); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1053 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1054 | return nullptr; |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1057 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1058 | Diag(Tok, diag::err_expected) |
| 1059 | << tok::identifier; // missing argument name. |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1060 | break; |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1063 | ArgInfo.Name = Tok.getIdentifierInfo(); |
| 1064 | ArgInfo.NameLoc = Tok.getLocation(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1065 | ConsumeToken(); // Eat the identifier. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1067 | ArgInfos.push_back(ArgInfo); |
| 1068 | KeyIdents.push_back(SelIdent); |
Argyrios Kyrtzidis | dfd6570 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1069 | KeyLocs.push_back(selLoc); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1070 | |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1071 | // Make sure the attributes persist. |
| 1072 | allParamAttrs.takeAllFrom(paramAttrs.getPool()); |
| 1073 | |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1074 | // Code completion for the next piece of the selector. |
| 1075 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1076 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1077 | mType == tok::minus, |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1078 | /*AtParameterName=*/false, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 1079 | ReturnType, KeyIdents); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1080 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1081 | return nullptr; |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1084 | // Check for another keyword selector. |
Argyrios Kyrtzidis | dfd6570 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1085 | SelIdent = ParseObjCSelectorPiece(selLoc); |
Ted Kremenek | 191ffd3 | 2012-09-12 16:50:35 +0000 | [diff] [blame] | 1086 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 1087 | break; |
Fariborz Jahanian | 84f4984 | 2012-09-17 23:09:59 +0000 | [diff] [blame] | 1088 | if (!SelIdent) { |
Fariborz Jahanian | f4ffdf3 | 2012-09-17 19:15:26 +0000 | [diff] [blame] | 1089 | SourceLocation ColonLoc = Tok.getLocation(); |
| 1090 | if (PP.getLocForEndOfToken(ArgInfo.NameLoc) == ColonLoc) { |
Fariborz Jahanian | 84f4984 | 2012-09-17 23:09:59 +0000 | [diff] [blame] | 1091 | Diag(ArgInfo.NameLoc, diag::warn_missing_selector_name) << ArgInfo.Name; |
| 1092 | Diag(ArgInfo.NameLoc, diag::note_missing_selector_name) << ArgInfo.Name; |
| 1093 | Diag(ColonLoc, diag::note_force_empty_selector_name) << ArgInfo.Name; |
Fariborz Jahanian | f4ffdf3 | 2012-09-17 19:15:26 +0000 | [diff] [blame] | 1094 | } |
| 1095 | } |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1096 | // We have a selector or a colon, continue parsing. |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 1097 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1099 | bool isVariadic = false; |
Fariborz Jahanian | 45337f5 | 2012-06-21 18:43:08 +0000 | [diff] [blame] | 1100 | bool cStyleParamWarned = false; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1101 | // Parse the (optional) parameter list. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1102 | while (Tok.is(tok::comma)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1103 | ConsumeToken(); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1104 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1105 | isVariadic = true; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1106 | ConsumeToken(); |
| 1107 | break; |
| 1108 | } |
Fariborz Jahanian | 45337f5 | 2012-06-21 18:43:08 +0000 | [diff] [blame] | 1109 | if (!cStyleParamWarned) { |
| 1110 | Diag(Tok, diag::warn_cstyle_param); |
| 1111 | cStyleParamWarned = true; |
| 1112 | } |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1113 | DeclSpec DS(AttrFactory); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1114 | ParseDeclarationSpecifiers(DS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1115 | // Parse the declarator. |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1116 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 1117 | ParseDeclarator(ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1118 | IdentifierInfo *ParmII = ParmDecl.getIdentifier(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1119 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1120 | CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 1121 | ParmDecl.getIdentifierLoc(), |
| 1122 | Param, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1123 | nullptr)); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1124 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1125 | |
Cameron Esfahani | f6c73c4 | 2010-10-12 00:21:25 +0000 | [diff] [blame] | 1126 | // FIXME: Add support for optional parameter list... |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 1127 | // If attributes exist after the method, parse them. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1128 | if (getLangOpts().ObjC2) |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1129 | MaybeParseGNUAttributes(methodAttrs); |
Fariborz Jahanian | ca3566f | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1130 | |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1131 | if (KeyIdents.size() == 0) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1132 | return nullptr; |
| 1133 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1134 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 1135 | &KeyIdents[0]); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1136 | Decl *Result |
Fariborz Jahanian | ca3566f | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1137 | = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1138 | mType, DSRet, ReturnType, |
Argyrios Kyrtzidis | dfd6570 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1139 | KeyLocs, Sel, &ArgInfos[0], |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1140 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1141 | methodAttrs.getList(), |
Fariborz Jahanian | c677f69 | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 1142 | MethodImplKind, isVariadic, MethodDefinition); |
Fariborz Jahanian | ca3566f | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1143 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1144 | PD.complete(Result); |
| 1145 | return Result; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1148 | /// objc-protocol-refs: |
| 1149 | /// '<' identifier-list '>' |
| 1150 | /// |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1151 | bool Parser:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1152 | ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols, |
| 1153 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1154 | bool WarnOnDeclarations, |
| 1155 | SourceLocation &LAngleLoc, SourceLocation &EndLoc) { |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1156 | assert(Tok.is(tok::less) && "expected <"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1158 | LAngleLoc = ConsumeToken(); // the "<" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1159 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1160 | SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1162 | while (1) { |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1163 | if (Tok.is(tok::code_completion)) { |
| 1164 | Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), |
| 1165 | ProtocolIdents.size()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1166 | cutOffParsing(); |
| 1167 | return true; |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1170 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1171 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1172 | SkipUntil(tok::greater, StopAtSemi); |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1173 | return true; |
| 1174 | } |
| 1175 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 1176 | Tok.getLocation())); |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1177 | ProtocolLocs.push_back(Tok.getLocation()); |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1178 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1180 | if (!TryConsumeToken(tok::comma)) |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1181 | break; |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1182 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1183 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1184 | // Consume the '>'. |
Nico Weber | 7aa4a88 | 2012-12-14 18:22:38 +0000 | [diff] [blame] | 1185 | if (ParseGreaterThanInTemplateList(EndLoc, /*ConsumeLastToken=*/true)) |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1186 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1188 | // Convert the list of protocols identifiers into a list of protocol decls. |
| 1189 | Actions.FindProtocolDeclaration(WarnOnDeclarations, |
| 1190 | &ProtocolIdents[0], ProtocolIdents.size(), |
| 1191 | Protocols); |
| 1192 | return false; |
| 1193 | } |
| 1194 | |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1195 | /// \brief Parse the Objective-C protocol qualifiers that follow a typename |
| 1196 | /// in a decl-specifier-seq, starting at the '<'. |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1197 | bool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1198 | assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1199 | assert(getLangOpts().ObjC1 && "Protocol qualifiers only exist in Objective-C"); |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1200 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1201 | SmallVector<Decl *, 8> ProtocolDecl; |
| 1202 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1203 | bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, |
| 1204 | LAngleLoc, EndProtoLoc); |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1205 | DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), |
| 1206 | ProtocolLocs.data(), LAngleLoc); |
| 1207 | if (EndProtoLoc.isValid()) |
| 1208 | DS.SetRangeEnd(EndProtoLoc); |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1209 | return Result; |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Fariborz Jahanian | 089f39e | 2013-03-20 18:09:33 +0000 | [diff] [blame] | 1212 | void Parser::HelperActionsForIvarDeclarations(Decl *interfaceDecl, SourceLocation atLoc, |
| 1213 | BalancedDelimiterTracker &T, |
| 1214 | SmallVectorImpl<Decl *> &AllIvarDecls, |
| 1215 | bool RBraceMissing) { |
| 1216 | if (!RBraceMissing) |
| 1217 | T.consumeClose(); |
| 1218 | |
| 1219 | Actions.ActOnObjCContainerStartDefinition(interfaceDecl); |
| 1220 | Actions.ActOnLastBitfield(T.getCloseLocation(), AllIvarDecls); |
| 1221 | Actions.ActOnObjCContainerFinishDefinition(); |
| 1222 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 1223 | // for code rewriting tools that need to be aware of the empty list. |
| 1224 | Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, |
| 1225 | AllIvarDecls, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1226 | T.getOpenLocation(), T.getCloseLocation(), nullptr); |
Fariborz Jahanian | 089f39e | 2013-03-20 18:09:33 +0000 | [diff] [blame] | 1227 | } |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1228 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1229 | /// objc-class-instance-variables: |
| 1230 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 1231 | /// |
| 1232 | /// objc-instance-variable-decl-list: |
| 1233 | /// objc-visibility-spec |
| 1234 | /// objc-instance-variable-decl ';' |
| 1235 | /// ';' |
| 1236 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 1237 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 1238 | /// objc-instance-variable-decl-list ';' |
| 1239 | /// |
| 1240 | /// objc-visibility-spec: |
| 1241 | /// @private |
| 1242 | /// @protected |
| 1243 | /// @public |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1244 | /// @package [OBJC2] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1245 | /// |
| 1246 | /// objc-instance-variable-decl: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | /// struct-declaration |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1248 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1249 | void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1250 | tok::ObjCKeywordKind visibility, |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1251 | SourceLocation atLoc) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1252 | assert(Tok.is(tok::l_brace) && "expected {"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1253 | SmallVector<Decl *, 32> AllIvarDecls; |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | 45a33ec | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 1255 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
Argyrios Kyrtzidis | 9321ad3 | 2011-10-06 23:23:20 +0000 | [diff] [blame] | 1256 | ObjCDeclContextSwitch ObjCDC(*this); |
Douglas Gregor | 82ac25e | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 1257 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 1258 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 1259 | T.consumeOpen(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1260 | // While we still have something to read, read the instance variables. |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 1261 | while (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1262 | // Each iteration of this loop reads one objc-instance-variable-decl. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1264 | // Check for extraneous top-level semicolon. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1265 | if (Tok.is(tok::semi)) { |
Richard Trieu | 2f7dc46 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 1266 | ConsumeExtraSemi(InstanceVariableList); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1267 | continue; |
| 1268 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1269 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1270 | // Set the default visibility to private. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1271 | if (TryConsumeToken(tok::at)) { // parse objc-visibility-spec |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1272 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1273 | Actions.CodeCompleteObjCAtVisibility(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1274 | return cutOffParsing(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1277 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1278 | case tok::objc_private: |
| 1279 | case tok::objc_public: |
| 1280 | case tok::objc_protected: |
| 1281 | case tok::objc_package: |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1282 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1283 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | continue; |
Fariborz Jahanian | 0b17193 | 2013-03-20 18:45:49 +0000 | [diff] [blame] | 1285 | |
| 1286 | case tok::objc_end: |
| 1287 | Diag(Tok, diag::err_objc_unexpected_atend); |
Fariborz Jahanian | 089f39e | 2013-03-20 18:09:33 +0000 | [diff] [blame] | 1288 | Tok.setLocation(Tok.getLocation().getLocWithOffset(-1)); |
| 1289 | Tok.setKind(tok::at); |
| 1290 | Tok.setLength(1); |
| 1291 | PP.EnterToken(Tok); |
| 1292 | HelperActionsForIvarDeclarations(interfaceDecl, atLoc, |
| 1293 | T, AllIvarDecls, true); |
| 1294 | return; |
Fariborz Jahanian | 0b17193 | 2013-03-20 18:45:49 +0000 | [diff] [blame] | 1295 | |
| 1296 | default: |
| 1297 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
| 1298 | continue; |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1299 | } |
| 1300 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1302 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1303 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1304 | Sema::PCC_ObjCInstanceVariableList); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1305 | return cutOffParsing(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1306 | } |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1307 | |
Benjamin Kramer | a39beb9 | 2014-09-03 11:06:10 +0000 | [diff] [blame] | 1308 | auto ObjCIvarCallback = [&](ParsingFieldDeclarator &FD) { |
| 1309 | Actions.ActOnObjCContainerStartDefinition(interfaceDecl); |
| 1310 | // Install the declarator into the interface decl. |
| 1311 | Decl *Field = Actions.ActOnIvar( |
| 1312 | getCurScope(), FD.D.getDeclSpec().getSourceRange().getBegin(), FD.D, |
| 1313 | FD.BitfieldSize, visibility); |
| 1314 | Actions.ActOnObjCContainerFinishDefinition(); |
| 1315 | if (Field) |
| 1316 | AllIvarDecls.push_back(Field); |
| 1317 | FD.complete(Field); |
| 1318 | }; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1319 | |
Chris Lattner | a12405b | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1320 | // Parse all the comma separated declarators. |
Eli Friedman | 89b1f2c | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 1321 | ParsingDeclSpec DS(*this); |
Benjamin Kramer | a39beb9 | 2014-09-03 11:06:10 +0000 | [diff] [blame] | 1322 | ParseStructDeclaration(DS, ObjCIvarCallback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1324 | if (Tok.is(tok::semi)) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1325 | ConsumeToken(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1326 | } else { |
| 1327 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1328 | // Skip to end of block or statement |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1329 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1330 | } |
| 1331 | } |
Fariborz Jahanian | 089f39e | 2013-03-20 18:09:33 +0000 | [diff] [blame] | 1332 | HelperActionsForIvarDeclarations(interfaceDecl, atLoc, |
| 1333 | T, AllIvarDecls, false); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1334 | return; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1335 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1336 | |
| 1337 | /// objc-protocol-declaration: |
| 1338 | /// objc-protocol-definition |
| 1339 | /// objc-protocol-forward-reference |
| 1340 | /// |
| 1341 | /// objc-protocol-definition: |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 1342 | /// \@protocol identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1343 | /// objc-protocol-refs[opt] |
| 1344 | /// objc-interface-decl-list |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 1345 | /// \@end |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1346 | /// |
| 1347 | /// objc-protocol-forward-reference: |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 1348 | /// \@protocol identifier-list ';' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1349 | /// |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 1350 | /// "\@protocol identifier ;" should be resolved as "\@protocol |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1351 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1352 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1353 | Parser::DeclGroupPtrTy |
| 1354 | Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
| 1355 | ParsedAttributes &attrs) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1356 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1357 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 1358 | ConsumeToken(); // the "protocol" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1359 | |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1360 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1361 | Actions.CodeCompleteObjCProtocolDecl(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1362 | cutOffParsing(); |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1363 | return DeclGroupPtrTy(); |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 1366 | MaybeSkipAttributes(tok::objc_protocol); |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 1367 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1368 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1369 | Diag(Tok, diag::err_expected) << tok::identifier; // missing protocol name. |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1370 | return DeclGroupPtrTy(); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1371 | } |
| 1372 | // Save the protocol name, then consume it. |
| 1373 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 1374 | SourceLocation nameLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1375 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1376 | if (TryConsumeToken(tok::semi)) { // forward declaration of one protocol. |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1377 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1379 | attrs.getList()); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | |
Erik Verbruggen | f988785 | 2011-12-08 09:58:43 +0000 | [diff] [blame] | 1382 | CheckNestedObjCContexts(AtLoc); |
| 1383 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1384 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1385 | SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1386 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 1387 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1388 | // Parse the list of forward declarations. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1389 | while (1) { |
| 1390 | ConsumeToken(); // the ',' |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1391 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1392 | Diag(Tok, diag::err_expected) << tok::identifier; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1393 | SkipUntil(tok::semi); |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1394 | return DeclGroupPtrTy(); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1395 | } |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1396 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 1397 | Tok.getLocation())); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1398 | ConsumeToken(); // the identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1400 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1401 | break; |
| 1402 | } |
| 1403 | // Consume the ';'. |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1404 | if (ExpectAndConsume(tok::semi, diag::err_expected_after, "@protocol")) |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1405 | return DeclGroupPtrTy(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | |
Steve Naroff | 93eb5f1 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1407 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | &ProtocolRefs[0], |
Fariborz Jahanian | 1470e93 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1409 | ProtocolRefs.size(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1410 | attrs.getList()); |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1411 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1413 | // Last, and definitely not least, parse a protocol declaration. |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1414 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1415 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1416 | SmallVector<Decl *, 8> ProtocolRefs; |
| 1417 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1418 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1419 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, |
| 1420 | LAngleLoc, EndProtoLoc)) |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1421 | return DeclGroupPtrTy(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1422 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1423 | Decl *ProtoType = |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1424 | Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1425 | ProtocolRefs.data(), |
| 1426 | ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1427 | ProtocolLocs.data(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1428 | EndProtoLoc, attrs.getList()); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1429 | |
Fariborz Jahanian | b66de9f | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 1430 | ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType); |
Douglas Gregor | f610267 | 2012-01-01 21:23:57 +0000 | [diff] [blame] | 1431 | return Actions.ConvertDeclToDeclGroup(ProtoType); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1432 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1433 | |
| 1434 | /// objc-implementation: |
| 1435 | /// objc-class-implementation-prologue |
| 1436 | /// objc-category-implementation-prologue |
| 1437 | /// |
| 1438 | /// objc-class-implementation-prologue: |
| 1439 | /// @implementation identifier objc-superclass[opt] |
| 1440 | /// objc-class-instance-variables[opt] |
| 1441 | /// |
| 1442 | /// objc-category-implementation-prologue: |
| 1443 | /// @implementation identifier ( identifier ) |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1444 | Parser::DeclGroupPtrTy |
| 1445 | Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1446 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 1447 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 1448 | CheckNestedObjCContexts(AtLoc); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1449 | ConsumeToken(); // the "implementation" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1450 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1451 | // Code completion after '@implementation'. |
| 1452 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1453 | Actions.CodeCompleteObjCImplementationDecl(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1454 | cutOffParsing(); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1455 | return DeclGroupPtrTy(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Nico Weber | 69a7914 | 2013-04-04 00:15:10 +0000 | [diff] [blame] | 1458 | MaybeSkipAttributes(tok::objc_implementation); |
Nico Weber | 04e213b | 2013-04-03 17:36:11 +0000 | [diff] [blame] | 1459 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1460 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1461 | Diag(Tok, diag::err_expected) |
| 1462 | << tok::identifier; // missing class or category name. |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1463 | return DeclGroupPtrTy(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1464 | } |
| 1465 | // We have a class or category name - consume it. |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1466 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1467 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1468 | Decl *ObjCImpDecl = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1469 | |
| 1470 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1471 | // we have a category implementation. |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1472 | ConsumeParen(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1473 | SourceLocation categoryLoc, rparenLoc; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1474 | IdentifierInfo *categoryId = nullptr; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1475 | |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1476 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1477 | Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1478 | cutOffParsing(); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1479 | return DeclGroupPtrTy(); |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1482 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1483 | categoryId = Tok.getIdentifierInfo(); |
| 1484 | categoryLoc = ConsumeToken(); |
| 1485 | } else { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1486 | Diag(Tok, diag::err_expected) |
| 1487 | << tok::identifier; // missing category name. |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1488 | return DeclGroupPtrTy(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1489 | } |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1490 | if (Tok.isNot(tok::r_paren)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1491 | Diag(Tok, diag::err_expected) << tok::r_paren; |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1492 | SkipUntil(tok::r_paren); // don't stop at ';' |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1493 | return DeclGroupPtrTy(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1494 | } |
| 1495 | rparenLoc = ConsumeParen(); |
Fariborz Jahanian | 8588855 | 2013-05-17 17:58:11 +0000 | [diff] [blame] | 1496 | if (Tok.is(tok::less)) { // we have illegal '<' try to recover |
| 1497 | Diag(Tok, diag::err_unexpected_protocol_qualifier); |
| 1498 | AttributeFactory attr; |
| 1499 | DeclSpec DS(attr); |
| 1500 | (void)ParseObjCProtocolQualifiers(DS); |
| 1501 | } |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1502 | ObjCImpDecl = Actions.ActOnStartCategoryImplementation( |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 1503 | AtLoc, nameId, nameLoc, categoryId, |
Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1504 | categoryLoc); |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1505 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1506 | } else { |
| 1507 | // We have a class implementation |
| 1508 | SourceLocation superClassLoc; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1509 | IdentifierInfo *superClassId = nullptr; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1510 | if (TryConsumeToken(tok::colon)) { |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1511 | // We have a super class |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1512 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1513 | Diag(Tok, diag::err_expected) |
| 1514 | << tok::identifier; // missing super class name. |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1515 | return DeclGroupPtrTy(); |
| 1516 | } |
| 1517 | superClassId = Tok.getIdentifierInfo(); |
| 1518 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1519 | } |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1520 | ObjCImpDecl = Actions.ActOnStartClassImplementation( |
| 1521 | AtLoc, nameId, nameLoc, |
| 1522 | superClassId, superClassLoc); |
| 1523 | |
| 1524 | if (Tok.is(tok::l_brace)) // we have ivars |
| 1525 | ParseObjCClassInstanceVariables(ObjCImpDecl, tok::objc_private, AtLoc); |
Fariborz Jahanian | 46ed4d9 | 2013-04-24 23:23:47 +0000 | [diff] [blame] | 1526 | else if (Tok.is(tok::less)) { // we have illegal '<' try to recover |
| 1527 | Diag(Tok, diag::err_unexpected_protocol_qualifier); |
| 1528 | // try to recover. |
| 1529 | AttributeFactory attr; |
| 1530 | DeclSpec DS(attr); |
| 1531 | (void)ParseObjCProtocolQualifiers(DS); |
| 1532 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1533 | } |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1534 | assert(ObjCImpDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1536 | SmallVector<Decl *, 8> DeclsInGroup; |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1537 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1538 | { |
| 1539 | ObjCImplParsingDataRAII ObjCImplParsing(*this, ObjCImpDecl); |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 1540 | while (!ObjCImplParsing.isFinished() && !isEofOrEom()) { |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1541 | ParsedAttributesWithRange attrs(AttrFactory); |
Richard Smith | 89645bc | 2013-01-02 12:01:23 +0000 | [diff] [blame] | 1542 | MaybeParseCXX11Attributes(attrs); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1543 | MaybeParseMicrosoftAttributes(attrs); |
| 1544 | if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) { |
| 1545 | DeclGroupRef DG = DGP.get(); |
| 1546 | DeclsInGroup.append(DG.begin(), DG.end()); |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
Argyrios Kyrtzidis | 2e85c5f | 2012-02-23 21:11:20 +0000 | [diff] [blame] | 1551 | return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1552 | } |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1553 | |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1554 | Parser::DeclGroupPtrTy |
| 1555 | Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1556 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 1557 | "ParseObjCAtEndDeclaration(): Expected @end"); |
| 1558 | ConsumeToken(); // the "end" identifier |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1559 | if (CurParsedObjCImpl) |
| 1560 | CurParsedObjCImpl->finish(atEnd); |
Fariborz Jahanian | 97d744b | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 1561 | else |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1562 | // missing @implementation |
Erik Verbruggen | c6c8d93 | 2011-12-06 09:25:23 +0000 | [diff] [blame] | 1563 | Diag(atEnd.getBegin(), diag::err_expected_objc_container); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1564 | return DeclGroupPtrTy(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1565 | } |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1566 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1567 | Parser::ObjCImplParsingDataRAII::~ObjCImplParsingDataRAII() { |
| 1568 | if (!Finished) { |
| 1569 | finish(P.Tok.getLocation()); |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 1570 | if (P.isEofOrEom()) { |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1571 | P.Diag(P.Tok, diag::err_objc_missing_end) |
| 1572 | << FixItHint::CreateInsertion(P.Tok.getLocation(), "\n@end\n"); |
| 1573 | P.Diag(Dcl->getLocStart(), diag::note_objc_container_start) |
| 1574 | << Sema::OCK_Implementation; |
| 1575 | } |
| 1576 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1577 | P.CurParsedObjCImpl = nullptr; |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1578 | assert(LateParsedObjCMethods.empty()); |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1581 | void Parser::ObjCImplParsingDataRAII::finish(SourceRange AtEnd) { |
| 1582 | assert(!Finished); |
| 1583 | P.Actions.DefaultSynthesizeProperties(P.getCurScope(), Dcl); |
| 1584 | for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1585 | P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], |
| 1586 | true/*Methods*/); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1587 | |
| 1588 | P.Actions.ActOnAtEnd(P.getCurScope(), AtEnd); |
| 1589 | |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1590 | if (HasCFunction) |
| 1591 | for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) |
| 1592 | P.ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i], |
| 1593 | false/*c-functions*/); |
| 1594 | |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1595 | /// \brief Clear and free the cached objc methods. |
Argyrios Kyrtzidis | 004685b | 2011-11-29 08:14:54 +0000 | [diff] [blame] | 1596 | for (LateParsedObjCMethodContainer::iterator |
| 1597 | I = LateParsedObjCMethods.begin(), |
| 1598 | E = LateParsedObjCMethods.end(); I != E; ++I) |
| 1599 | delete *I; |
| 1600 | LateParsedObjCMethods.clear(); |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1601 | |
| 1602 | Finished = true; |
Argyrios Kyrtzidis | 004685b | 2011-11-29 08:14:54 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1605 | /// compatibility-alias-decl: |
| 1606 | /// @compatibility_alias alias-name class-name ';' |
| 1607 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1608 | Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1609 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1610 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1611 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1612 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1613 | Diag(Tok, diag::err_expected) << tok::identifier; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1614 | return nullptr; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1615 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1616 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1617 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1618 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1619 | Diag(Tok, diag::err_expected) << tok::identifier; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1620 | return nullptr; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1621 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1622 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1623 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1624 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@compatibility_alias"); |
Richard Smith | ac4e36d | 2012-08-08 23:32:13 +0000 | [diff] [blame] | 1625 | return Actions.ActOnCompatibilityAlias(atLoc, aliasId, aliasLoc, |
| 1626 | classId, classLoc); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1629 | /// property-synthesis: |
| 1630 | /// @synthesize property-ivar-list ';' |
| 1631 | /// |
| 1632 | /// property-ivar-list: |
| 1633 | /// property-ivar |
| 1634 | /// property-ivar-list ',' property-ivar |
| 1635 | /// |
| 1636 | /// property-ivar: |
| 1637 | /// identifier |
| 1638 | /// identifier '=' identifier |
| 1639 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1640 | Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1641 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
Fariborz Jahanian | d56a262 | 2013-04-29 15:35:35 +0000 | [diff] [blame] | 1642 | "ParseObjCPropertySynthesize(): Expected '@synthesize'"); |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1643 | ConsumeToken(); // consume synthesize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1645 | while (true) { |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1646 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1647 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1648 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1649 | return nullptr; |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1652 | if (Tok.isNot(tok::identifier)) { |
| 1653 | Diag(Tok, diag::err_synthesized_property_name); |
| 1654 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1655 | return nullptr; |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1656 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1657 | |
| 1658 | IdentifierInfo *propertyIvar = nullptr; |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1659 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1660 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1661 | SourceLocation propertyIvarLoc; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1662 | if (TryConsumeToken(tok::equal)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1663 | // property '=' ivar-name |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1664 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1665 | Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1666 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1667 | return nullptr; |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1670 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1671 | Diag(Tok, diag::err_expected) << tok::identifier; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1672 | break; |
| 1673 | } |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1674 | propertyIvar = Tok.getIdentifierInfo(); |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1675 | propertyIvarLoc = ConsumeToken(); // consume ivar-name |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1676 | } |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1677 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1678 | propertyId, propertyIvar, propertyIvarLoc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1679 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1680 | break; |
| 1681 | ConsumeToken(); // consume ',' |
| 1682 | } |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1683 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@synthesize"); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1684 | return nullptr; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1687 | /// property-dynamic: |
| 1688 | /// @dynamic property-list |
| 1689 | /// |
| 1690 | /// property-list: |
| 1691 | /// identifier |
| 1692 | /// property-list ',' identifier |
| 1693 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1694 | Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1695 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1696 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1697 | ConsumeToken(); // consume dynamic |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1698 | while (true) { |
| 1699 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1700 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1701 | cutOffParsing(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1702 | return nullptr; |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | if (Tok.isNot(tok::identifier)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1706 | Diag(Tok, diag::err_expected) << tok::identifier; |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1707 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1708 | return nullptr; |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1711 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1712 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1713 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1714 | propertyId, nullptr, SourceLocation()); |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1715 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1716 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1717 | break; |
| 1718 | ConsumeToken(); // consume ',' |
| 1719 | } |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1720 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@dynamic"); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1721 | return nullptr; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1722 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1723 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1724 | /// objc-throw-statement: |
| 1725 | /// throw expression[opt]; |
| 1726 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1727 | StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 1728 | ExprResult Res; |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1729 | ConsumeToken(); // consume throw |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1730 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | adfbbc3 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1731 | Res = ParseExpression(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1732 | if (Res.isInvalid()) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1733 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1734 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1735 | } |
| 1736 | } |
Ted Kremenek | 15a81e5 | 2010-04-20 21:21:51 +0000 | [diff] [blame] | 1737 | // consume ';' |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 1738 | ExpectAndConsume(tok::semi, diag::err_expected_after, "@throw"); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1739 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.get(), getCurScope()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1742 | /// objc-synchronized-statement: |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1743 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1744 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1745 | StmtResult |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1746 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1747 | ConsumeToken(); // consume synchronized |
| 1748 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1749 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1750 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1751 | } |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1752 | |
| 1753 | // The operand is surrounded with parentheses. |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1754 | ConsumeParen(); // '(' |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1755 | ExprResult operand(ParseExpression()); |
| 1756 | |
| 1757 | if (Tok.is(tok::r_paren)) { |
| 1758 | ConsumeParen(); // ')' |
| 1759 | } else { |
| 1760 | if (!operand.isInvalid()) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1761 | Diag(Tok, diag::err_expected) << tok::r_paren; |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1762 | |
| 1763 | // Skip forward until we see a left brace, but don't consume it. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1764 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1765 | } |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1766 | |
| 1767 | // Require a compound statement. |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1768 | if (Tok.isNot(tok::l_brace)) { |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1769 | if (!operand.isInvalid()) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1770 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1771 | return StmtError(); |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1772 | } |
Steve Naroff | d9c2607 | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1773 | |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1774 | // Check the @synchronized operand now. |
| 1775 | if (!operand.isInvalid()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1776 | operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.get()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1777 | |
John McCall | d9bb743 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1778 | // Parse the compound statement within a new scope. |
| 1779 | ParseScope bodyScope(this, Scope::DeclScope); |
| 1780 | StmtResult body(ParseCompoundStatementBody()); |
| 1781 | bodyScope.Exit(); |
| 1782 | |
| 1783 | // If there was a semantic or parse error earlier with the |
| 1784 | // operand, fail now. |
| 1785 | if (operand.isInvalid()) |
| 1786 | return StmtError(); |
| 1787 | |
| 1788 | if (body.isInvalid()) |
| 1789 | body = Actions.ActOnNullStmt(Tok.getLocation()); |
| 1790 | |
| 1791 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get()); |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1794 | /// objc-try-catch-statement: |
| 1795 | /// @try compound-statement objc-catch-list[opt] |
| 1796 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1797 | /// |
| 1798 | /// objc-catch-list: |
| 1799 | /// @catch ( parameter-declaration ) compound-statement |
| 1800 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1801 | /// catch-parameter-declaration: |
| 1802 | /// parameter-declaration |
| 1803 | /// '...' [OBJC2] |
| 1804 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1805 | StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1806 | bool catch_or_finally_seen = false; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1807 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1808 | ConsumeToken(); // consume try |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1809 | if (Tok.isNot(tok::l_brace)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1810 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1811 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1812 | } |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 1813 | StmtVector CatchStmts; |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1814 | StmtResult FinallyStmt; |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1815 | ParseScope TryScope(this, Scope::DeclScope); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1816 | StmtResult TryBody(ParseCompoundStatementBody()); |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1817 | TryScope.Exit(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1818 | if (TryBody.isInvalid()) |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1819 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1820 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1821 | while (Tok.is(tok::at)) { |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1822 | // At this point, we need to lookahead to determine if this @ is the start |
| 1823 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1824 | // is an @try or @encode or something else. |
| 1825 | Token AfterAt = GetLookAheadToken(1); |
| 1826 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1827 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1828 | break; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1829 | |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1830 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1831 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1832 | Decl *FirstPart = nullptr; |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1833 | ConsumeToken(); // consume catch |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1834 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1835 | ConsumeParen(); |
Steve Naroff | 5ee2c02 | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1836 | ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1837 | if (Tok.isNot(tok::ellipsis)) { |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1838 | DeclSpec DS(AttrFactory); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1839 | ParseDeclarationSpecifiers(DS); |
Argyrios Kyrtzidis | 7745069 | 2011-07-01 22:22:40 +0000 | [diff] [blame] | 1840 | Declarator ParmDecl(DS, Declarator::ObjCCatchContext); |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1841 | ParseDeclarator(ParmDecl); |
| 1842 | |
Douglas Gregor | e11ee11 | 2010-04-23 23:01:43 +0000 | [diff] [blame] | 1843 | // Inform the actions module about the declarator, so it |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1844 | // gets added to the current scope. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1845 | FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1846 | } else |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1847 | ConsumeToken(); // consume '...' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1848 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1849 | SourceLocation RParenLoc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1850 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1851 | if (Tok.is(tok::r_paren)) |
| 1852 | RParenLoc = ConsumeParen(); |
| 1853 | else // Skip over garbage, until we get to ')'. Eat the ')'. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1854 | SkipUntil(tok::r_paren, StopAtSemi); |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1855 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1856 | StmtResult CatchBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1857 | if (Tok.is(tok::l_brace)) |
| 1858 | CatchBody = ParseCompoundStatementBody(); |
| 1859 | else |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1860 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1861 | if (CatchBody.isInvalid()) |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1862 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1863 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1864 | StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1865 | RParenLoc, |
| 1866 | FirstPart, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1867 | CatchBody.get()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1868 | if (!Catch.isInvalid()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1869 | CatchStmts.push_back(Catch.get()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1870 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1871 | } else { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1872 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 1873 | << "@catch clause"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1874 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1875 | } |
| 1876 | catch_or_finally_seen = true; |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1877 | } else { |
| 1878 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1879 | ConsumeToken(); // consume finally |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1880 | ParseScope FinallyScope(this, Scope::DeclScope); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1881 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1882 | StmtResult FinallyBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1883 | if (Tok.is(tok::l_brace)) |
| 1884 | FinallyBody = ParseCompoundStatementBody(); |
| 1885 | else |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1886 | Diag(Tok, diag::err_expected) << tok::l_brace; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1887 | if (FinallyBody.isInvalid()) |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1888 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1889 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1890 | FinallyBody.get()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1891 | catch_or_finally_seen = true; |
| 1892 | break; |
| 1893 | } |
| 1894 | } |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1895 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1896 | Diag(atLoc, diag::err_missing_catch_finally); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1897 | return StmtError(); |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1898 | } |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1899 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1900 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.get(), |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 1901 | CatchStmts, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1902 | FinallyStmt.get()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1903 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1904 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1905 | /// objc-autoreleasepool-statement: |
| 1906 | /// @autoreleasepool compound-statement |
| 1907 | /// |
| 1908 | StmtResult |
| 1909 | Parser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { |
| 1910 | ConsumeToken(); // consume autoreleasepool |
| 1911 | if (Tok.isNot(tok::l_brace)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1912 | Diag(Tok, diag::err_expected) << tok::l_brace; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1913 | return StmtError(); |
| 1914 | } |
| 1915 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1916 | // statements can always hold declarations. |
| 1917 | ParseScope BodyScope(this, Scope::DeclScope); |
| 1918 | |
| 1919 | StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); |
| 1920 | |
| 1921 | BodyScope.Exit(); |
| 1922 | if (AutoreleasePoolBody.isInvalid()) |
| 1923 | AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 1924 | return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1925 | AutoreleasePoolBody.get()); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1928 | /// StashAwayMethodOrFunctionBodyTokens - Consume the tokens and store them |
| 1929 | /// for later parsing. |
| 1930 | void Parser::StashAwayMethodOrFunctionBodyTokens(Decl *MDecl) { |
| 1931 | LexedMethod* LM = new LexedMethod(this, MDecl); |
| 1932 | CurParsedObjCImpl->LateParsedObjCMethods.push_back(LM); |
| 1933 | CachedTokens &Toks = LM->Toks; |
Fariborz Jahanian | f64b472 | 2012-08-10 21:15:06 +0000 | [diff] [blame] | 1934 | // Begin by storing the '{' or 'try' or ':' token. |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1935 | Toks.push_back(Tok); |
Fariborz Jahanian | 8cecfe9 | 2012-08-10 18:10:56 +0000 | [diff] [blame] | 1936 | if (Tok.is(tok::kw_try)) { |
| 1937 | ConsumeToken(); |
Fariborz Jahanian | 053227f | 2012-08-10 20:34:17 +0000 | [diff] [blame] | 1938 | if (Tok.is(tok::colon)) { |
| 1939 | Toks.push_back(Tok); |
| 1940 | ConsumeToken(); |
| 1941 | while (Tok.isNot(tok::l_brace)) { |
| 1942 | ConsumeAndStoreUntil(tok::l_paren, Toks, /*StopAtSemi=*/false); |
| 1943 | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
| 1944 | } |
| 1945 | } |
Fariborz Jahanian | f64b472 | 2012-08-10 21:15:06 +0000 | [diff] [blame] | 1946 | Toks.push_back(Tok); // also store '{' |
| 1947 | } |
| 1948 | else if (Tok.is(tok::colon)) { |
| 1949 | ConsumeToken(); |
| 1950 | while (Tok.isNot(tok::l_brace)) { |
| 1951 | ConsumeAndStoreUntil(tok::l_paren, Toks, /*StopAtSemi=*/false); |
| 1952 | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
| 1953 | } |
Fariborz Jahanian | 8cecfe9 | 2012-08-10 18:10:56 +0000 | [diff] [blame] | 1954 | Toks.push_back(Tok); // also store '{' |
| 1955 | } |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1956 | ConsumeBrace(); |
| 1957 | // Consume everything up to (and including) the matching right brace. |
| 1958 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Fariborz Jahanian | 8cecfe9 | 2012-08-10 18:10:56 +0000 | [diff] [blame] | 1959 | while (Tok.is(tok::kw_catch)) { |
| 1960 | ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false); |
| 1961 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
| 1962 | } |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1965 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1966 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1967 | Decl *Parser::ParseObjCMethodDefinition() { |
Fariborz Jahanian | 8d382dc | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1968 | Decl *MDecl = ParseObjCMethodPrototype(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1969 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1970 | PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), |
| 1971 | "parsing Objective-C method"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1972 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1973 | // parse optional ';' |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1974 | if (Tok.is(tok::semi)) { |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1975 | if (CurParsedObjCImpl) { |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1976 | Diag(Tok, diag::warn_semicolon_before_method_body) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1977 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1978 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1979 | ConsumeToken(); |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1980 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1981 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1982 | // We should have an opening brace now. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1983 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | 83777fe | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1984 | Diag(Tok, diag::err_expected_method_body); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1985 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1986 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1987 | SkipUntil(tok::l_brace, StopAtSemi | StopBeforeMatch); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1988 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1989 | // If we didn't find the '{', bail out. |
| 1990 | if (Tok.isNot(tok::l_brace)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1991 | return nullptr; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1992 | } |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1993 | |
| 1994 | if (!MDecl) { |
| 1995 | ConsumeBrace(); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1996 | SkipUntil(tok::r_brace); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1997 | return nullptr; |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2000 | // Allow the rest of sema to find private method decl implementations. |
Argyrios Kyrtzidis | b6c6a58 | 2012-02-07 16:50:53 +0000 | [diff] [blame] | 2001 | Actions.AddAnyMethodToGlobalPool(MDecl); |
Fariborz Jahanian | db5743d | 2012-08-09 17:15:00 +0000 | [diff] [blame] | 2002 | assert (CurParsedObjCImpl |
| 2003 | && "ParseObjCMethodDefinition - Method out of @implementation"); |
| 2004 | // Consume the tokens and store them for later parsing. |
| 2005 | StashAwayMethodOrFunctionBodyTokens(MDecl); |
Steve Naroff | 7b8fa47 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 2006 | return MDecl; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 2007 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2008 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2009 | StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 2010 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2011 | Actions.CodeCompleteObjCAtStatement(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2012 | cutOffParsing(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 2013 | return StmtError(); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | if (Tok.isObjCAtKeyword(tok::objc_try)) |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 2017 | return ParseObjCTryStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 2018 | |
| 2019 | if (Tok.isObjCAtKeyword(tok::objc_throw)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2020 | return ParseObjCThrowStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 2021 | |
| 2022 | if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2023 | return ParseObjCSynchronizedStmt(AtLoc); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2024 | |
| 2025 | if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) |
| 2026 | return ParseObjCAutoreleasePoolStmt(AtLoc); |
Sean Callanan | 8759649 | 2014-12-09 23:47:56 +0000 | [diff] [blame^] | 2027 | |
| 2028 | if (Tok.isObjCAtKeyword(tok::objc_import) && |
| 2029 | getLangOpts().DebuggerSupport) { |
| 2030 | SkipUntil(tok::semi); |
| 2031 | return Actions.ActOnNullStmt(Tok.getLocation()); |
| 2032 | } |
| 2033 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2034 | ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2035 | if (Res.isInvalid()) { |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2036 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 2037 | // doing this opens us up to the possibility of infinite loops if |
| 2038 | // ParseExpression does not consume any tokens. |
| 2039 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 2040 | return StmtError(); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2041 | } |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 2042 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2043 | // Otherwise, eat the semicolon. |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 2044 | ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); |
Richard Smith | 945f8d3 | 2013-01-14 22:39:08 +0000 | [diff] [blame] | 2045 | return Actions.ActOnExprStmt(Res); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2048 | ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2049 | switch (Tok.getKind()) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 2050 | case tok::code_completion: |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2051 | Actions.CodeCompleteObjCAtExpression(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2052 | cutOffParsing(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 2053 | return ExprError(); |
| 2054 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2055 | case tok::minus: |
| 2056 | case tok::plus: { |
| 2057 | tok::TokenKind Kind = Tok.getKind(); |
| 2058 | SourceLocation OpLoc = ConsumeToken(); |
| 2059 | |
| 2060 | if (!Tok.is(tok::numeric_constant)) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2061 | const char *Symbol = nullptr; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2062 | switch (Kind) { |
| 2063 | case tok::minus: Symbol = "-"; break; |
| 2064 | case tok::plus: Symbol = "+"; break; |
| 2065 | default: llvm_unreachable("missing unary operator case"); |
| 2066 | } |
| 2067 | Diag(Tok, diag::err_nsnumber_nonliteral_unary) |
| 2068 | << Symbol; |
| 2069 | return ExprError(); |
| 2070 | } |
| 2071 | |
| 2072 | ExprResult Lit(Actions.ActOnNumericConstant(Tok)); |
| 2073 | if (Lit.isInvalid()) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2074 | return Lit; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2075 | } |
Benjamin Kramer | e6a4aff | 2012-03-07 00:14:40 +0000 | [diff] [blame] | 2076 | ConsumeToken(); // Consume the literal token. |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2077 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2078 | Lit = Actions.ActOnUnaryOp(getCurScope(), OpLoc, Kind, Lit.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2079 | if (Lit.isInvalid()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2080 | return Lit; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2081 | |
| 2082 | return ParsePostfixExpressionSuffix( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2083 | Actions.BuildObjCNumericLiteral(AtLoc, Lit.get())); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2086 | case tok::string_literal: // primary-expression: string-literal |
| 2087 | case tok::wide_string_literal: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2088 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2089 | |
| 2090 | case tok::char_constant: |
| 2091 | return ParsePostfixExpressionSuffix(ParseObjCCharacterLiteral(AtLoc)); |
| 2092 | |
| 2093 | case tok::numeric_constant: |
| 2094 | return ParsePostfixExpressionSuffix(ParseObjCNumericLiteral(AtLoc)); |
| 2095 | |
| 2096 | case tok::kw_true: // Objective-C++, etc. |
| 2097 | case tok::kw___objc_yes: // c/c++/objc/objc++ __objc_yes |
| 2098 | return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, true)); |
| 2099 | case tok::kw_false: // Objective-C++, etc. |
| 2100 | case tok::kw___objc_no: // c/c++/objc/objc++ __objc_no |
| 2101 | return ParsePostfixExpressionSuffix(ParseObjCBooleanLiteral(AtLoc, false)); |
| 2102 | |
| 2103 | case tok::l_square: |
| 2104 | // Objective-C array literal |
| 2105 | return ParsePostfixExpressionSuffix(ParseObjCArrayLiteral(AtLoc)); |
| 2106 | |
| 2107 | case tok::l_brace: |
| 2108 | // Objective-C dictionary literal |
| 2109 | return ParsePostfixExpressionSuffix(ParseObjCDictionaryLiteral(AtLoc)); |
| 2110 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2111 | case tok::l_paren: |
| 2112 | // Objective-C boxed expression |
| 2113 | return ParsePostfixExpressionSuffix(ParseObjCBoxedExpr(AtLoc)); |
| 2114 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2115 | default: |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2116 | if (Tok.getIdentifierInfo() == nullptr) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2117 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Sebastian Redl | 59b5e51 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 2118 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2119 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 2120 | case tok::objc_encode: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2121 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2122 | case tok::objc_protocol: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2123 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2124 | case tok::objc_selector: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2125 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Fariborz Jahanian | 05d0d44 | 2012-07-09 20:00:35 +0000 | [diff] [blame] | 2126 | default: { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2127 | const char *str = nullptr; |
Fariborz Jahanian | 05d0d44 | 2012-07-09 20:00:35 +0000 | [diff] [blame] | 2128 | if (GetLookAheadToken(1).is(tok::l_brace)) { |
| 2129 | char ch = Tok.getIdentifierInfo()->getNameStart()[0]; |
| 2130 | str = |
| 2131 | ch == 't' ? "try" |
| 2132 | : (ch == 'f' ? "finally" |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2133 | : (ch == 'a' ? "autoreleasepool" : nullptr)); |
Fariborz Jahanian | 05d0d44 | 2012-07-09 20:00:35 +0000 | [diff] [blame] | 2134 | } |
| 2135 | if (str) { |
| 2136 | SourceLocation kwLoc = Tok.getLocation(); |
| 2137 | return ExprError(Diag(AtLoc, diag::err_unexpected_at) << |
| 2138 | FixItHint::CreateReplacement(kwLoc, str)); |
| 2139 | } |
| 2140 | else |
| 2141 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
| 2142 | } |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2143 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2144 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
Dmitri Gribenko | 00bcdd3 | 2012-09-12 17:01:48 +0000 | [diff] [blame] | 2147 | /// \brief Parse the receiver of an Objective-C++ message send. |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2148 | /// |
| 2149 | /// This routine parses the receiver of a message send in |
| 2150 | /// Objective-C++ either as a type or as an expression. Note that this |
| 2151 | /// routine must not be called to parse a send to 'super', since it |
| 2152 | /// has no way to return such a result. |
| 2153 | /// |
| 2154 | /// \param IsExpr Whether the receiver was parsed as an expression. |
| 2155 | /// |
| 2156 | /// \param TypeOrExpr If the receiver was parsed as an expression (\c |
| 2157 | /// IsExpr is true), the parsed expression. If the receiver was parsed |
| 2158 | /// as a type (\c IsExpr is false), the parsed type. |
| 2159 | /// |
| 2160 | /// \returns True if an error occurred during parsing or semantic |
| 2161 | /// analysis, in which case the arguments do not have valid |
| 2162 | /// values. Otherwise, returns false for a successful parse. |
| 2163 | /// |
| 2164 | /// objc-receiver: [C++] |
| 2165 | /// 'super' [not parsed here] |
| 2166 | /// expression |
| 2167 | /// simple-type-specifier |
| 2168 | /// typename-specifier |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2169 | bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2170 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2171 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2172 | if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || |
| 2173 | Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) |
| 2174 | TryAnnotateTypeOrScopeToken(); |
| 2175 | |
Kaelyn Uhrain | 237c7d3 | 2012-06-15 23:45:51 +0000 | [diff] [blame] | 2176 | if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) { |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2177 | // objc-receiver: |
| 2178 | // expression |
Kaelyn Takata | b16e632 | 2014-11-20 22:06:40 +0000 | [diff] [blame] | 2179 | // Make sure any typos in the receiver are corrected or diagnosed, so that |
| 2180 | // proper recovery can happen. FIXME: Perhaps filter the corrected expr to |
| 2181 | // only the things that are valid ObjC receivers? |
| 2182 | ExprResult Receiver = Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2183 | if (Receiver.isInvalid()) |
| 2184 | return true; |
| 2185 | |
| 2186 | IsExpr = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2187 | TypeOrExpr = Receiver.get(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2188 | return false; |
| 2189 | } |
| 2190 | |
| 2191 | // objc-receiver: |
| 2192 | // typename-specifier |
| 2193 | // simple-type-specifier |
| 2194 | // expression (that starts with one of the above) |
John McCall | 084e83d | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 2195 | DeclSpec DS(AttrFactory); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2196 | ParseCXXSimpleTypeSpecifier(DS); |
| 2197 | |
| 2198 | if (Tok.is(tok::l_paren)) { |
| 2199 | // If we see an opening parentheses at this point, we are |
| 2200 | // actually parsing an expression that starts with a |
| 2201 | // function-style cast, e.g., |
| 2202 | // |
| 2203 | // postfix-expression: |
| 2204 | // simple-type-specifier ( expression-list [opt] ) |
| 2205 | // typename-specifier ( expression-list [opt] ) |
| 2206 | // |
| 2207 | // Parse the remainder of this case, then the (optional) |
| 2208 | // postfix-expression suffix, followed by the (optional) |
| 2209 | // right-hand side of the binary expression. We have an |
| 2210 | // instance method. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2211 | ExprResult Receiver = ParseCXXTypeConstructExpression(DS); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2212 | if (!Receiver.isInvalid()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2213 | Receiver = ParsePostfixExpressionSuffix(Receiver.get()); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2214 | if (!Receiver.isInvalid()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2215 | Receiver = ParseRHSOfBinaryExpression(Receiver.get(), prec::Comma); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2216 | if (Receiver.isInvalid()) |
| 2217 | return true; |
| 2218 | |
| 2219 | IsExpr = true; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2220 | TypeOrExpr = Receiver.get(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2221 | return false; |
| 2222 | } |
| 2223 | |
| 2224 | // We have a class message. Turn the simple-type-specifier or |
| 2225 | // typename-specifier we parsed into a type and parse the |
| 2226 | // remainder of the class message. |
| 2227 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2228 | TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2229 | if (Type.isInvalid()) |
| 2230 | return true; |
| 2231 | |
| 2232 | IsExpr = false; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2233 | TypeOrExpr = Type.get().getAsOpaquePtr(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2234 | return false; |
| 2235 | } |
| 2236 | |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2237 | /// \brief Determine whether the parser is currently referring to a an |
| 2238 | /// Objective-C message send, using a simplified heuristic to avoid overhead. |
| 2239 | /// |
| 2240 | /// This routine will only return true for a subset of valid message-send |
| 2241 | /// expressions. |
| 2242 | bool Parser::isSimpleObjCMessageExpression() { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2243 | assert(Tok.is(tok::l_square) && getLangOpts().ObjC1 && |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2244 | "Incorrect start for isSimpleObjCMessageExpression"); |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2245 | return GetLookAheadToken(1).is(tok::identifier) && |
| 2246 | GetLookAheadToken(2).is(tok::identifier); |
| 2247 | } |
| 2248 | |
Douglas Gregor | abf4a3e | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 2249 | bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2250 | if (!getLangOpts().ObjC1 || !NextToken().is(tok::identifier) || |
Douglas Gregor | abf4a3e | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 2251 | InMessageExpression) |
| 2252 | return false; |
| 2253 | |
| 2254 | |
| 2255 | ParsedType Type; |
| 2256 | |
| 2257 | if (Tok.is(tok::annot_typename)) |
| 2258 | Type = getTypeAnnotation(Tok); |
| 2259 | else if (Tok.is(tok::identifier)) |
| 2260 | Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), |
| 2261 | getCurScope()); |
| 2262 | else |
| 2263 | return false; |
| 2264 | |
| 2265 | if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { |
| 2266 | const Token &AfterNext = GetLookAheadToken(2); |
| 2267 | if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { |
| 2268 | if (Tok.is(tok::identifier)) |
| 2269 | TryAnnotateTypeOrScopeToken(); |
| 2270 | |
| 2271 | return Tok.is(tok::annot_typename); |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | return false; |
| 2276 | } |
| 2277 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2278 | /// objc-message-expr: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2279 | /// '[' objc-receiver objc-message-args ']' |
| 2280 | /// |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2281 | /// objc-receiver: [C] |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 2282 | /// 'super' |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2283 | /// expression |
| 2284 | /// class-name |
| 2285 | /// type-name |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2286 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2287 | ExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2288 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 2289 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 2290 | |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 2291 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2292 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2293 | cutOffParsing(); |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 2294 | return ExprError(); |
| 2295 | } |
| 2296 | |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2297 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2298 | |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2299 | if (getLangOpts().CPlusPlus) { |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2300 | // We completely separate the C and C++ cases because C++ requires |
| 2301 | // more complicated (read: slower) parsing. |
| 2302 | |
| 2303 | // Handle send to super. |
| 2304 | // FIXME: This doesn't benefit from the same typo-correction we |
| 2305 | // get in Objective-C. |
| 2306 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2307 | NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2308 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2309 | ParsedType(), nullptr); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2310 | |
| 2311 | // Parse the receiver, which is either a type or an expression. |
| 2312 | bool IsExpr; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2313 | void *TypeOrExpr = nullptr; |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2314 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2315 | SkipUntil(tok::r_square, StopAtSemi); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2316 | return ExprError(); |
| 2317 | } |
| 2318 | |
| 2319 | if (IsExpr) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2320 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 2321 | ParsedType(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2322 | static_cast<Expr*>(TypeOrExpr)); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2323 | |
| 2324 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2325 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2326 | nullptr); |
Chris Lattner | 47054fb | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2330 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 2331 | SourceLocation NameLoc = Tok.getLocation(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2332 | ParsedType ReceiverType; |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2333 | switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2334 | Name == Ident_super, |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2335 | NextToken().is(tok::period), |
| 2336 | ReceiverType)) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2337 | case Sema::ObjCSuperMessage: |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2338 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2339 | ParsedType(), nullptr); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2340 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2341 | case Sema::ObjCClassMessage: |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2342 | if (!ReceiverType) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2343 | SkipUntil(tok::r_square, StopAtSemi); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2344 | return ExprError(); |
| 2345 | } |
| 2346 | |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2347 | ConsumeToken(); // the type name |
| 2348 | |
| 2349 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2350 | ReceiverType, nullptr); |
| 2351 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2352 | case Sema::ObjCInstanceMessage: |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2353 | // Fall through to parse an expression. |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2354 | break; |
Fariborz Jahanian | fc58ca4 | 2009-04-08 19:50:10 +0000 | [diff] [blame] | 2355 | } |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2356 | } |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 2357 | |
| 2358 | // Otherwise, an arbitrary expression can be the receiver of a send. |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 2359 | ExprResult Res = Actions.CorrectDelayedTyposInExpr(ParseExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2360 | if (Res.isInvalid()) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2361 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2362 | return Res; |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2363 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2364 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2365 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2366 | ParsedType(), Res.get()); |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2367 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2368 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2369 | /// \brief Parse the remainder of an Objective-C message following the |
| 2370 | /// '[' objc-receiver. |
| 2371 | /// |
| 2372 | /// This routine handles sends to super, class messages (sent to a |
| 2373 | /// class name), and instance messages (sent to an object), and the |
| 2374 | /// target is represented by \p SuperLoc, \p ReceiverType, or \p |
| 2375 | /// ReceiverExpr, respectively. Only one of these parameters may have |
| 2376 | /// a valid value. |
| 2377 | /// |
| 2378 | /// \param LBracLoc The location of the opening '['. |
| 2379 | /// |
| 2380 | /// \param SuperLoc If this is a send to 'super', the location of the |
| 2381 | /// 'super' keyword that indicates a send to the superclass. |
| 2382 | /// |
| 2383 | /// \param ReceiverType If this is a class message, the type of the |
| 2384 | /// class we are sending a message to. |
| 2385 | /// |
| 2386 | /// \param ReceiverExpr If this is an instance message, the expression |
| 2387 | /// used to compute the receiver object. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2388 | /// |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2389 | /// objc-message-args: |
| 2390 | /// objc-selector |
| 2391 | /// objc-keywordarg-list |
| 2392 | /// |
| 2393 | /// objc-keywordarg-list: |
| 2394 | /// objc-keywordarg |
| 2395 | /// objc-keywordarg-list objc-keywordarg |
| 2396 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2397 | /// objc-keywordarg: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2398 | /// selector-name[opt] ':' objc-keywordexpr |
| 2399 | /// |
| 2400 | /// objc-keywordexpr: |
| 2401 | /// nonempty-expr-list |
| 2402 | /// |
| 2403 | /// nonempty-expr-list: |
| 2404 | /// assignment-expression |
| 2405 | /// nonempty-expr-list , assignment-expression |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2406 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2407 | ExprResult |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2408 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2409 | SourceLocation SuperLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2410 | ParsedType ReceiverType, |
Craig Topper | a2c5153 | 2014-10-30 05:30:05 +0000 | [diff] [blame] | 2411 | Expr *ReceiverExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2412 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2413 | |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2414 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2415 | if (SuperLoc.isValid()) |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2416 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, None, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2417 | false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2418 | else if (ReceiverType) |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2419 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, None, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2420 | false); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2421 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2422 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2423 | None, false); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2424 | cutOffParsing(); |
| 2425 | return ExprError(); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2426 | } |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2427 | |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2428 | // Parse objc-selector |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 2429 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2430 | IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); |
Fariborz Jahanian | 02447d8 | 2013-01-22 18:35:43 +0000 | [diff] [blame] | 2431 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2432 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Argyrios Kyrtzidis | f934ec8 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2433 | SmallVector<SourceLocation, 12> KeyLocs; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2434 | ExprVector KeyExprs; |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2435 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2436 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2437 | while (1) { |
| 2438 | // Each iteration parses a single keyword argument. |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2439 | KeyIdents.push_back(selIdent); |
Argyrios Kyrtzidis | f934ec8 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2440 | KeyLocs.push_back(Loc); |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2441 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2442 | if (ExpectAndConsume(tok::colon)) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2443 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2444 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2445 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2446 | SkipUntil(tok::r_square, StopAtSemi); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2447 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2448 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2449 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2450 | /// Parse the expression after ':' |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2451 | |
| 2452 | if (Tok.is(tok::code_completion)) { |
| 2453 | if (SuperLoc.isValid()) |
| 2454 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2455 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2456 | /*AtArgumentEpression=*/true); |
| 2457 | else if (ReceiverType) |
| 2458 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2459 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2460 | /*AtArgumentEpression=*/true); |
| 2461 | else |
| 2462 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2463 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2464 | /*AtArgumentEpression=*/true); |
| 2465 | |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2466 | cutOffParsing(); |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2467 | return ExprError(); |
| 2468 | } |
| 2469 | |
Fariborz Jahanian | d5d6f3d | 2013-04-18 23:43:21 +0000 | [diff] [blame] | 2470 | ExprResult Expr; |
| 2471 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 2472 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 2473 | Expr = ParseBraceInitializer(); |
| 2474 | } else |
| 2475 | Expr = ParseAssignmentExpression(); |
| 2476 | |
| 2477 | ExprResult Res(Expr); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2478 | if (Res.isInvalid()) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2479 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2480 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2481 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2482 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2483 | return Res; |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2484 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2485 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2486 | // We have a valid expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2487 | KeyExprs.push_back(Res.get()); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2488 | |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2489 | // Code completion after each argument. |
| 2490 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2491 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2492 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2493 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2494 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2495 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2496 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2497 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2498 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2499 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2500 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2501 | KeyIdents, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2502 | /*AtArgumentEpression=*/false); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2503 | cutOffParsing(); |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2504 | return ExprError(); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2507 | // Check for another keyword selector. |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2508 | selIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2509 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2510 | break; |
| 2511 | // We have a selector or a colon, continue parsing. |
| 2512 | } |
| 2513 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2514 | while (Tok.is(tok::comma)) { |
Fariborz Jahanian | 945b2f4 | 2012-05-21 22:43:44 +0000 | [diff] [blame] | 2515 | SourceLocation commaLoc = ConsumeToken(); // Eat the ','. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2516 | /// Parse the expression after ',' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2517 | ExprResult Res(ParseAssignmentExpression()); |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 2518 | if (Tok.is(tok::colon)) |
| 2519 | Res = Actions.CorrectDelayedTyposInExpr(Res); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2520 | if (Res.isInvalid()) { |
Fariborz Jahanian | 945b2f4 | 2012-05-21 22:43:44 +0000 | [diff] [blame] | 2521 | if (Tok.is(tok::colon)) { |
| 2522 | Diag(commaLoc, diag::note_extra_comma_message_arg) << |
| 2523 | FixItHint::CreateRemoval(commaLoc); |
| 2524 | } |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2525 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2526 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2527 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2528 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2529 | return Res; |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2530 | } |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2531 | |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2532 | // We have a valid expression. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2533 | KeyExprs.push_back(Res.get()); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2534 | } |
| 2535 | } else if (!selIdent) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2536 | Diag(Tok, diag::err_expected) << tok::identifier; // missing selector name. |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2537 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2538 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2539 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2540 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2541 | SkipUntil(tok::r_square, StopAtSemi); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2542 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2543 | } |
Fariborz Jahanian | 083712f | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2544 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2545 | if (Tok.isNot(tok::r_square)) { |
Alp Toker | 35d8703 | 2013-12-30 23:29:50 +0000 | [diff] [blame] | 2546 | Diag(Tok, diag::err_expected) |
| 2547 | << (Tok.is(tok::identifier) ? tok::colon : tok::r_square); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2548 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2549 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2550 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2551 | SkipUntil(tok::r_square, StopAtSemi); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2552 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2553 | } |
Fariborz Jahanian | 02447d8 | 2013-01-22 18:35:43 +0000 | [diff] [blame] | 2554 | |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2555 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2556 | |
Steve Naroff | e61bfa8 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 2557 | unsigned nKeys = KeyIdents.size(); |
Argyrios Kyrtzidis | f934ec8 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2558 | if (nKeys == 0) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2559 | KeyIdents.push_back(selIdent); |
Argyrios Kyrtzidis | f934ec8 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2560 | KeyLocs.push_back(Loc); |
| 2561 | } |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2562 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2563 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2564 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2565 | return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2566 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2567 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2568 | return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2569 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2570 | return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2571 | LBracLoc, KeyLocs, RBracLoc, KeyExprs); |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2572 | } |
| 2573 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2574 | ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
| 2575 | ExprResult Res(ParseStringLiteralExpression()); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2576 | if (Res.isInvalid()) return Res; |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2577 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2578 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 2579 | // expressions. At this point, we know that the only valid thing that starts |
| 2580 | // with '@' is an @"". |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2581 | SmallVector<SourceLocation, 4> AtLocs; |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2582 | ExprVector AtStrings; |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2583 | AtLocs.push_back(AtLoc); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2584 | AtStrings.push_back(Res.get()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2585 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2586 | while (Tok.is(tok::at)) { |
| 2587 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2588 | |
Sebastian Redl | c13f268 | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 2589 | // Invalid unless there is a string literal. |
Chris Lattner | d3b5d5d | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 2590 | if (!isTokenStringLiteral()) |
| 2591 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2592 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2593 | ExprResult Lit(ParseStringLiteralExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2594 | if (Lit.isInvalid()) |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2595 | return Lit; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2596 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2597 | AtStrings.push_back(Lit.get()); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2598 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2599 | |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2600 | return Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.data(), |
| 2601 | AtStrings.size()); |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2602 | } |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2603 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2604 | /// ParseObjCBooleanLiteral - |
| 2605 | /// objc-scalar-literal : '@' boolean-keyword |
| 2606 | /// ; |
| 2607 | /// boolean-keyword: 'true' | 'false' | '__objc_yes' | '__objc_no' |
| 2608 | /// ; |
| 2609 | ExprResult Parser::ParseObjCBooleanLiteral(SourceLocation AtLoc, |
| 2610 | bool ArgValue) { |
| 2611 | SourceLocation EndLoc = ConsumeToken(); // consume the keyword. |
| 2612 | return Actions.ActOnObjCBoolLiteral(AtLoc, EndLoc, ArgValue); |
| 2613 | } |
| 2614 | |
| 2615 | /// ParseObjCCharacterLiteral - |
| 2616 | /// objc-scalar-literal : '@' character-literal |
| 2617 | /// ; |
| 2618 | ExprResult Parser::ParseObjCCharacterLiteral(SourceLocation AtLoc) { |
| 2619 | ExprResult Lit(Actions.ActOnCharacterConstant(Tok)); |
| 2620 | if (Lit.isInvalid()) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2621 | return Lit; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2622 | } |
Benjamin Kramer | e6a4aff | 2012-03-07 00:14:40 +0000 | [diff] [blame] | 2623 | ConsumeToken(); // Consume the literal token. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2624 | return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | /// ParseObjCNumericLiteral - |
| 2628 | /// objc-scalar-literal : '@' scalar-literal |
| 2629 | /// ; |
| 2630 | /// scalar-literal : | numeric-constant /* any numeric constant. */ |
| 2631 | /// ; |
| 2632 | ExprResult Parser::ParseObjCNumericLiteral(SourceLocation AtLoc) { |
| 2633 | ExprResult Lit(Actions.ActOnNumericConstant(Tok)); |
| 2634 | if (Lit.isInvalid()) { |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2635 | return Lit; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2636 | } |
Benjamin Kramer | e6a4aff | 2012-03-07 00:14:40 +0000 | [diff] [blame] | 2637 | ConsumeToken(); // Consume the literal token. |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2638 | return Actions.BuildObjCNumericLiteral(AtLoc, Lit.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2639 | } |
| 2640 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2641 | /// ParseObjCBoxedExpr - |
| 2642 | /// objc-box-expression: |
| 2643 | /// @( assignment-expression ) |
| 2644 | ExprResult |
| 2645 | Parser::ParseObjCBoxedExpr(SourceLocation AtLoc) { |
| 2646 | if (Tok.isNot(tok::l_paren)) |
| 2647 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@"); |
| 2648 | |
| 2649 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2650 | T.consumeOpen(); |
| 2651 | ExprResult ValueExpr(ParseAssignmentExpression()); |
| 2652 | if (T.consumeClose()) |
| 2653 | return ExprError(); |
Argyrios Kyrtzidis | 9b4fe35 | 2012-05-10 20:02:36 +0000 | [diff] [blame] | 2654 | |
| 2655 | if (ValueExpr.isInvalid()) |
| 2656 | return ExprError(); |
| 2657 | |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2658 | // Wrap the sub-expression in a parenthesized expression, to distinguish |
| 2659 | // a boxed expression from a literal. |
| 2660 | SourceLocation LPLoc = T.getOpenLocation(), RPLoc = T.getCloseLocation(); |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2661 | ValueExpr = Actions.ActOnParenExpr(LPLoc, RPLoc, ValueExpr.get()); |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2662 | return Actions.BuildObjCBoxedExpr(SourceRange(AtLoc, RPLoc), |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2663 | ValueExpr.get()); |
Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2666 | ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) { |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2667 | ExprVector ElementExprs; // array elements. |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2668 | ConsumeBracket(); // consume the l_square. |
| 2669 | |
| 2670 | while (Tok.isNot(tok::r_square)) { |
| 2671 | // Parse list of array element expressions (all must be id types). |
| 2672 | ExprResult Res(ParseAssignmentExpression()); |
| 2673 | if (Res.isInvalid()) { |
| 2674 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2675 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2676 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2677 | SkipUntil(tok::r_square, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2678 | return Res; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | // Parse the ellipsis that indicates a pack expansion. |
| 2682 | if (Tok.is(tok::ellipsis)) |
| 2683 | Res = Actions.ActOnPackExpansion(Res.get(), ConsumeToken()); |
| 2684 | if (Res.isInvalid()) |
| 2685 | return true; |
| 2686 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 2687 | ElementExprs.push_back(Res.get()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2688 | |
| 2689 | if (Tok.is(tok::comma)) |
| 2690 | ConsumeToken(); // Eat the ','. |
| 2691 | else if (Tok.isNot(tok::r_square)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2692 | return ExprError(Diag(Tok, diag::err_expected_either) << tok::r_square |
| 2693 | << tok::comma); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2694 | } |
| 2695 | SourceLocation EndLoc = ConsumeBracket(); // location of ']' |
Benjamin Kramer | f062343 | 2012-08-23 22:51:59 +0000 | [diff] [blame] | 2696 | MultiExprArg Args(ElementExprs); |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2697 | return Actions.BuildObjCArrayLiteral(SourceRange(AtLoc, EndLoc), Args); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | ExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) { |
| 2701 | SmallVector<ObjCDictionaryElement, 4> Elements; // dictionary elements. |
| 2702 | ConsumeBrace(); // consume the l_square. |
| 2703 | while (Tok.isNot(tok::r_brace)) { |
| 2704 | // Parse the comma separated key : value expressions. |
| 2705 | ExprResult KeyExpr; |
| 2706 | { |
| 2707 | ColonProtectionRAIIObject X(*this); |
| 2708 | KeyExpr = ParseAssignmentExpression(); |
| 2709 | if (KeyExpr.isInvalid()) { |
| 2710 | // We must manually skip to a '}', otherwise the expression skipper will |
| 2711 | // stop at the '}' when it skips to the ';'. We want it to skip beyond |
| 2712 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2713 | SkipUntil(tok::r_brace, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2714 | return KeyExpr; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2718 | if (ExpectAndConsume(tok::colon)) { |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2719 | SkipUntil(tok::r_brace, StopAtSemi); |
Fariborz Jahanian | 507a5f8 | 2013-04-18 19:37:43 +0000 | [diff] [blame] | 2720 | return ExprError(); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | ExprResult ValueExpr(ParseAssignmentExpression()); |
| 2724 | if (ValueExpr.isInvalid()) { |
| 2725 | // We must manually skip to a '}', otherwise the expression skipper will |
| 2726 | // stop at the '}' when it skips to the ';'. We want it to skip beyond |
| 2727 | // the enclosing expression. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 2728 | SkipUntil(tok::r_brace, StopAtSemi); |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 2729 | return ValueExpr; |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | // Parse the ellipsis that designates this as a pack expansion. |
| 2733 | SourceLocation EllipsisLoc; |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2734 | if (getLangOpts().CPlusPlus) |
| 2735 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 2736 | |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2737 | // We have a valid expression. Collect it in a vector so we can |
| 2738 | // build the argument list. |
| 2739 | ObjCDictionaryElement Element = { |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 2740 | KeyExpr.get(), ValueExpr.get(), EllipsisLoc, None |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2741 | }; |
| 2742 | Elements.push_back(Element); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2743 | |
| 2744 | if (!TryConsumeToken(tok::comma) && Tok.isNot(tok::r_brace)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2745 | return ExprError(Diag(Tok, diag::err_expected_either) << tok::r_brace |
| 2746 | << tok::comma); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2747 | } |
| 2748 | SourceLocation EndLoc = ConsumeBrace(); |
| 2749 | |
| 2750 | // Create the ObjCDictionaryLiteral. |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2751 | return Actions.BuildObjCDictionaryLiteral(SourceRange(AtLoc, EndLoc), |
| 2752 | Elements.data(), Elements.size()); |
Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2755 | /// objc-encode-expression: |
Dmitri Gribenko | 00bcdd3 | 2012-09-12 17:01:48 +0000 | [diff] [blame] | 2756 | /// \@encode ( type-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2757 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2758 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 2759 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2760 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2761 | SourceLocation EncLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2762 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2763 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2764 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 2765 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2766 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2767 | T.consumeOpen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2768 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2769 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2770 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2771 | T.consumeClose(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2772 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2773 | if (Ty.isInvalid()) |
| 2774 | return ExprError(); |
| 2775 | |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2776 | return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, T.getOpenLocation(), |
| 2777 | Ty.get(), T.getCloseLocation()); |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2778 | } |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2779 | |
| 2780 | /// objc-protocol-expression |
James Dennett | 1355bd1 | 2012-06-11 06:19:40 +0000 | [diff] [blame] | 2781 | /// \@protocol ( protocol-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2782 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2783 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2784 | SourceLocation ProtoLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2785 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2786 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2787 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 2788 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2789 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2790 | T.consumeOpen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2791 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2792 | if (Tok.isNot(tok::identifier)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2793 | return ExprError(Diag(Tok, diag::err_expected) << tok::identifier); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2794 | |
Fariborz Jahanian | a32aaef | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2795 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Argyrios Kyrtzidis | b7e4367 | 2012-05-16 00:50:02 +0000 | [diff] [blame] | 2796 | SourceLocation ProtoIdLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2797 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2798 | T.consumeClose(); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2799 | |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2800 | return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 2801 | T.getOpenLocation(), ProtoIdLoc, |
| 2802 | T.getCloseLocation()); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2803 | } |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2804 | |
| 2805 | /// objc-selector-expression |
Fariborz Jahanian | dacffc0 | 2014-06-24 17:02:19 +0000 | [diff] [blame] | 2806 | /// @selector '(' '('[opt] objc-keyword-selector ')'[opt] ')' |
Fariborz Jahanian | 02447d8 | 2013-01-22 18:35:43 +0000 | [diff] [blame] | 2807 | ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2808 | SourceLocation SelectorLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2809 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2810 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2811 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 2812 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2813 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2814 | SourceLocation sLoc; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2815 | |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2816 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2817 | T.consumeOpen(); |
Fariborz Jahanian | dacffc0 | 2014-06-24 17:02:19 +0000 | [diff] [blame] | 2818 | bool HasOptionalParen = Tok.is(tok::l_paren); |
| 2819 | if (HasOptionalParen) |
| 2820 | ConsumeParen(); |
| 2821 | |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2822 | if (Tok.is(tok::code_completion)) { |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2823 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2824 | cutOffParsing(); |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2825 | return ExprError(); |
| 2826 | } |
| 2827 | |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2828 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2829 | if (!SelIdent && // missing selector name. |
| 2830 | Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2831 | return ExprError(Diag(Tok, diag::err_expected) << tok::identifier); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2832 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2833 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | dacffc0 | 2014-06-24 17:02:19 +0000 | [diff] [blame] | 2834 | |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2835 | unsigned nColons = 0; |
| 2836 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2837 | while (1) { |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2838 | if (TryConsumeToken(tok::coloncolon)) { // Handle :: in C++. |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2839 | ++nColons; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2840 | KeyIdents.push_back(nullptr); |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2841 | } else if (ExpectAndConsume(tok::colon)) // Otherwise expect ':'. |
| 2842 | return ExprError(); |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2843 | ++nColons; |
Alp Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 2844 | |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2845 | if (Tok.is(tok::r_paren)) |
| 2846 | break; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2847 | |
| 2848 | if (Tok.is(tok::code_completion)) { |
Dmitri Gribenko | 070a10e | 2013-06-16 03:47:57 +0000 | [diff] [blame] | 2849 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents); |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2850 | cutOffParsing(); |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2851 | return ExprError(); |
| 2852 | } |
| 2853 | |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2854 | // Check for another keyword selector. |
| 2855 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2856 | SelIdent = ParseObjCSelectorPiece(Loc); |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2857 | KeyIdents.push_back(SelIdent); |
Chris Lattner | 85222c6 | 2011-03-26 18:11:38 +0000 | [diff] [blame] | 2858 | if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2859 | break; |
| 2860 | } |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2861 | } |
Fariborz Jahanian | dacffc0 | 2014-06-24 17:02:19 +0000 | [diff] [blame] | 2862 | if (HasOptionalParen && Tok.is(tok::r_paren)) |
| 2863 | ConsumeParen(); // ')' |
Douglas Gregor | e7a8e3b | 2011-10-12 16:37:45 +0000 | [diff] [blame] | 2864 | T.consumeClose(); |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2865 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Nico Weber | a7c7e60 | 2012-12-31 00:28:03 +0000 | [diff] [blame] | 2866 | return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 2867 | T.getOpenLocation(), |
Fariborz Jahanian | dacffc0 | 2014-06-24 17:02:19 +0000 | [diff] [blame] | 2868 | T.getCloseLocation(), |
| 2869 | !HasOptionalParen); |
Gabor Greif | 24032f1 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 2870 | } |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2871 | |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 2872 | void Parser::ParseLexedObjCMethodDefs(LexedMethod &LM, bool parseMethod) { |
| 2873 | // MCDecl might be null due to error in method or c-function prototype, etc. |
| 2874 | Decl *MCDecl = LM.D; |
| 2875 | bool skip = MCDecl && |
| 2876 | ((parseMethod && !Actions.isObjCMethodDecl(MCDecl)) || |
| 2877 | (!parseMethod && Actions.isObjCMethodDecl(MCDecl))); |
| 2878 | if (skip) |
| 2879 | return; |
| 2880 | |
Argyrios Kyrtzidis | 9a174fb | 2011-12-17 04:13:18 +0000 | [diff] [blame] | 2881 | // Save the current token position. |
| 2882 | SourceLocation OrigLoc = Tok.getLocation(); |
| 2883 | |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2884 | assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!"); |
| 2885 | // Append the current token at the end of the new token stream so that it |
| 2886 | // doesn't get lost. |
| 2887 | LM.Toks.push_back(Tok); |
| 2888 | PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); |
| 2889 | |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2890 | // Consume the previously pushed token. |
Argyrios Kyrtzidis | c36633c | 2013-03-27 23:58:17 +0000 | [diff] [blame] | 2891 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2892 | |
Fariborz Jahanian | f64b472 | 2012-08-10 21:15:06 +0000 | [diff] [blame] | 2893 | assert((Tok.is(tok::l_brace) || Tok.is(tok::kw_try) || |
| 2894 | Tok.is(tok::colon)) && |
| 2895 | "Inline objective-c method not starting with '{' or 'try' or ':'"); |
Alp Toker | f6a24ce | 2013-12-05 16:25:25 +0000 | [diff] [blame] | 2896 | // Enter a scope for the method or c-function body. |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2897 | ParseScope BodyScope(this, |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 2898 | parseMethod |
| 2899 | ? Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope |
| 2900 | : Scope::FnScope|Scope::DeclScope); |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2901 | |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 2902 | // Tell the actions module that we have entered a method or c-function definition |
| 2903 | // with the specified Declarator for the method/function. |
Fariborz Jahanian | 18d0a5d | 2012-08-08 23:41:08 +0000 | [diff] [blame] | 2904 | if (parseMethod) |
| 2905 | Actions.ActOnStartOfObjCMethodDef(getCurScope(), MCDecl); |
| 2906 | else |
| 2907 | Actions.ActOnStartOfFunctionDef(getCurScope(), MCDecl); |
Fariborz Jahanian | 8cecfe9 | 2012-08-10 18:10:56 +0000 | [diff] [blame] | 2908 | if (Tok.is(tok::kw_try)) |
Arnaud A. de Grandmaison | 6756a49 | 2014-03-23 20:28:07 +0000 | [diff] [blame] | 2909 | ParseFunctionTryBlock(MCDecl, BodyScope); |
Fariborz Jahanian | f64b472 | 2012-08-10 21:15:06 +0000 | [diff] [blame] | 2910 | else { |
| 2911 | if (Tok.is(tok::colon)) |
| 2912 | ParseConstructorInitializer(MCDecl); |
Arnaud A. de Grandmaison | 6756a49 | 2014-03-23 20:28:07 +0000 | [diff] [blame] | 2913 | ParseFunctionStatementBody(MCDecl, BodyScope); |
Fariborz Jahanian | f64b472 | 2012-08-10 21:15:06 +0000 | [diff] [blame] | 2914 | } |
Fariborz Jahanian | 656b5a0 | 2012-08-09 21:12:39 +0000 | [diff] [blame] | 2915 | |
Argyrios Kyrtzidis | 9a174fb | 2011-12-17 04:13:18 +0000 | [diff] [blame] | 2916 | if (Tok.getLocation() != OrigLoc) { |
| 2917 | // Due to parsing error, we either went over the cached tokens or |
| 2918 | // there are still cached tokens left. If it's the latter case skip the |
| 2919 | // leftover tokens. |
| 2920 | // Since this is an uncommon situation that should be avoided, use the |
| 2921 | // expensive isBeforeInTranslationUnit call. |
| 2922 | if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(), |
| 2923 | OrigLoc)) |
| 2924 | while (Tok.getLocation() != OrigLoc && Tok.isNot(tok::eof)) |
| 2925 | ConsumeAnyToken(); |
| 2926 | } |
| 2927 | |
Fariborz Jahanian | 577574a | 2012-07-02 23:37:09 +0000 | [diff] [blame] | 2928 | return; |
Fariborz Jahanian | bd0642f | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2929 | } |