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 |
| 24 | /// [OBJC] objc-class-declaration [TODO] |
| 25 | /// [OBJC] objc-alias-declaration [TODO] |
| 26 | /// [OBJC] objc-protocol-definition [TODO] |
| 27 | /// [OBJC] objc-method-definition [TODO] |
| 28 | /// [OBJC] '@' 'end' [TODO] |
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) { |
| 65 | if (Tok.getKind() != tok::identifier) { |
| 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 | |
| 73 | if (Tok.getKind() != tok::comma) |
| 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 | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 83 | return Actions.ObjcClassDeclaration(CurScope, atLoc, |
| 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 | |
| 121 | if (Tok.getKind() != tok::identifier) { |
| 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 | |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 129 | if (Tok.getKind() == 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; |
| 133 | |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 134 | // For ObjC2, the category name is optional (not an error). |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 135 | if (Tok.getKind() == tok::identifier) { |
| 136 | categoryId = Tok.getIdentifierInfo(); |
| 137 | categoryLoc = ConsumeToken(); |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 138 | } else if (!getLang().ObjC2) { |
| 139 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 140 | return 0; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 141 | } |
| 142 | if (Tok.getKind() != tok::r_paren) { |
| 143 | Diag(Tok, diag::err_expected_rparen); |
| 144 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 145 | return 0; |
| 146 | } |
| 147 | rparenLoc = ConsumeParen(); |
| 148 | // Next, we need to check for any protocol references. |
| 149 | if (Tok.getKind() == tok::less) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 150 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
| 151 | if (ParseObjCProtocolReferences(ProtocolRefs)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | if (attrList) // categories don't support attributes. |
| 155 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
| 156 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 157 | ParseObjCInterfaceDeclList(0/*FIXME*/); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 158 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 159 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 160 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 161 | ConsumeToken(); // the "end" identifier |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 162 | return 0; |
| 163 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 164 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | // Parse a class interface. |
| 168 | IdentifierInfo *superClassId = 0; |
| 169 | SourceLocation superClassLoc; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 170 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 171 | if (Tok.getKind() == tok::colon) { // a super class is specified. |
| 172 | ConsumeToken(); |
| 173 | if (Tok.getKind() != tok::identifier) { |
| 174 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 175 | return 0; |
| 176 | } |
| 177 | superClassId = Tok.getIdentifierInfo(); |
| 178 | superClassLoc = ConsumeToken(); |
| 179 | } |
| 180 | // Next, we need to check for any protocol references. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 181 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 182 | if (Tok.getKind() == tok::less) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 183 | if (ParseObjCProtocolReferences(ProtocolRefs)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 184 | return 0; |
| 185 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 186 | DeclTy *ClsType = Actions.ObjcStartClassInterface(atLoc, nameId, nameLoc, |
| 187 | superClassId, superClassLoc, &ProtocolRefs[0], |
| 188 | ProtocolRefs.size(), attrList); |
| 189 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 190 | if (Tok.getKind() == tok::l_brace) |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 191 | ParseObjCClassInstanceVariables(ClsType); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 192 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 193 | ParseObjCInterfaceDeclList(ClsType); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 194 | |
| 195 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 196 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 197 | ConsumeToken(); // the "end" identifier |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 200 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | /// objc-interface-decl-list: |
| 205 | /// empty |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 206 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 207 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 208 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 209 | /// objc-interface-decl-list declaration |
| 210 | /// objc-interface-decl-list ';' |
| 211 | /// |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 212 | /// objc-method-requirement: [OBJC2] |
| 213 | /// @required |
| 214 | /// @optional |
| 215 | /// |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 216 | void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 217 | while (1) { |
| 218 | if (Tok.getKind() == tok::at) { |
| 219 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 220 | tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID(); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 221 | |
| 222 | if (ocKind == tok::objc_end) { // terminate list |
| 223 | return; |
| 224 | } else if (ocKind == tok::objc_required) { // protocols only |
| 225 | ConsumeToken(); |
| 226 | continue; |
| 227 | } else if (ocKind == tok::objc_optional) { // protocols only |
| 228 | ConsumeToken(); |
| 229 | continue; |
| 230 | } else if (ocKind == tok::objc_property) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 231 | ParseObjCPropertyDecl(0/*FIXME*/); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 232 | continue; |
| 233 | } else { |
| 234 | Diag(Tok, diag::err_objc_illegal_interface_qual); |
| 235 | ConsumeToken(); |
| 236 | } |
| 237 | } |
| 238 | if (Tok.getKind() == tok::minus || Tok.getKind() == tok::plus) { |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 239 | ParseObjCMethodPrototype(interfaceDecl); |
| 240 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 241 | // method definitions. |
| 242 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "method proto"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 243 | continue; |
| 244 | } |
| 245 | if (Tok.getKind() == tok::semi) |
| 246 | ConsumeToken(); |
| 247 | else if (Tok.getKind() == tok::eof) |
| 248 | return; |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 249 | else { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 250 | // FIXME: as the name implies, this rule allows function definitions. |
| 251 | // We could pass a flag or check for functions during semantic analysis. |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 252 | ParseDeclarationOrFunctionDefinition(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 253 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 257 | /// Parse property attribute declarations. |
| 258 | /// |
| 259 | /// property-attr-decl: '(' property-attrlist ')' |
| 260 | /// property-attrlist: |
| 261 | /// property-attribute |
| 262 | /// property-attrlist ',' property-attribute |
| 263 | /// property-attribute: |
| 264 | /// getter '=' identifier |
| 265 | /// setter '=' identifier ':' |
| 266 | /// readonly |
| 267 | /// readwrite |
| 268 | /// assign |
| 269 | /// retain |
| 270 | /// copy |
| 271 | /// nonatomic |
| 272 | /// |
| 273 | void Parser::ParseObjCPropertyAttribute (DeclTy *interfaceDecl) { |
| 274 | SourceLocation loc = ConsumeParen(); // consume '(' |
| 275 | while (isObjCPropertyAttribute()) { |
| 276 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 277 | // getter/setter require extra treatment. |
| 278 | if (II == ObjcPropertyAttrs[objc_getter] || |
| 279 | II == ObjcPropertyAttrs[objc_setter]) { |
| 280 | // skip getter/setter part. |
| 281 | SourceLocation loc = ConsumeToken(); |
| 282 | if (Tok.getKind() == tok::equal) { |
| 283 | loc = ConsumeToken(); |
| 284 | if (Tok.getKind() == tok::identifier) { |
| 285 | if (II == ObjcPropertyAttrs[objc_setter]) { |
| 286 | loc = ConsumeToken(); // consume method name |
| 287 | if (Tok.getKind() != tok::colon) { |
| 288 | Diag(loc, diag::err_expected_colon); |
| 289 | SkipUntil(tok::r_paren,true,true); |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | else { |
| 295 | Diag(loc, diag::err_expected_ident); |
| 296 | SkipUntil(tok::r_paren,true,true); |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | else { |
| 301 | Diag(loc, diag::err_objc_expected_equal); |
| 302 | SkipUntil(tok::r_paren,true,true); |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | ConsumeToken(); // consume last attribute token |
| 307 | if (Tok.getKind() == tok::comma) { |
| 308 | loc = ConsumeToken(); |
| 309 | continue; |
| 310 | } |
| 311 | if (Tok.getKind() == tok::r_paren) |
| 312 | break; |
| 313 | Diag(loc, diag::err_expected_rparen); |
| 314 | SkipUntil(tok::semi); |
| 315 | return; |
| 316 | } |
| 317 | if (Tok.getKind() == tok::r_paren) |
| 318 | ConsumeParen(); |
| 319 | else { |
| 320 | Diag(loc, diag::err_objc_expected_property_attr); |
| 321 | SkipUntil(tok::r_paren); // recover from error inside attribute list |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /// Main routine to parse property declaration. |
| 326 | /// |
| 327 | /// @property property-attr-decl[opt] property-component-decl ';' |
| 328 | /// |
| 329 | void Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl) { |
| 330 | assert(Tok.isObjCAtKeyword(tok::objc_property) && |
| 331 | "ParseObjCPropertyDecl(): Expected @property"); |
| 332 | ConsumeToken(); // the "property" identifier |
| 333 | // Parse property attribute list, if any. |
| 334 | if (Tok.getKind() == tok::l_paren) { |
| 335 | // property has attribute list. |
| 336 | ParseObjCPropertyAttribute(0/*FIXME*/); |
| 337 | } |
| 338 | // Parse declaration portion of @property. |
| 339 | llvm::SmallVector<DeclTy*, 32> PropertyDecls; |
| 340 | ParseStructDeclaration(interfaceDecl, PropertyDecls); |
| 341 | if (Tok.getKind() == tok::semi) |
| 342 | ConsumeToken(); |
| 343 | else { |
| 344 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 345 | SkipUntil(tok::r_brace, true, true); |
| 346 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 347 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 348 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 349 | /// objc-method-proto: |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 350 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 351 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 352 | /// |
| 353 | /// objc-instance-method: '-' |
| 354 | /// objc-class-method: '+' |
| 355 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 356 | /// objc-method-attributes: [OBJC2] |
| 357 | /// __attribute__((deprecated)) |
| 358 | /// |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 359 | Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *CDecl) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 360 | assert((Tok.getKind() == tok::minus || Tok.getKind() == tok::plus) && |
| 361 | "expected +/-"); |
| 362 | |
| 363 | tok::TokenKind methodType = Tok.getKind(); |
| 364 | SourceLocation methodLoc = ConsumeToken(); |
| 365 | |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 366 | DeclTy *MDecl = ParseObjCMethodDecl(methodType, methodLoc); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 367 | |
| 368 | AttributeList *methodAttrs = 0; |
| 369 | // If attributes exist after the method, parse them. |
| 370 | if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) |
| 371 | methodAttrs = ParseAttributes(); |
| 372 | |
| 373 | if (CDecl) |
| 374 | Actions.ObjcAddMethod(CDecl, MDecl, methodAttrs); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 375 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 376 | // Since this rule is used for both method declarations and definitions, |
| 377 | // the caller is responsible for consuming the ';'. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 378 | return MDecl; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /// objc-selector: |
| 382 | /// identifier |
| 383 | /// one of |
| 384 | /// enum struct union if else while do for switch case default |
| 385 | /// break continue return goto asm sizeof typeof __alignof |
| 386 | /// unsigned long const short volatile signed restrict _Complex |
| 387 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 388 | /// |
| 389 | IdentifierInfo *Parser::ParseObjCSelector() { |
| 390 | tok::TokenKind tKind = Tok.getKind(); |
| 391 | IdentifierInfo *II = 0; |
| 392 | |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 393 | if (tKind == tok::identifier || tKind == tok::kw_typeof || |
| 394 | tKind == tok::kw___alignof || |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 395 | (tKind >= tok::kw_auto && tKind <= tok::kw__Complex)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 396 | II = Tok.getIdentifierInfo(); |
| 397 | ConsumeToken(); |
| 398 | } |
| 399 | return II; |
| 400 | } |
| 401 | |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 402 | /// objc-type-qualifier: one of |
| 403 | /// in out inout bycopy byref oneway |
| 404 | /// |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 405 | bool Parser::isObjCTypeQualifier() { |
| 406 | if (Tok.getKind() == tok::identifier) { |
Chris Lattner | 3235246 | 2007-08-29 22:54:08 +0000 | [diff] [blame] | 407 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 408 | for (unsigned i = 0; i < objc_NumQuals; ++i) |
| 409 | if (II == ObjcTypeQuals[i]) return true; |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 410 | } |
| 411 | return false; |
| 412 | } |
| 413 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 414 | /// property-attrlist: one of |
| 415 | /// readonly getter setter assign retain copy nonatomic |
| 416 | /// |
| 417 | bool Parser::isObjCPropertyAttribute() { |
| 418 | if (Tok.getKind() == tok::identifier) { |
| 419 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 420 | for (unsigned i = 0; i < objc_NumAttrs; ++i) |
| 421 | if (II == ObjcPropertyAttrs[i]) return true; |
| 422 | } |
| 423 | return false; |
| 424 | } |
| 425 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 426 | /// objc-type-name: |
| 427 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 428 | /// '(' objc-type-qualifiers[opt] ')' |
| 429 | /// |
| 430 | /// objc-type-qualifiers: |
| 431 | /// objc-type-qualifier |
| 432 | /// objc-type-qualifiers objc-type-qualifier |
| 433 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 434 | Parser::TypeTy *Parser::ParseObjCTypeName() { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 435 | assert(Tok.getKind() == tok::l_paren && "expected ("); |
| 436 | |
| 437 | SourceLocation LParenLoc = ConsumeParen(), RParenLoc; |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 438 | TypeTy *Ty; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 439 | |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 440 | while (isObjCTypeQualifier()) |
| 441 | ConsumeToken(); |
| 442 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 443 | if (isTypeSpecifierQualifier()) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 444 | Ty = ParseTypeName(); |
| 445 | // FIXME: back when Sema support is in place... |
| 446 | // assert(Ty && "Parser::ParseObjCTypeName(): missing type"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 447 | } |
| 448 | if (Tok.getKind() != tok::r_paren) { |
| 449 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 450 | return 0; // FIXME: decide how we want to handle this error... |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 451 | } |
| 452 | RParenLoc = ConsumeParen(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 453 | return Ty; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /// objc-method-decl: |
| 457 | /// objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 458 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 459 | /// objc-type-name objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 460 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 461 | /// |
| 462 | /// objc-keyword-selector: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 463 | /// objc-keyword-decl |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 464 | /// objc-keyword-selector objc-keyword-decl |
| 465 | /// |
| 466 | /// objc-keyword-decl: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 467 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 468 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 469 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 470 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 471 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 472 | /// objc-parmlist: |
| 473 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 474 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 475 | /// objc-parms: |
| 476 | /// objc-parms , parameter-declaration |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 477 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 478 | /// objc-ellipsis: |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 479 | /// , ... |
| 480 | /// |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 481 | /// objc-keyword-attributes: [OBJC2] |
| 482 | /// __attribute__((unused)) |
| 483 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 484 | Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType, SourceLocation mLoc) { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 485 | |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 486 | TypeTy *ReturnType = 0; |
| 487 | |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 488 | // Parse the return type. |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 489 | if (Tok.getKind() == tok::l_paren) |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 490 | ReturnType = ParseObjCTypeName(); |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 491 | IdentifierInfo *selIdent = ParseObjCSelector(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 492 | |
| 493 | llvm::SmallVector<ObjcKeywordInfo, 12> KeyInfo; |
| 494 | int KeySlot = 0; |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 495 | |
| 496 | if (Tok.getKind() == tok::colon) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 497 | |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 498 | while (1) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 499 | KeyInfo[KeySlot].SelectorName = selIdent; |
| 500 | |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 501 | // Each iteration parses a single keyword argument. |
| 502 | if (Tok.getKind() != tok::colon) { |
| 503 | Diag(Tok, diag::err_expected_colon); |
| 504 | break; |
| 505 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 506 | KeyInfo[KeySlot].ColonLoc = ConsumeToken(); // Eat the ':'. |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 507 | if (Tok.getKind() == tok::l_paren) // Parse the argument type. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 508 | KeyInfo[KeySlot].TypeInfo = ParseObjCTypeName(); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 509 | |
| 510 | // If attributes exist before the argument name, parse them. |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 511 | if (getLang().ObjC2 && Tok.getKind() == tok::kw___attribute) |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 512 | KeyInfo[KeySlot].AttrList = ParseAttributes(); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 513 | |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 514 | if (Tok.getKind() != tok::identifier) { |
| 515 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 516 | break; |
| 517 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 518 | KeyInfo[KeySlot].ArgumentName = Tok.getIdentifierInfo(); |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 519 | ConsumeToken(); // Eat the identifier. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 520 | |
| 521 | // Rather than call out to the actions, try packaging up the info |
| 522 | // locally, like we do for Declarator. |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 523 | // FIXME: add Actions.BuildObjCKeyword() |
| 524 | |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 525 | selIdent = ParseObjCSelector(); |
| 526 | if (!selIdent && Tok.getKind() != tok::colon) |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 527 | break; |
| 528 | // We have a selector or a colon, continue parsing. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 529 | KeySlot++; |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 530 | } |
| 531 | // Parse the (optional) parameter list. |
| 532 | while (Tok.getKind() == tok::comma) { |
| 533 | ConsumeToken(); |
| 534 | if (Tok.getKind() == tok::ellipsis) { |
| 535 | ConsumeToken(); |
| 536 | break; |
| 537 | } |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 538 | // Parse the c-style argument declaration-specifier. |
| 539 | DeclSpec DS; |
| 540 | ParseDeclarationSpecifiers(DS); |
| 541 | // Parse the declarator. |
| 542 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 543 | ParseDeclarator(ParmDecl); |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 544 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 545 | // FIXME: Add support for optional parmameter list... |
| 546 | return Actions.ObjcBuildMethodDeclaration(mLoc, mType, ReturnType, |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 547 | &KeyInfo[0], KeyInfo.size()); |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 548 | } else if (!selIdent) { |
| 549 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 550 | } |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 551 | return Actions.ObjcBuildMethodDeclaration(mLoc, mType, ReturnType, selIdent); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 554 | /// objc-protocol-refs: |
| 555 | /// '<' identifier-list '>' |
| 556 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 557 | bool Parser::ParseObjCProtocolReferences( |
| 558 | llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 559 | assert(Tok.getKind() == tok::less && "expected <"); |
| 560 | |
| 561 | ConsumeToken(); // the "<" |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 562 | |
| 563 | while (1) { |
| 564 | if (Tok.getKind() != tok::identifier) { |
| 565 | Diag(Tok, diag::err_expected_ident); |
| 566 | SkipUntil(tok::greater); |
| 567 | return true; |
| 568 | } |
| 569 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 570 | ConsumeToken(); |
| 571 | |
| 572 | if (Tok.getKind() != tok::comma) |
| 573 | break; |
| 574 | ConsumeToken(); |
| 575 | } |
| 576 | // Consume the '>'. |
| 577 | return ExpectAndConsume(tok::greater, diag::err_expected_greater); |
| 578 | } |
| 579 | |
| 580 | /// objc-class-instance-variables: |
| 581 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 582 | /// |
| 583 | /// objc-instance-variable-decl-list: |
| 584 | /// objc-visibility-spec |
| 585 | /// objc-instance-variable-decl ';' |
| 586 | /// ';' |
| 587 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 588 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 589 | /// objc-instance-variable-decl-list ';' |
| 590 | /// |
| 591 | /// objc-visibility-spec: |
| 592 | /// @private |
| 593 | /// @protected |
| 594 | /// @public |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 595 | /// @package [OBJC2] |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 596 | /// |
| 597 | /// objc-instance-variable-decl: |
| 598 | /// struct-declaration |
| 599 | /// |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 600 | void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 601 | assert(Tok.getKind() == tok::l_brace && "expected {"); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 602 | llvm::SmallVector<DeclTy*, 16> IvarDecls; |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 603 | |
| 604 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 605 | |
| 606 | // While we still have something to read, read the instance variables. |
| 607 | while (Tok.getKind() != tok::r_brace && |
| 608 | Tok.getKind() != tok::eof) { |
| 609 | // Each iteration of this loop reads one objc-instance-variable-decl. |
| 610 | |
| 611 | // Check for extraneous top-level semicolon. |
| 612 | if (Tok.getKind() == tok::semi) { |
| 613 | Diag(Tok, diag::ext_extra_struct_semi); |
| 614 | ConsumeToken(); |
| 615 | continue; |
| 616 | } |
| 617 | // Set the default visibility to private. |
| 618 | tok::ObjCKeywordKind visibility = tok::objc_private; |
| 619 | if (Tok.getKind() == tok::at) { // parse objc-visibility-spec |
| 620 | ConsumeToken(); // eat the @ sign |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 621 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 622 | case tok::objc_private: |
| 623 | case tok::objc_public: |
| 624 | case tok::objc_protected: |
| 625 | case tok::objc_package: |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 626 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 627 | ConsumeToken(); |
| 628 | continue; |
| 629 | default: |
| 630 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
| 631 | ConsumeToken(); |
| 632 | continue; |
| 633 | } |
| 634 | } |
| 635 | ParseStructDeclaration(interfaceDecl, IvarDecls); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 636 | for (unsigned i = 0; i < IvarDecls.size(); i++) |
| 637 | Actions.ObjcAddInstanceVariable(interfaceDecl, IvarDecls[i], visibility); |
| 638 | IvarDecls.clear(); |
| 639 | |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 640 | if (Tok.getKind() == tok::semi) { |
| 641 | ConsumeToken(); |
| 642 | } else if (Tok.getKind() == tok::r_brace) { |
| 643 | Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list); |
| 644 | break; |
| 645 | } else { |
| 646 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 647 | // Skip to end of block or statement |
| 648 | SkipUntil(tok::r_brace, true, true); |
| 649 | } |
| 650 | } |
| 651 | MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
| 652 | return; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 653 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 654 | |
| 655 | /// objc-protocol-declaration: |
| 656 | /// objc-protocol-definition |
| 657 | /// objc-protocol-forward-reference |
| 658 | /// |
| 659 | /// objc-protocol-definition: |
| 660 | /// @protocol identifier |
| 661 | /// objc-protocol-refs[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 662 | /// objc-interface-decl-list |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 663 | /// @end |
| 664 | /// |
| 665 | /// objc-protocol-forward-reference: |
| 666 | /// @protocol identifier-list ';' |
| 667 | /// |
| 668 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 669 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 670 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
| 671 | |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 672 | Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 673 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 674 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 675 | ConsumeToken(); // the "protocol" identifier |
| 676 | |
| 677 | if (Tok.getKind() != tok::identifier) { |
| 678 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
| 679 | return 0; |
| 680 | } |
| 681 | // Save the protocol name, then consume it. |
| 682 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 683 | SourceLocation nameLoc = ConsumeToken(); |
| 684 | |
| 685 | if (Tok.getKind() == tok::semi) { // forward declaration. |
| 686 | ConsumeToken(); |
| 687 | return 0; // FIXME: add protocolName |
| 688 | } |
| 689 | if (Tok.getKind() == tok::comma) { // list of forward declarations. |
| 690 | // Parse the list of forward declarations. |
| 691 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
| 692 | ProtocolRefs.push_back(protocolName); |
| 693 | |
| 694 | while (1) { |
| 695 | ConsumeToken(); // the ',' |
| 696 | if (Tok.getKind() != tok::identifier) { |
| 697 | Diag(Tok, diag::err_expected_ident); |
| 698 | SkipUntil(tok::semi); |
| 699 | return 0; |
| 700 | } |
| 701 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 702 | ConsumeToken(); // the identifier |
| 703 | |
| 704 | if (Tok.getKind() != tok::comma) |
| 705 | break; |
| 706 | } |
| 707 | // Consume the ';'. |
| 708 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
| 709 | return 0; |
| 710 | return 0; // FIXME |
| 711 | } |
| 712 | // Last, and definitely not least, parse a protocol declaration. |
| 713 | if (Tok.getKind() == tok::less) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 714 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
| 715 | if (ParseObjCProtocolReferences(ProtocolRefs)) |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 716 | return 0; |
| 717 | } |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 718 | ParseObjCInterfaceDeclList(0/*FIXME*/); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 719 | |
| 720 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 721 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 722 | ConsumeToken(); // the "end" identifier |
| 723 | return 0; |
| 724 | } |
| 725 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 726 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 727 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 728 | |
| 729 | /// objc-implementation: |
| 730 | /// objc-class-implementation-prologue |
| 731 | /// objc-category-implementation-prologue |
| 732 | /// |
| 733 | /// objc-class-implementation-prologue: |
| 734 | /// @implementation identifier objc-superclass[opt] |
| 735 | /// objc-class-instance-variables[opt] |
| 736 | /// |
| 737 | /// objc-category-implementation-prologue: |
| 738 | /// @implementation identifier ( identifier ) |
| 739 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 740 | Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( |
| 741 | SourceLocation atLoc) { |
| 742 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 743 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 744 | ConsumeToken(); // the "implementation" identifier |
| 745 | |
| 746 | if (Tok.getKind() != tok::identifier) { |
| 747 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 748 | return 0; |
| 749 | } |
| 750 | // We have a class or category name - consume it. |
| 751 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
| 752 | |
| 753 | if (Tok.getKind() == tok::l_paren) { |
| 754 | // we have a category implementation. |
| 755 | SourceLocation lparenLoc = ConsumeParen(); |
| 756 | SourceLocation categoryLoc, rparenLoc; |
| 757 | IdentifierInfo *categoryId = 0; |
| 758 | |
| 759 | if (Tok.getKind() == tok::identifier) { |
| 760 | categoryId = Tok.getIdentifierInfo(); |
| 761 | categoryLoc = ConsumeToken(); |
| 762 | } else { |
| 763 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 764 | return 0; |
| 765 | } |
| 766 | if (Tok.getKind() != tok::r_paren) { |
| 767 | Diag(Tok, diag::err_expected_rparen); |
| 768 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 769 | return 0; |
| 770 | } |
| 771 | rparenLoc = ConsumeParen(); |
| 772 | return 0; |
| 773 | } |
| 774 | // We have a class implementation |
| 775 | if (Tok.getKind() == tok::colon) { |
| 776 | // We have a super class |
| 777 | ConsumeToken(); |
| 778 | if (Tok.getKind() != tok::identifier) { |
| 779 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 780 | return 0; |
| 781 | } |
| 782 | ConsumeToken(); // Consume super class name |
| 783 | } |
| 784 | if (Tok.getKind() == tok::l_brace) |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 785 | ParseObjCClassInstanceVariables(0/*FIXME*/); // we have ivars |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 786 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 787 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 788 | } |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 789 | Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { |
| 790 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 791 | "ParseObjCAtEndDeclaration(): Expected @end"); |
| 792 | ConsumeToken(); // the "end" identifier |
| 793 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 794 | return 0; |
| 795 | } |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 796 | |
| 797 | /// compatibility-alias-decl: |
| 798 | /// @compatibility_alias alias-name class-name ';' |
| 799 | /// |
| 800 | Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
| 801 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 802 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 803 | ConsumeToken(); // consume compatibility_alias |
| 804 | if (Tok.getKind() != tok::identifier) { |
| 805 | Diag(Tok, diag::err_expected_ident); |
| 806 | return 0; |
| 807 | } |
| 808 | ConsumeToken(); // consume alias-name |
| 809 | if (Tok.getKind() != tok::identifier) { |
| 810 | Diag(Tok, diag::err_expected_ident); |
| 811 | return 0; |
| 812 | } |
| 813 | ConsumeToken(); // consume class-name; |
| 814 | if (Tok.getKind() != tok::semi) |
Fariborz Jahanian | 6c30fa6 | 2007-09-04 21:42:12 +0000 | [diff] [blame] | 815 | Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias"); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 816 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 819 | /// property-synthesis: |
| 820 | /// @synthesize property-ivar-list ';' |
| 821 | /// |
| 822 | /// property-ivar-list: |
| 823 | /// property-ivar |
| 824 | /// property-ivar-list ',' property-ivar |
| 825 | /// |
| 826 | /// property-ivar: |
| 827 | /// identifier |
| 828 | /// identifier '=' identifier |
| 829 | /// |
| 830 | Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
| 831 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 832 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
| 833 | SourceLocation loc = ConsumeToken(); // consume dynamic |
| 834 | if (Tok.getKind() != tok::identifier) { |
| 835 | Diag(Tok, diag::err_expected_ident); |
| 836 | return 0; |
| 837 | } |
| 838 | while (Tok.getKind() == tok::identifier) { |
| 839 | ConsumeToken(); // consume property name |
| 840 | if (Tok.getKind() == tok::equal) { |
| 841 | // property '=' ivar-name |
| 842 | ConsumeToken(); // consume '=' |
| 843 | if (Tok.getKind() != tok::identifier) { |
| 844 | Diag(Tok, diag::err_expected_ident); |
| 845 | break; |
| 846 | } |
| 847 | ConsumeToken(); // consume ivar-name |
| 848 | } |
| 849 | if (Tok.getKind() != tok::comma) |
| 850 | break; |
| 851 | ConsumeToken(); // consume ',' |
| 852 | } |
| 853 | if (Tok.getKind() != tok::semi) |
| 854 | Diag(Tok, diag::err_expected_semi_after, "@synthesize"); |
| 855 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 858 | /// property-dynamic: |
| 859 | /// @dynamic property-list |
| 860 | /// |
| 861 | /// property-list: |
| 862 | /// identifier |
| 863 | /// property-list ',' identifier |
| 864 | /// |
| 865 | Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
| 866 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 867 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 868 | SourceLocation loc = ConsumeToken(); // consume dynamic |
| 869 | if (Tok.getKind() != tok::identifier) { |
| 870 | Diag(Tok, diag::err_expected_ident); |
| 871 | return 0; |
| 872 | } |
| 873 | while (Tok.getKind() == tok::identifier) { |
| 874 | ConsumeToken(); // consume property name |
| 875 | if (Tok.getKind() != tok::comma) |
| 876 | break; |
| 877 | ConsumeToken(); // consume ',' |
| 878 | } |
| 879 | if (Tok.getKind() != tok::semi) |
| 880 | Diag(Tok, diag::err_expected_semi_after, "@dynamic"); |
| 881 | return 0; |
| 882 | } |
| 883 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 884 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 885 | /// |
| 886 | void Parser::ParseObjCInstanceMethodDefinition() { |
| 887 | assert(Tok.getKind() == tok::minus && |
| 888 | "ParseObjCInstanceMethodDefinition(): Expected '-'"); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 889 | ParseObjCMethodPrototype(ObjcImpDecl); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 890 | // parse optional ';' |
| 891 | if (Tok.getKind() == tok::semi) |
| 892 | ConsumeToken(); |
| 893 | |
| 894 | if (Tok.getKind() != tok::l_brace) { |
| 895 | Diag (Tok, diag::err_expected_lbrace); |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | StmtResult FnBody = ParseCompoundStatementBody(); |
| 900 | } |
| 901 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 902 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 903 | /// |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 904 | void Parser::ParseObjCClassMethodDefinition() { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 905 | assert(Tok.getKind() == tok::plus && |
| 906 | "ParseObjCClassMethodDefinition(): Expected '+'"); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame^] | 907 | ParseObjCMethodPrototype(ObjcImpDecl); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 908 | // parse optional ';' |
| 909 | if (Tok.getKind() == tok::semi) |
| 910 | ConsumeToken(); |
| 911 | if (Tok.getKind() != tok::l_brace) { |
| 912 | Diag (Tok, diag::err_expected_lbrace); |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | StmtResult FnBody = ParseCompoundStatementBody(); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 917 | } |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 918 | |
| 919 | Parser::ExprResult Parser::ParseObjCExpression() { |
| 920 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
| 921 | |
| 922 | switch (Tok.getKind()) { |
| 923 | case tok::string_literal: // primary-expression: string-literal |
| 924 | case tok::wide_string_literal: |
| 925 | return ParseObjCStringLiteral(); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 926 | default: |
| 927 | break; |
| 928 | } |
| 929 | |
| 930 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 931 | case tok::objc_encode: |
| 932 | return ParseObjCEncodeExpression(); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 933 | case tok::objc_protocol: |
| 934 | return ParseObjCProtocolExpression(); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 935 | default: |
| 936 | Diag(AtLoc, diag::err_unexpected_at); |
| 937 | SkipUntil(tok::semi); |
| 938 | break; |
| 939 | } |
| 940 | |
| 941 | return 0; |
| 942 | } |
| 943 | |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 944 | /// objc-message-expr: |
| 945 | /// '[' objc-receiver objc-message-args ']' |
| 946 | /// |
| 947 | /// objc-receiver: |
| 948 | /// expression |
| 949 | /// class-name |
| 950 | /// type-name |
| 951 | /// |
| 952 | /// objc-message-args: |
| 953 | /// objc-selector |
| 954 | /// objc-keywordarg-list |
| 955 | /// |
| 956 | /// objc-keywordarg-list: |
| 957 | /// objc-keywordarg |
| 958 | /// objc-keywordarg-list objc-keywordarg |
| 959 | /// |
| 960 | /// objc-keywordarg: |
| 961 | /// selector-name[opt] ':' objc-keywordexpr |
| 962 | /// |
| 963 | /// objc-keywordexpr: |
| 964 | /// nonempty-expr-list |
| 965 | /// |
| 966 | /// nonempty-expr-list: |
| 967 | /// assignment-expression |
| 968 | /// nonempty-expr-list , assignment-expression |
| 969 | /// |
| 970 | Parser::ExprResult Parser::ParseObjCMessageExpression() { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 971 | assert(Tok.getKind() == tok::l_square && "'[' expected"); |
| 972 | SourceLocation Loc = ConsumeBracket(); // consume '[' |
| 973 | // Parse receiver |
| 974 | // FIXME: receiver as type-name/class-name |
| 975 | ParseAssignmentExpression(); |
| 976 | // Parse objc-selector |
| 977 | IdentifierInfo *selIdent = ParseObjCSelector(); |
| 978 | if (Tok.getKind() == tok::colon) { |
| 979 | while (1) { |
| 980 | // Each iteration parses a single keyword argument. |
| 981 | if (Tok.getKind() != tok::colon) { |
| 982 | Diag(Tok, diag::err_expected_colon); |
| 983 | SkipUntil(tok::semi); |
| 984 | return 0; |
| 985 | } |
| 986 | ConsumeToken(); // Eat the ':'. |
| 987 | /// Parse the expression after ':' |
| 988 | ParseAssignmentExpression(); |
| 989 | IdentifierInfo *keywordSelector = ParseObjCSelector(); |
| 990 | |
| 991 | if (!keywordSelector && Tok.getKind() != tok::colon) |
| 992 | break; |
| 993 | // We have a selector or a colon, continue parsing. |
| 994 | } |
| 995 | // Parse the, optional, argument list, comma separated. |
| 996 | while (Tok.getKind() == tok::comma) { |
| 997 | ConsumeToken(); |
| 998 | /// Parse the expression after ',' |
| 999 | ParseAssignmentExpression(); |
| 1000 | } |
| 1001 | } else if (!selIdent) { |
| 1002 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 1003 | SkipUntil(tok::semi); |
| 1004 | return 0; |
| 1005 | } |
| 1006 | if (Tok.getKind() != tok::r_square) { |
| 1007 | Diag(Tok, diag::err_expected_rsquare); |
| 1008 | SkipUntil(tok::semi); |
| 1009 | return 0; |
| 1010 | } |
| 1011 | ConsumeBracket(); // consume ']' |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
| 1014 | |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1015 | Parser::ExprResult Parser::ParseObjCStringLiteral() { |
| 1016 | ExprResult Res = ParseStringLiteralExpression(); |
| 1017 | |
| 1018 | if (Res.isInvalid) return Res; |
| 1019 | |
| 1020 | return Actions.ParseObjCStringLiteral(Res.Val); |
| 1021 | } |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1022 | |
| 1023 | /// objc-encode-expression: |
| 1024 | /// @encode ( type-name ) |
| 1025 | Parser::ExprResult Parser::ParseObjCEncodeExpression() { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1026 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1027 | |
| 1028 | SourceLocation EncLoc = ConsumeToken(); |
| 1029 | |
| 1030 | if (Tok.getKind() != tok::l_paren) { |
| 1031 | Diag(Tok, diag::err_expected_lparen_after, "@encode"); |
| 1032 | return true; |
| 1033 | } |
| 1034 | |
| 1035 | SourceLocation LParenLoc = ConsumeParen(); |
| 1036 | |
| 1037 | TypeTy *Ty = ParseTypeName(); |
| 1038 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1039 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1040 | |
| 1041 | return Actions.ParseObjCEncodeExpression(EncLoc, LParenLoc, Ty, |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1042 | RParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1043 | } |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1044 | |
| 1045 | /// objc-protocol-expression |
| 1046 | /// @protocol ( protocol-name ) |
| 1047 | |
| 1048 | Parser::ExprResult Parser::ParseObjCProtocolExpression() |
| 1049 | { |
| 1050 | SourceLocation ProtoLoc = ConsumeToken(); |
| 1051 | |
| 1052 | if (Tok.getKind() != tok::l_paren) { |
| 1053 | Diag(Tok, diag::err_expected_lparen_after, "@protocol"); |
| 1054 | return true; |
| 1055 | } |
| 1056 | |
| 1057 | SourceLocation LParenLoc = ConsumeParen(); |
| 1058 | |
| 1059 | if (Tok.getKind() != tok::identifier) { |
| 1060 | Diag(Tok, diag::err_expected_ident); |
| 1061 | return true; |
| 1062 | } |
| 1063 | |
| 1064 | // FIXME: Do something with the protocol name |
| 1065 | ConsumeToken(); |
| 1066 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1067 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1068 | |
| 1069 | // FIXME |
| 1070 | return 0; |
| 1071 | } |