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 | |
Chris Lattner | 60f3622 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 16 | #include "RAIIObjectsForParser.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/DeclSpec.h" |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 18 | #include "clang/Sema/PrettyDeclStackTrace.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Scope.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | |
Chris Lattner | 3a90716 | 2008-12-08 21:53:24 +0000 | [diff] [blame] | 24 | /// ParseObjCAtDirectives - Handle parts of the external-declaration production: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 25 | /// external-declaration: [C99 6.9] |
| 26 | /// [OBJC] objc-class-definition |
Steve Naroff | e093339 | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 27 | /// [OBJC] objc-class-declaration |
| 28 | /// [OBJC] objc-alias-declaration |
| 29 | /// [OBJC] objc-protocol-definition |
| 30 | /// [OBJC] objc-method-definition |
| 31 | /// [OBJC] '@' 'end' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 32 | Decl *Parser::ParseObjCAtDirectives() { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 33 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 35 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 36 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 37 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 40 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 41 | case tok::objc_class: |
| 42 | return ParseObjCAtClassDeclaration(AtLoc); |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 43 | case tok::objc_interface: { |
| 44 | ParsedAttributes attrs; |
| 45 | return ParseObjCAtInterfaceDeclaration(AtLoc, attrs); |
| 46 | } |
| 47 | case tok::objc_protocol: { |
| 48 | ParsedAttributes attrs; |
| 49 | return ParseObjCAtProtocolDeclaration(AtLoc, attrs); |
| 50 | } |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 51 | case tok::objc_implementation: |
| 52 | return ParseObjCAtImplementationDeclaration(AtLoc); |
| 53 | case tok::objc_end: |
| 54 | return ParseObjCAtEndDeclaration(AtLoc); |
| 55 | case tok::objc_compatibility_alias: |
| 56 | return ParseObjCAtAliasDeclaration(AtLoc); |
| 57 | case tok::objc_synthesize: |
| 58 | return ParseObjCPropertySynthesize(AtLoc); |
| 59 | case tok::objc_dynamic: |
| 60 | return ParseObjCPropertyDynamic(AtLoc); |
| 61 | default: |
| 62 | Diag(AtLoc, diag::err_unexpected_at); |
| 63 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 64 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
| 68 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | /// objc-class-declaration: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 70 | /// '@' 'class' identifier-list ';' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 72 | Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 73 | ConsumeToken(); // the identifier "class" |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 74 | llvm::SmallVector<IdentifierInfo *, 8> ClassNames; |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 75 | llvm::SmallVector<SourceLocation, 8> ClassLocs; |
| 76 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 77 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 78 | while (1) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 79 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | bd63892 | 2006-11-10 05:19:25 +0000 | [diff] [blame] | 80 | Diag(Tok, diag::err_expected_ident); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 81 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 82 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 83 | } |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 84 | ClassNames.push_back(Tok.getIdentifierInfo()); |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 85 | ClassLocs.push_back(Tok.getLocation()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 86 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 88 | if (Tok.isNot(tok::comma)) |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 89 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 91 | ConsumeToken(); |
| 92 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 94 | // Consume the ';'. |
| 95 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 96 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 97 | |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 98 | return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), |
| 99 | ClassLocs.data(), |
| 100 | ClassNames.size()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 103 | /// |
| 104 | /// objc-interface: |
| 105 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 106 | /// objc-category-interface |
| 107 | /// |
| 108 | /// objc-class-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 109 | /// '@' 'interface' identifier objc-superclass[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 110 | /// objc-protocol-refs[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | /// objc-class-instance-variables[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 112 | /// objc-interface-decl-list |
| 113 | /// @end |
| 114 | /// |
| 115 | /// objc-category-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 117 | /// objc-protocol-refs[opt] |
| 118 | /// objc-interface-decl-list |
| 119 | /// @end |
| 120 | /// |
| 121 | /// objc-superclass: |
| 122 | /// ':' identifier |
| 123 | /// |
| 124 | /// objc-class-interface-attributes: |
| 125 | /// __attribute__((visibility("default"))) |
| 126 | /// __attribute__((visibility("hidden"))) |
| 127 | /// __attribute__((deprecated)) |
| 128 | /// __attribute__((unavailable)) |
| 129 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 130 | /// |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 131 | Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, |
| 132 | ParsedAttributes &attrs) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 133 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 134 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 135 | ConsumeToken(); // the "interface" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 136 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 137 | // Code completion after '@interface'. |
| 138 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 139 | Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 140 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 143 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 144 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 145 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 146 | } |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 147 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 148 | // We have a class or category name - consume it. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 149 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 150 | SourceLocation nameLoc = ConsumeToken(); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 151 | if (Tok.is(tok::l_paren) && |
| 152 | !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame^] | 153 | // TODO(dgregor): Use the return value from the next line to provide better |
| 154 | // recovery. |
| 155 | ConsumeParen(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 156 | SourceLocation categoryLoc, rparenLoc; |
| 157 | IdentifierInfo *categoryId = 0; |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 158 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 159 | Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 160 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Steve Naroff | 4e1f80d | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 163 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 164 | if (Tok.is(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 165 | categoryId = Tok.getIdentifierInfo(); |
| 166 | categoryLoc = ConsumeToken(); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 167 | } |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 168 | else if (!getLang().ObjC2) { |
Steve Naroff | 4e1f80d | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 169 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 170 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 171 | } |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 172 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 173 | Diag(Tok, diag::err_expected_rparen); |
| 174 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 175 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 176 | } |
| 177 | rparenLoc = ConsumeParen(); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 178 | // Next, we need to check for any protocol references. |
| 179 | SourceLocation LAngleLoc, EndProtoLoc; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 180 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 181 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
| 182 | if (Tok.is(tok::less) && |
| 183 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 184 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 185 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 186 | |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 187 | if (!attrs.empty()) // categories don't support attributes. |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 188 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 190 | Decl *CategoryType = |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 191 | Actions.ActOnStartCategoryInterface(atLoc, |
| 192 | nameId, nameLoc, |
| 193 | categoryId, categoryLoc, |
| 194 | ProtocolRefs.data(), |
| 195 | ProtocolRefs.size(), |
| 196 | ProtocolLocs.data(), |
| 197 | EndProtoLoc); |
| 198 | if (Tok.is(tok::l_brace)) |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 199 | ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, |
| 200 | atLoc); |
| 201 | |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 202 | ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); |
| 203 | return CategoryType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 204 | } |
| 205 | // Parse a class interface. |
| 206 | IdentifierInfo *superClassId = 0; |
| 207 | SourceLocation superClassLoc; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 208 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 209 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 210 | ConsumeToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 211 | |
| 212 | // Code completion of superclass names. |
| 213 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 214 | Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 215 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 218 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 219 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 220 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 221 | } |
| 222 | superClassId = Tok.getIdentifierInfo(); |
| 223 | superClassLoc = ConsumeToken(); |
| 224 | } |
| 225 | // Next, we need to check for any protocol references. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 226 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 227 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
| 228 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 229 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 230 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
| 231 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 232 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 233 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 234 | Decl *ClsType = |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 235 | Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 236 | superClassId, superClassLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 237 | ProtocolRefs.data(), ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 238 | ProtocolLocs.data(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 239 | EndProtoLoc, attrs.getList()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 241 | if (Tok.is(tok::l_brace)) |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 242 | ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 243 | |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 244 | ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 245 | return ClsType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 246 | } |
| 247 | |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 248 | /// The Objective-C property callback. This should be defined where |
| 249 | /// it's used, but instead it's been lifted to here to support VS2005. |
| 250 | struct Parser::ObjCPropertyCallback : FieldCallback { |
| 251 | Parser &P; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 252 | Decl *IDecl; |
| 253 | llvm::SmallVectorImpl<Decl *> &Props; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 254 | ObjCDeclSpec &OCDS; |
| 255 | SourceLocation AtLoc; |
| 256 | tok::ObjCKeywordKind MethodImplKind; |
| 257 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 258 | ObjCPropertyCallback(Parser &P, Decl *IDecl, |
| 259 | llvm::SmallVectorImpl<Decl *> &Props, |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 260 | ObjCDeclSpec &OCDS, SourceLocation AtLoc, |
| 261 | tok::ObjCKeywordKind MethodImplKind) : |
| 262 | P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), |
| 263 | MethodImplKind(MethodImplKind) { |
| 264 | } |
| 265 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 266 | Decl *invoke(FieldDeclarator &FD) { |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 267 | if (FD.D.getIdentifier() == 0) { |
| 268 | P.Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 269 | << FD.D.getSourceRange(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 270 | return 0; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 271 | } |
| 272 | if (FD.BitfieldSize) { |
| 273 | P.Diag(AtLoc, diag::err_objc_property_bitfield) |
| 274 | << FD.D.getSourceRange(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 275 | return 0; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | // Install the property declarator into interfaceDecl. |
| 279 | IdentifierInfo *SelName = |
| 280 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 281 | |
| 282 | Selector GetterSel = |
| 283 | P.PP.getSelectorTable().getNullarySelector(SelName); |
| 284 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 285 | Selector SetterSel; |
| 286 | if (SetterName) |
| 287 | SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); |
| 288 | else |
| 289 | SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), |
| 290 | P.PP.getSelectorTable(), |
| 291 | FD.D.getIdentifier()); |
| 292 | bool isOverridingProperty = false; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 293 | Decl *Property = |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 294 | P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 295 | GetterSel, SetterSel, IDecl, |
| 296 | &isOverridingProperty, |
| 297 | MethodImplKind); |
| 298 | if (!isOverridingProperty) |
| 299 | Props.push_back(Property); |
| 300 | |
| 301 | return Property; |
| 302 | } |
| 303 | }; |
| 304 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 305 | /// objc-interface-decl-list: |
| 306 | /// empty |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 307 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 308 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 309 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 310 | /// objc-interface-decl-list declaration |
| 311 | /// objc-interface-decl-list ';' |
| 312 | /// |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 313 | /// objc-method-requirement: [OBJC2] |
| 314 | /// @required |
| 315 | /// @optional |
| 316 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 317 | void Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl, |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 318 | tok::ObjCKeywordKind contextKey) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 319 | llvm::SmallVector<Decl *, 32> allMethods; |
| 320 | llvm::SmallVector<Decl *, 16> allProperties; |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 321 | llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; |
Fariborz Jahanian | 0c74e9d | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 322 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 324 | SourceRange AtEnd; |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 325 | |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 326 | while (1) { |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 327 | // If this is a method prototype, parse it. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 328 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 329 | Decl *methodPrototype = |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 330 | ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 331 | allMethods.push_back(methodPrototype); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 332 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 333 | // method definitions. |
Chris Lattner | 8510b90 | 2009-02-15 22:24:30 +0000 | [diff] [blame] | 334 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, |
| 335 | "", tok::semi); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 336 | continue; |
| 337 | } |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 338 | if (Tok.is(tok::l_paren)) { |
| 339 | Diag(Tok, diag::err_expected_minus_or_plus); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 340 | ParseObjCMethodDecl(Tok.getLocation(), |
| 341 | tok::minus, |
| 342 | interfaceDecl, |
| 343 | MethodImplKind); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 344 | continue; |
| 345 | } |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 346 | // Ignore excess semicolons. |
| 347 | if (Tok.is(tok::semi)) { |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 348 | ConsumeToken(); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 349 | continue; |
| 350 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 352 | // If we got to the end of the file, exit the loop. |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 353 | if (Tok.is(tok::eof)) |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 354 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 356 | // Code completion within an Objective-C interface. |
| 357 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 358 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 359 | ObjCImpDecl? Sema::PCC_ObjCImplementation |
| 360 | : Sema::PCC_ObjCInterface); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 361 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 364 | // If we don't have an @ directive, parse it as a function definition. |
| 365 | if (Tok.isNot(tok::at)) { |
Chris Lattner | c7c9ab7 | 2009-01-09 04:34:13 +0000 | [diff] [blame] | 366 | // The code below does not consume '}'s because it is afraid of eating the |
| 367 | // end of a namespace. Because of the way this code is structured, an |
| 368 | // erroneous r_brace would cause an infinite loop if not handled here. |
| 369 | if (Tok.is(tok::r_brace)) |
| 370 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 372 | // FIXME: as the name implies, this rule allows function definitions. |
| 373 | // We could pass a flag or check for functions during semantic analysis. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 374 | ParsedAttributes attrs; |
| 375 | allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 376 | continue; |
| 377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 379 | // Otherwise, we have an @ directive, eat the @. |
| 380 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 381 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 382 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 383 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 387 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 389 | if (DirectiveKind == tok::objc_end) { // @end -> terminate list |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 390 | AtEnd.setBegin(AtLoc); |
| 391 | AtEnd.setEnd(Tok.getLocation()); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 392 | break; |
Douglas Gregor | 00a0cf7 | 2010-03-16 06:04:47 +0000 | [diff] [blame] | 393 | } else if (DirectiveKind == tok::objc_not_keyword) { |
| 394 | Diag(Tok, diag::err_objc_unknown_at); |
| 395 | SkipUntil(tok::semi); |
| 396 | continue; |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 399 | // Eat the identifier. |
| 400 | ConsumeToken(); |
| 401 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 402 | switch (DirectiveKind) { |
| 403 | default: |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 404 | // FIXME: If someone forgets an @end on a protocol, this loop will |
| 405 | // continue to eat up tons of stuff and spew lots of nonsense errors. It |
| 406 | // would probably be better to bail out if we saw an @class or @interface |
| 407 | // or something like that. |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 408 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 409 | // Skip until we see an '@' or '}' or ';'. |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 410 | SkipUntil(tok::r_brace, tok::at); |
| 411 | break; |
Fariborz Jahanian | d4c5348 | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 412 | |
| 413 | case tok::objc_implementation: |
Fariborz Jahanian | dbee986 | 2010-11-09 20:38:00 +0000 | [diff] [blame] | 414 | case tok::objc_interface: |
Fariborz Jahanian | d4c5348 | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 415 | Diag(Tok, diag::err_objc_missing_end); |
| 416 | ConsumeToken(); |
| 417 | break; |
| 418 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 419 | case tok::objc_required: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 420 | case tok::objc_optional: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 421 | // This is only valid on protocols. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 422 | // FIXME: Should this check for ObjC2 being enabled? |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 423 | if (contextKey != tok::objc_protocol) |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 424 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 425 | else |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 426 | MethodImplKind = DirectiveKind; |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 427 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 429 | case tok::objc_property: |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 430 | if (!getLang().ObjC2) |
Chris Lattner | 4da4e25 | 2010-12-17 05:40:22 +0000 | [diff] [blame] | 431 | Diag(AtLoc, diag::err_objc_properties_require_objc2); |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 432 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 433 | ObjCDeclSpec OCDS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 434 | // Parse property attribute list, if any. |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 435 | if (Tok.is(tok::l_paren)) |
Douglas Gregor | 87e9275 | 2010-12-21 17:34:17 +0000 | [diff] [blame] | 436 | ParseObjCPropertyAttribute(OCDS, interfaceDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 438 | ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, |
| 439 | OCDS, AtLoc, MethodImplKind); |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 440 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 441 | // Parse all the comma separated declarators. |
| 442 | DeclSpec DS; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 443 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 444 | |
Chris Lattner | e0d3fe9 | 2008-10-20 06:15:13 +0000 | [diff] [blame] | 445 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", |
| 446 | tok::at); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 447 | break; |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 448 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 449 | } |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 450 | |
| 451 | // We break out of the big loop in two cases: when we see @end or when we see |
| 452 | // 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] | 453 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 454 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 455 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 456 | } else if (Tok.isObjCAtKeyword(tok::objc_end)) |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 457 | ConsumeToken(); // the "end" identifier |
| 458 | else |
| 459 | Diag(Tok, diag::err_objc_missing_end); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 461 | // Insert collected methods declarations into the @interface object. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 462 | // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 463 | Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 464 | allMethods.data(), allMethods.size(), |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 465 | allProperties.data(), allProperties.size(), |
| 466 | allTUVariables.data(), allTUVariables.size()); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 469 | /// Parse property attribute declarations. |
| 470 | /// |
| 471 | /// property-attr-decl: '(' property-attrlist ')' |
| 472 | /// property-attrlist: |
| 473 | /// property-attribute |
| 474 | /// property-attrlist ',' property-attribute |
| 475 | /// property-attribute: |
| 476 | /// getter '=' identifier |
| 477 | /// setter '=' identifier ':' |
| 478 | /// readonly |
| 479 | /// readwrite |
| 480 | /// assign |
| 481 | /// retain |
| 482 | /// copy |
| 483 | /// nonatomic |
| 484 | /// |
Douglas Gregor | 87e9275 | 2010-12-21 17:34:17 +0000 | [diff] [blame] | 485 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 486 | assert(Tok.getKind() == tok::l_paren); |
Chris Lattner | 43c76c3 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 487 | SourceLocation LHSLoc = ConsumeParen(); // consume '(' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 489 | while (1) { |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 490 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 491 | Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 492 | ConsumeCodeCompletionToken(); |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 493 | } |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 494 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 495 | |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 496 | // If this is not an identifier at all, bail out early. |
| 497 | if (II == 0) { |
| 498 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
| 499 | return; |
| 500 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 502 | SourceLocation AttrName = ConsumeToken(); // consume last attribute name |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 503 | |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 504 | if (II->isStr("readonly")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 505 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 506 | else if (II->isStr("assign")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 507 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 508 | else if (II->isStr("readwrite")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 509 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 510 | else if (II->isStr("retain")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 511 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 512 | else if (II->isStr("copy")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 513 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 514 | else if (II->isStr("nonatomic")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 515 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Fariborz Jahanian | 382c040 | 2010-12-17 22:28:16 +0000 | [diff] [blame] | 516 | else if (II->isStr("atomic")) |
| 517 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 518 | else if (II->isStr("getter") || II->isStr("setter")) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 519 | bool IsSetter = II->getNameStart()[0] == 's'; |
| 520 | |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 521 | // getter/setter require extra treatment. |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 522 | unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : |
| 523 | diag::err_objc_expected_equal_for_getter; |
| 524 | |
| 525 | if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) |
Chris Lattner | 43c76c3 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 526 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 527 | |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 528 | if (Tok.is(tok::code_completion)) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 529 | if (IsSetter) |
Douglas Gregor | 87e9275 | 2010-12-21 17:34:17 +0000 | [diff] [blame] | 530 | Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl); |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 531 | else |
Douglas Gregor | 87e9275 | 2010-12-21 17:34:17 +0000 | [diff] [blame] | 532 | Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 533 | ConsumeCodeCompletionToken(); |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 536 | |
| 537 | SourceLocation SelLoc; |
| 538 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); |
| 539 | |
| 540 | if (!SelIdent) { |
| 541 | Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) |
| 542 | << IsSetter; |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 543 | SkipUntil(tok::r_paren); |
| 544 | return; |
| 545 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 547 | if (IsSetter) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 548 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 549 | DS.setSetterName(SelIdent); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Fariborz Jahanian | 8efe0ec | 2010-02-15 22:20:11 +0000 | [diff] [blame] | 551 | if (ExpectAndConsume(tok::colon, |
| 552 | diag::err_expected_colon_after_setter_name, "", |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 553 | tok::r_paren)) |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 554 | return; |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 555 | } else { |
| 556 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 557 | DS.setGetterName(SelIdent); |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 558 | } |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 559 | } else { |
Chris Lattner | 406c096 | 2008-11-19 07:49:38 +0000 | [diff] [blame] | 560 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 561 | SkipUntil(tok::r_paren); |
| 562 | return; |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 563 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 565 | if (Tok.isNot(tok::comma)) |
| 566 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 568 | ConsumeToken(); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 569 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 571 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 574 | /// objc-method-proto: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 575 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 576 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 577 | /// |
| 578 | /// objc-instance-method: '-' |
| 579 | /// objc-class-method: '+' |
| 580 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 581 | /// objc-method-attributes: [OBJC2] |
| 582 | /// __attribute__((deprecated)) |
| 583 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 584 | Decl *Parser::ParseObjCMethodPrototype(Decl *IDecl, |
| 585 | tok::ObjCKeywordKind MethodImplKind) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 586 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 587 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 589 | SourceLocation mLoc = ConsumeToken(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 590 | Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 591 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | acb1e74 | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 592 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 593 | return MDecl; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /// objc-selector: |
| 597 | /// identifier |
| 598 | /// one of |
| 599 | /// enum struct union if else while do for switch case default |
| 600 | /// break continue return goto asm sizeof typeof __alignof |
| 601 | /// unsigned long const short volatile signed restrict _Complex |
| 602 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 603 | /// |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 604 | IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { |
Fariborz Jahanian | 0389df4a | 2010-09-03 01:26:16 +0000 | [diff] [blame] | 605 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 606 | switch (Tok.getKind()) { |
| 607 | default: |
| 608 | return 0; |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 609 | case tok::ampamp: |
| 610 | case tok::ampequal: |
| 611 | case tok::amp: |
| 612 | case tok::pipe: |
| 613 | case tok::tilde: |
| 614 | case tok::exclaim: |
| 615 | case tok::exclaimequal: |
| 616 | case tok::pipepipe: |
| 617 | case tok::pipeequal: |
| 618 | case tok::caret: |
| 619 | case tok::caretequal: { |
Fariborz Jahanian | dadfc1c | 2010-09-03 18:01:09 +0000 | [diff] [blame] | 620 | std::string ThisTok(PP.getSpelling(Tok)); |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 621 | if (isalpha(ThisTok[0])) { |
| 622 | IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); |
| 623 | Tok.setKind(tok::identifier); |
| 624 | SelectorLoc = ConsumeToken(); |
| 625 | return II; |
| 626 | } |
| 627 | return 0; |
| 628 | } |
| 629 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 630 | case tok::identifier: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 631 | case tok::kw_asm: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 632 | case tok::kw_auto: |
Chris Lattner | bb31a42 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 633 | case tok::kw_bool: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 634 | case tok::kw_break: |
| 635 | case tok::kw_case: |
| 636 | case tok::kw_catch: |
| 637 | case tok::kw_char: |
| 638 | case tok::kw_class: |
| 639 | case tok::kw_const: |
| 640 | case tok::kw_const_cast: |
| 641 | case tok::kw_continue: |
| 642 | case tok::kw_default: |
| 643 | case tok::kw_delete: |
| 644 | case tok::kw_do: |
| 645 | case tok::kw_double: |
| 646 | case tok::kw_dynamic_cast: |
| 647 | case tok::kw_else: |
| 648 | case tok::kw_enum: |
| 649 | case tok::kw_explicit: |
| 650 | case tok::kw_export: |
| 651 | case tok::kw_extern: |
| 652 | case tok::kw_false: |
| 653 | case tok::kw_float: |
| 654 | case tok::kw_for: |
| 655 | case tok::kw_friend: |
| 656 | case tok::kw_goto: |
| 657 | case tok::kw_if: |
| 658 | case tok::kw_inline: |
| 659 | case tok::kw_int: |
| 660 | case tok::kw_long: |
| 661 | case tok::kw_mutable: |
| 662 | case tok::kw_namespace: |
| 663 | case tok::kw_new: |
| 664 | case tok::kw_operator: |
| 665 | case tok::kw_private: |
| 666 | case tok::kw_protected: |
| 667 | case tok::kw_public: |
| 668 | case tok::kw_register: |
| 669 | case tok::kw_reinterpret_cast: |
| 670 | case tok::kw_restrict: |
| 671 | case tok::kw_return: |
| 672 | case tok::kw_short: |
| 673 | case tok::kw_signed: |
| 674 | case tok::kw_sizeof: |
| 675 | case tok::kw_static: |
| 676 | case tok::kw_static_cast: |
| 677 | case tok::kw_struct: |
| 678 | case tok::kw_switch: |
| 679 | case tok::kw_template: |
| 680 | case tok::kw_this: |
| 681 | case tok::kw_throw: |
| 682 | case tok::kw_true: |
| 683 | case tok::kw_try: |
| 684 | case tok::kw_typedef: |
| 685 | case tok::kw_typeid: |
| 686 | case tok::kw_typename: |
| 687 | case tok::kw_typeof: |
| 688 | case tok::kw_union: |
| 689 | case tok::kw_unsigned: |
| 690 | case tok::kw_using: |
| 691 | case tok::kw_virtual: |
| 692 | case tok::kw_void: |
| 693 | case tok::kw_volatile: |
| 694 | case tok::kw_wchar_t: |
| 695 | case tok::kw_while: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 696 | case tok::kw__Bool: |
| 697 | case tok::kw__Complex: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 698 | case tok::kw___alignof: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 699 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 700 | SelectorLoc = ConsumeToken(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 701 | return II; |
Fariborz Jahanian | fa80e80 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 702 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 705 | /// objc-for-collection-in: 'in' |
| 706 | /// |
Fariborz Jahanian | 3622e59 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 707 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 732b8c2 | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 708 | // FIXME: May have to do additional look-ahead to only allow for |
| 709 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 710 | // '[' etc. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | return (getLang().ObjC2 && Tok.is(tok::identifier) && |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 712 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 715 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 716 | /// qualifier list and builds their bitmask representation in the input |
| 717 | /// argument. |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 718 | /// |
| 719 | /// objc-type-qualifiers: |
| 720 | /// objc-type-qualifier |
| 721 | /// objc-type-qualifiers objc-type-qualifier |
| 722 | /// |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 723 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) { |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 724 | while (1) { |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 725 | if (Tok.is(tok::code_completion)) { |
| 726 | Actions.CodeCompleteObjCPassingType(getCurScope(), DS); |
| 727 | ConsumeCodeCompletionToken(); |
| 728 | } |
| 729 | |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 730 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 731 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 733 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 734 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 735 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 736 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 737 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 738 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 739 | switch (i) { |
| 740 | default: assert(0 && "Unknown decl qualifier"); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 741 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 742 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 743 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 744 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 745 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 746 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 747 | } |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 748 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 749 | ConsumeToken(); |
| 750 | II = 0; |
| 751 | break; |
| 752 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 754 | // If this wasn't a recognized qualifier, bail out. |
| 755 | if (II) return; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | /// objc-type-name: |
| 760 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 761 | /// '(' objc-type-qualifiers[opt] ')' |
| 762 | /// |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 763 | ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 764 | assert(Tok.is(tok::l_paren) && "expected ("); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 766 | SourceLocation LParenLoc = ConsumeParen(); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 767 | SourceLocation TypeStartLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Fariborz Jahanian | d822d68 | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 769 | // Parse type qualifiers, in, inout, etc. |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 770 | ParseObjCTypeQualifierList(DS, IsParameter); |
Steve Naroff | 7e901fd | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 771 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 772 | ParsedType Ty; |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 773 | if (isTypeSpecifierQualifier()) { |
| 774 | TypeResult TypeSpec = ParseTypeName(); |
| 775 | if (!TypeSpec.isInvalid()) |
| 776 | Ty = TypeSpec.get(); |
| 777 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Steve Naroff | 90255b4 | 2008-10-21 14:15:04 +0000 | [diff] [blame] | 779 | if (Tok.is(tok::r_paren)) |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 780 | ConsumeParen(); |
| 781 | else if (Tok.getLocation() == TypeStartLoc) { |
| 782 | // 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] | 783 | Diag(Tok, diag::err_expected_type); |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 784 | SkipUntil(tok::r_paren); |
| 785 | } else { |
| 786 | // Otherwise, we found *something*, but didn't get a ')' in the right |
| 787 | // place. Emit an error then return what we have as the type. |
| 788 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 789 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 790 | return Ty; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /// objc-method-decl: |
| 794 | /// objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 795 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 796 | /// objc-type-name objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 797 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 798 | /// |
| 799 | /// objc-keyword-selector: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | /// objc-keyword-decl |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 801 | /// objc-keyword-selector objc-keyword-decl |
| 802 | /// |
| 803 | /// objc-keyword-decl: |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 804 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 805 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 806 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 807 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 808 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 809 | /// objc-parmlist: |
| 810 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 811 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 812 | /// objc-parms: |
| 813 | /// objc-parms , parameter-declaration |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 814 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 815 | /// objc-ellipsis: |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 816 | /// , ... |
| 817 | /// |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 818 | /// objc-keyword-attributes: [OBJC2] |
| 819 | /// __attribute__((unused)) |
| 820 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 821 | Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Douglas Gregor | c49f5b2 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 822 | tok::TokenKind mType, |
| 823 | Decl *IDecl, |
| 824 | tok::ObjCKeywordKind MethodImplKind) { |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 825 | ParsingDeclRAIIObject PD(*this); |
| 826 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 827 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 828 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 829 | /*ReturnType=*/ ParsedType(), IDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 830 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 831 | } |
| 832 | |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 833 | // Parse the return type if present. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 834 | ParsedType ReturnType; |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 835 | ObjCDeclSpec DSRet; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 836 | if (Tok.is(tok::l_paren)) |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 837 | ReturnType = ParseObjCTypeName(DSRet, false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 839 | // If attributes exist before the method, parse them. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 840 | ParsedAttributes attrs; |
| 841 | if (getLang().ObjC2) |
| 842 | MaybeParseGNUAttributes(attrs); |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 844 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 845 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 846 | ReturnType, IDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 847 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 850 | // Now parse the selector. |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 851 | SourceLocation selLoc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 852 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 853 | |
Steve Naroff | 7a54c0d | 2009-02-11 20:43:13 +0000 | [diff] [blame] | 854 | // An unnamed colon is valid. |
| 855 | if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 856 | Diag(Tok, diag::err_expected_selector_for_method) |
| 857 | << SourceRange(mLoc, Tok.getLocation()); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 858 | // Skip until we get a ; or {}. |
| 859 | SkipUntil(tok::r_brace); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 860 | return 0; |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 861 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 863 | llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 864 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 865 | // If attributes exist after the method, parse them. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 866 | if (getLang().ObjC2) |
| 867 | MaybeParseGNUAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 868 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 869 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 870 | Decl *Result |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 871 | = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | b560517 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 872 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 873 | 0, |
| 874 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 875 | attrs.getList(), MethodImplKind); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 876 | PD.complete(Result); |
| 877 | return Result; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 878 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 879 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 880 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 881 | llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 883 | while (1) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 884 | Sema::ObjCArgInfo ArgInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 885 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 886 | // Each iteration parses a single keyword argument. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 887 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 888 | Diag(Tok, diag::err_expected_colon); |
| 889 | break; |
| 890 | } |
| 891 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 893 | ArgInfo.Type = ParsedType(); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 894 | if (Tok.is(tok::l_paren)) // Parse the argument type if present. |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 895 | ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, true); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 896 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 897 | // If attributes exist before the argument name, parse them. |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 898 | ArgInfo.ArgAttrs = 0; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 899 | if (getLang().ObjC2) { |
| 900 | ParsedAttributes attrs; |
| 901 | MaybeParseGNUAttributes(attrs); |
| 902 | ArgInfo.ArgAttrs = attrs.getList(); |
| 903 | } |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 904 | |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 905 | // Code completion for the next piece of the selector. |
| 906 | if (Tok.is(tok::code_completion)) { |
| 907 | ConsumeCodeCompletionToken(); |
| 908 | KeyIdents.push_back(SelIdent); |
| 909 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 910 | mType == tok::minus, |
| 911 | /*AtParameterName=*/true, |
| 912 | ReturnType, |
| 913 | KeyIdents.data(), |
| 914 | KeyIdents.size()); |
| 915 | KeyIdents.pop_back(); |
| 916 | break; |
| 917 | } |
| 918 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 919 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 920 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 921 | break; |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 922 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 923 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 924 | ArgInfo.Name = Tok.getIdentifierInfo(); |
| 925 | ArgInfo.NameLoc = Tok.getLocation(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 926 | ConsumeToken(); // Eat the identifier. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 928 | ArgInfos.push_back(ArgInfo); |
| 929 | KeyIdents.push_back(SelIdent); |
| 930 | |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 931 | // Code completion for the next piece of the selector. |
| 932 | if (Tok.is(tok::code_completion)) { |
| 933 | ConsumeCodeCompletionToken(); |
| 934 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 935 | mType == tok::minus, |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 936 | /*AtParameterName=*/false, |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 937 | ReturnType, |
| 938 | KeyIdents.data(), |
| 939 | KeyIdents.size()); |
| 940 | break; |
| 941 | } |
| 942 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 943 | // Check for another keyword selector. |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 944 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 945 | SelIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 946 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 947 | break; |
| 948 | // We have a selector or a colon, continue parsing. |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 949 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 950 | |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 951 | bool isVariadic = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 952 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 953 | // Parse the (optional) parameter list. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 954 | while (Tok.is(tok::comma)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 955 | ConsumeToken(); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 956 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 957 | isVariadic = true; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 958 | ConsumeToken(); |
| 959 | break; |
| 960 | } |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 961 | DeclSpec DS; |
| 962 | ParseDeclarationSpecifiers(DS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | // Parse the declarator. |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 964 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 965 | ParseDeclarator(ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 966 | IdentifierInfo *ParmII = ParmDecl.getIdentifier(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 967 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 968 | CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 969 | ParmDecl.getIdentifierLoc(), |
| 970 | Param, |
| 971 | 0)); |
| 972 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 973 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | |
Cameron Esfahani | f6c73c4 | 2010-10-12 00:21:25 +0000 | [diff] [blame] | 975 | // FIXME: Add support for optional parameter list... |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 976 | // If attributes exist after the method, parse them. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 977 | if (getLang().ObjC2) |
| 978 | MaybeParseGNUAttributes(attrs); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 979 | |
Fariborz Jahanian | 6e9e4f3 | 2009-06-24 17:00:18 +0000 | [diff] [blame] | 980 | if (KeyIdents.size() == 0) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 981 | return 0; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 982 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 983 | &KeyIdents[0]); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 984 | Decl *Result |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 985 | = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 6e9e4f3 | 2009-06-24 17:00:18 +0000 | [diff] [blame] | 986 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 987 | &ArgInfos[0], |
| 988 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 989 | attrs.getList(), |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 990 | MethodImplKind, isVariadic); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 991 | PD.complete(Result); |
| 992 | return Result; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 995 | /// objc-protocol-refs: |
| 996 | /// '<' identifier-list '>' |
| 997 | /// |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 998 | bool Parser:: |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 999 | ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1000 | llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, |
| 1001 | bool WarnOnDeclarations, |
| 1002 | SourceLocation &LAngleLoc, SourceLocation &EndLoc) { |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1003 | assert(Tok.is(tok::less) && "expected <"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1005 | LAngleLoc = ConsumeToken(); // the "<" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1007 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1009 | while (1) { |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1010 | if (Tok.is(tok::code_completion)) { |
| 1011 | Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), |
| 1012 | ProtocolIdents.size()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1013 | ConsumeCodeCompletionToken(); |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1016 | if (Tok.isNot(tok::identifier)) { |
| 1017 | Diag(Tok, diag::err_expected_ident); |
| 1018 | SkipUntil(tok::greater); |
| 1019 | return true; |
| 1020 | } |
| 1021 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 1022 | Tok.getLocation())); |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1023 | ProtocolLocs.push_back(Tok.getLocation()); |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1024 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1025 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1026 | if (Tok.isNot(tok::comma)) |
| 1027 | break; |
| 1028 | ConsumeToken(); |
| 1029 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1031 | // Consume the '>'. |
| 1032 | if (Tok.isNot(tok::greater)) { |
| 1033 | Diag(Tok, diag::err_expected_greater); |
| 1034 | return true; |
| 1035 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1037 | EndLoc = ConsumeAnyToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1039 | // Convert the list of protocols identifiers into a list of protocol decls. |
| 1040 | Actions.FindProtocolDeclaration(WarnOnDeclarations, |
| 1041 | &ProtocolIdents[0], ProtocolIdents.size(), |
| 1042 | Protocols); |
| 1043 | return false; |
| 1044 | } |
| 1045 | |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1046 | /// \brief Parse the Objective-C protocol qualifiers that follow a typename |
| 1047 | /// in a decl-specifier-seq, starting at the '<'. |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1048 | bool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1049 | assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); |
| 1050 | assert(getLang().ObjC1 && "Protocol qualifiers only exist in Objective-C"); |
| 1051 | SourceLocation LAngleLoc, EndProtoLoc; |
| 1052 | llvm::SmallVector<Decl *, 8> ProtocolDecl; |
| 1053 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1054 | bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, |
| 1055 | LAngleLoc, EndProtoLoc); |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1056 | DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), |
| 1057 | ProtocolLocs.data(), LAngleLoc); |
| 1058 | if (EndProtoLoc.isValid()) |
| 1059 | DS.SetRangeEnd(EndProtoLoc); |
Douglas Gregor | 3a001f4 | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1060 | return Result; |
Douglas Gregor | 06e41ae | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1064 | /// objc-class-instance-variables: |
| 1065 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 1066 | /// |
| 1067 | /// objc-instance-variable-decl-list: |
| 1068 | /// objc-visibility-spec |
| 1069 | /// objc-instance-variable-decl ';' |
| 1070 | /// ';' |
| 1071 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 1072 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 1073 | /// objc-instance-variable-decl-list ';' |
| 1074 | /// |
| 1075 | /// objc-visibility-spec: |
| 1076 | /// @private |
| 1077 | /// @protected |
| 1078 | /// @public |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1079 | /// @package [OBJC2] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1080 | /// |
| 1081 | /// objc-instance-variable-decl: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1082 | /// struct-declaration |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1083 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1084 | void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1085 | tok::ObjCKeywordKind visibility, |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1086 | SourceLocation atLoc) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1087 | assert(Tok.is(tok::l_brace) && "expected {"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1088 | llvm::SmallVector<Decl *, 32> AllIvarDecls; |
Chris Lattner | a12405b | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1089 | |
Douglas Gregor | 45a33ec | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 1090 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
Douglas Gregor | 82ac25e | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 1091 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1092 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1094 | // While we still have something to read, read the instance variables. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1095 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1096 | // Each iteration of this loop reads one objc-instance-variable-decl. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1098 | // Check for extraneous top-level semicolon. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1099 | if (Tok.is(tok::semi)) { |
Douglas Gregor | 13d0568 | 2010-06-16 23:08:59 +0000 | [diff] [blame] | 1100 | Diag(Tok, diag::ext_extra_ivar_semi) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1101 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1102 | ConsumeToken(); |
| 1103 | continue; |
| 1104 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1106 | // Set the default visibility to private. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1107 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1108 | ConsumeToken(); // eat the @ sign |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1109 | |
| 1110 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1111 | Actions.CodeCompleteObjCAtVisibility(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1112 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1115 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1116 | case tok::objc_private: |
| 1117 | case tok::objc_public: |
| 1118 | case tok::objc_protected: |
| 1119 | case tok::objc_package: |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1120 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1121 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1122 | continue; |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1123 | default: |
| 1124 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1125 | continue; |
| 1126 | } |
| 1127 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1129 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1130 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1131 | Sema::PCC_ObjCInstanceVariableList); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1132 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1135 | struct ObjCIvarCallback : FieldCallback { |
| 1136 | Parser &P; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1137 | Decl *IDecl; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1138 | tok::ObjCKeywordKind visibility; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1139 | llvm::SmallVectorImpl<Decl *> &AllIvarDecls; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1140 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1141 | ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, |
| 1142 | llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1143 | P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { |
| 1144 | } |
| 1145 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1146 | Decl *invoke(FieldDeclarator &FD) { |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1147 | // Install the declarator into the interface decl. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1148 | Decl *Field |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1149 | = P.Actions.ActOnIvar(P.getCurScope(), |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1150 | FD.D.getDeclSpec().getSourceRange().getBegin(), |
| 1151 | IDecl, FD.D, FD.BitfieldSize, visibility); |
Fariborz Jahanian | 6a0a2e0 | 2010-04-06 22:43:48 +0000 | [diff] [blame] | 1152 | if (Field) |
| 1153 | AllIvarDecls.push_back(Field); |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1154 | return Field; |
| 1155 | } |
| 1156 | } Callback(*this, interfaceDecl, visibility, AllIvarDecls); |
Fariborz Jahanian | 616d3e7 | 2010-08-23 22:46:52 +0000 | [diff] [blame] | 1157 | |
Chris Lattner | a12405b | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1158 | // Parse all the comma separated declarators. |
| 1159 | DeclSpec DS; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1160 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1161 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1162 | if (Tok.is(tok::semi)) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1163 | ConsumeToken(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1164 | } else { |
| 1165 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1166 | // Skip to end of block or statement |
| 1167 | SkipUntil(tok::r_brace, true, true); |
| 1168 | } |
| 1169 | } |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1170 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Fariborz Jahanian | 616d3e7 | 2010-08-23 22:46:52 +0000 | [diff] [blame] | 1171 | Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls); |
Steve Naroff | 9c4fddd | 2007-10-31 22:11:35 +0000 | [diff] [blame] | 1172 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 1173 | // for code rewriting tools that need to be aware of the empty list. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1174 | Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1175 | AllIvarDecls.data(), AllIvarDecls.size(), |
Daniel Dunbar | 15619c7 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 1176 | LBraceLoc, RBraceLoc, 0); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1177 | return; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1178 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1179 | |
| 1180 | /// objc-protocol-declaration: |
| 1181 | /// objc-protocol-definition |
| 1182 | /// objc-protocol-forward-reference |
| 1183 | /// |
| 1184 | /// objc-protocol-definition: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1185 | /// @protocol identifier |
| 1186 | /// objc-protocol-refs[opt] |
| 1187 | /// objc-interface-decl-list |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1188 | /// @end |
| 1189 | /// |
| 1190 | /// objc-protocol-forward-reference: |
| 1191 | /// @protocol identifier-list ';' |
| 1192 | /// |
| 1193 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1194 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1195 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1196 | Decl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1197 | ParsedAttributes &attrs) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1198 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1199 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 1200 | ConsumeToken(); // the "protocol" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1202 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1203 | Actions.CodeCompleteObjCProtocolDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1204 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1207 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1208 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1209 | return 0; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1210 | } |
| 1211 | // Save the protocol name, then consume it. |
| 1212 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 1213 | SourceLocation nameLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1215 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1216 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1217 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1219 | attrs.getList()); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1220 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1221 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1222 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1223 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
| 1224 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 1225 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1226 | // Parse the list of forward declarations. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1227 | while (1) { |
| 1228 | ConsumeToken(); // the ',' |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1229 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1230 | Diag(Tok, diag::err_expected_ident); |
| 1231 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1232 | return 0; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1233 | } |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1234 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 1235 | Tok.getLocation())); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1236 | ConsumeToken(); // the identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1238 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | } |
| 1241 | // Consume the ';'. |
| 1242 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1243 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Steve Naroff | 93eb5f1 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1245 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | &ProtocolRefs[0], |
Fariborz Jahanian | 1470e93 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1247 | ProtocolRefs.size(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1248 | attrs.getList()); |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1249 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1251 | // Last, and definitely not least, parse a protocol declaration. |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1252 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1253 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1254 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1255 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1256 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1257 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, |
| 1258 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1259 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1261 | Decl *ProtoType = |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1262 | Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1263 | ProtocolRefs.data(), |
| 1264 | ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1265 | ProtocolLocs.data(), |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1266 | EndProtoLoc, attrs.getList()); |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1267 | ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 1268 | return ProtoType; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1269 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1270 | |
| 1271 | /// objc-implementation: |
| 1272 | /// objc-class-implementation-prologue |
| 1273 | /// objc-category-implementation-prologue |
| 1274 | /// |
| 1275 | /// objc-class-implementation-prologue: |
| 1276 | /// @implementation identifier objc-superclass[opt] |
| 1277 | /// objc-class-instance-variables[opt] |
| 1278 | /// |
| 1279 | /// objc-category-implementation-prologue: |
| 1280 | /// @implementation identifier ( identifier ) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1281 | Decl *Parser::ParseObjCAtImplementationDeclaration( |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1282 | SourceLocation atLoc) { |
| 1283 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 1284 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 1285 | ConsumeToken(); // the "implementation" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1287 | // Code completion after '@implementation'. |
| 1288 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1289 | Actions.CodeCompleteObjCImplementationDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1290 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1293 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1294 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1295 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1296 | } |
| 1297 | // We have a class or category name - consume it. |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1298 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1299 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1300 | |
| 1301 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1302 | // we have a category implementation. |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame^] | 1303 | ConsumeParen(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1304 | SourceLocation categoryLoc, rparenLoc; |
| 1305 | IdentifierInfo *categoryId = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1306 | |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1307 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1308 | Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1309 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1312 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1313 | categoryId = Tok.getIdentifierInfo(); |
| 1314 | categoryLoc = ConsumeToken(); |
| 1315 | } else { |
| 1316 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1317 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | } |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1319 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1320 | Diag(Tok, diag::err_expected_rparen); |
| 1321 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1322 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1323 | } |
| 1324 | rparenLoc = ConsumeParen(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1325 | Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | atLoc, nameId, nameLoc, categoryId, |
Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1327 | categoryLoc); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1328 | ObjCImpDecl = ImplCatType; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1329 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1330 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1331 | } |
| 1332 | // We have a class implementation |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1333 | SourceLocation superClassLoc; |
| 1334 | IdentifierInfo *superClassId = 0; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1335 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1336 | // We have a super class |
| 1337 | ConsumeToken(); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1338 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1339 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1340 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1341 | } |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1342 | superClassId = Tok.getIdentifierInfo(); |
| 1343 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1344 | } |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1345 | Decl *ImplClsType = Actions.ActOnStartClassImplementation( |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1346 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1347 | superClassId, superClassLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1349 | if (Tok.is(tok::l_brace)) // we have ivars |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1350 | ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, |
Fariborz Jahanian | a9effb5 | 2010-03-22 19:04:14 +0000 | [diff] [blame] | 1351 | tok::objc_private, atLoc); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1352 | ObjCImpDecl = ImplClsType; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1353 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
| 1354 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1355 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1356 | } |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1357 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1358 | Decl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1359 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 1360 | "ParseObjCAtEndDeclaration(): Expected @end"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1361 | Decl *Result = ObjCImpDecl; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1362 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1363 | if (ObjCImpDecl) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1364 | Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1365 | ObjCImpDecl = 0; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1366 | PendingObjCImpDecl.pop_back(); |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1367 | } |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1368 | else { |
| 1369 | // missing @implementation |
| 1370 | Diag(atEnd.getBegin(), diag::warn_expected_implementation); |
| 1371 | } |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1372 | return Result; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1373 | } |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1374 | |
Fariborz Jahanian | 6e7e8cc | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 1375 | Parser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { |
| 1376 | Actions.DiagnoseUseOfUnimplementedSelectors(); |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1377 | if (PendingObjCImpDecl.empty()) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1378 | return Actions.ConvertDeclToDeclGroup(0); |
| 1379 | Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1380 | Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1381 | return Actions.ConvertDeclToDeclGroup(ImpDecl); |
| 1382 | } |
| 1383 | |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1384 | /// compatibility-alias-decl: |
| 1385 | /// @compatibility_alias alias-name class-name ';' |
| 1386 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1387 | Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1388 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1389 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1390 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1391 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1392 | Diag(Tok, diag::err_expected_ident); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1393 | return 0; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1394 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1395 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1396 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1397 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1398 | Diag(Tok, diag::err_expected_ident); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1399 | return 0; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1400 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1401 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1402 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
Douglas Gregor | 78edf99 | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1403 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 1404 | "@compatibility_alias"); |
Chris Lattner | 83f095c | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1405 | return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, |
| 1406 | classId, classLoc); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1409 | /// property-synthesis: |
| 1410 | /// @synthesize property-ivar-list ';' |
| 1411 | /// |
| 1412 | /// property-ivar-list: |
| 1413 | /// property-ivar |
| 1414 | /// property-ivar-list ',' property-ivar |
| 1415 | /// |
| 1416 | /// property-ivar: |
| 1417 | /// identifier |
| 1418 | /// identifier '=' identifier |
| 1419 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1420 | Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1421 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 1422 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame^] | 1423 | ConsumeToken(); // consume synthesize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1424 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1425 | while (true) { |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1426 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1427 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1428 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1431 | if (Tok.isNot(tok::identifier)) { |
| 1432 | Diag(Tok, diag::err_synthesized_property_name); |
| 1433 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1434 | return 0; |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1437 | IdentifierInfo *propertyIvar = 0; |
| 1438 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1439 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1440 | SourceLocation propertyIvarLoc; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1441 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1442 | // property '=' ivar-name |
| 1443 | ConsumeToken(); // consume '=' |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1444 | |
| 1445 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1446 | Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1447 | ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1448 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1451 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1452 | Diag(Tok, diag::err_expected_ident); |
| 1453 | break; |
| 1454 | } |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1455 | propertyIvar = Tok.getIdentifierInfo(); |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1456 | propertyIvarLoc = ConsumeToken(); // consume ivar-name |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1457 | } |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1458 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1459 | propertyId, propertyIvar, propertyIvarLoc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1460 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | ConsumeToken(); // consume ',' |
| 1463 | } |
Douglas Gregor | 78edf99 | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1464 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1465 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1468 | /// property-dynamic: |
| 1469 | /// @dynamic property-list |
| 1470 | /// |
| 1471 | /// property-list: |
| 1472 | /// identifier |
| 1473 | /// property-list ',' identifier |
| 1474 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1475 | Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1476 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1477 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
Jeffrey Yasskin | 8dfa5f1 | 2011-01-18 02:00:16 +0000 | [diff] [blame^] | 1478 | ConsumeToken(); // consume dynamic |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1479 | while (true) { |
| 1480 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1481 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1482 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | if (Tok.isNot(tok::identifier)) { |
| 1486 | Diag(Tok, diag::err_expected_ident); |
| 1487 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1488 | return 0; |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1491 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1492 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1493 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, |
Douglas Gregor | b1b71e5 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1494 | propertyId, 0, SourceLocation()); |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1495 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1496 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1497 | break; |
| 1498 | ConsumeToken(); // consume ',' |
| 1499 | } |
Douglas Gregor | 78edf99 | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1500 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1501 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1502 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1503 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1504 | /// objc-throw-statement: |
| 1505 | /// throw expression[opt]; |
| 1506 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1507 | StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 1508 | ExprResult Res; |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1509 | ConsumeToken(); // consume throw |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1510 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | adfbbc3 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1511 | Res = ParseExpression(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1512 | if (Res.isInvalid()) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1513 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1514 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1515 | } |
| 1516 | } |
Ted Kremenek | 15a81e5 | 2010-04-20 21:21:51 +0000 | [diff] [blame] | 1517 | // consume ';' |
| 1518 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1519 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1522 | /// objc-synchronized-statement: |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1523 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1524 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1525 | StmtResult |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1526 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1527 | ConsumeToken(); // consume synchronized |
| 1528 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1529 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1530 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1531 | } |
| 1532 | ConsumeParen(); // '(' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1533 | ExprResult Res(ParseExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1534 | if (Res.isInvalid()) { |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1535 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1536 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1537 | } |
| 1538 | if (Tok.isNot(tok::r_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1539 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1540 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1541 | } |
| 1542 | ConsumeParen(); // ')' |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1543 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1544 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1545 | return StmtError(); |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1546 | } |
Steve Naroff | d9c2607 | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1547 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1548 | // statements can always hold declarations. |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1549 | ParseScope BodyScope(this, Scope::DeclScope); |
Steve Naroff | d9c2607 | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1550 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1551 | StmtResult SynchBody(ParseCompoundStatementBody()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1552 | |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1553 | BodyScope.Exit(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1554 | if (SynchBody.isInvalid()) |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1555 | SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1556 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1559 | /// objc-try-catch-statement: |
| 1560 | /// @try compound-statement objc-catch-list[opt] |
| 1561 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1562 | /// |
| 1563 | /// objc-catch-list: |
| 1564 | /// @catch ( parameter-declaration ) compound-statement |
| 1565 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1566 | /// catch-parameter-declaration: |
| 1567 | /// parameter-declaration |
| 1568 | /// '...' [OBJC2] |
| 1569 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1570 | StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1571 | bool catch_or_finally_seen = false; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1572 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1573 | ConsumeToken(); // consume try |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1574 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1575 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1576 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1577 | } |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1578 | StmtVector CatchStmts(Actions); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1579 | StmtResult FinallyStmt; |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1580 | ParseScope TryScope(this, Scope::DeclScope); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1581 | StmtResult TryBody(ParseCompoundStatementBody()); |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1582 | TryScope.Exit(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1583 | if (TryBody.isInvalid()) |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1584 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1585 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1586 | while (Tok.is(tok::at)) { |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1587 | // At this point, we need to lookahead to determine if this @ is the start |
| 1588 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1589 | // is an @try or @encode or something else. |
| 1590 | Token AfterAt = GetLookAheadToken(1); |
| 1591 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1592 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1593 | break; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1594 | |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1595 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1596 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1597 | Decl *FirstPart = 0; |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1598 | ConsumeToken(); // consume catch |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1599 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1600 | ConsumeParen(); |
Steve Naroff | 5ee2c02 | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1601 | ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1602 | if (Tok.isNot(tok::ellipsis)) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1603 | DeclSpec DS; |
| 1604 | ParseDeclarationSpecifiers(DS); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1605 | // For some odd reason, the name of the exception variable is |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1606 | // optional. As a result, we need to use "PrototypeContext", because |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1607 | // we must accept either 'declarator' or 'abstract-declarator' here. |
| 1608 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 1609 | ParseDeclarator(ParmDecl); |
| 1610 | |
Douglas Gregor | e11ee11 | 2010-04-23 23:01:43 +0000 | [diff] [blame] | 1611 | // Inform the actions module about the declarator, so it |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1612 | // gets added to the current scope. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1613 | FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1614 | } else |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1615 | ConsumeToken(); // consume '...' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1616 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1617 | SourceLocation RParenLoc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1618 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1619 | if (Tok.is(tok::r_paren)) |
| 1620 | RParenLoc = ConsumeParen(); |
| 1621 | else // Skip over garbage, until we get to ')'. Eat the ')'. |
| 1622 | SkipUntil(tok::r_paren, true, false); |
| 1623 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1624 | StmtResult CatchBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1625 | if (Tok.is(tok::l_brace)) |
| 1626 | CatchBody = ParseCompoundStatementBody(); |
| 1627 | else |
| 1628 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1629 | if (CatchBody.isInvalid()) |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1630 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1631 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1632 | StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1633 | RParenLoc, |
| 1634 | FirstPart, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1635 | CatchBody.take()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1636 | if (!Catch.isInvalid()) |
| 1637 | CatchStmts.push_back(Catch.release()); |
| 1638 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1639 | } else { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1640 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 1641 | << "@catch clause"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1642 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1643 | } |
| 1644 | catch_or_finally_seen = true; |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1645 | } else { |
| 1646 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1647 | ConsumeToken(); // consume finally |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1648 | ParseScope FinallyScope(this, Scope::DeclScope); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1649 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1650 | StmtResult FinallyBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1651 | if (Tok.is(tok::l_brace)) |
| 1652 | FinallyBody = ParseCompoundStatementBody(); |
| 1653 | else |
| 1654 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1655 | if (FinallyBody.isInvalid()) |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1656 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1657 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1658 | FinallyBody.take()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1659 | catch_or_finally_seen = true; |
| 1660 | break; |
| 1661 | } |
| 1662 | } |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1663 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1664 | Diag(atLoc, diag::err_missing_catch_finally); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1665 | return StmtError(); |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1666 | } |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1667 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1668 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1669 | move_arg(CatchStmts), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1670 | FinallyStmt.take()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1671 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1672 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1673 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1674 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1675 | Decl *Parser::ParseObjCMethodDefinition() { |
| 1676 | Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1677 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1678 | PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), |
| 1679 | "parsing Objective-C method"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1681 | // parse optional ';' |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1682 | if (Tok.is(tok::semi)) { |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1683 | if (ObjCImpDecl) { |
| 1684 | Diag(Tok, diag::warn_semicolon_before_method_body) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1685 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1686 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1687 | ConsumeToken(); |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1688 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1689 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1690 | // We should have an opening brace now. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1691 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | 83777fe | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1692 | Diag(Tok, diag::err_expected_method_body); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1693 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1694 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 1695 | SkipUntil(tok::l_brace, true, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1697 | // If we didn't find the '{', bail out. |
| 1698 | if (Tok.isNot(tok::l_brace)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1699 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1700 | } |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1701 | SourceLocation BraceLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1703 | // Enter a scope for the method body. |
Chris Lattner | c2ebb03 | 2010-04-12 05:38:43 +0000 | [diff] [blame] | 1704 | ParseScope BodyScope(this, |
| 1705 | Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1706 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1707 | // Tell the actions module that we have entered a method definition with the |
Steve Naroff | 542cd5d | 2008-07-25 17:57:26 +0000 | [diff] [blame] | 1708 | // specified Declarator for the method. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1709 | Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); |
Sebastian Redl | 042ad95 | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1710 | |
Argyrios Kyrtzidis | bd9dfb2 | 2011-01-04 00:27:27 +0000 | [diff] [blame] | 1711 | if (PP.isCodeCompletionEnabled()) |
| 1712 | if (trySkippingFunctionBodyForCodeCompletion()) |
| 1713 | return Actions.ActOnFinishFunctionBody(MDecl, 0); |
Argyrios Kyrtzidis | d5756a6 | 2011-01-03 22:33:06 +0000 | [diff] [blame] | 1714 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1715 | StmtResult FnBody(ParseCompoundStatementBody()); |
Sebastian Redl | 042ad95 | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1716 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1717 | // If the function body could not be parsed, make a bogus compoundstmt. |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1718 | if (FnBody.isInvalid()) |
Sebastian Redl | 52f03ba | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1719 | FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, |
| 1720 | MultiStmtArg(Actions), false); |
Sebastian Redl | c675bab | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1721 | |
Steve Naroff | b94d7f6 | 2009-03-02 22:00:56 +0000 | [diff] [blame] | 1722 | // TODO: Pass argument information. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1723 | Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1724 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1725 | // Leave the function body scope. |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1726 | BodyScope.Exit(); |
Sebastian Redl | c675bab | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1727 | |
Steve Naroff | 7b8fa47 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1728 | return MDecl; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1729 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1730 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1731 | StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1732 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1733 | Actions.CodeCompleteObjCAtStatement(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1734 | ConsumeCodeCompletionToken(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1735 | return StmtError(); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | if (Tok.isObjCAtKeyword(tok::objc_try)) |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1739 | return ParseObjCTryStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1740 | |
| 1741 | if (Tok.isObjCAtKeyword(tok::objc_throw)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1742 | return ParseObjCThrowStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1743 | |
| 1744 | if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1745 | return ParseObjCSynchronizedStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1746 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1747 | ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1748 | if (Res.isInvalid()) { |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1749 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 1750 | // doing this opens us up to the possibility of infinite loops if |
| 1751 | // ParseExpression does not consume any tokens. |
| 1752 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1753 | return StmtError(); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1754 | } |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1755 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1756 | // Otherwise, eat the semicolon. |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 1757 | ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1758 | return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1759 | } |
| 1760 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1761 | ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1762 | switch (Tok.getKind()) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1763 | case tok::code_completion: |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1764 | Actions.CodeCompleteObjCAtExpression(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1765 | ConsumeCodeCompletionToken(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1766 | return ExprError(); |
| 1767 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1768 | case tok::string_literal: // primary-expression: string-literal |
| 1769 | case tok::wide_string_literal: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1770 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1771 | default: |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1772 | if (Tok.getIdentifierInfo() == 0) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1773 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Sebastian Redl | 59b5e51 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1774 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1775 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 1776 | case tok::objc_encode: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1777 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1778 | case tok::objc_protocol: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1779 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1780 | case tok::objc_selector: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1781 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1782 | default: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1783 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1784 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1785 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1788 | /// \brirg Parse the receiver of an Objective-C++ message send. |
| 1789 | /// |
| 1790 | /// This routine parses the receiver of a message send in |
| 1791 | /// Objective-C++ either as a type or as an expression. Note that this |
| 1792 | /// routine must not be called to parse a send to 'super', since it |
| 1793 | /// has no way to return such a result. |
| 1794 | /// |
| 1795 | /// \param IsExpr Whether the receiver was parsed as an expression. |
| 1796 | /// |
| 1797 | /// \param TypeOrExpr If the receiver was parsed as an expression (\c |
| 1798 | /// IsExpr is true), the parsed expression. If the receiver was parsed |
| 1799 | /// as a type (\c IsExpr is false), the parsed type. |
| 1800 | /// |
| 1801 | /// \returns True if an error occurred during parsing or semantic |
| 1802 | /// analysis, in which case the arguments do not have valid |
| 1803 | /// values. Otherwise, returns false for a successful parse. |
| 1804 | /// |
| 1805 | /// objc-receiver: [C++] |
| 1806 | /// 'super' [not parsed here] |
| 1807 | /// expression |
| 1808 | /// simple-type-specifier |
| 1809 | /// typename-specifier |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1810 | bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 1811 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 1812 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1813 | if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || |
| 1814 | Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) |
| 1815 | TryAnnotateTypeOrScopeToken(); |
| 1816 | |
| 1817 | if (!isCXXSimpleTypeSpecifier()) { |
| 1818 | // objc-receiver: |
| 1819 | // expression |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1820 | ExprResult Receiver = ParseExpression(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1821 | if (Receiver.isInvalid()) |
| 1822 | return true; |
| 1823 | |
| 1824 | IsExpr = true; |
| 1825 | TypeOrExpr = Receiver.take(); |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
| 1829 | // objc-receiver: |
| 1830 | // typename-specifier |
| 1831 | // simple-type-specifier |
| 1832 | // expression (that starts with one of the above) |
| 1833 | DeclSpec DS; |
| 1834 | ParseCXXSimpleTypeSpecifier(DS); |
| 1835 | |
| 1836 | if (Tok.is(tok::l_paren)) { |
| 1837 | // If we see an opening parentheses at this point, we are |
| 1838 | // actually parsing an expression that starts with a |
| 1839 | // function-style cast, e.g., |
| 1840 | // |
| 1841 | // postfix-expression: |
| 1842 | // simple-type-specifier ( expression-list [opt] ) |
| 1843 | // typename-specifier ( expression-list [opt] ) |
| 1844 | // |
| 1845 | // Parse the remainder of this case, then the (optional) |
| 1846 | // postfix-expression suffix, followed by the (optional) |
| 1847 | // right-hand side of the binary expression. We have an |
| 1848 | // instance method. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1849 | ExprResult Receiver = ParseCXXTypeConstructExpression(DS); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1850 | if (!Receiver.isInvalid()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1851 | Receiver = ParsePostfixExpressionSuffix(Receiver.take()); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1852 | if (!Receiver.isInvalid()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1853 | Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1854 | if (Receiver.isInvalid()) |
| 1855 | return true; |
| 1856 | |
| 1857 | IsExpr = true; |
| 1858 | TypeOrExpr = Receiver.take(); |
| 1859 | return false; |
| 1860 | } |
| 1861 | |
| 1862 | // We have a class message. Turn the simple-type-specifier or |
| 1863 | // typename-specifier we parsed into a type and parse the |
| 1864 | // remainder of the class message. |
| 1865 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1866 | TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1867 | if (Type.isInvalid()) |
| 1868 | return true; |
| 1869 | |
| 1870 | IsExpr = false; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1871 | TypeOrExpr = Type.get().getAsOpaquePtr(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1875 | /// \brief Determine whether the parser is currently referring to a an |
| 1876 | /// Objective-C message send, using a simplified heuristic to avoid overhead. |
| 1877 | /// |
| 1878 | /// This routine will only return true for a subset of valid message-send |
| 1879 | /// expressions. |
| 1880 | bool Parser::isSimpleObjCMessageExpression() { |
Chris Lattner | 47054fb | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 1881 | assert(Tok.is(tok::l_square) && getLang().ObjC1 && |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1882 | "Incorrect start for isSimpleObjCMessageExpression"); |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1883 | return GetLookAheadToken(1).is(tok::identifier) && |
| 1884 | GetLookAheadToken(2).is(tok::identifier); |
| 1885 | } |
| 1886 | |
Douglas Gregor | abf4a3e | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1887 | bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { |
| 1888 | if (!getLang().ObjC1 || !NextToken().is(tok::identifier) || |
| 1889 | InMessageExpression) |
| 1890 | return false; |
| 1891 | |
| 1892 | |
| 1893 | ParsedType Type; |
| 1894 | |
| 1895 | if (Tok.is(tok::annot_typename)) |
| 1896 | Type = getTypeAnnotation(Tok); |
| 1897 | else if (Tok.is(tok::identifier)) |
| 1898 | Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), |
| 1899 | getCurScope()); |
| 1900 | else |
| 1901 | return false; |
| 1902 | |
| 1903 | if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { |
| 1904 | const Token &AfterNext = GetLookAheadToken(2); |
| 1905 | if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { |
| 1906 | if (Tok.is(tok::identifier)) |
| 1907 | TryAnnotateTypeOrScopeToken(); |
| 1908 | |
| 1909 | return Tok.is(tok::annot_typename); |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1916 | /// objc-message-expr: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1917 | /// '[' objc-receiver objc-message-args ']' |
| 1918 | /// |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1919 | /// objc-receiver: [C] |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 1920 | /// 'super' |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1921 | /// expression |
| 1922 | /// class-name |
| 1923 | /// type-name |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1924 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1925 | ExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1926 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 1927 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 1928 | |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 1929 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1930 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 1931 | ConsumeCodeCompletionToken(); |
| 1932 | SkipUntil(tok::r_square); |
| 1933 | return ExprError(); |
| 1934 | } |
| 1935 | |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 1936 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 1937 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1938 | if (getLang().CPlusPlus) { |
| 1939 | // We completely separate the C and C++ cases because C++ requires |
| 1940 | // more complicated (read: slower) parsing. |
| 1941 | |
| 1942 | // Handle send to super. |
| 1943 | // FIXME: This doesn't benefit from the same typo-correction we |
| 1944 | // get in Objective-C. |
| 1945 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1946 | NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1947 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 1948 | ParsedType(), 0); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1949 | |
| 1950 | // Parse the receiver, which is either a type or an expression. |
| 1951 | bool IsExpr; |
Nick Lewycky | 970aed9 | 2010-09-15 18:35:19 +0000 | [diff] [blame] | 1952 | void *TypeOrExpr = NULL; |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1953 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
| 1954 | SkipUntil(tok::r_square); |
| 1955 | return ExprError(); |
| 1956 | } |
| 1957 | |
| 1958 | if (IsExpr) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1959 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 1960 | ParsedType(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1961 | static_cast<Expr*>(TypeOrExpr)); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1962 | |
| 1963 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1964 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
| 1965 | 0); |
Chris Lattner | 47054fb | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
| 1968 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1969 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 1970 | SourceLocation NameLoc = Tok.getLocation(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1971 | ParsedType ReceiverType; |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1972 | switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1973 | Name == Ident_super, |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1974 | NextToken().is(tok::period), |
| 1975 | ReceiverType)) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1976 | case Sema::ObjCSuperMessage: |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1977 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 1978 | ParsedType(), 0); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1979 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1980 | case Sema::ObjCClassMessage: |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1981 | if (!ReceiverType) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1982 | SkipUntil(tok::r_square); |
| 1983 | return ExprError(); |
| 1984 | } |
| 1985 | |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1986 | ConsumeToken(); // the type name |
| 1987 | |
| 1988 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1989 | ReceiverType, 0); |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1990 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1991 | case Sema::ObjCInstanceMessage: |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1992 | // Fall through to parse an expression. |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1993 | break; |
Fariborz Jahanian | fc58ca4 | 2009-04-08 19:50:10 +0000 | [diff] [blame] | 1994 | } |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1995 | } |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 1996 | |
| 1997 | // Otherwise, an arbitrary expression can be the receiver of a send. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1998 | ExprResult Res(ParseExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1999 | if (Res.isInvalid()) { |
Chris Lattner | 77927cc | 2008-01-25 19:43:26 +0000 | [diff] [blame] | 2000 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2001 | return move(Res); |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2002 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2003 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2004 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 2005 | ParsedType(), Res.take()); |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2006 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2008 | /// \brief Parse the remainder of an Objective-C message following the |
| 2009 | /// '[' objc-receiver. |
| 2010 | /// |
| 2011 | /// This routine handles sends to super, class messages (sent to a |
| 2012 | /// class name), and instance messages (sent to an object), and the |
| 2013 | /// target is represented by \p SuperLoc, \p ReceiverType, or \p |
| 2014 | /// ReceiverExpr, respectively. Only one of these parameters may have |
| 2015 | /// a valid value. |
| 2016 | /// |
| 2017 | /// \param LBracLoc The location of the opening '['. |
| 2018 | /// |
| 2019 | /// \param SuperLoc If this is a send to 'super', the location of the |
| 2020 | /// 'super' keyword that indicates a send to the superclass. |
| 2021 | /// |
| 2022 | /// \param ReceiverType If this is a class message, the type of the |
| 2023 | /// class we are sending a message to. |
| 2024 | /// |
| 2025 | /// \param ReceiverExpr If this is an instance message, the expression |
| 2026 | /// used to compute the receiver object. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2027 | /// |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2028 | /// objc-message-args: |
| 2029 | /// objc-selector |
| 2030 | /// objc-keywordarg-list |
| 2031 | /// |
| 2032 | /// objc-keywordarg-list: |
| 2033 | /// objc-keywordarg |
| 2034 | /// objc-keywordarg-list objc-keywordarg |
| 2035 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2036 | /// objc-keywordarg: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2037 | /// selector-name[opt] ':' objc-keywordexpr |
| 2038 | /// |
| 2039 | /// objc-keywordexpr: |
| 2040 | /// nonempty-expr-list |
| 2041 | /// |
| 2042 | /// nonempty-expr-list: |
| 2043 | /// assignment-expression |
| 2044 | /// nonempty-expr-list , assignment-expression |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2045 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2046 | ExprResult |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2047 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2048 | SourceLocation SuperLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2049 | ParsedType ReceiverType, |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2050 | ExprArg ReceiverExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2051 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2052 | |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2053 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2054 | if (SuperLoc.isValid()) |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2055 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, |
| 2056 | false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2057 | else if (ReceiverType) |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2058 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, |
| 2059 | false); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2060 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2061 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2062 | 0, 0, false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 2063 | ConsumeCodeCompletionToken(); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2064 | } |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2065 | |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2066 | // Parse objc-selector |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 2067 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2068 | IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2069 | |
Anders Carlsson | 978f08d | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 2070 | SourceLocation SelectorLoc = Loc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2071 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2072 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2073 | ExprVector KeyExprs(Actions); |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2074 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2075 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2076 | while (1) { |
| 2077 | // Each iteration parses a single keyword argument. |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2078 | KeyIdents.push_back(selIdent); |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2079 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2080 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2081 | Diag(Tok, diag::err_expected_colon); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2082 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2083 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2084 | // the enclosing expression. |
| 2085 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2086 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2087 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2088 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2089 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2090 | /// Parse the expression after ':' |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2091 | |
| 2092 | if (Tok.is(tok::code_completion)) { |
| 2093 | if (SuperLoc.isValid()) |
| 2094 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
| 2095 | KeyIdents.data(), |
| 2096 | KeyIdents.size(), |
| 2097 | /*AtArgumentEpression=*/true); |
| 2098 | else if (ReceiverType) |
| 2099 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
| 2100 | KeyIdents.data(), |
| 2101 | KeyIdents.size(), |
| 2102 | /*AtArgumentEpression=*/true); |
| 2103 | else |
| 2104 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 2105 | KeyIdents.data(), |
| 2106 | KeyIdents.size(), |
| 2107 | /*AtArgumentEpression=*/true); |
| 2108 | |
| 2109 | ConsumeCodeCompletionToken(); |
| 2110 | SkipUntil(tok::r_square); |
| 2111 | return ExprError(); |
| 2112 | } |
| 2113 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2114 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2115 | if (Res.isInvalid()) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2116 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2117 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2118 | // the enclosing expression. |
| 2119 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2120 | return move(Res); |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2121 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2122 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2123 | // We have a valid expression. |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2124 | KeyExprs.push_back(Res.release()); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2125 | |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2126 | // Code completion after each argument. |
| 2127 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2128 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2129 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2130 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2131 | KeyIdents.size(), |
| 2132 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2133 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2134 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2135 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2136 | KeyIdents.size(), |
| 2137 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2138 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2139 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2140 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2141 | KeyIdents.size(), |
| 2142 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 2143 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2144 | SkipUntil(tok::r_square); |
| 2145 | return ExprError(); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2148 | // Check for another keyword selector. |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2149 | selIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2150 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2151 | break; |
| 2152 | // We have a selector or a colon, continue parsing. |
| 2153 | } |
| 2154 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2155 | while (Tok.is(tok::comma)) { |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2156 | ConsumeToken(); // Eat the ','. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2157 | /// Parse the expression after ',' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2158 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2159 | if (Res.isInvalid()) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2160 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2161 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2162 | // the enclosing expression. |
| 2163 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2164 | return move(Res); |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2165 | } |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2166 | |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2167 | // We have a valid expression. |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2168 | KeyExprs.push_back(Res.release()); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2169 | } |
| 2170 | } else if (!selIdent) { |
| 2171 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2172 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2173 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2174 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2175 | // the enclosing expression. |
| 2176 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2177 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2178 | } |
Fariborz Jahanian | 083712f | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2179 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2180 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | 083712f | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2181 | if (Tok.is(tok::identifier)) |
| 2182 | Diag(Tok, diag::err_expected_colon); |
| 2183 | else |
| 2184 | Diag(Tok, diag::err_expected_rsquare); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2185 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2186 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2187 | // the enclosing expression. |
| 2188 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2189 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2190 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2191 | |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2192 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2193 | |
Steve Naroff | e61bfa8 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 2194 | unsigned nKeys = KeyIdents.size(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2195 | if (nKeys == 0) |
| 2196 | KeyIdents.push_back(selIdent); |
| 2197 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2198 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2199 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2200 | return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2201 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2202 | MultiExprArg(Actions, |
| 2203 | KeyExprs.take(), |
| 2204 | KeyExprs.size())); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2205 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2206 | return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2207 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2208 | MultiExprArg(Actions, |
| 2209 | KeyExprs.take(), |
| 2210 | KeyExprs.size())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2211 | return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2212 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2213 | MultiExprArg(Actions, |
| 2214 | KeyExprs.take(), |
| 2215 | KeyExprs.size())); |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2216 | } |
| 2217 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2218 | ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
| 2219 | ExprResult Res(ParseStringLiteralExpression()); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2220 | if (Res.isInvalid()) return move(Res); |
| 2221 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2222 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 2223 | // expressions. At this point, we know that the only valid thing that starts |
| 2224 | // with '@' is an @"". |
| 2225 | llvm::SmallVector<SourceLocation, 4> AtLocs; |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2226 | ExprVector AtStrings(Actions); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2227 | AtLocs.push_back(AtLoc); |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2228 | AtStrings.push_back(Res.release()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2229 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2230 | while (Tok.is(tok::at)) { |
| 2231 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2232 | |
Sebastian Redl | c13f268 | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 2233 | // Invalid unless there is a string literal. |
Chris Lattner | d3b5d5d | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 2234 | if (!isTokenStringLiteral()) |
| 2235 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2236 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2237 | ExprResult Lit(ParseStringLiteralExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2238 | if (Lit.isInvalid()) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2239 | return move(Lit); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2240 | |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2241 | AtStrings.push_back(Lit.release()); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2242 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2243 | |
| 2244 | return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), |
| 2245 | AtStrings.size())); |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2246 | } |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2247 | |
| 2248 | /// objc-encode-expression: |
| 2249 | /// @encode ( type-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2250 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2251 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 2252 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2253 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2254 | SourceLocation EncLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2255 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2256 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2257 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 2258 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2259 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2261 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2262 | |
Anders Carlsson | cb8f832 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2263 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2264 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2265 | if (Ty.isInvalid()) |
| 2266 | return ExprError(); |
| 2267 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2268 | return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2269 | Ty.get(), RParenLoc)); |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2270 | } |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2271 | |
| 2272 | /// objc-protocol-expression |
| 2273 | /// @protocol ( protocol-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2274 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2275 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2276 | SourceLocation ProtoLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2277 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2278 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2279 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 2280 | |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2281 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2282 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2283 | if (Tok.isNot(tok::identifier)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2284 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2285 | |
Fariborz Jahanian | a32aaef | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2286 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2287 | ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2288 | |
Anders Carlsson | cb8f832 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2289 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2290 | |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2291 | return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 2292 | LParenLoc, RParenLoc)); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2293 | } |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2294 | |
| 2295 | /// objc-selector-expression |
| 2296 | /// @selector '(' objc-keyword-selector ')' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2297 | ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2298 | SourceLocation SelectorLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2299 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2300 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2301 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 2302 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2303 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2304 | SourceLocation LParenLoc = ConsumeParen(); |
| 2305 | SourceLocation sLoc; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2306 | |
| 2307 | if (Tok.is(tok::code_completion)) { |
| 2308 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2309 | KeyIdents.size()); |
| 2310 | ConsumeCodeCompletionToken(); |
| 2311 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2312 | return ExprError(); |
| 2313 | } |
| 2314 | |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2315 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2316 | if (!SelIdent && // missing selector name. |
| 2317 | Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2318 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2319 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2320 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2321 | unsigned nColons = 0; |
| 2322 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2323 | while (1) { |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2324 | if (Tok.is(tok::coloncolon)) { // Handle :: in C++. |
| 2325 | ++nColons; |
| 2326 | KeyIdents.push_back(0); |
| 2327 | } else if (Tok.isNot(tok::colon)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2328 | return ExprError(Diag(Tok, diag::err_expected_colon)); |
| 2329 | |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2330 | ++nColons; |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2331 | ConsumeToken(); // Eat the ':'. |
| 2332 | if (Tok.is(tok::r_paren)) |
| 2333 | break; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2334 | |
| 2335 | if (Tok.is(tok::code_completion)) { |
| 2336 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2337 | KeyIdents.size()); |
| 2338 | ConsumeCodeCompletionToken(); |
| 2339 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2340 | return ExprError(); |
| 2341 | } |
| 2342 | |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2343 | // Check for another keyword selector. |
| 2344 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2345 | SelIdent = ParseObjCSelectorPiece(Loc); |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2346 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2347 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 2348 | break; |
| 2349 | } |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2350 | } |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2351 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2352 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2353 | return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 2354 | LParenLoc, RParenLoc)); |
Gabor Greif | 24032f1 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 2355 | } |