Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- ParseObjc.cpp - Objective C Parsing ------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Steve Naroff and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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 | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 15 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 16 | #include "clang/Basic/Diagnostic.h" |
| 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | using namespace clang; |
| 19 | |
| 20 | |
| 21 | /// ParseExternalDeclaration: |
| 22 | /// external-declaration: [C99 6.9] |
| 23 | /// [OBJC] objc-class-definition |
Steve Naroff | 5b96e2e | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 24 | /// [OBJC] objc-class-declaration |
| 25 | /// [OBJC] objc-alias-declaration |
| 26 | /// [OBJC] objc-protocol-definition |
| 27 | /// [OBJC] objc-method-definition |
| 28 | /// [OBJC] '@' 'end' |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 29 | Parser::DeclTy *Parser::ParseObjCAtDirectives() { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 30 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
| 31 | |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 32 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 33 | case tok::objc_class: |
| 34 | return ParseObjCAtClassDeclaration(AtLoc); |
| 35 | case tok::objc_interface: |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 36 | return ParseObjCAtInterfaceDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 37 | case tok::objc_protocol: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 38 | return ParseObjCAtProtocolDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 39 | case tok::objc_implementation: |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 40 | return ObjcImpDecl = ParseObjCAtImplementationDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 41 | case tok::objc_end: |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 42 | return ParseObjCAtEndDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 43 | case tok::objc_compatibility_alias: |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 44 | return ParseObjCAtAliasDeclaration(AtLoc); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 45 | case tok::objc_synthesize: |
| 46 | return ParseObjCPropertySynthesize(AtLoc); |
| 47 | case tok::objc_dynamic: |
| 48 | return ParseObjCPropertyDynamic(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 49 | default: |
| 50 | Diag(AtLoc, diag::err_unexpected_at); |
| 51 | SkipUntil(tok::semi); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 52 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
| 56 | /// |
| 57 | /// objc-class-declaration: |
| 58 | /// '@' 'class' identifier-list ';' |
| 59 | /// |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 60 | Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 61 | ConsumeToken(); // the identifier "class" |
| 62 | llvm::SmallVector<IdentifierInfo *, 8> ClassNames; |
| 63 | |
| 64 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 65 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 66 | Diag(Tok, diag::err_expected_ident); |
| 67 | SkipUntil(tok::semi); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 68 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 69 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 70 | ClassNames.push_back(Tok.getIdentifierInfo()); |
| 71 | ConsumeToken(); |
| 72 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 73 | if (Tok.isNot(tok::comma)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 74 | break; |
| 75 | |
| 76 | ConsumeToken(); |
| 77 | } |
| 78 | |
| 79 | // Consume the ';'. |
| 80 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 81 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 82 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 83 | return Actions.ActOnForwardClassDeclaration(atLoc, |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 84 | &ClassNames[0], ClassNames.size()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 87 | /// |
| 88 | /// objc-interface: |
| 89 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 90 | /// objc-category-interface |
| 91 | /// |
| 92 | /// objc-class-interface: |
| 93 | /// '@' 'interface' identifier objc-superclass[opt] |
| 94 | /// objc-protocol-refs[opt] |
| 95 | /// objc-class-instance-variables[opt] |
| 96 | /// objc-interface-decl-list |
| 97 | /// @end |
| 98 | /// |
| 99 | /// objc-category-interface: |
| 100 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
| 101 | /// objc-protocol-refs[opt] |
| 102 | /// objc-interface-decl-list |
| 103 | /// @end |
| 104 | /// |
| 105 | /// objc-superclass: |
| 106 | /// ':' identifier |
| 107 | /// |
| 108 | /// objc-class-interface-attributes: |
| 109 | /// __attribute__((visibility("default"))) |
| 110 | /// __attribute__((visibility("hidden"))) |
| 111 | /// __attribute__((deprecated)) |
| 112 | /// __attribute__((unavailable)) |
| 113 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 114 | /// |
| 115 | Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( |
| 116 | SourceLocation atLoc, AttributeList *attrList) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 117 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 118 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 119 | ConsumeToken(); // the "interface" identifier |
| 120 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 121 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 122 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 123 | return 0; |
| 124 | } |
| 125 | // We have a class or category name - consume it. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 126 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 127 | SourceLocation nameLoc = ConsumeToken(); |
| 128 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 129 | if (Tok.is(tok::l_paren)) { // we have a category. |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 130 | SourceLocation lparenLoc = ConsumeParen(); |
| 131 | SourceLocation categoryLoc, rparenLoc; |
| 132 | IdentifierInfo *categoryId = 0; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 133 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 134 | |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 135 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 136 | if (Tok.is(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 137 | categoryId = Tok.getIdentifierInfo(); |
| 138 | categoryLoc = ConsumeToken(); |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 139 | } else if (!getLang().ObjC2) { |
| 140 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 141 | return 0; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 143 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 144 | Diag(Tok, diag::err_expected_rparen); |
| 145 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 146 | return 0; |
| 147 | } |
| 148 | rparenLoc = ConsumeParen(); |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 149 | SourceLocation endProtoLoc; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 150 | // Next, we need to check for any protocol references. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 151 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 152 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | if (attrList) // categories don't support attributes. |
| 156 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
| 157 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 158 | DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, |
Steve Naroff | 25aace8 | 2007-10-03 21:00:46 +0000 | [diff] [blame] | 159 | nameId, nameLoc, categoryId, categoryLoc, |
| 160 | &ProtocolRefs[0], ProtocolRefs.size()); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 161 | |
| 162 | ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 163 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 164 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 165 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 166 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | ac20be2 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 167 | return CategoryType; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 168 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 169 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | // Parse a class interface. |
| 173 | IdentifierInfo *superClassId = 0; |
| 174 | SourceLocation superClassLoc; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 175 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 176 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 177 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 178 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 179 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 180 | return 0; |
| 181 | } |
| 182 | superClassId = Tok.getIdentifierInfo(); |
| 183 | superClassLoc = ConsumeToken(); |
| 184 | } |
| 185 | // Next, we need to check for any protocol references. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 186 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 187 | SourceLocation endProtoLoc; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 188 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 189 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 190 | return 0; |
| 191 | } |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 192 | DeclTy *ClsType = Actions.ActOnStartClassInterface( |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 193 | atLoc, nameId, nameLoc, |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 194 | superClassId, superClassLoc, &ProtocolRefs[0], |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 195 | ProtocolRefs.size(), endProtoLoc, attrList); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 196 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 197 | if (Tok.is(tok::l_brace)) |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 198 | ParseObjCClassInstanceVariables(ClsType, atLoc); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 199 | |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 200 | ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 201 | |
| 202 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 203 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 204 | ConsumeToken(); // the "end" identifier |
Steve Naroff | faed3bf | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 205 | return ClsType; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 206 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 207 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | /// objc-interface-decl-list: |
| 212 | /// empty |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 213 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 214 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 215 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 216 | /// objc-interface-decl-list declaration |
| 217 | /// objc-interface-decl-list ';' |
| 218 | /// |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 219 | /// objc-method-requirement: [OBJC2] |
| 220 | /// @required |
| 221 | /// @optional |
| 222 | /// |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 223 | void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, |
| 224 | tok::ObjCKeywordKind contextKey) { |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 225 | llvm::SmallVector<DeclTy*, 32> allMethods; |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 226 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 227 | SourceLocation AtEndLoc; |
| 228 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 229 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 230 | if (Tok.is(tok::at)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 231 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 232 | tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID(); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 233 | |
| 234 | if (ocKind == tok::objc_end) { // terminate list |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 235 | AtEndLoc = AtLoc; |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 236 | break; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 237 | } else if (ocKind == tok::objc_required) { // protocols only |
| 238 | ConsumeToken(); |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 239 | MethodImplKind = ocKind; |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 240 | if (contextKey != tok::objc_protocol) |
| 241 | Diag(AtLoc, diag::err_objc_protocol_required); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 242 | } else if (ocKind == tok::objc_optional) { // protocols only |
| 243 | ConsumeToken(); |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 244 | MethodImplKind = ocKind; |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 245 | if (contextKey != tok::objc_protocol) |
| 246 | Diag(AtLoc, diag::err_objc_protocol_optional); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 247 | } else if (ocKind == tok::objc_property) { |
Fariborz Jahanian | 86f74a4 | 2007-09-12 18:23:47 +0000 | [diff] [blame] | 248 | ParseObjCPropertyDecl(interfaceDecl); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 249 | continue; |
| 250 | } else { |
| 251 | Diag(Tok, diag::err_objc_illegal_interface_qual); |
| 252 | ConsumeToken(); |
| 253 | } |
| 254 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 255 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
| 256 | DeclTy *methodPrototype = |
| 257 | ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 258 | allMethods.push_back(methodPrototype); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 259 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 260 | // method definitions. |
Steve Naroff | aa1b6d4 | 2007-09-17 15:07:43 +0000 | [diff] [blame] | 261 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 262 | continue; |
| 263 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 264 | if (Tok.is(tok::semi)) |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 265 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 266 | else if (Tok.is(tok::eof)) |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 267 | break; |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 268 | else { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 269 | // FIXME: as the name implies, this rule allows function definitions. |
| 270 | // We could pass a flag or check for functions during semantic analysis. |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 271 | ParseDeclarationOrFunctionDefinition(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 272 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 273 | } |
Steve Naroff | 8255b04 | 2007-10-14 00:58:41 +0000 | [diff] [blame] | 274 | if (allMethods.size()) |
| 275 | /// Insert collected methods declarations into the @interface object. |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 276 | Actions.ActOnAddMethodsToObjcDecl(CurScope, interfaceDecl, &allMethods[0], |
| 277 | allMethods.size(), AtEndLoc); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 280 | /// Parse property attribute declarations. |
| 281 | /// |
| 282 | /// property-attr-decl: '(' property-attrlist ')' |
| 283 | /// property-attrlist: |
| 284 | /// property-attribute |
| 285 | /// property-attrlist ',' property-attribute |
| 286 | /// property-attribute: |
| 287 | /// getter '=' identifier |
| 288 | /// setter '=' identifier ':' |
| 289 | /// readonly |
| 290 | /// readwrite |
| 291 | /// assign |
| 292 | /// retain |
| 293 | /// copy |
| 294 | /// nonatomic |
| 295 | /// |
| 296 | void Parser::ParseObjCPropertyAttribute (DeclTy *interfaceDecl) { |
| 297 | SourceLocation loc = ConsumeParen(); // consume '(' |
| 298 | while (isObjCPropertyAttribute()) { |
| 299 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 300 | // getter/setter require extra treatment. |
| 301 | if (II == ObjcPropertyAttrs[objc_getter] || |
| 302 | II == ObjcPropertyAttrs[objc_setter]) { |
| 303 | // skip getter/setter part. |
| 304 | SourceLocation loc = ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 305 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 306 | loc = ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 307 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 308 | if (II == ObjcPropertyAttrs[objc_setter]) { |
| 309 | loc = ConsumeToken(); // consume method name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 310 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 311 | Diag(loc, diag::err_expected_colon); |
| 312 | SkipUntil(tok::r_paren,true,true); |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | else { |
| 318 | Diag(loc, diag::err_expected_ident); |
| 319 | SkipUntil(tok::r_paren,true,true); |
| 320 | break; |
| 321 | } |
| 322 | } |
| 323 | else { |
| 324 | Diag(loc, diag::err_objc_expected_equal); |
| 325 | SkipUntil(tok::r_paren,true,true); |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | ConsumeToken(); // consume last attribute token |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 330 | if (Tok.is(tok::comma)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 331 | loc = ConsumeToken(); |
| 332 | continue; |
| 333 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 334 | if (Tok.is(tok::r_paren)) |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 335 | break; |
| 336 | Diag(loc, diag::err_expected_rparen); |
| 337 | SkipUntil(tok::semi); |
| 338 | return; |
| 339 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 340 | if (Tok.is(tok::r_paren)) |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 341 | ConsumeParen(); |
| 342 | else { |
| 343 | Diag(loc, diag::err_objc_expected_property_attr); |
| 344 | SkipUntil(tok::r_paren); // recover from error inside attribute list |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /// Main routine to parse property declaration. |
| 349 | /// |
| 350 | /// @property property-attr-decl[opt] property-component-decl ';' |
| 351 | /// |
| 352 | void Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl) { |
| 353 | assert(Tok.isObjCAtKeyword(tok::objc_property) && |
| 354 | "ParseObjCPropertyDecl(): Expected @property"); |
| 355 | ConsumeToken(); // the "property" identifier |
| 356 | // Parse property attribute list, if any. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 357 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 358 | // property has attribute list. |
| 359 | ParseObjCPropertyAttribute(0/*FIXME*/); |
| 360 | } |
| 361 | // Parse declaration portion of @property. |
| 362 | llvm::SmallVector<DeclTy*, 32> PropertyDecls; |
| 363 | ParseStructDeclaration(interfaceDecl, PropertyDecls); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 364 | if (Tok.is(tok::semi)) |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 365 | ConsumeToken(); |
| 366 | else { |
| 367 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 368 | SkipUntil(tok::r_brace, true, true); |
| 369 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 370 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 371 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 372 | /// objc-method-proto: |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 373 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 374 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 375 | /// |
| 376 | /// objc-instance-method: '-' |
| 377 | /// objc-class-method: '+' |
| 378 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 379 | /// objc-method-attributes: [OBJC2] |
| 380 | /// __attribute__((deprecated)) |
| 381 | /// |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 382 | Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, |
| 383 | tok::ObjCKeywordKind MethodImplKind) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 384 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 385 | |
| 386 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 387 | SourceLocation mLoc = ConsumeToken(); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 388 | |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 389 | DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 390 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | faed3bf | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 391 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 392 | return MDecl; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /// objc-selector: |
| 396 | /// identifier |
| 397 | /// one of |
| 398 | /// enum struct union if else while do for switch case default |
| 399 | /// break continue return goto asm sizeof typeof __alignof |
| 400 | /// unsigned long const short volatile signed restrict _Complex |
| 401 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 402 | /// |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 403 | IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 404 | switch (Tok.getKind()) { |
| 405 | default: |
| 406 | return 0; |
| 407 | case tok::identifier: |
| 408 | case tok::kw_typeof: |
| 409 | case tok::kw___alignof: |
| 410 | case tok::kw_auto: |
| 411 | case tok::kw_break: |
| 412 | case tok::kw_case: |
| 413 | case tok::kw_char: |
| 414 | case tok::kw_const: |
| 415 | case tok::kw_continue: |
| 416 | case tok::kw_default: |
| 417 | case tok::kw_do: |
| 418 | case tok::kw_double: |
| 419 | case tok::kw_else: |
| 420 | case tok::kw_enum: |
| 421 | case tok::kw_extern: |
| 422 | case tok::kw_float: |
| 423 | case tok::kw_for: |
| 424 | case tok::kw_goto: |
| 425 | case tok::kw_if: |
| 426 | case tok::kw_inline: |
| 427 | case tok::kw_int: |
| 428 | case tok::kw_long: |
| 429 | case tok::kw_register: |
| 430 | case tok::kw_restrict: |
| 431 | case tok::kw_return: |
| 432 | case tok::kw_short: |
| 433 | case tok::kw_signed: |
| 434 | case tok::kw_sizeof: |
| 435 | case tok::kw_static: |
| 436 | case tok::kw_struct: |
| 437 | case tok::kw_switch: |
| 438 | case tok::kw_typedef: |
| 439 | case tok::kw_union: |
| 440 | case tok::kw_unsigned: |
| 441 | case tok::kw_void: |
| 442 | case tok::kw_volatile: |
| 443 | case tok::kw_while: |
| 444 | case tok::kw__Bool: |
| 445 | case tok::kw__Complex: |
| 446 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 447 | SelectorLoc = ConsumeToken(); |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 448 | return II; |
Fariborz Jahanian | 171ceb5 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 449 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 452 | /// objc-type-qualifier: one of |
| 453 | /// in out inout bycopy byref oneway |
| 454 | /// |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 455 | bool Parser::isObjCTypeQualifier() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 456 | if (Tok.is(tok::identifier)) { |
Chris Lattner | 3235246 | 2007-08-29 22:54:08 +0000 | [diff] [blame] | 457 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 458 | for (unsigned i = 0; i < objc_NumQuals; ++i) |
| 459 | if (II == ObjcTypeQuals[i]) return true; |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 460 | } |
| 461 | return false; |
| 462 | } |
| 463 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 464 | /// property-attrlist: one of |
| 465 | /// readonly getter setter assign retain copy nonatomic |
| 466 | /// |
| 467 | bool Parser::isObjCPropertyAttribute() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 468 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 469 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 470 | for (unsigned i = 0; i < objc_NumAttrs; ++i) |
| 471 | if (II == ObjcPropertyAttrs[i]) return true; |
| 472 | } |
| 473 | return false; |
| 474 | } |
| 475 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 476 | /// objc-type-name: |
| 477 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 478 | /// '(' objc-type-qualifiers[opt] ')' |
| 479 | /// |
| 480 | /// objc-type-qualifiers: |
| 481 | /// objc-type-qualifier |
| 482 | /// objc-type-qualifiers objc-type-qualifier |
| 483 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 484 | Parser::TypeTy *Parser::ParseObjCTypeName() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 485 | assert(Tok.is(tok::l_paren) && "expected ("); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 486 | |
| 487 | SourceLocation LParenLoc = ConsumeParen(), RParenLoc; |
Chris Lattner | 265c817 | 2007-09-27 15:15:46 +0000 | [diff] [blame] | 488 | TypeTy *Ty = 0; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 489 | |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 490 | while (isObjCTypeQualifier()) |
| 491 | ConsumeToken(); |
| 492 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 493 | if (isTypeSpecifierQualifier()) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 494 | Ty = ParseTypeName(); |
| 495 | // FIXME: back when Sema support is in place... |
| 496 | // assert(Ty && "Parser::ParseObjCTypeName(): missing type"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 497 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 498 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 499 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 500 | return 0; // FIXME: decide how we want to handle this error... |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 501 | } |
| 502 | RParenLoc = ConsumeParen(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 503 | return Ty; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /// objc-method-decl: |
| 507 | /// objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 508 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 509 | /// objc-type-name objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 510 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 511 | /// |
| 512 | /// objc-keyword-selector: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 513 | /// objc-keyword-decl |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 514 | /// objc-keyword-selector objc-keyword-decl |
| 515 | /// |
| 516 | /// objc-keyword-decl: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 517 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 518 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 519 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 520 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 521 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 522 | /// objc-parmlist: |
| 523 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 524 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 525 | /// objc-parms: |
| 526 | /// objc-parms , parameter-declaration |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 527 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 528 | /// objc-ellipsis: |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 529 | /// , ... |
| 530 | /// |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 531 | /// objc-keyword-attributes: [OBJC2] |
| 532 | /// __attribute__((unused)) |
| 533 | /// |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 534 | Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
| 535 | tok::TokenKind mType, |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 536 | tok::ObjCKeywordKind MethodImplKind) |
| 537 | { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 538 | // Parse the return type. |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 539 | TypeTy *ReturnType = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 540 | if (Tok.is(tok::l_paren)) |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 541 | ReturnType = ParseObjCTypeName(); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 542 | SourceLocation selLoc; |
| 543 | IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 544 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 545 | if (!SelIdent) { |
| 546 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 547 | // FIXME: this creates a unary selector with a null identifier, is this |
| 548 | // ok?? Maybe we should skip to the next semicolon or something. |
| 549 | } |
| 550 | |
| 551 | // If attributes exist after the method, parse them. |
| 552 | AttributeList *MethodAttrs = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 553 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 554 | MethodAttrs = ParseAttributes(); |
| 555 | |
| 556 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 557 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
| 558 | mType, ReturnType, Sel, |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 559 | 0, 0, MethodAttrs, MethodImplKind); |
| 560 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 561 | |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 562 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 563 | llvm::SmallVector<Action::TypeTy *, 12> KeyTypes; |
| 564 | llvm::SmallVector<IdentifierInfo *, 12> ArgNames; |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 565 | |
| 566 | Action::TypeTy *TypeInfo; |
| 567 | while (1) { |
| 568 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 569 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 570 | // Each iteration parses a single keyword argument. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 571 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 572 | Diag(Tok, diag::err_expected_colon); |
| 573 | break; |
| 574 | } |
| 575 | ConsumeToken(); // Eat the ':'. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 576 | if (Tok.is(tok::l_paren)) // Parse the argument type. |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 577 | TypeInfo = ParseObjCTypeName(); |
| 578 | else |
| 579 | TypeInfo = 0; |
| 580 | KeyTypes.push_back(TypeInfo); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 581 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 582 | // If attributes exist before the argument name, parse them. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 583 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 584 | ParseAttributes(); // FIXME: pass attributes through. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 585 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 586 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 587 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 588 | break; |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 589 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 590 | ArgNames.push_back(Tok.getIdentifierInfo()); |
| 591 | ConsumeToken(); // Eat the identifier. |
Steve Naroff | f9e80db | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 592 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 593 | // Check for another keyword selector. |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 594 | SourceLocation Loc; |
| 595 | SelIdent = ParseObjCSelector(Loc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 596 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 597 | break; |
| 598 | // We have a selector or a colon, continue parsing. |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 599 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 600 | |
| 601 | // Parse the (optional) parameter list. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 602 | while (Tok.is(tok::comma)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 603 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 604 | if (Tok.is(tok::ellipsis)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 605 | ConsumeToken(); |
| 606 | break; |
| 607 | } |
| 608 | // Parse the c-style argument declaration-specifier. |
| 609 | DeclSpec DS; |
| 610 | ParseDeclarationSpecifiers(DS); |
| 611 | // Parse the declarator. |
| 612 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 613 | ParseDeclarator(ParmDecl); |
| 614 | } |
| 615 | |
| 616 | // FIXME: Add support for optional parmameter list... |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 617 | // If attributes exist after the method, parse them. |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 618 | AttributeList *MethodAttrs = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 619 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 620 | MethodAttrs = ParseAttributes(); |
| 621 | |
| 622 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 623 | &KeyIdents[0]); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 624 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
| 625 | mType, ReturnType, Sel, |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 626 | &KeyTypes[0], &ArgNames[0], |
| 627 | MethodAttrs, MethodImplKind); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Fariborz Jahanian | c04aff1 | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 630 | /// CmpProtocolVals - Comparison predicate for sorting protocols. |
| 631 | static bool CmpProtocolVals(const IdentifierInfo* const& lhs, |
| 632 | const IdentifierInfo* const& rhs) { |
| 633 | return strcmp(lhs->getName(), rhs->getName()) < 0; |
| 634 | } |
| 635 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 636 | /// objc-protocol-refs: |
| 637 | /// '<' identifier-list '>' |
| 638 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 639 | bool Parser::ParseObjCProtocolReferences( |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 640 | llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc) |
| 641 | { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 642 | assert(Tok.is(tok::less) && "expected <"); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 643 | |
| 644 | ConsumeToken(); // the "<" |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 645 | |
| 646 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 647 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 648 | Diag(Tok, diag::err_expected_ident); |
| 649 | SkipUntil(tok::greater); |
| 650 | return true; |
| 651 | } |
| 652 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 653 | ConsumeToken(); |
| 654 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 655 | if (Tok.isNot(tok::comma)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 656 | break; |
| 657 | ConsumeToken(); |
| 658 | } |
Fariborz Jahanian | c04aff1 | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 659 | |
| 660 | // Sort protocols, keyed by name. |
| 661 | // Later on, we remove duplicates. |
| 662 | std::stable_sort(ProtocolRefs.begin(), ProtocolRefs.end(), CmpProtocolVals); |
| 663 | |
| 664 | // Make protocol names unique. |
| 665 | ProtocolRefs.erase(std::unique(ProtocolRefs.begin(), ProtocolRefs.end()), |
| 666 | ProtocolRefs.end()); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 667 | // Consume the '>'. |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 668 | if (Tok.is(tok::greater)) { |
| 669 | endLoc = ConsumeAnyToken(); |
| 670 | return false; |
| 671 | } |
| 672 | Diag(Tok, diag::err_expected_greater); |
| 673 | return true; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | /// objc-class-instance-variables: |
| 677 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 678 | /// |
| 679 | /// objc-instance-variable-decl-list: |
| 680 | /// objc-visibility-spec |
| 681 | /// objc-instance-variable-decl ';' |
| 682 | /// ';' |
| 683 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 684 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 685 | /// objc-instance-variable-decl-list ';' |
| 686 | /// |
| 687 | /// objc-visibility-spec: |
| 688 | /// @private |
| 689 | /// @protected |
| 690 | /// @public |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 691 | /// @package [OBJC2] |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 692 | /// |
| 693 | /// objc-instance-variable-decl: |
| 694 | /// struct-declaration |
| 695 | /// |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 696 | void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, |
| 697 | SourceLocation atLoc) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 698 | assert(Tok.is(tok::l_brace) && "expected {"); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 699 | llvm::SmallVector<DeclTy*, 16> IvarDecls; |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 700 | llvm::SmallVector<DeclTy*, 32> AllIvarDecls; |
| 701 | llvm::SmallVector<tok::ObjCKeywordKind, 32> AllVisibilities; |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 702 | |
| 703 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 704 | |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 705 | tok::ObjCKeywordKind visibility = tok::objc_private; |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 706 | // While we still have something to read, read the instance variables. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 707 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 708 | // Each iteration of this loop reads one objc-instance-variable-decl. |
| 709 | |
| 710 | // Check for extraneous top-level semicolon. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 711 | if (Tok.is(tok::semi)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 712 | Diag(Tok, diag::ext_extra_struct_semi); |
| 713 | ConsumeToken(); |
| 714 | continue; |
| 715 | } |
| 716 | // Set the default visibility to private. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 717 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 718 | ConsumeToken(); // eat the @ sign |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 719 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 720 | case tok::objc_private: |
| 721 | case tok::objc_public: |
| 722 | case tok::objc_protected: |
| 723 | case tok::objc_package: |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 724 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 725 | ConsumeToken(); |
| 726 | continue; |
| 727 | default: |
| 728 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
| 729 | ConsumeToken(); |
| 730 | continue; |
| 731 | } |
| 732 | } |
| 733 | ParseStructDeclaration(interfaceDecl, IvarDecls); |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 734 | for (unsigned i = 0; i < IvarDecls.size(); i++) { |
| 735 | AllIvarDecls.push_back(IvarDecls[i]); |
| 736 | AllVisibilities.push_back(visibility); |
| 737 | } |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 738 | IvarDecls.clear(); |
| 739 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 740 | if (Tok.is(tok::semi)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 741 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 742 | } else if (Tok.is(tok::r_brace)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 743 | Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list); |
| 744 | break; |
| 745 | } else { |
| 746 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 747 | // Skip to end of block or statement |
| 748 | SkipUntil(tok::r_brace, true, true); |
| 749 | } |
| 750 | } |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 751 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 752 | if (AllIvarDecls.size()) { // Check for {} - no ivars in braces |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 753 | Actions.ActOnFields(CurScope, atLoc, interfaceDecl, |
Steve Naroff | 0acc9c9 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 754 | &AllIvarDecls[0], AllIvarDecls.size(), |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 755 | LBraceLoc, RBraceLoc, &AllVisibilities[0]); |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 756 | } |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 757 | return; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 758 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 759 | |
| 760 | /// objc-protocol-declaration: |
| 761 | /// objc-protocol-definition |
| 762 | /// objc-protocol-forward-reference |
| 763 | /// |
| 764 | /// objc-protocol-definition: |
| 765 | /// @protocol identifier |
| 766 | /// objc-protocol-refs[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 767 | /// objc-interface-decl-list |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 768 | /// @end |
| 769 | /// |
| 770 | /// objc-protocol-forward-reference: |
| 771 | /// @protocol identifier-list ';' |
| 772 | /// |
| 773 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 774 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 775 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
| 776 | |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 777 | Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 778 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 779 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 780 | ConsumeToken(); // the "protocol" identifier |
| 781 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 782 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 783 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
| 784 | return 0; |
| 785 | } |
| 786 | // Save the protocol name, then consume it. |
| 787 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 788 | SourceLocation nameLoc = ConsumeToken(); |
| 789 | |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 790 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 791 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 792 | ConsumeToken(); |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 793 | ProtocolRefs.push_back(protocolName); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 794 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 795 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 796 | // Parse the list of forward declarations. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 797 | ProtocolRefs.push_back(protocolName); |
| 798 | |
| 799 | while (1) { |
| 800 | ConsumeToken(); // the ',' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 801 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 802 | Diag(Tok, diag::err_expected_ident); |
| 803 | SkipUntil(tok::semi); |
| 804 | return 0; |
| 805 | } |
| 806 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 807 | ConsumeToken(); // the identifier |
| 808 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 809 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | // Consume the ';'. |
| 813 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
| 814 | return 0; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 815 | } |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 816 | if (ProtocolRefs.size() > 0) |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 817 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Steve Naroff | b4dfe36 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 818 | &ProtocolRefs[0], |
| 819 | ProtocolRefs.size()); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 820 | // Last, and definitely not least, parse a protocol declaration. |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 821 | SourceLocation endProtoLoc; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 822 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 823 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 824 | return 0; |
| 825 | } |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 826 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 827 | DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 828 | protocolName, nameLoc, |
| 829 | &ProtocolRefs[0], |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame^] | 830 | ProtocolRefs.size(), endProtoLoc); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 831 | ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 832 | |
| 833 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 834 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 835 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | ac20be2 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 836 | return ProtoType; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 837 | } |
| 838 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 839 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 840 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 841 | |
| 842 | /// objc-implementation: |
| 843 | /// objc-class-implementation-prologue |
| 844 | /// objc-category-implementation-prologue |
| 845 | /// |
| 846 | /// objc-class-implementation-prologue: |
| 847 | /// @implementation identifier objc-superclass[opt] |
| 848 | /// objc-class-instance-variables[opt] |
| 849 | /// |
| 850 | /// objc-category-implementation-prologue: |
| 851 | /// @implementation identifier ( identifier ) |
| 852 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 853 | Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( |
| 854 | SourceLocation atLoc) { |
| 855 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 856 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 857 | ConsumeToken(); // the "implementation" identifier |
| 858 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 859 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 860 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 861 | return 0; |
| 862 | } |
| 863 | // We have a class or category name - consume it. |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 864 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 865 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
| 866 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 867 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 868 | // we have a category implementation. |
| 869 | SourceLocation lparenLoc = ConsumeParen(); |
| 870 | SourceLocation categoryLoc, rparenLoc; |
| 871 | IdentifierInfo *categoryId = 0; |
| 872 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 873 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 874 | categoryId = Tok.getIdentifierInfo(); |
| 875 | categoryLoc = ConsumeToken(); |
| 876 | } else { |
| 877 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 878 | return 0; |
| 879 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 880 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 881 | Diag(Tok, diag::err_expected_rparen); |
| 882 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 883 | return 0; |
| 884 | } |
| 885 | rparenLoc = ConsumeParen(); |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 886 | DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 887 | atLoc, nameId, nameLoc, categoryId, |
| 888 | categoryLoc); |
| 889 | return ImplCatType; |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 890 | } |
| 891 | // We have a class implementation |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 892 | SourceLocation superClassLoc; |
| 893 | IdentifierInfo *superClassId = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 894 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 895 | // We have a super class |
| 896 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 897 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 898 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 899 | return 0; |
| 900 | } |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 901 | superClassId = Tok.getIdentifierInfo(); |
| 902 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 903 | } |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 904 | DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( |
Steve Naroff | 25aace8 | 2007-10-03 21:00:46 +0000 | [diff] [blame] | 905 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 906 | superClassId, superClassLoc); |
| 907 | |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 908 | if (Tok.is(tok::l_brace)) // we have ivars |
| 909 | ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 910 | |
Fariborz Jahanian | 1e4e82f | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 911 | return ImplClsType; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 912 | } |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 913 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 914 | Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { |
| 915 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 916 | "ParseObjCAtEndDeclaration(): Expected @end"); |
| 917 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | 1e4e82f | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 918 | if (ObjcImpDecl) { |
| 919 | // Checking is not necessary except that a parse error might have caused |
| 920 | // @implementation not to have been parsed to completion and ObjcImpDecl |
| 921 | // could be 0. |
| 922 | /// Insert collected methods declarations into the @interface object. |
Steve Naroff | 25aace8 | 2007-10-03 21:00:46 +0000 | [diff] [blame] | 923 | Actions.ActOnAddMethodsToObjcDecl(CurScope, ObjcImpDecl, |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 924 | &AllImplMethods[0], AllImplMethods.size(), |
| 925 | atLoc); |
Fariborz Jahanian | 1e4e82f | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 926 | ObjcImpDecl = 0; |
| 927 | AllImplMethods.clear(); |
| 928 | } |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 929 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 930 | return 0; |
| 931 | } |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 932 | |
| 933 | /// compatibility-alias-decl: |
| 934 | /// @compatibility_alias alias-name class-name ';' |
| 935 | /// |
| 936 | Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
| 937 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 938 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 939 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 940 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 941 | Diag(Tok, diag::err_expected_ident); |
| 942 | return 0; |
| 943 | } |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 944 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 945 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 946 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 947 | Diag(Tok, diag::err_expected_ident); |
| 948 | return 0; |
| 949 | } |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 950 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 951 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
| 952 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 6c30fa6 | 2007-09-04 21:42:12 +0000 | [diff] [blame] | 953 | Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias"); |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, |
| 957 | aliasId, aliasLoc, |
| 958 | classId, classLoc); |
| 959 | return ClsType; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 962 | /// property-synthesis: |
| 963 | /// @synthesize property-ivar-list ';' |
| 964 | /// |
| 965 | /// property-ivar-list: |
| 966 | /// property-ivar |
| 967 | /// property-ivar-list ',' property-ivar |
| 968 | /// |
| 969 | /// property-ivar: |
| 970 | /// identifier |
| 971 | /// identifier '=' identifier |
| 972 | /// |
| 973 | Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
| 974 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 975 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
| 976 | SourceLocation loc = ConsumeToken(); // consume dynamic |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 977 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 978 | Diag(Tok, diag::err_expected_ident); |
| 979 | return 0; |
| 980 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 981 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 982 | ConsumeToken(); // consume property name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 983 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 984 | // property '=' ivar-name |
| 985 | ConsumeToken(); // consume '=' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 986 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 987 | Diag(Tok, diag::err_expected_ident); |
| 988 | break; |
| 989 | } |
| 990 | ConsumeToken(); // consume ivar-name |
| 991 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 992 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 993 | break; |
| 994 | ConsumeToken(); // consume ',' |
| 995 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 996 | if (Tok.isNot(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 997 | Diag(Tok, diag::err_expected_semi_after, "@synthesize"); |
| 998 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1001 | /// property-dynamic: |
| 1002 | /// @dynamic property-list |
| 1003 | /// |
| 1004 | /// property-list: |
| 1005 | /// identifier |
| 1006 | /// property-list ',' identifier |
| 1007 | /// |
| 1008 | Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
| 1009 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1010 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 1011 | SourceLocation loc = ConsumeToken(); // consume dynamic |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1012 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1013 | Diag(Tok, diag::err_expected_ident); |
| 1014 | return 0; |
| 1015 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1016 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1017 | ConsumeToken(); // consume property name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1018 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1019 | break; |
| 1020 | ConsumeToken(); // consume ',' |
| 1021 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1022 | if (Tok.isNot(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1023 | Diag(Tok, diag::err_expected_semi_after, "@dynamic"); |
| 1024 | return 0; |
| 1025 | } |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1026 | |
| 1027 | /// objc-throw-statement: |
| 1028 | /// throw expression[opt]; |
| 1029 | /// |
Fariborz Jahanian | 37c9c61 | 2007-10-04 20:19:06 +0000 | [diff] [blame] | 1030 | Parser::DeclTy *Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1031 | ConsumeToken(); // consume throw |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1032 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 37c9c61 | 2007-10-04 20:19:06 +0000 | [diff] [blame] | 1033 | ExprResult Res = ParseExpression(); |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1034 | if (Res.isInvalid) { |
| 1035 | SkipUntil(tok::semi); |
| 1036 | return 0; |
| 1037 | } |
| 1038 | } |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | /// objc-try-catch-statement: |
| 1043 | /// @try compound-statement objc-catch-list[opt] |
| 1044 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1045 | /// |
| 1046 | /// objc-catch-list: |
| 1047 | /// @catch ( parameter-declaration ) compound-statement |
| 1048 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1049 | /// catch-parameter-declaration: |
| 1050 | /// parameter-declaration |
| 1051 | /// '...' [OBJC2] |
| 1052 | /// |
Fariborz Jahanian | 37c9c61 | 2007-10-04 20:19:06 +0000 | [diff] [blame] | 1053 | Parser::DeclTy *Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1054 | bool catch_or_finally_seen = false; |
| 1055 | ConsumeToken(); // consume try |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1056 | if (Tok.isNot(tok::l_brace)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1057 | Diag (Tok, diag::err_expected_lbrace); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | StmtResult TryBody = ParseCompoundStatementBody(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1061 | while (Tok.is(tok::at)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1062 | ConsumeToken(); |
| 1063 | if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_catch) { |
| 1064 | SourceLocation catchLoc = ConsumeToken(); // consume catch |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1065 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1066 | ConsumeParen(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1067 | if (Tok.isNot(tok::ellipsis)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1068 | DeclSpec DS; |
| 1069 | ParseDeclarationSpecifiers(DS); |
| 1070 | // Parse the parameter-declaration. |
| 1071 | // FIXME: BlockContext may not be the right context! |
| 1072 | Declarator ParmDecl(DS, Declarator::BlockContext); |
| 1073 | ParseDeclarator(ParmDecl); |
| 1074 | } |
| 1075 | else |
| 1076 | ConsumeToken(); // consume '...' |
| 1077 | ConsumeParen(); |
| 1078 | StmtResult CatchMody = ParseCompoundStatementBody(); |
| 1079 | } |
| 1080 | else { |
| 1081 | Diag(catchLoc, diag::err_expected_lparen_after, "@catch clause"); |
| 1082 | return 0; |
| 1083 | } |
| 1084 | catch_or_finally_seen = true; |
| 1085 | } |
| 1086 | else if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_finally) { |
| 1087 | ConsumeToken(); // consume finally |
| 1088 | StmtResult FinallyBody = ParseCompoundStatementBody(); |
| 1089 | catch_or_finally_seen = true; |
| 1090 | break; |
| 1091 | } |
| 1092 | } |
| 1093 | if (!catch_or_finally_seen) |
| 1094 | Diag(atLoc, diag::err_missing_catch_finally); |
| 1095 | return 0; |
| 1096 | } |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1097 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1098 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1099 | /// |
| 1100 | void Parser::ParseObjCInstanceMethodDefinition() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1101 | assert(Tok.is(tok::minus) && "Method definitions should start with '-'"); |
| 1102 | |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1103 | // FIXME: @optional/@protocol?? |
Fariborz Jahanian | 1e4e82f | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 1104 | AllImplMethods.push_back(ParseObjCMethodPrototype(ObjcImpDecl)); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1105 | // parse optional ';' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1106 | if (Tok.is(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1107 | ConsumeToken(); |
| 1108 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1109 | if (Tok.isNot(tok::l_brace)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1110 | Diag (Tok, diag::err_expected_lbrace); |
| 1111 | return; |
| 1112 | } |
| 1113 | |
| 1114 | StmtResult FnBody = ParseCompoundStatementBody(); |
| 1115 | } |
| 1116 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1117 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1118 | /// |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1119 | void Parser::ParseObjCClassMethodDefinition() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1120 | assert(Tok.is(tok::plus) && "Class method definitions should start with '+'"); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1121 | // FIXME: @optional/@protocol?? |
Fariborz Jahanian | 1e4e82f | 2007-09-27 18:57:03 +0000 | [diff] [blame] | 1122 | AllImplMethods.push_back(ParseObjCMethodPrototype(ObjcImpDecl)); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1123 | // parse optional ';' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1124 | if (Tok.is(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1125 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1126 | if (Tok.isNot(tok::l_brace)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1127 | Diag (Tok, diag::err_expected_lbrace); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | StmtResult FnBody = ParseCompoundStatementBody(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1132 | } |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1133 | |
Steve Naroff | fb9dd75 | 2007-10-15 20:55:58 +0000 | [diff] [blame] | 1134 | Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1135 | |
| 1136 | switch (Tok.getKind()) { |
| 1137 | case tok::string_literal: // primary-expression: string-literal |
| 1138 | case tok::wide_string_literal: |
Fariborz Jahanian | 37c9c61 | 2007-10-04 20:19:06 +0000 | [diff] [blame] | 1139 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral()); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1140 | default: |
| 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1145 | case tok::objc_encode: |
| 1146 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
| 1147 | case tok::objc_protocol: |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1148 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1149 | case tok::objc_selector: |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1150 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1151 | default: |
| 1152 | Diag(AtLoc, diag::err_unexpected_at); |
| 1153 | SkipUntil(tok::semi); |
| 1154 | break; |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1160 | /// objc-message-expr: |
| 1161 | /// '[' objc-receiver objc-message-args ']' |
| 1162 | /// |
| 1163 | /// objc-receiver: |
| 1164 | /// expression |
| 1165 | /// class-name |
| 1166 | /// type-name |
| 1167 | /// |
| 1168 | /// objc-message-args: |
| 1169 | /// objc-selector |
| 1170 | /// objc-keywordarg-list |
| 1171 | /// |
| 1172 | /// objc-keywordarg-list: |
| 1173 | /// objc-keywordarg |
| 1174 | /// objc-keywordarg-list objc-keywordarg |
| 1175 | /// |
| 1176 | /// objc-keywordarg: |
| 1177 | /// selector-name[opt] ':' objc-keywordexpr |
| 1178 | /// |
| 1179 | /// objc-keywordexpr: |
| 1180 | /// nonempty-expr-list |
| 1181 | /// |
| 1182 | /// nonempty-expr-list: |
| 1183 | /// assignment-expression |
| 1184 | /// nonempty-expr-list , assignment-expression |
| 1185 | /// |
| 1186 | Parser::ExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1187 | assert(Tok.is(tok::l_square) && "'[' expected"); |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1188 | SourceLocation LBracloc = ConsumeBracket(); // consume '[' |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1189 | IdentifierInfo *ReceiverName = 0; |
| 1190 | ExprTy *ReceiverExpr = 0; |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1191 | // Parse receiver |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1192 | if (Tok.is(tok::identifier) && |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1193 | Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { |
| 1194 | ReceiverName = Tok.getIdentifierInfo(); |
Steve Naroff | f0c31dd | 2007-09-16 16:16:00 +0000 | [diff] [blame] | 1195 | ConsumeToken(); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1196 | } else { |
| 1197 | ExprResult Res = ParseAssignmentExpression(); |
| 1198 | if (Res.isInvalid) { |
| 1199 | SkipUntil(tok::identifier); |
| 1200 | return Res; |
| 1201 | } |
| 1202 | ReceiverExpr = Res.Val; |
| 1203 | } |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1204 | // Parse objc-selector |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1205 | SourceLocation Loc; |
| 1206 | IdentifierInfo *selIdent = ParseObjCSelector(Loc); |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1207 | |
| 1208 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 1209 | llvm::SmallVector<Action::ExprTy *, 12> KeyExprs; |
| 1210 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1211 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1212 | while (1) { |
| 1213 | // Each iteration parses a single keyword argument. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1214 | KeyIdents.push_back(selIdent); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1215 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1216 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1217 | Diag(Tok, diag::err_expected_colon); |
| 1218 | SkipUntil(tok::semi); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1219 | return true; |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1220 | } |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1221 | ConsumeToken(); // Eat the ':'. |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1222 | /// Parse the expression after ':' |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1223 | ExprResult Res = ParseAssignmentExpression(); |
| 1224 | if (Res.isInvalid) { |
| 1225 | SkipUntil(tok::identifier); |
| 1226 | return Res; |
| 1227 | } |
| 1228 | // We have a valid expression. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1229 | KeyExprs.push_back(Res.Val); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1230 | |
| 1231 | // Check for another keyword selector. |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1232 | selIdent = ParseObjCSelector(Loc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1233 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1234 | break; |
| 1235 | // We have a selector or a colon, continue parsing. |
| 1236 | } |
| 1237 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1238 | while (Tok.is(tok::comma)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1239 | ConsumeToken(); |
| 1240 | /// Parse the expression after ',' |
| 1241 | ParseAssignmentExpression(); |
| 1242 | } |
| 1243 | } else if (!selIdent) { |
| 1244 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 1245 | SkipUntil(tok::semi); |
| 1246 | return 0; |
| 1247 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1248 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1249 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1250 | Diag(Tok, diag::err_expected_rsquare); |
| 1251 | SkipUntil(tok::semi); |
| 1252 | return 0; |
| 1253 | } |
Steve Naroff | c39ca26 | 2007-09-18 23:55:05 +0000 | [diff] [blame] | 1254 | SourceLocation RBracloc = ConsumeBracket(); // consume ']' |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1255 | |
Steve Naroff | f9e80db | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 1256 | unsigned nKeys = KeyIdents.size(); |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1257 | if (nKeys == 0) |
| 1258 | KeyIdents.push_back(selIdent); |
| 1259 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
| 1260 | |
| 1261 | // We've just parsed a keyword message. |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1262 | if (ReceiverName) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1263 | return Actions.ActOnClassMessage(ReceiverName, Sel, LBracloc, RBracloc, |
| 1264 | &KeyExprs[0]); |
| 1265 | return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracloc, RBracloc, |
| 1266 | &KeyExprs[0]); |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1269 | Parser::ExprResult Parser::ParseObjCStringLiteral() { |
| 1270 | ExprResult Res = ParseStringLiteralExpression(); |
| 1271 | |
| 1272 | if (Res.isInvalid) return Res; |
| 1273 | |
| 1274 | return Actions.ParseObjCStringLiteral(Res.Val); |
| 1275 | } |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1276 | |
| 1277 | /// objc-encode-expression: |
| 1278 | /// @encode ( type-name ) |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1279 | Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1280 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1281 | |
| 1282 | SourceLocation EncLoc = ConsumeToken(); |
| 1283 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1284 | if (Tok.isNot(tok::l_paren)) { |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1285 | Diag(Tok, diag::err_expected_lparen_after, "@encode"); |
| 1286 | return true; |
| 1287 | } |
| 1288 | |
| 1289 | SourceLocation LParenLoc = ConsumeParen(); |
| 1290 | |
| 1291 | TypeTy *Ty = ParseTypeName(); |
| 1292 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1293 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1294 | |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1295 | return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty, |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1296 | RParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1297 | } |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1298 | |
| 1299 | /// objc-protocol-expression |
| 1300 | /// @protocol ( protocol-name ) |
| 1301 | |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1302 | Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1303 | { |
| 1304 | SourceLocation ProtoLoc = ConsumeToken(); |
| 1305 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1306 | if (Tok.isNot(tok::l_paren)) { |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1307 | Diag(Tok, diag::err_expected_lparen_after, "@protocol"); |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | SourceLocation LParenLoc = ConsumeParen(); |
| 1312 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1313 | if (Tok.isNot(tok::identifier)) { |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1314 | Diag(Tok, diag::err_expected_ident); |
| 1315 | return true; |
| 1316 | } |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1317 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1318 | ConsumeToken(); |
| 1319 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1320 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1321 | |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1322 | return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 1323 | LParenLoc, RParenLoc); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1324 | } |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1325 | |
| 1326 | /// objc-selector-expression |
| 1327 | /// @selector '(' objc-keyword-selector ')' |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1328 | Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1329 | { |
| 1330 | SourceLocation SelectorLoc = ConsumeToken(); |
| 1331 | |
| 1332 | if (Tok.isNot(tok::l_paren)) { |
| 1333 | Diag(Tok, diag::err_expected_lparen_after, "@selector"); |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1337 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1338 | SourceLocation LParenLoc = ConsumeParen(); |
| 1339 | SourceLocation sLoc; |
| 1340 | IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); |
| 1341 | if (!SelIdent && Tok.isNot(tok::colon)) { |
| 1342 | |
| 1343 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 1344 | return 0; |
| 1345 | } |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1346 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1347 | if (Tok.isNot(tok::r_paren)) |
| 1348 | while (1) { |
| 1349 | if (Tok.isNot(tok::colon)) { |
| 1350 | Diag(Tok, diag::err_expected_colon); |
| 1351 | break; |
| 1352 | } |
| 1353 | ConsumeToken(); // Eat the ':'. |
| 1354 | if (Tok.is(tok::r_paren)) |
| 1355 | break; |
| 1356 | // Check for another keyword selector. |
| 1357 | SourceLocation Loc; |
| 1358 | SelIdent = ParseObjCSelector(Loc); |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1359 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1360 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 1361 | break; |
| 1362 | } |
| 1363 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1364 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 1365 | &KeyIdents[0]); |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1366 | return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, LParenLoc, |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1367 | RParenLoc); |
Gabor Greif | a823dd1 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 1368 | } |