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