Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1 | //===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C portions of the Parser interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 15 | #include "clang/Parse/DeclSpec.h" |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Scope.h" |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 17 | #include "AstGuard.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 18 | #include "clang/Parse/ParseDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | using namespace clang; |
| 21 | |
| 22 | |
Chris Lattner | 891dca6 | 2008-12-08 21:53:24 +0000 | [diff] [blame] | 23 | /// ParseObjCAtDirectives - Handle parts of the external-declaration production: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | /// external-declaration: [C99 6.9] |
| 25 | /// [OBJC] objc-class-definition |
Steve Naroff | 91fa0b7 | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 26 | /// [OBJC] objc-class-declaration |
| 27 | /// [OBJC] objc-alias-declaration |
| 28 | /// [OBJC] objc-protocol-definition |
| 29 | /// [OBJC] objc-method-definition |
| 30 | /// [OBJC] '@' 'end' |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 31 | Parser::DeclTy *Parser::ParseObjCAtDirectives() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 32 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
| 33 | |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 34 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 35 | case tok::objc_class: |
| 36 | return ParseObjCAtClassDeclaration(AtLoc); |
| 37 | case tok::objc_interface: |
| 38 | return ParseObjCAtInterfaceDeclaration(AtLoc); |
| 39 | case tok::objc_protocol: |
| 40 | return ParseObjCAtProtocolDeclaration(AtLoc); |
| 41 | case tok::objc_implementation: |
| 42 | return ParseObjCAtImplementationDeclaration(AtLoc); |
| 43 | case tok::objc_end: |
| 44 | return ParseObjCAtEndDeclaration(AtLoc); |
| 45 | case tok::objc_compatibility_alias: |
| 46 | return ParseObjCAtAliasDeclaration(AtLoc); |
| 47 | case tok::objc_synthesize: |
| 48 | return ParseObjCPropertySynthesize(AtLoc); |
| 49 | case tok::objc_dynamic: |
| 50 | return ParseObjCPropertyDynamic(AtLoc); |
| 51 | default: |
| 52 | Diag(AtLoc, diag::err_unexpected_at); |
| 53 | SkipUntil(tok::semi); |
| 54 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | /// |
| 59 | /// objc-class-declaration: |
| 60 | /// '@' 'class' identifier-list ';' |
| 61 | /// |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 62 | Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 63 | ConsumeToken(); // the identifier "class" |
| 64 | llvm::SmallVector<IdentifierInfo *, 8> ClassNames; |
| 65 | |
| 66 | while (1) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 67 | if (Tok.isNot(tok::identifier)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | Diag(Tok, diag::err_expected_ident); |
| 69 | SkipUntil(tok::semi); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 70 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 71 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 72 | ClassNames.push_back(Tok.getIdentifierInfo()); |
| 73 | ConsumeToken(); |
| 74 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 75 | if (Tok.isNot(tok::comma)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | break; |
| 77 | |
| 78 | ConsumeToken(); |
| 79 | } |
| 80 | |
| 81 | // Consume the ';'. |
| 82 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 83 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 84 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 85 | return Actions.ActOnForwardClassDeclaration(atLoc, |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 86 | &ClassNames[0], ClassNames.size()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 89 | /// |
| 90 | /// objc-interface: |
| 91 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 92 | /// objc-category-interface |
| 93 | /// |
| 94 | /// objc-class-interface: |
| 95 | /// '@' 'interface' identifier objc-superclass[opt] |
| 96 | /// objc-protocol-refs[opt] |
| 97 | /// objc-class-instance-variables[opt] |
| 98 | /// objc-interface-decl-list |
| 99 | /// @end |
| 100 | /// |
| 101 | /// objc-category-interface: |
| 102 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
| 103 | /// objc-protocol-refs[opt] |
| 104 | /// objc-interface-decl-list |
| 105 | /// @end |
| 106 | /// |
| 107 | /// objc-superclass: |
| 108 | /// ':' identifier |
| 109 | /// |
| 110 | /// objc-class-interface-attributes: |
| 111 | /// __attribute__((visibility("default"))) |
| 112 | /// __attribute__((visibility("hidden"))) |
| 113 | /// __attribute__((deprecated)) |
| 114 | /// __attribute__((unavailable)) |
| 115 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 116 | /// |
| 117 | Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( |
| 118 | SourceLocation atLoc, AttributeList *attrList) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 119 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 120 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 121 | ConsumeToken(); // the "interface" identifier |
| 122 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 123 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 124 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 125 | return 0; |
| 126 | } |
| 127 | // We have a class or category name - consume it. |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 128 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 129 | SourceLocation nameLoc = ConsumeToken(); |
| 130 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 131 | if (Tok.is(tok::l_paren)) { // we have a category. |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 132 | SourceLocation lparenLoc = ConsumeParen(); |
| 133 | SourceLocation categoryLoc, rparenLoc; |
| 134 | IdentifierInfo *categoryId = 0; |
| 135 | |
Steve Naroff | 527fe23 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 136 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 137 | if (Tok.is(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 138 | categoryId = Tok.getIdentifierInfo(); |
| 139 | categoryLoc = ConsumeToken(); |
Steve Naroff | 527fe23 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 140 | } else if (!getLang().ObjC2) { |
| 141 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 142 | return 0; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 143 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 144 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 145 | Diag(Tok, diag::err_expected_rparen); |
| 146 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 147 | return 0; |
| 148 | } |
| 149 | rparenLoc = ConsumeParen(); |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 150 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 151 | // Next, we need to check for any protocol references. |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 152 | SourceLocation EndProtoLoc; |
| 153 | llvm::SmallVector<DeclTy *, 8> ProtocolRefs; |
| 154 | if (Tok.is(tok::less) && |
| 155 | ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) |
| 156 | return 0; |
| 157 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 158 | if (attrList) // categories don't support attributes. |
| 159 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
| 160 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 161 | DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, |
Steve Naroff | 3a165b0 | 2007-10-03 21:00:46 +0000 | [diff] [blame] | 162 | nameId, nameLoc, categoryId, categoryLoc, |
Steve Naroff | 423cb56 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 163 | &ProtocolRefs[0], ProtocolRefs.size(), |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 164 | EndProtoLoc); |
Fariborz Jahanian | fd225cc | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 165 | |
| 166 | ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 167 | return CategoryType; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 168 | } |
| 169 | // Parse a class interface. |
| 170 | IdentifierInfo *superClassId = 0; |
| 171 | SourceLocation superClassLoc; |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 172 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 173 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 174 | ConsumeToken(); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 175 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 176 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 177 | return 0; |
| 178 | } |
| 179 | superClassId = Tok.getIdentifierInfo(); |
| 180 | superClassLoc = ConsumeToken(); |
| 181 | } |
| 182 | // Next, we need to check for any protocol references. |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 183 | llvm::SmallVector<Action::DeclTy*, 8> ProtocolRefs; |
| 184 | SourceLocation EndProtoLoc; |
| 185 | if (Tok.is(tok::less) && |
| 186 | ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) |
| 187 | return 0; |
| 188 | |
| 189 | DeclTy *ClsType = |
| 190 | Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, |
| 191 | superClassId, superClassLoc, |
| 192 | &ProtocolRefs[0], ProtocolRefs.size(), |
| 193 | EndProtoLoc, attrList); |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 194 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 195 | if (Tok.is(tok::l_brace)) |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 196 | ParseObjCClassInstanceVariables(ClsType, atLoc); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 197 | |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 198 | ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 199 | return ClsType; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /// objc-interface-decl-list: |
| 203 | /// empty |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 204 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 205 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 206 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 207 | /// objc-interface-decl-list declaration |
| 208 | /// objc-interface-decl-list ';' |
| 209 | /// |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 210 | /// objc-method-requirement: [OBJC2] |
| 211 | /// @required |
| 212 | /// @optional |
| 213 | /// |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 214 | void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 215 | tok::ObjCKeywordKind contextKey) { |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 216 | llvm::SmallVector<DeclTy*, 32> allMethods; |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 217 | llvm::SmallVector<DeclTy*, 16> allProperties; |
Fariborz Jahanian | 0093359 | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 218 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 219 | |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 220 | SourceLocation AtEndLoc; |
| 221 | |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 222 | while (1) { |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 223 | // If this is a method prototype, parse it. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 224 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
| 225 | DeclTy *methodPrototype = |
| 226 | ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 227 | allMethods.push_back(methodPrototype); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 228 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 229 | // method definitions. |
Chris Lattner | b6d74a1 | 2009-02-15 22:24:30 +0000 | [diff] [blame] | 230 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, |
| 231 | "", tok::semi); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 232 | continue; |
| 233 | } |
Fariborz Jahanian | f366b4c | 2007-12-11 18:34:51 +0000 | [diff] [blame] | 234 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 235 | // Ignore excess semicolons. |
| 236 | if (Tok.is(tok::semi)) { |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 237 | ConsumeToken(); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 238 | continue; |
| 239 | } |
| 240 | |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 241 | // If we got to the end of the file, exit the loop. |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 242 | if (Tok.is(tok::eof)) |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 243 | break; |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 244 | |
| 245 | // If we don't have an @ directive, parse it as a function definition. |
| 246 | if (Tok.isNot(tok::at)) { |
Chris Lattner | 1fd8011 | 2009-01-09 04:34:13 +0000 | [diff] [blame] | 247 | // The code below does not consume '}'s because it is afraid of eating the |
| 248 | // end of a namespace. Because of the way this code is structured, an |
| 249 | // erroneous r_brace would cause an infinite loop if not handled here. |
| 250 | if (Tok.is(tok::r_brace)) |
| 251 | break; |
| 252 | |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 253 | // FIXME: as the name implies, this rule allows function definitions. |
| 254 | // We could pass a flag or check for functions during semantic analysis. |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 255 | ParseDeclarationOrFunctionDefinition(); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 256 | continue; |
| 257 | } |
| 258 | |
| 259 | // Otherwise, we have an @ directive, eat the @. |
| 260 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 261 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 262 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 263 | if (DirectiveKind == tok::objc_end) { // @end -> terminate list |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 264 | AtEndLoc = AtLoc; |
| 265 | break; |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 266 | } |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 267 | |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 268 | // Eat the identifier. |
| 269 | ConsumeToken(); |
| 270 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 271 | switch (DirectiveKind) { |
| 272 | default: |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 273 | // FIXME: If someone forgets an @end on a protocol, this loop will |
| 274 | // continue to eat up tons of stuff and spew lots of nonsense errors. It |
| 275 | // would probably be better to bail out if we saw an @class or @interface |
| 276 | // or something like that. |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 277 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 278 | // Skip until we see an '@' or '}' or ';'. |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 279 | SkipUntil(tok::r_brace, tok::at); |
| 280 | break; |
| 281 | |
| 282 | case tok::objc_required: |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 283 | case tok::objc_optional: |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 284 | // This is only valid on protocols. |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 285 | // FIXME: Should this check for ObjC2 being enabled? |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 286 | if (contextKey != tok::objc_protocol) |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 287 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 288 | else |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 289 | MethodImplKind = DirectiveKind; |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 290 | break; |
| 291 | |
| 292 | case tok::objc_property: |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 293 | if (!getLang().ObjC2) |
| 294 | Diag(AtLoc, diag::err_objc_propertoes_require_objc2); |
| 295 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 296 | ObjCDeclSpec OCDS; |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 297 | // Parse property attribute list, if any. |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 298 | if (Tok.is(tok::l_paren)) |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 299 | ParseObjCPropertyAttribute(OCDS); |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 300 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 301 | // Parse all the comma separated declarators. |
| 302 | DeclSpec DS; |
| 303 | llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; |
| 304 | ParseStructDeclaration(DS, FieldDeclarators); |
| 305 | |
Chris Lattner | a1fed7e | 2008-10-20 06:15:13 +0000 | [diff] [blame] | 306 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", |
| 307 | tok::at); |
| 308 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 309 | // Convert them all to property declarations. |
| 310 | for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { |
| 311 | FieldDeclarator &FD = FieldDeclarators[i]; |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 312 | if (FD.D.getIdentifier() == 0) { |
Chris Lattner | ef708fd | 2008-11-18 07:50:21 +0000 | [diff] [blame] | 313 | Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 314 | << FD.D.getSourceRange(); |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 315 | continue; |
| 316 | } |
Fariborz Jahanian | 573acde | 2009-01-17 23:21:10 +0000 | [diff] [blame] | 317 | if (FD.BitfieldSize) { |
| 318 | Diag(AtLoc, diag::err_objc_property_bitfield) |
| 319 | << FD.D.getSourceRange(); |
| 320 | continue; |
| 321 | } |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 322 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 323 | // Install the property declarator into interfaceDecl. |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 324 | IdentifierInfo *SelName = |
| 325 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 326 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 327 | Selector GetterSel = |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 328 | PP.getSelectorTable().getNullarySelector(SelName); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 329 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 330 | if (!SetterName) |
Steve Naroff | 61f72cb | 2009-03-09 21:12:44 +0000 | [diff] [blame] | 331 | SetterName = |
| 332 | SelectorTable::constructSetterName(PP.getIdentifierTable(), |
| 333 | FD.D.getIdentifier()); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 334 | Selector SetterSel = |
| 335 | PP.getSelectorTable().getUnarySelector(SetterName); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 336 | bool isOverridingProperty = false; |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 337 | DeclTy *Property = Actions.ActOnProperty(CurScope, AtLoc, FD, OCDS, |
| 338 | GetterSel, SetterSel, |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 339 | interfaceDecl, |
| 340 | &isOverridingProperty, |
Chris Lattner | da3253d | 2008-10-20 06:33:53 +0000 | [diff] [blame] | 341 | MethodImplKind); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 342 | if (!isOverridingProperty) |
| 343 | allProperties.push_back(Property); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 344 | } |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 345 | break; |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 346 | } |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 347 | } |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 348 | |
| 349 | // We break out of the big loop in two cases: when we see @end or when we see |
| 350 | // EOF. In the former case, eat the @end. In the later case, emit an error. |
| 351 | if (Tok.isObjCAtKeyword(tok::objc_end)) |
| 352 | ConsumeToken(); // the "end" identifier |
| 353 | else |
| 354 | Diag(Tok, diag::err_objc_missing_end); |
| 355 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 356 | // Insert collected methods declarations into the @interface object. |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 357 | // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. |
Ted Kremenek | 8a77931 | 2008-06-06 16:45:15 +0000 | [diff] [blame] | 358 | Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, |
| 359 | allMethods.empty() ? 0 : &allMethods[0], |
| 360 | allMethods.size(), |
| 361 | allProperties.empty() ? 0 : &allProperties[0], |
| 362 | allProperties.size()); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 365 | /// Parse property attribute declarations. |
| 366 | /// |
| 367 | /// property-attr-decl: '(' property-attrlist ')' |
| 368 | /// property-attrlist: |
| 369 | /// property-attribute |
| 370 | /// property-attrlist ',' property-attribute |
| 371 | /// property-attribute: |
| 372 | /// getter '=' identifier |
| 373 | /// setter '=' identifier ':' |
| 374 | /// readonly |
| 375 | /// readwrite |
| 376 | /// assign |
| 377 | /// retain |
| 378 | /// copy |
| 379 | /// nonatomic |
| 380 | /// |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 381 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 382 | assert(Tok.getKind() == tok::l_paren); |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 383 | SourceLocation LHSLoc = ConsumeParen(); // consume '(' |
| 384 | |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 385 | while (1) { |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 386 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 387 | |
| 388 | // If this is not an identifier at all, bail out early. |
| 389 | if (II == 0) { |
| 390 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
| 391 | return; |
| 392 | } |
| 393 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 394 | SourceLocation AttrName = ConsumeToken(); // consume last attribute name |
| 395 | |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 396 | if (II->isStr("readonly")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 397 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 398 | else if (II->isStr("assign")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 399 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 400 | else if (II->isStr("readwrite")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 401 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 402 | else if (II->isStr("retain")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 403 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 404 | else if (II->isStr("copy")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 405 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 406 | else if (II->isStr("nonatomic")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 407 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 408 | else if (II->isStr("getter") || II->isStr("setter")) { |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 409 | // getter/setter require extra treatment. |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 410 | if (ExpectAndConsume(tok::equal, diag::err_objc_expected_equal, "", |
| 411 | tok::r_paren)) |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 412 | return; |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 413 | |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 414 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 415 | Diag(Tok, diag::err_expected_ident); |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 416 | SkipUntil(tok::r_paren); |
| 417 | return; |
| 418 | } |
| 419 | |
Chris Lattner | 5fd80fa | 2008-10-20 07:43:01 +0000 | [diff] [blame] | 420 | if (II->getName()[0] == 's') { |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 421 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
| 422 | DS.setSetterName(Tok.getIdentifierInfo()); |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 423 | ConsumeToken(); // consume method name |
| 424 | |
| 425 | if (ExpectAndConsume(tok::colon, diag::err_expected_colon, "", |
| 426 | tok::r_paren)) |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 427 | return; |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 428 | } else { |
| 429 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
| 430 | DS.setGetterName(Tok.getIdentifierInfo()); |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 431 | ConsumeToken(); // consume method name |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 432 | } |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 433 | } else { |
Chris Lattner | a9500f0 | 2008-11-19 07:49:38 +0000 | [diff] [blame] | 434 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 435 | SkipUntil(tok::r_paren); |
| 436 | return; |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 437 | } |
Fariborz Jahanian | 82a5fe3 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 438 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 439 | if (Tok.isNot(tok::comma)) |
| 440 | break; |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 441 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 442 | ConsumeToken(); |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 443 | } |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 444 | |
| 445 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 448 | /// objc-method-proto: |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 449 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 450 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 451 | /// |
| 452 | /// objc-instance-method: '-' |
| 453 | /// objc-class-method: '+' |
| 454 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 455 | /// objc-method-attributes: [OBJC2] |
| 456 | /// __attribute__((deprecated)) |
| 457 | /// |
Fariborz Jahanian | 0093359 | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 458 | Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 459 | tok::ObjCKeywordKind MethodImplKind) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 460 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 461 | |
| 462 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 463 | SourceLocation mLoc = ConsumeToken(); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 464 | |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 465 | DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 466 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | 2bd42fa | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 467 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 468 | return MDecl; |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /// objc-selector: |
| 472 | /// identifier |
| 473 | /// one of |
| 474 | /// enum struct union if else while do for switch case default |
| 475 | /// break continue return goto asm sizeof typeof __alignof |
| 476 | /// unsigned long const short volatile signed restrict _Complex |
| 477 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 478 | /// |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 479 | IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 480 | switch (Tok.getKind()) { |
| 481 | default: |
| 482 | return 0; |
| 483 | case tok::identifier: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 484 | case tok::kw_asm: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 485 | case tok::kw_auto: |
Chris Lattner | 9298d96 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 486 | case tok::kw_bool: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 487 | case tok::kw_break: |
| 488 | case tok::kw_case: |
| 489 | case tok::kw_catch: |
| 490 | case tok::kw_char: |
| 491 | case tok::kw_class: |
| 492 | case tok::kw_const: |
| 493 | case tok::kw_const_cast: |
| 494 | case tok::kw_continue: |
| 495 | case tok::kw_default: |
| 496 | case tok::kw_delete: |
| 497 | case tok::kw_do: |
| 498 | case tok::kw_double: |
| 499 | case tok::kw_dynamic_cast: |
| 500 | case tok::kw_else: |
| 501 | case tok::kw_enum: |
| 502 | case tok::kw_explicit: |
| 503 | case tok::kw_export: |
| 504 | case tok::kw_extern: |
| 505 | case tok::kw_false: |
| 506 | case tok::kw_float: |
| 507 | case tok::kw_for: |
| 508 | case tok::kw_friend: |
| 509 | case tok::kw_goto: |
| 510 | case tok::kw_if: |
| 511 | case tok::kw_inline: |
| 512 | case tok::kw_int: |
| 513 | case tok::kw_long: |
| 514 | case tok::kw_mutable: |
| 515 | case tok::kw_namespace: |
| 516 | case tok::kw_new: |
| 517 | case tok::kw_operator: |
| 518 | case tok::kw_private: |
| 519 | case tok::kw_protected: |
| 520 | case tok::kw_public: |
| 521 | case tok::kw_register: |
| 522 | case tok::kw_reinterpret_cast: |
| 523 | case tok::kw_restrict: |
| 524 | case tok::kw_return: |
| 525 | case tok::kw_short: |
| 526 | case tok::kw_signed: |
| 527 | case tok::kw_sizeof: |
| 528 | case tok::kw_static: |
| 529 | case tok::kw_static_cast: |
| 530 | case tok::kw_struct: |
| 531 | case tok::kw_switch: |
| 532 | case tok::kw_template: |
| 533 | case tok::kw_this: |
| 534 | case tok::kw_throw: |
| 535 | case tok::kw_true: |
| 536 | case tok::kw_try: |
| 537 | case tok::kw_typedef: |
| 538 | case tok::kw_typeid: |
| 539 | case tok::kw_typename: |
| 540 | case tok::kw_typeof: |
| 541 | case tok::kw_union: |
| 542 | case tok::kw_unsigned: |
| 543 | case tok::kw_using: |
| 544 | case tok::kw_virtual: |
| 545 | case tok::kw_void: |
| 546 | case tok::kw_volatile: |
| 547 | case tok::kw_wchar_t: |
| 548 | case tok::kw_while: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 549 | case tok::kw__Bool: |
| 550 | case tok::kw__Complex: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 551 | case tok::kw___alignof: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 552 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 553 | SelectorLoc = ConsumeToken(); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 554 | return II; |
Fariborz Jahanian | d064951 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 555 | } |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 556 | } |
| 557 | |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 558 | /// objc-for-collection-in: 'in' |
| 559 | /// |
Fariborz Jahanian | 335a2d4 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 560 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 561 | // FIXME: May have to do additional look-ahead to only allow for |
| 562 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 563 | // '[' etc. |
Fariborz Jahanian | 335a2d4 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 564 | return (getLang().ObjC2 && Tok.is(tok::identifier) && |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 565 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 566 | } |
| 567 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 568 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 569 | /// qualifier list and builds their bitmask representation in the input |
| 570 | /// argument. |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 571 | /// |
| 572 | /// objc-type-qualifiers: |
| 573 | /// objc-type-qualifier |
| 574 | /// objc-type-qualifiers objc-type-qualifier |
| 575 | /// |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 576 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 577 | while (1) { |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 578 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 579 | return; |
| 580 | |
| 581 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 582 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 583 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 584 | continue; |
| 585 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 586 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 587 | switch (i) { |
| 588 | default: assert(0 && "Unknown decl qualifier"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 589 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 590 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 591 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 592 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 593 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 594 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 595 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 596 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 597 | ConsumeToken(); |
| 598 | II = 0; |
| 599 | break; |
| 600 | } |
| 601 | |
| 602 | // If this wasn't a recognized qualifier, bail out. |
| 603 | if (II) return; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | /// objc-type-name: |
| 608 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 609 | /// '(' objc-type-qualifiers[opt] ')' |
| 610 | /// |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 611 | Parser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 612 | assert(Tok.is(tok::l_paren) && "expected ("); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 613 | |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 614 | SourceLocation LParenLoc = ConsumeParen(); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 615 | SourceLocation TypeStartLoc = Tok.getLocation(); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 616 | |
Fariborz Jahanian | 19d74e1 | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 617 | // Parse type qualifiers, in, inout, etc. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 618 | ParseObjCTypeQualifierList(DS); |
Steve Naroff | 4fa7afd | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 619 | |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 620 | TypeTy *Ty = 0; |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 621 | if (isTypeSpecifierQualifier()) { |
| 622 | TypeResult TypeSpec = ParseTypeName(); |
| 623 | if (!TypeSpec.isInvalid()) |
| 624 | Ty = TypeSpec.get(); |
| 625 | } |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 626 | |
Steve Naroff | d7333c2 | 2008-10-21 14:15:04 +0000 | [diff] [blame] | 627 | if (Tok.is(tok::r_paren)) |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 628 | ConsumeParen(); |
| 629 | else if (Tok.getLocation() == TypeStartLoc) { |
| 630 | // If we didn't eat any tokens, then this isn't a type. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 631 | Diag(Tok, diag::err_expected_type); |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 632 | SkipUntil(tok::r_paren); |
| 633 | } else { |
| 634 | // Otherwise, we found *something*, but didn't get a ')' in the right |
| 635 | // place. Emit an error then return what we have as the type. |
| 636 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 637 | } |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 638 | return Ty; |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /// objc-method-decl: |
| 642 | /// objc-selector |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 643 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 644 | /// objc-type-name objc-selector |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 645 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 646 | /// |
| 647 | /// objc-keyword-selector: |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 648 | /// objc-keyword-decl |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 649 | /// objc-keyword-selector objc-keyword-decl |
| 650 | /// |
| 651 | /// objc-keyword-decl: |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 652 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 653 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 654 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 655 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 656 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 657 | /// objc-parmlist: |
| 658 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 659 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 660 | /// objc-parms: |
| 661 | /// objc-parms , parameter-declaration |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 662 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 663 | /// objc-ellipsis: |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 664 | /// , ... |
| 665 | /// |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 666 | /// objc-keyword-attributes: [OBJC2] |
| 667 | /// __attribute__((unused)) |
| 668 | /// |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 669 | Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 670 | tok::TokenKind mType, |
| 671 | DeclTy *IDecl, |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 672 | tok::ObjCKeywordKind MethodImplKind) |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 673 | { |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 674 | // Parse the return type if present. |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 675 | TypeTy *ReturnType = 0; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 676 | ObjCDeclSpec DSRet; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 677 | if (Tok.is(tok::l_paren)) |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 678 | ReturnType = ParseObjCTypeName(DSRet); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 679 | |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 680 | SourceLocation selLoc; |
| 681 | IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 682 | |
Steve Naroff | 84c4310 | 2009-02-11 20:43:13 +0000 | [diff] [blame] | 683 | // An unnamed colon is valid. |
| 684 | if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 685 | Diag(Tok, diag::err_expected_selector_for_method) |
| 686 | << SourceRange(mLoc, Tok.getLocation()); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 687 | // Skip until we get a ; or {}. |
| 688 | SkipUntil(tok::r_brace); |
| 689 | return 0; |
| 690 | } |
| 691 | |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 692 | llvm::SmallVector<Declarator, 8> CargNames; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 693 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 694 | // If attributes exist after the method, parse them. |
| 695 | AttributeList *MethodAttrs = 0; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 696 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 697 | MethodAttrs = ParseAttributes(); |
| 698 | |
| 699 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 700 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 701 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 702 | 0, 0, 0, CargNames, |
| 703 | MethodAttrs, MethodImplKind); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 704 | } |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 705 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 706 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 707 | llvm::SmallVector<Action::TypeTy *, 12> KeyTypes; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 708 | llvm::SmallVector<ObjCDeclSpec, 12> ArgTypeQuals; |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 709 | llvm::SmallVector<IdentifierInfo *, 12> ArgNames; |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 710 | |
| 711 | Action::TypeTy *TypeInfo; |
| 712 | while (1) { |
| 713 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 714 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 715 | // Each iteration parses a single keyword argument. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 716 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 717 | Diag(Tok, diag::err_expected_colon); |
| 718 | break; |
| 719 | } |
| 720 | ConsumeToken(); // Eat the ':'. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 721 | ObjCDeclSpec DSType; |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 722 | if (Tok.is(tok::l_paren)) // Parse the argument type. |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 723 | TypeInfo = ParseObjCTypeName(DSType); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 724 | else |
| 725 | TypeInfo = 0; |
| 726 | KeyTypes.push_back(TypeInfo); |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 727 | ArgTypeQuals.push_back(DSType); |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 728 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 729 | // If attributes exist before the argument name, parse them. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 730 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 731 | ParseAttributes(); // FIXME: pass attributes through. |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 732 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 733 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 734 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 735 | break; |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 736 | } |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 737 | ArgNames.push_back(Tok.getIdentifierInfo()); |
| 738 | ConsumeToken(); // Eat the identifier. |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 739 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 740 | // Check for another keyword selector. |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 741 | SourceLocation Loc; |
| 742 | SelIdent = ParseObjCSelector(Loc); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 743 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 744 | break; |
| 745 | // We have a selector or a colon, continue parsing. |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 746 | } |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 747 | |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 748 | bool isVariadic = false; |
| 749 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 750 | // Parse the (optional) parameter list. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 751 | while (Tok.is(tok::comma)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 752 | ConsumeToken(); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 753 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 754 | isVariadic = true; |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 755 | ConsumeToken(); |
| 756 | break; |
| 757 | } |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 758 | DeclSpec DS; |
| 759 | ParseDeclarationSpecifiers(DS); |
| 760 | // Parse the declarator. |
| 761 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 762 | ParseDeclarator(ParmDecl); |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 763 | CargNames.push_back(ParmDecl); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | // FIXME: Add support for optional parmameter list... |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 767 | // If attributes exist after the method, parse them. |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 768 | AttributeList *MethodAttrs = 0; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 769 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 770 | MethodAttrs = ParseAttributes(); |
| 771 | |
| 772 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 773 | &KeyIdents[0]); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 774 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 1f7b6f8 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 775 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | f1de0ca | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 776 | &ArgTypeQuals[0], &KeyTypes[0], |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 777 | &ArgNames[0], CargNames, |
| 778 | MethodAttrs, |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 779 | MethodImplKind, isVariadic); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 782 | /// objc-protocol-refs: |
| 783 | /// '<' identifier-list '>' |
| 784 | /// |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 785 | bool Parser:: |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 786 | ParseObjCProtocolReferences(llvm::SmallVectorImpl<Action::DeclTy*> &Protocols, |
| 787 | bool WarnOnDeclarations, SourceLocation &EndLoc) { |
| 788 | assert(Tok.is(tok::less) && "expected <"); |
| 789 | |
| 790 | ConsumeToken(); // the "<" |
| 791 | |
| 792 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
| 793 | |
| 794 | while (1) { |
| 795 | if (Tok.isNot(tok::identifier)) { |
| 796 | Diag(Tok, diag::err_expected_ident); |
| 797 | SkipUntil(tok::greater); |
| 798 | return true; |
| 799 | } |
| 800 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 801 | Tok.getLocation())); |
| 802 | ConsumeToken(); |
| 803 | |
| 804 | if (Tok.isNot(tok::comma)) |
| 805 | break; |
| 806 | ConsumeToken(); |
| 807 | } |
| 808 | |
| 809 | // Consume the '>'. |
| 810 | if (Tok.isNot(tok::greater)) { |
| 811 | Diag(Tok, diag::err_expected_greater); |
| 812 | return true; |
| 813 | } |
| 814 | |
| 815 | EndLoc = ConsumeAnyToken(); |
| 816 | |
| 817 | // Convert the list of protocols identifiers into a list of protocol decls. |
| 818 | Actions.FindProtocolDeclaration(WarnOnDeclarations, |
| 819 | &ProtocolIdents[0], ProtocolIdents.size(), |
| 820 | Protocols); |
| 821 | return false; |
| 822 | } |
| 823 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 824 | /// objc-class-instance-variables: |
| 825 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 826 | /// |
| 827 | /// objc-instance-variable-decl-list: |
| 828 | /// objc-visibility-spec |
| 829 | /// objc-instance-variable-decl ';' |
| 830 | /// ';' |
| 831 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 832 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 833 | /// objc-instance-variable-decl-list ';' |
| 834 | /// |
| 835 | /// objc-visibility-spec: |
| 836 | /// @private |
| 837 | /// @protected |
| 838 | /// @public |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 839 | /// @package [OBJC2] |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 840 | /// |
| 841 | /// objc-instance-variable-decl: |
| 842 | /// struct-declaration |
| 843 | /// |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 844 | void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, |
| 845 | SourceLocation atLoc) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 846 | assert(Tok.is(tok::l_brace) && "expected {"); |
Fariborz Jahanian | 7d6402f | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 847 | llvm::SmallVector<DeclTy*, 32> AllIvarDecls; |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 848 | llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; |
| 849 | |
Douglas Gregor | 1a0d31a | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 850 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 851 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 852 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 853 | |
Fariborz Jahanian | aa847fe | 2008-04-29 23:03:51 +0000 | [diff] [blame] | 854 | tok::ObjCKeywordKind visibility = tok::objc_protected; |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 855 | // While we still have something to read, read the instance variables. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 856 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 857 | // Each iteration of this loop reads one objc-instance-variable-decl. |
| 858 | |
| 859 | // Check for extraneous top-level semicolon. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 860 | if (Tok.is(tok::semi)) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 861 | Diag(Tok, diag::ext_extra_struct_semi); |
| 862 | ConsumeToken(); |
| 863 | continue; |
| 864 | } |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 865 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 866 | // Set the default visibility to private. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 867 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 868 | ConsumeToken(); // eat the @ sign |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 869 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 870 | case tok::objc_private: |
| 871 | case tok::objc_public: |
| 872 | case tok::objc_protected: |
| 873 | case tok::objc_package: |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 874 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 875 | ConsumeToken(); |
| 876 | continue; |
| 877 | default: |
| 878 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 879 | continue; |
| 880 | } |
| 881 | } |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 882 | |
| 883 | // Parse all the comma separated declarators. |
| 884 | DeclSpec DS; |
| 885 | FieldDeclarators.clear(); |
| 886 | ParseStructDeclaration(DS, FieldDeclarators); |
| 887 | |
| 888 | // Convert them all to fields. |
| 889 | for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { |
| 890 | FieldDeclarator &FD = FieldDeclarators[i]; |
| 891 | // Install the declarator into interfaceDecl. |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 892 | DeclTy *Field = Actions.ActOnIvar(CurScope, |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 893 | DS.getSourceRange().getBegin(), |
Fariborz Jahanian | 1d78cc4 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 894 | FD.D, FD.BitfieldSize, visibility); |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 895 | AllIvarDecls.push_back(Field); |
Fariborz Jahanian | 7d6402f | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 896 | } |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 897 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 898 | if (Tok.is(tok::semi)) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 899 | ConsumeToken(); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 900 | } else { |
| 901 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 902 | // Skip to end of block or statement |
| 903 | SkipUntil(tok::r_brace, true, true); |
| 904 | } |
| 905 | } |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 906 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Steve Naroff | 8749be5 | 2007-10-31 22:11:35 +0000 | [diff] [blame] | 907 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 908 | // for code rewriting tools that need to be aware of the empty list. |
| 909 | Actions.ActOnFields(CurScope, atLoc, interfaceDecl, |
| 910 | &AllIvarDecls[0], AllIvarDecls.size(), |
Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 911 | LBraceLoc, RBraceLoc, 0); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 912 | return; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 913 | } |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 914 | |
| 915 | /// objc-protocol-declaration: |
| 916 | /// objc-protocol-definition |
| 917 | /// objc-protocol-forward-reference |
| 918 | /// |
| 919 | /// objc-protocol-definition: |
| 920 | /// @protocol identifier |
| 921 | /// objc-protocol-refs[opt] |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 922 | /// objc-interface-decl-list |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 923 | /// @end |
| 924 | /// |
| 925 | /// objc-protocol-forward-reference: |
| 926 | /// @protocol identifier-list ';' |
| 927 | /// |
| 928 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 929 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 930 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 931 | Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
| 932 | AttributeList *attrList) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 933 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 934 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 935 | ConsumeToken(); // the "protocol" identifier |
| 936 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 937 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 938 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
| 939 | return 0; |
| 940 | } |
| 941 | // Save the protocol name, then consume it. |
| 942 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 943 | SourceLocation nameLoc = ConsumeToken(); |
| 944 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 945 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 946 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 947 | ConsumeToken(); |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 948 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, |
| 949 | attrList); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 950 | } |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 951 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 952 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 953 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
| 954 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 955 | |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 956 | // Parse the list of forward declarations. |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 957 | while (1) { |
| 958 | ConsumeToken(); // the ',' |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 959 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 960 | Diag(Tok, diag::err_expected_ident); |
| 961 | SkipUntil(tok::semi); |
| 962 | return 0; |
| 963 | } |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 964 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 965 | Tok.getLocation())); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 966 | ConsumeToken(); // the identifier |
| 967 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 968 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | // Consume the ';'. |
| 972 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
| 973 | return 0; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 974 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 975 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Steve Naroff | 37e58d1 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 976 | &ProtocolRefs[0], |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 977 | ProtocolRefs.size(), |
| 978 | attrList); |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 981 | // Last, and definitely not least, parse a protocol declaration. |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 982 | SourceLocation EndProtoLoc; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 983 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 984 | llvm::SmallVector<DeclTy *, 8> ProtocolRefs; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 985 | if (Tok.is(tok::less) && |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 986 | ParseObjCProtocolReferences(ProtocolRefs, true, EndProtoLoc)) |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 987 | return 0; |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 988 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 989 | DeclTy *ProtoType = |
| 990 | Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, |
| 991 | &ProtocolRefs[0], ProtocolRefs.size(), |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 992 | EndProtoLoc, attrList); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 993 | ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 994 | return ProtoType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 995 | } |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 996 | |
| 997 | /// objc-implementation: |
| 998 | /// objc-class-implementation-prologue |
| 999 | /// objc-category-implementation-prologue |
| 1000 | /// |
| 1001 | /// objc-class-implementation-prologue: |
| 1002 | /// @implementation identifier objc-superclass[opt] |
| 1003 | /// objc-class-instance-variables[opt] |
| 1004 | /// |
| 1005 | /// objc-category-implementation-prologue: |
| 1006 | /// @implementation identifier ( identifier ) |
| 1007 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1008 | Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( |
| 1009 | SourceLocation atLoc) { |
| 1010 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 1011 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 1012 | ConsumeToken(); // the "implementation" identifier |
| 1013 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1014 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1015 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 1016 | return 0; |
| 1017 | } |
| 1018 | // We have a class or category name - consume it. |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1019 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1020 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
| 1021 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1022 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1023 | // we have a category implementation. |
| 1024 | SourceLocation lparenLoc = ConsumeParen(); |
| 1025 | SourceLocation categoryLoc, rparenLoc; |
| 1026 | IdentifierInfo *categoryId = 0; |
| 1027 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1028 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1029 | categoryId = Tok.getIdentifierInfo(); |
| 1030 | categoryLoc = ConsumeToken(); |
| 1031 | } else { |
| 1032 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 1033 | return 0; |
| 1034 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1035 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1036 | Diag(Tok, diag::err_expected_rparen); |
| 1037 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 1038 | return 0; |
| 1039 | } |
| 1040 | rparenLoc = ConsumeParen(); |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1041 | DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1042 | atLoc, nameId, nameLoc, categoryId, |
| 1043 | categoryLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1044 | ObjCImpDecl = ImplCatType; |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 1045 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1046 | } |
| 1047 | // We have a class implementation |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1048 | SourceLocation superClassLoc; |
| 1049 | IdentifierInfo *superClassId = 0; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1050 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1051 | // We have a super class |
| 1052 | ConsumeToken(); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1053 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1054 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 1055 | return 0; |
| 1056 | } |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1057 | superClassId = Tok.getIdentifierInfo(); |
| 1058 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1059 | } |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1060 | DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1061 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1062 | superClassId, superClassLoc); |
| 1063 | |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1064 | if (Tok.is(tok::l_brace)) // we have ivars |
| 1065 | ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1066 | ObjCImpDecl = ImplClsType; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1067 | |
Fariborz Jahanian | db8f3d3 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 1068 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1069 | } |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1070 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1071 | Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { |
| 1072 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 1073 | "ParseObjCAtEndDeclaration(): Expected @end"); |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1074 | DeclTy *Result = ObjCImpDecl; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1075 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1076 | if (ObjCImpDecl) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1077 | Actions.ActOnAtEnd(atLoc, ObjCImpDecl); |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1078 | ObjCImpDecl = 0; |
| 1079 | } |
Fariborz Jahanian | 94cdb25 | 2008-01-10 17:58:07 +0000 | [diff] [blame] | 1080 | else |
| 1081 | Diag(atLoc, diag::warn_expected_implementation); // missing @implementation |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1082 | return Result; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1083 | } |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1084 | |
| 1085 | /// compatibility-alias-decl: |
| 1086 | /// @compatibility_alias alias-name class-name ';' |
| 1087 | /// |
| 1088 | Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
| 1089 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1090 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1091 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1092 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1093 | Diag(Tok, diag::err_expected_ident); |
| 1094 | return 0; |
| 1095 | } |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1096 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1097 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1098 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1099 | Diag(Tok, diag::err_expected_ident); |
| 1100 | return 0; |
| 1101 | } |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1102 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1103 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
| 1104 | if (Tok.isNot(tok::semi)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1105 | Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1106 | return 0; |
| 1107 | } |
| 1108 | DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, |
| 1109 | aliasId, aliasLoc, |
| 1110 | classId, classLoc); |
| 1111 | return ClsType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1114 | /// property-synthesis: |
| 1115 | /// @synthesize property-ivar-list ';' |
| 1116 | /// |
| 1117 | /// property-ivar-list: |
| 1118 | /// property-ivar |
| 1119 | /// property-ivar-list ',' property-ivar |
| 1120 | /// |
| 1121 | /// property-ivar: |
| 1122 | /// identifier |
| 1123 | /// identifier '=' identifier |
| 1124 | /// |
| 1125 | Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
| 1126 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 1127 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1128 | SourceLocation loc = ConsumeToken(); // consume synthesize |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1129 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1130 | Diag(Tok, diag::err_expected_ident); |
| 1131 | return 0; |
| 1132 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1133 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1134 | IdentifierInfo *propertyIvar = 0; |
| 1135 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1136 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1137 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1138 | // property '=' ivar-name |
| 1139 | ConsumeToken(); // consume '=' |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1140 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1141 | Diag(Tok, diag::err_expected_ident); |
| 1142 | break; |
| 1143 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1144 | propertyIvar = Tok.getIdentifierInfo(); |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1145 | ConsumeToken(); // consume ivar-name |
| 1146 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1147 | Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, |
| 1148 | propertyId, propertyIvar); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1149 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1150 | break; |
| 1151 | ConsumeToken(); // consume ',' |
| 1152 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1153 | if (Tok.isNot(tok::semi)) |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1154 | Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1155 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1158 | /// property-dynamic: |
| 1159 | /// @dynamic property-list |
| 1160 | /// |
| 1161 | /// property-list: |
| 1162 | /// identifier |
| 1163 | /// property-list ',' identifier |
| 1164 | /// |
| 1165 | Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
| 1166 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1167 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 1168 | SourceLocation loc = ConsumeToken(); // consume dynamic |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1169 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1170 | Diag(Tok, diag::err_expected_ident); |
| 1171 | return 0; |
| 1172 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1173 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1174 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1175 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
| 1176 | Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, |
| 1177 | propertyId, 0); |
| 1178 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1179 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1180 | break; |
| 1181 | ConsumeToken(); // consume ',' |
| 1182 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1183 | if (Tok.isNot(tok::semi)) |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1184 | Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1185 | return 0; |
| 1186 | } |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1187 | |
| 1188 | /// objc-throw-statement: |
| 1189 | /// throw expression[opt]; |
| 1190 | /// |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1191 | Parser::OwningStmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1192 | OwningExprResult Res(Actions); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1193 | ConsumeToken(); // consume throw |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1194 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1195 | Res = ParseExpression(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1196 | if (Res.isInvalid()) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1197 | SkipUntil(tok::semi); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1198 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1201 | ConsumeToken(); // consume ';' |
Steve Naroff | e21dd6f | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1202 | return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1205 | /// objc-synchronized-statement: |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1206 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1207 | /// |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1208 | Parser::OwningStmtResult |
| 1209 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1210 | ConsumeToken(); // consume synchronized |
| 1211 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1212 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1213 | return StmtError(); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1214 | } |
| 1215 | ConsumeParen(); // '(' |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1216 | OwningExprResult Res(ParseExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1217 | if (Res.isInvalid()) { |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1218 | SkipUntil(tok::semi); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1219 | return StmtError(); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1220 | } |
| 1221 | if (Tok.isNot(tok::r_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1222 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1223 | return StmtError(); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1224 | } |
| 1225 | ConsumeParen(); // ')' |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1226 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1227 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1228 | return StmtError(); |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1229 | } |
Steve Naroff | 3ac438c | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1230 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1231 | // statements can always hold declarations. |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1232 | ParseScope BodyScope(this, Scope::DeclScope); |
Steve Naroff | 3ac438c | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1233 | |
Sebastian Redl | 61364dd | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1234 | OwningStmtResult SynchBody(ParseCompoundStatementBody()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1236 | BodyScope.Exit(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1237 | if (SynchBody.isInvalid()) |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1238 | SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1239 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, move(Res), move(SynchBody)); |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1242 | /// objc-try-catch-statement: |
| 1243 | /// @try compound-statement objc-catch-list[opt] |
| 1244 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1245 | /// |
| 1246 | /// objc-catch-list: |
| 1247 | /// @catch ( parameter-declaration ) compound-statement |
| 1248 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1249 | /// catch-parameter-declaration: |
| 1250 | /// parameter-declaration |
| 1251 | /// '...' [OBJC2] |
| 1252 | /// |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1253 | Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1254 | bool catch_or_finally_seen = false; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1255 | |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1256 | ConsumeToken(); // consume try |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1257 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1258 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1259 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1260 | } |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1261 | OwningStmtResult CatchStmts(Actions); |
| 1262 | OwningStmtResult FinallyStmt(Actions); |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1263 | ParseScope TryScope(this, Scope::DeclScope); |
Sebastian Redl | 61364dd | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1264 | OwningStmtResult TryBody(ParseCompoundStatementBody()); |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1265 | TryScope.Exit(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1266 | if (TryBody.isInvalid()) |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1267 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1268 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1269 | while (Tok.is(tok::at)) { |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1270 | // At this point, we need to lookahead to determine if this @ is the start |
| 1271 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1272 | // is an @try or @encode or something else. |
| 1273 | Token AfterAt = GetLookAheadToken(1); |
| 1274 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1275 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1276 | break; |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1277 | |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1278 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1279 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1280 | DeclTy *FirstPart = 0; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1281 | ConsumeToken(); // consume catch |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1282 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1283 | ConsumeParen(); |
Steve Naroff | e21dd6f | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1284 | ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1285 | if (Tok.isNot(tok::ellipsis)) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1286 | DeclSpec DS; |
| 1287 | ParseDeclarationSpecifiers(DS); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1288 | // For some odd reason, the name of the exception variable is |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1289 | // optional. As a result, we need to use "PrototypeContext", because |
| 1290 | // we must accept either 'declarator' or 'abstract-declarator' here. |
| 1291 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 1292 | ParseDeclarator(ParmDecl); |
| 1293 | |
| 1294 | // Inform the actions module about the parameter declarator, so it |
| 1295 | // gets added to the current scope. |
| 1296 | FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1297 | } else |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1298 | ConsumeToken(); // consume '...' |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1299 | SourceLocation RParenLoc = ConsumeParen(); |
Chris Lattner | c1b3ba5 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1300 | |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1301 | OwningStmtResult CatchBody(Actions, true); |
Chris Lattner | c1b3ba5 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1302 | if (Tok.is(tok::l_brace)) |
| 1303 | CatchBody = ParseCompoundStatementBody(); |
| 1304 | else |
| 1305 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1306 | if (CatchBody.isInvalid()) |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1307 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1308 | CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1309 | RParenLoc, FirstPart, move(CatchBody), |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1310 | move(CatchStmts)); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1311 | } else { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1312 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 1313 | << "@catch clause"; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1314 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1315 | } |
| 1316 | catch_or_finally_seen = true; |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1317 | } else { |
| 1318 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1319 | ConsumeToken(); // consume finally |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1320 | ParseScope FinallyScope(this, Scope::DeclScope); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1321 | |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1322 | OwningStmtResult FinallyBody(Actions, true); |
Chris Lattner | c1b3ba5 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1323 | if (Tok.is(tok::l_brace)) |
| 1324 | FinallyBody = ParseCompoundStatementBody(); |
| 1325 | else |
| 1326 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1327 | if (FinallyBody.isInvalid()) |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1328 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1329 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1330 | move(FinallyBody)); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1331 | catch_or_finally_seen = true; |
| 1332 | break; |
| 1333 | } |
| 1334 | } |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1335 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1336 | Diag(atLoc, diag::err_missing_catch_finally); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1337 | return StmtError(); |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1338 | } |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1339 | return Actions.ActOnObjCAtTryStmt(atLoc, move(TryBody), move(CatchStmts), |
| 1340 | move(FinallyStmt)); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1341 | } |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1342 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1343 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1344 | /// |
Steve Naroff | 71c0a95 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1345 | Parser::DeclTy *Parser::ParseObjCMethodDefinition() { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1346 | DeclTy *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); |
Chris Lattner | 73e80f6 | 2009-03-05 02:03:49 +0000 | [diff] [blame] | 1347 | |
Chris Lattner | 49f28ca | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 1348 | PrettyStackTraceActionsDecl CrashInfo(MDecl, Tok.getLocation(), Actions, |
| 1349 | PP.getSourceManager(), |
| 1350 | "parsing Objective-C method"); |
Chris Lattner | 73e80f6 | 2009-03-05 02:03:49 +0000 | [diff] [blame] | 1351 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1352 | // parse optional ';' |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1353 | if (Tok.is(tok::semi)) |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1354 | ConsumeToken(); |
| 1355 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1356 | // We should have an opening brace now. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1357 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1358 | Diag(Tok, diag::err_expected_method_body); |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1359 | |
| 1360 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 1361 | SkipUntil(tok::l_brace, true, true); |
| 1362 | |
| 1363 | // If we didn't find the '{', bail out. |
| 1364 | if (Tok.isNot(tok::l_brace)) |
Steve Naroff | 71c0a95 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1365 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1366 | } |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1367 | SourceLocation BraceLoc = Tok.getLocation(); |
| 1368 | |
| 1369 | // Enter a scope for the method body. |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1370 | ParseScope BodyScope(this, Scope::FnScope|Scope::DeclScope); |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1371 | |
| 1372 | // Tell the actions module that we have entered a method definition with the |
Steve Naroff | 394f3f4 | 2008-07-25 17:57:26 +0000 | [diff] [blame] | 1373 | // specified Declarator for the method. |
Steve Naroff | ebf6443 | 2009-02-28 16:59:13 +0000 | [diff] [blame] | 1374 | Actions.ActOnStartOfObjCMethodDef(CurScope, MDecl); |
Sebastian Redl | 61364dd | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1375 | |
| 1376 | OwningStmtResult FnBody(ParseCompoundStatementBody()); |
| 1377 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1378 | // If the function body could not be parsed, make a bogus compoundstmt. |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1379 | if (FnBody.isInvalid()) |
Sebastian Redl | a60528c | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1380 | FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, |
| 1381 | MultiStmtArg(Actions), false); |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1382 | |
Steve Naroff | 32ce837 | 2009-03-02 22:00:56 +0000 | [diff] [blame] | 1383 | // TODO: Pass argument information. |
| 1384 | Actions.ActOnFinishFunctionBody(MDecl, move(FnBody)); |
| 1385 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1386 | // Leave the function body scope. |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1387 | BodyScope.Exit(); |
Sebastian Redl | 798d119 | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1388 | |
Steve Naroff | 71c0a95 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1389 | return MDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1390 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1391 | |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1392 | Parser::OwningStmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1393 | if (Tok.isObjCAtKeyword(tok::objc_try)) { |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1394 | return ParseObjCTryStmt(AtLoc); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1395 | } else if (Tok.isObjCAtKeyword(tok::objc_throw)) |
| 1396 | return ParseObjCThrowStmt(AtLoc); |
| 1397 | else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
| 1398 | return ParseObjCSynchronizedStmt(AtLoc); |
Sebastian Redl | d8c4e15 | 2008-12-11 22:33:27 +0000 | [diff] [blame] | 1399 | OwningExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1400 | if (Res.isInvalid()) { |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1401 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 1402 | // doing this opens us up to the possibility of infinite loops if |
| 1403 | // ParseExpression does not consume any tokens. |
| 1404 | SkipUntil(tok::semi); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1405 | return StmtError(); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1406 | } |
| 1407 | // Otherwise, eat the semicolon. |
| 1408 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1409 | return Actions.ActOnExprStmt(move(Res)); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1412 | Parser::OwningExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1413 | switch (Tok.getKind()) { |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1414 | case tok::string_literal: // primary-expression: string-literal |
| 1415 | case tok::wide_string_literal: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1416 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1417 | default: |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1418 | if (Tok.getIdentifierInfo() == 0) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1419 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1420 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1421 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 1422 | case tok::objc_encode: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1423 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1424 | case tok::objc_protocol: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1425 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1426 | case tok::objc_selector: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1427 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1428 | default: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1429 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1430 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1431 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1434 | /// objc-message-expr: |
| 1435 | /// '[' objc-receiver objc-message-args ']' |
| 1436 | /// |
| 1437 | /// objc-receiver: |
| 1438 | /// expression |
| 1439 | /// class-name |
| 1440 | /// type-name |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1441 | Parser::OwningExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1442 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 1443 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 1444 | |
| 1445 | // Parse receiver |
Chris Lattner | 14dd98a | 2008-01-25 19:25:00 +0000 | [diff] [blame] | 1446 | if (isTokObjCMessageIdentifierReceiver()) { |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1447 | IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); |
Steve Naroff | 5cb93b8 | 2008-11-19 15:54:23 +0000 | [diff] [blame] | 1448 | SourceLocation NameLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1449 | return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, |
| 1450 | ExprArg(Actions)); |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1453 | OwningExprResult Res(ParseExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1454 | if (Res.isInvalid()) { |
Chris Lattner | 5c74942 | 2008-01-25 19:43:26 +0000 | [diff] [blame] | 1455 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1456 | return move(Res); |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1457 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1458 | |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1459 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
Sebastian Redl | 76ad2e8 | 2009-02-05 15:02:23 +0000 | [diff] [blame] | 1460 | 0, move(Res)); |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1461 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1462 | |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1463 | /// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse |
| 1464 | /// the rest of a message expression. |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1465 | /// |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1466 | /// objc-message-args: |
| 1467 | /// objc-selector |
| 1468 | /// objc-keywordarg-list |
| 1469 | /// |
| 1470 | /// objc-keywordarg-list: |
| 1471 | /// objc-keywordarg |
| 1472 | /// objc-keywordarg-list objc-keywordarg |
| 1473 | /// |
| 1474 | /// objc-keywordarg: |
| 1475 | /// selector-name[opt] ':' objc-keywordexpr |
| 1476 | /// |
| 1477 | /// objc-keywordexpr: |
| 1478 | /// nonempty-expr-list |
| 1479 | /// |
| 1480 | /// nonempty-expr-list: |
| 1481 | /// assignment-expression |
| 1482 | /// nonempty-expr-list , assignment-expression |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1483 | /// |
| 1484 | Parser::OwningExprResult |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1485 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
Steve Naroff | 5cb93b8 | 2008-11-19 15:54:23 +0000 | [diff] [blame] | 1486 | SourceLocation NameLoc, |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1487 | IdentifierInfo *ReceiverName, |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1488 | ExprArg ReceiverExpr) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1489 | // Parse objc-selector |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1490 | SourceLocation Loc; |
| 1491 | IdentifierInfo *selIdent = ParseObjCSelector(Loc); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1492 | |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 1493 | SourceLocation SelectorLoc = Loc; |
| 1494 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1495 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1496 | ExprVector KeyExprs(Actions); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1497 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1498 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1499 | while (1) { |
| 1500 | // Each iteration parses a single keyword argument. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1501 | KeyIdents.push_back(selIdent); |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1502 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1503 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1504 | Diag(Tok, diag::err_expected_colon); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1505 | // We must manually skip to a ']', otherwise the expression skipper will |
| 1506 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 1507 | // the enclosing expression. |
| 1508 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1509 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1510 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1511 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1512 | ConsumeToken(); // Eat the ':'. |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1513 | /// Parse the expression after ':' |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1514 | OwningExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1515 | if (Res.isInvalid()) { |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1516 | // We must manually skip to a ']', otherwise the expression skipper will |
| 1517 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 1518 | // the enclosing expression. |
| 1519 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1520 | return move(Res); |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1521 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1522 | |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1523 | // We have a valid expression. |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1524 | KeyExprs.push_back(Res.release()); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1525 | |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1526 | // Check for another keyword selector. |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1527 | selIdent = ParseObjCSelector(Loc); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1528 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1529 | break; |
| 1530 | // We have a selector or a colon, continue parsing. |
| 1531 | } |
| 1532 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1533 | while (Tok.is(tok::comma)) { |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1534 | ConsumeToken(); // Eat the ','. |
| 1535 | /// Parse the expression after ',' |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1536 | OwningExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1537 | if (Res.isInvalid()) { |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1538 | // We must manually skip to a ']', otherwise the expression skipper will |
| 1539 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 1540 | // the enclosing expression. |
| 1541 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1542 | return move(Res); |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1543 | } |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1544 | |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1545 | // We have a valid expression. |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1546 | KeyExprs.push_back(Res.release()); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } else if (!selIdent) { |
| 1549 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1550 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1551 | // We must manually skip to a ']', otherwise the expression skipper will |
| 1552 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 1553 | // the enclosing expression. |
| 1554 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1555 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1556 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1557 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1558 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1559 | Diag(Tok, diag::err_expected_rsquare); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1560 | // We must manually skip to a ']', otherwise the expression skipper will |
| 1561 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 1562 | // the enclosing expression. |
| 1563 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1564 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1565 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1566 | |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1567 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1568 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 1569 | unsigned nKeys = KeyIdents.size(); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1570 | if (nKeys == 0) |
| 1571 | KeyIdents.push_back(selIdent); |
| 1572 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1573 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1574 | // We've just parsed a keyword message. |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1575 | if (ReceiverName) |
| 1576 | return Owned(Actions.ActOnClassMessage(CurScope, ReceiverName, Sel, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 1577 | LBracLoc, NameLoc, SelectorLoc, |
| 1578 | RBracLoc, |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1579 | KeyExprs.take(), KeyExprs.size())); |
| 1580 | return Owned(Actions.ActOnInstanceMessage(ReceiverExpr.release(), Sel, |
Anders Carlsson | ff975cf | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 1581 | LBracLoc, SelectorLoc, RBracLoc, |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1582 | KeyExprs.take(), KeyExprs.size())); |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1585 | Parser::OwningExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 1586 | OwningExprResult Res(ParseStringLiteralExpression()); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1587 | if (Res.isInvalid()) return move(Res); |
| 1588 | |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1589 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 1590 | // expressions. At this point, we know that the only valid thing that starts |
| 1591 | // with '@' is an @"". |
| 1592 | llvm::SmallVector<SourceLocation, 4> AtLocs; |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1593 | ExprVector AtStrings(Actions); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1594 | AtLocs.push_back(AtLoc); |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1595 | AtStrings.push_back(Res.release()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1596 | |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1597 | while (Tok.is(tok::at)) { |
| 1598 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1599 | |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 1600 | // Invalid unless there is a string literal. |
Chris Lattner | 97cf6eb | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 1601 | if (!isTokenStringLiteral()) |
| 1602 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1603 | |
Chris Lattner | 97cf6eb | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 1604 | OwningExprResult Lit(ParseStringLiteralExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1605 | if (Lit.isInvalid()) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1606 | return move(Lit); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1607 | |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 1608 | AtStrings.push_back(Lit.release()); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1609 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1610 | |
| 1611 | return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), |
| 1612 | AtStrings.size())); |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1613 | } |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1614 | |
| 1615 | /// objc-encode-expression: |
| 1616 | /// @encode ( type-name ) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1617 | Parser::OwningExprResult |
| 1618 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1619 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1620 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1621 | SourceLocation EncLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1622 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1623 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1624 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 1625 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1626 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1627 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1628 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1629 | |
Anders Carlsson | 4988ae3 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1630 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1631 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1632 | if (Ty.isInvalid()) |
| 1633 | return ExprError(); |
| 1634 | |
| 1635 | return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, |
| 1636 | Ty.get(), RParenLoc)); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1637 | } |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1638 | |
| 1639 | /// objc-protocol-expression |
| 1640 | /// @protocol ( protocol-name ) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1641 | Parser::OwningExprResult |
| 1642 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1643 | SourceLocation ProtoLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1644 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1645 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1646 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 1647 | |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1648 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1649 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1650 | if (Tok.isNot(tok::identifier)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1651 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 1652 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1653 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1654 | ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1655 | |
Anders Carlsson | 4988ae3 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1656 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1657 | |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1658 | return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 1659 | LParenLoc, RParenLoc)); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1660 | } |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1661 | |
| 1662 | /// objc-selector-expression |
| 1663 | /// @selector '(' objc-keyword-selector ')' |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1664 | Parser::OwningExprResult |
| 1665 | Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1666 | SourceLocation SelectorLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1667 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1668 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1669 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 1670 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1671 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1672 | SourceLocation LParenLoc = ConsumeParen(); |
| 1673 | SourceLocation sLoc; |
| 1674 | IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1675 | if (!SelIdent && Tok.isNot(tok::colon)) // missing selector name. |
| 1676 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 1677 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1678 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1679 | unsigned nColons = 0; |
| 1680 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1681 | while (1) { |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1682 | if (Tok.isNot(tok::colon)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1683 | return ExprError(Diag(Tok, diag::err_expected_colon)); |
| 1684 | |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1685 | nColons++; |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1686 | ConsumeToken(); // Eat the ':'. |
| 1687 | if (Tok.is(tok::r_paren)) |
| 1688 | break; |
| 1689 | // Check for another keyword selector. |
| 1690 | SourceLocation Loc; |
| 1691 | SelIdent = ParseObjCSelector(Loc); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1692 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1693 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 1694 | break; |
| 1695 | } |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1696 | } |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1697 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1698 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1699 | return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 1700 | LParenLoc, RParenLoc)); |
Gabor Greif | 58065b2 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 1701 | } |