Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1 | //===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C portions of the Parser interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 15 | #include "clang/Parse/DeclSpec.h" |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Scope.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 17 | #include "clang/Basic/Diagnostic.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | using namespace clang; |
| 20 | |
| 21 | |
| 22 | /// ParseExternalDeclaration: |
| 23 | /// external-declaration: [C99 6.9] |
| 24 | /// [OBJC] objc-class-definition |
Steve Naroff | 5b96e2e | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 25 | /// [OBJC] objc-class-declaration |
| 26 | /// [OBJC] objc-alias-declaration |
| 27 | /// [OBJC] objc-protocol-definition |
| 28 | /// [OBJC] objc-method-definition |
| 29 | /// [OBJC] '@' 'end' |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 30 | Parser::DeclTy *Parser::ParseObjCAtDirectives() { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 31 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
| 32 | |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 33 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 34 | case tok::objc_class: |
| 35 | return ParseObjCAtClassDeclaration(AtLoc); |
| 36 | case tok::objc_interface: |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 37 | return ParseObjCAtInterfaceDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 38 | case tok::objc_protocol: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 39 | return ParseObjCAtProtocolDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 40 | case tok::objc_implementation: |
Fariborz Jahanian | 83ddf82 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 41 | return ParseObjCAtImplementationDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 42 | case tok::objc_end: |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 43 | return ParseObjCAtEndDeclaration(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | case tok::objc_compatibility_alias: |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 45 | return ParseObjCAtAliasDeclaration(AtLoc); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 46 | case tok::objc_synthesize: |
| 47 | return ParseObjCPropertySynthesize(AtLoc); |
| 48 | case tok::objc_dynamic: |
| 49 | return ParseObjCPropertyDynamic(AtLoc); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 50 | default: |
| 51 | Diag(AtLoc, diag::err_unexpected_at); |
| 52 | SkipUntil(tok::semi); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 53 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | /// |
| 58 | /// objc-class-declaration: |
| 59 | /// '@' 'class' identifier-list ';' |
| 60 | /// |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 61 | Parser::DeclTy *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 62 | ConsumeToken(); // the identifier "class" |
| 63 | llvm::SmallVector<IdentifierInfo *, 8> ClassNames; |
| 64 | |
| 65 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 66 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 67 | Diag(Tok, diag::err_expected_ident); |
| 68 | SkipUntil(tok::semi); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 69 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 70 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 71 | ClassNames.push_back(Tok.getIdentifierInfo()); |
| 72 | ConsumeToken(); |
| 73 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 74 | if (Tok.isNot(tok::comma)) |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 75 | break; |
| 76 | |
| 77 | ConsumeToken(); |
| 78 | } |
| 79 | |
| 80 | // Consume the ';'. |
| 81 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 82 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 83 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 84 | return Actions.ActOnForwardClassDeclaration(atLoc, |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 85 | &ClassNames[0], ClassNames.size()); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 88 | /// |
| 89 | /// objc-interface: |
| 90 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 91 | /// objc-category-interface |
| 92 | /// |
| 93 | /// objc-class-interface: |
| 94 | /// '@' 'interface' identifier objc-superclass[opt] |
| 95 | /// objc-protocol-refs[opt] |
| 96 | /// objc-class-instance-variables[opt] |
| 97 | /// objc-interface-decl-list |
| 98 | /// @end |
| 99 | /// |
| 100 | /// objc-category-interface: |
| 101 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
| 102 | /// objc-protocol-refs[opt] |
| 103 | /// objc-interface-decl-list |
| 104 | /// @end |
| 105 | /// |
| 106 | /// objc-superclass: |
| 107 | /// ':' identifier |
| 108 | /// |
| 109 | /// objc-class-interface-attributes: |
| 110 | /// __attribute__((visibility("default"))) |
| 111 | /// __attribute__((visibility("hidden"))) |
| 112 | /// __attribute__((deprecated)) |
| 113 | /// __attribute__((unavailable)) |
| 114 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 115 | /// |
| 116 | Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration( |
| 117 | SourceLocation atLoc, AttributeList *attrList) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 118 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 119 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 120 | ConsumeToken(); // the "interface" identifier |
| 121 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 122 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 123 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 124 | return 0; |
| 125 | } |
| 126 | // We have a class or category name - consume it. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 127 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 128 | SourceLocation nameLoc = ConsumeToken(); |
| 129 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 130 | if (Tok.is(tok::l_paren)) { // we have a category. |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 131 | SourceLocation lparenLoc = ConsumeParen(); |
| 132 | SourceLocation categoryLoc, rparenLoc; |
| 133 | IdentifierInfo *categoryId = 0; |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 134 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 135 | |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 136 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 137 | if (Tok.is(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 138 | categoryId = Tok.getIdentifierInfo(); |
| 139 | categoryLoc = ConsumeToken(); |
Steve Naroff | a7f6278 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 140 | } else if (!getLang().ObjC2) { |
| 141 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 142 | return 0; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 143 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 144 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 145 | Diag(Tok, diag::err_expected_rparen); |
| 146 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 147 | return 0; |
| 148 | } |
| 149 | rparenLoc = ConsumeParen(); |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 150 | SourceLocation endProtoLoc; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 151 | // Next, we need to check for any protocol references. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 152 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 153 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | if (attrList) // categories don't support attributes. |
| 157 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
| 158 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 159 | DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc, |
Steve Naroff | 25aace8 | 2007-10-03 21:00:46 +0000 | [diff] [blame] | 160 | nameId, nameLoc, categoryId, categoryLoc, |
Steve Naroff | 667f168 | 2007-10-30 13:30:57 +0000 | [diff] [blame] | 161 | &ProtocolRefs[0], ProtocolRefs.size(), |
| 162 | endProtoLoc); |
Fariborz Jahanian | f25220e | 2007-09-18 20:26:58 +0000 | [diff] [blame] | 163 | |
| 164 | ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 165 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 166 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 167 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 168 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | ac20be2 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 169 | return CategoryType; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 170 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 171 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | // Parse a class interface. |
| 175 | IdentifierInfo *superClassId = 0; |
| 176 | SourceLocation superClassLoc; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 177 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 178 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 179 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 180 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 181 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 182 | return 0; |
| 183 | } |
| 184 | superClassId = Tok.getIdentifierInfo(); |
| 185 | superClassLoc = ConsumeToken(); |
| 186 | } |
| 187 | // Next, we need to check for any protocol references. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 188 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 189 | SourceLocation endProtoLoc; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 190 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 191 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 192 | return 0; |
| 193 | } |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 194 | DeclTy *ClsType = Actions.ActOnStartClassInterface( |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 195 | atLoc, nameId, nameLoc, |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 196 | superClassId, superClassLoc, &ProtocolRefs[0], |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 197 | ProtocolRefs.size(), endProtoLoc, attrList); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 198 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 199 | if (Tok.is(tok::l_brace)) |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 200 | ParseObjCClassInstanceVariables(ClsType, atLoc); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 201 | |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 202 | ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 203 | |
| 204 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 205 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 206 | ConsumeToken(); // the "end" identifier |
Steve Naroff | faed3bf | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 207 | return ClsType; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 208 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 209 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | /// objc-interface-decl-list: |
| 214 | /// empty |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 215 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 216 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 217 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 218 | /// objc-interface-decl-list declaration |
| 219 | /// objc-interface-decl-list ';' |
| 220 | /// |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 221 | /// objc-method-requirement: [OBJC2] |
| 222 | /// @required |
| 223 | /// @optional |
| 224 | /// |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 225 | void Parser::ParseObjCInterfaceDeclList(DeclTy *interfaceDecl, |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 226 | tok::ObjCKeywordKind contextKey) { |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame^] | 227 | llvm::SmallVector<DeclTy*, 32> allMethods; |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 228 | llvm::SmallVector<DeclTy*, 16> allProperties; |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 229 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 230 | SourceLocation AtEndLoc; |
| 231 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 232 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 233 | if (Tok.is(tok::at)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 234 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 235 | tok::ObjCKeywordKind ocKind = Tok.getObjCKeywordID(); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 236 | |
| 237 | if (ocKind == tok::objc_end) { // terminate list |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 238 | AtEndLoc = AtLoc; |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 239 | break; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 240 | } else if (ocKind == tok::objc_required) { // protocols only |
| 241 | ConsumeToken(); |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 242 | MethodImplKind = ocKind; |
| 243 | if (contextKey != tok::objc_protocol) |
| 244 | Diag(AtLoc, diag::err_objc_protocol_required); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 245 | } else if (ocKind == tok::objc_optional) { // protocols only |
| 246 | ConsumeToken(); |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 247 | MethodImplKind = ocKind; |
| 248 | if (contextKey != tok::objc_protocol) |
| 249 | Diag(AtLoc, diag::err_objc_protocol_optional); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 250 | } else if (ocKind == tok::objc_property) { |
Fariborz Jahanian | 0ceb4be | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 251 | ObjCDeclSpec OCDS; |
| 252 | ConsumeToken(); // the "property" identifier |
| 253 | // Parse property attribute list, if any. |
| 254 | if (Tok.is(tok::l_paren)) { |
| 255 | // property has attribute list. |
| 256 | ParseObjCPropertyAttribute(OCDS); |
| 257 | } |
| 258 | // Parse all the comma separated declarators. |
| 259 | DeclSpec DS; |
| 260 | llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; |
| 261 | ParseStructDeclaration(DS, FieldDeclarators); |
| 262 | |
| 263 | if (Tok.is(tok::semi)) |
| 264 | ConsumeToken(); |
| 265 | else { |
| 266 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 267 | SkipUntil(tok::r_brace, true, true); |
| 268 | } |
| 269 | // Convert them all to property declarations. |
| 270 | for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { |
| 271 | FieldDeclarator &FD = FieldDeclarators[i]; |
| 272 | // Install the property declarator into interfaceDecl. |
Fariborz Jahanian | b7080ae | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 273 | Selector GetterSel = |
Fariborz Jahanian | e4534e7 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 274 | PP.getSelectorTable().getNullarySelector(OCDS.getGetterName() |
| 275 | ? OCDS.getGetterName() |
| 276 | : FD.D.getIdentifier()); |
Fariborz Jahanian | b7080ae | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 277 | Selector SetterSel = |
Fariborz Jahanian | e4534e7 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 278 | PP.getSelectorTable().getNullarySelector(OCDS.getSetterName() |
| 279 | ? OCDS.getSetterName() |
| 280 | // FIXME. This is not right! |
| 281 | : FD.D.getIdentifier()); |
Fariborz Jahanian | 0ceb4be | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 282 | DeclTy *Property = Actions.ActOnProperty(CurScope, |
Steve Naroff | 638d6a4 | 2008-05-22 23:24:08 +0000 | [diff] [blame] | 283 | AtLoc, FD, OCDS, |
Fariborz Jahanian | b7080ae | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 284 | GetterSel, SetterSel, |
Fariborz Jahanian | 4aa72a7 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 285 | MethodImplKind); |
Fariborz Jahanian | 0ceb4be | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 286 | allProperties.push_back(Property); |
| 287 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 288 | continue; |
| 289 | } else { |
| 290 | Diag(Tok, diag::err_objc_illegal_interface_qual); |
| 291 | ConsumeToken(); |
| 292 | } |
| 293 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 294 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
| 295 | DeclTy *methodPrototype = |
| 296 | ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 297 | allMethods.push_back(methodPrototype); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 298 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 299 | // method definitions. |
Steve Naroff | aa1b6d4 | 2007-09-17 15:07:43 +0000 | [diff] [blame] | 300 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after,"method proto"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 301 | continue; |
| 302 | } |
Fariborz Jahanian | 5d175c3 | 2007-12-11 18:34:51 +0000 | [diff] [blame] | 303 | else if (Tok.is(tok::at)) |
| 304 | continue; |
| 305 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 306 | if (Tok.is(tok::semi)) |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 307 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 308 | else if (Tok.is(tok::eof)) |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 309 | break; |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 310 | else { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 311 | // FIXME: as the name implies, this rule allows function definitions. |
| 312 | // We could pass a flag or check for functions during semantic analysis. |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 313 | ParseDeclarationOrFunctionDefinition(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 314 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 315 | } |
Steve Naroff | 1ccf463 | 2007-10-30 03:43:13 +0000 | [diff] [blame] | 316 | /// Insert collected methods declarations into the @interface object. |
Ted Kremenek | 8c945b1 | 2008-06-06 16:45:15 +0000 | [diff] [blame^] | 317 | Actions.ActOnAtEnd(AtEndLoc, interfaceDecl, |
| 318 | allMethods.empty() ? 0 : &allMethods[0], |
| 319 | allMethods.size(), |
| 320 | allProperties.empty() ? 0 : &allProperties[0], |
| 321 | allProperties.size()); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 322 | } |
| 323 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 324 | /// Parse property attribute declarations. |
| 325 | /// |
| 326 | /// property-attr-decl: '(' property-attrlist ')' |
| 327 | /// property-attrlist: |
| 328 | /// property-attribute |
| 329 | /// property-attrlist ',' property-attribute |
| 330 | /// property-attribute: |
| 331 | /// getter '=' identifier |
| 332 | /// setter '=' identifier ':' |
| 333 | /// readonly |
| 334 | /// readwrite |
| 335 | /// assign |
| 336 | /// retain |
| 337 | /// copy |
| 338 | /// nonatomic |
| 339 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 340 | void Parser::ParseObjCPropertyAttribute (ObjCDeclSpec &DS) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 341 | SourceLocation loc = ConsumeParen(); // consume '(' |
| 342 | while (isObjCPropertyAttribute()) { |
| 343 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 344 | // getter/setter require extra treatment. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 345 | if (II == ObjCPropertyAttrs[objc_getter] || |
| 346 | II == ObjCPropertyAttrs[objc_setter]) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 347 | // skip getter/setter part. |
| 348 | SourceLocation loc = ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 349 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 350 | loc = ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 351 | if (Tok.is(tok::identifier)) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 352 | if (II == ObjCPropertyAttrs[objc_setter]) { |
| 353 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 354 | DS.setSetterName(Tok.getIdentifierInfo()); |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 355 | loc = ConsumeToken(); // consume method name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 356 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 357 | Diag(loc, diag::err_expected_colon); |
| 358 | SkipUntil(tok::r_paren,true,true); |
| 359 | break; |
| 360 | } |
| 361 | } |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 362 | else { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 363 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 364 | DS.setGetterName(Tok.getIdentifierInfo()); |
| 365 | } |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 366 | } |
| 367 | else { |
| 368 | Diag(loc, diag::err_expected_ident); |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 369 | SkipUntil(tok::r_paren,true,true); |
| 370 | break; |
| 371 | } |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 372 | } |
| 373 | else { |
| 374 | Diag(loc, diag::err_objc_expected_equal); |
| 375 | SkipUntil(tok::r_paren,true,true); |
| 376 | break; |
| 377 | } |
| 378 | } |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 379 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 380 | else if (II == ObjCPropertyAttrs[objc_readonly]) |
| 381 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
| 382 | else if (II == ObjCPropertyAttrs[objc_assign]) |
| 383 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
| 384 | else if (II == ObjCPropertyAttrs[objc_readwrite]) |
| 385 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
| 386 | else if (II == ObjCPropertyAttrs[objc_retain]) |
| 387 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
| 388 | else if (II == ObjCPropertyAttrs[objc_copy]) |
| 389 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
| 390 | else if (II == ObjCPropertyAttrs[objc_nonatomic]) |
| 391 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Fariborz Jahanian | d8df6d8 | 2007-11-06 22:01:00 +0000 | [diff] [blame] | 392 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 393 | ConsumeToken(); // consume last attribute token |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 394 | if (Tok.is(tok::comma)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 395 | loc = ConsumeToken(); |
| 396 | continue; |
| 397 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 398 | if (Tok.is(tok::r_paren)) |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 399 | break; |
| 400 | Diag(loc, diag::err_expected_rparen); |
| 401 | SkipUntil(tok::semi); |
| 402 | return; |
| 403 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 404 | if (Tok.is(tok::r_paren)) |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 405 | ConsumeParen(); |
| 406 | else { |
| 407 | Diag(loc, diag::err_objc_expected_property_attr); |
| 408 | SkipUntil(tok::r_paren); // recover from error inside attribute list |
| 409 | } |
| 410 | } |
| 411 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 412 | /// objc-method-proto: |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 413 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 414 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 415 | /// |
| 416 | /// objc-instance-method: '-' |
| 417 | /// objc-class-method: '+' |
| 418 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 419 | /// objc-method-attributes: [OBJC2] |
| 420 | /// __attribute__((deprecated)) |
| 421 | /// |
Fariborz Jahanian | 8b5ab6f | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 422 | Parser::DeclTy *Parser::ParseObjCMethodPrototype(DeclTy *IDecl, |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 423 | tok::ObjCKeywordKind MethodImplKind) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 424 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 425 | |
| 426 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 427 | SourceLocation mLoc = ConsumeToken(); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 428 | |
Fariborz Jahanian | 8473b22 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 429 | DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl, MethodImplKind); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 430 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | faed3bf | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 431 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 432 | return MDecl; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /// objc-selector: |
| 436 | /// identifier |
| 437 | /// one of |
| 438 | /// enum struct union if else while do for switch case default |
| 439 | /// break continue return goto asm sizeof typeof __alignof |
| 440 | /// unsigned long const short volatile signed restrict _Complex |
| 441 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 442 | /// |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 443 | IdentifierInfo *Parser::ParseObjCSelector(SourceLocation &SelectorLoc) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 444 | switch (Tok.getKind()) { |
| 445 | default: |
| 446 | return 0; |
| 447 | case tok::identifier: |
| 448 | case tok::kw_typeof: |
| 449 | case tok::kw___alignof: |
| 450 | case tok::kw_auto: |
| 451 | case tok::kw_break: |
| 452 | case tok::kw_case: |
| 453 | case tok::kw_char: |
| 454 | case tok::kw_const: |
| 455 | case tok::kw_continue: |
| 456 | case tok::kw_default: |
| 457 | case tok::kw_do: |
| 458 | case tok::kw_double: |
| 459 | case tok::kw_else: |
| 460 | case tok::kw_enum: |
| 461 | case tok::kw_extern: |
| 462 | case tok::kw_float: |
| 463 | case tok::kw_for: |
| 464 | case tok::kw_goto: |
| 465 | case tok::kw_if: |
| 466 | case tok::kw_inline: |
| 467 | case tok::kw_int: |
| 468 | case tok::kw_long: |
| 469 | case tok::kw_register: |
| 470 | case tok::kw_restrict: |
| 471 | case tok::kw_return: |
| 472 | case tok::kw_short: |
| 473 | case tok::kw_signed: |
| 474 | case tok::kw_sizeof: |
| 475 | case tok::kw_static: |
| 476 | case tok::kw_struct: |
| 477 | case tok::kw_switch: |
| 478 | case tok::kw_typedef: |
| 479 | case tok::kw_union: |
| 480 | case tok::kw_unsigned: |
| 481 | case tok::kw_void: |
| 482 | case tok::kw_volatile: |
| 483 | case tok::kw_while: |
Chris Lattner | 2baef2e | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 484 | case tok::kw_bool: |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 485 | case tok::kw__Bool: |
| 486 | case tok::kw__Complex: |
| 487 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 488 | SelectorLoc = ConsumeToken(); |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 489 | return II; |
Fariborz Jahanian | 171ceb5 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 490 | } |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 493 | /// property-attrlist: one of |
| 494 | /// readonly getter setter assign retain copy nonatomic |
| 495 | /// |
| 496 | bool Parser::isObjCPropertyAttribute() { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 497 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 498 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 499 | for (unsigned i = 0; i < objc_NumAttrs; ++i) |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 500 | if (II == ObjCPropertyAttrs[i]) return true; |
Fariborz Jahanian | 6668b8c | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 501 | } |
| 502 | return false; |
| 503 | } |
| 504 | |
Fariborz Jahanian | 9e920f3 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 505 | /// objc-for-collection-in: 'in' |
| 506 | /// |
Fariborz Jahanian | cadb070 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 507 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 1300bc7 | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 508 | // FIXME: May have to do additional look-ahead to only allow for |
| 509 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 510 | // '[' etc. |
Fariborz Jahanian | cadb070 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 511 | return (getLang().ObjC2 && Tok.is(tok::identifier) && |
| 512 | Tok.getIdentifierInfo() == ObjCForCollectionInKW); |
Fariborz Jahanian | 9e920f3 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 515 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 516 | /// qualifier list and builds their bitmask representation in the input |
| 517 | /// argument. |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 518 | /// |
| 519 | /// objc-type-qualifiers: |
| 520 | /// objc-type-qualifier |
| 521 | /// objc-type-qualifiers objc-type-qualifier |
| 522 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 523 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS) { |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 524 | while (1) { |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 525 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 526 | return; |
| 527 | |
| 528 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 529 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 530 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 531 | continue; |
| 532 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 533 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 534 | switch (i) { |
| 535 | default: assert(0 && "Unknown decl qualifier"); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 536 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 537 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 538 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 539 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 540 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 541 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 542 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 543 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | 2b740db | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 544 | ConsumeToken(); |
| 545 | II = 0; |
| 546 | break; |
| 547 | } |
| 548 | |
| 549 | // If this wasn't a recognized qualifier, bail out. |
| 550 | if (II) return; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | /// objc-type-name: |
| 555 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 556 | /// '(' objc-type-qualifiers[opt] ')' |
| 557 | /// |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 558 | Parser::TypeTy *Parser::ParseObjCTypeName(ObjCDeclSpec &DS) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 559 | assert(Tok.is(tok::l_paren) && "expected ("); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 560 | |
| 561 | SourceLocation LParenLoc = ConsumeParen(), RParenLoc; |
Chris Lattner | 265c817 | 2007-09-27 15:15:46 +0000 | [diff] [blame] | 562 | TypeTy *Ty = 0; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 563 | |
Fariborz Jahanian | 6dab49b | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 564 | // Parse type qualifiers, in, inout, etc. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 565 | ParseObjCTypeQualifierList(DS); |
Steve Naroff | a8ee226 | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 566 | |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 567 | if (isTypeSpecifierQualifier()) { |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 568 | Ty = ParseTypeName(); |
| 569 | // FIXME: back when Sema support is in place... |
| 570 | // assert(Ty && "Parser::ParseObjCTypeName(): missing type"); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 571 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 572 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 573 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 574 | return 0; // FIXME: decide how we want to handle this error... |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 575 | } |
| 576 | RParenLoc = ConsumeParen(); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 577 | return Ty; |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /// objc-method-decl: |
| 581 | /// objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 582 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 583 | /// objc-type-name objc-selector |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 584 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 585 | /// |
| 586 | /// objc-keyword-selector: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 587 | /// objc-keyword-decl |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 588 | /// objc-keyword-selector objc-keyword-decl |
| 589 | /// |
| 590 | /// objc-keyword-decl: |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 591 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 592 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 593 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 594 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 595 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 596 | /// objc-parmlist: |
| 597 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 598 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 599 | /// objc-parms: |
| 600 | /// objc-parms , parameter-declaration |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 601 | /// |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 602 | /// objc-ellipsis: |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 603 | /// , ... |
| 604 | /// |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 605 | /// objc-keyword-attributes: [OBJC2] |
| 606 | /// __attribute__((unused)) |
| 607 | /// |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 608 | Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Fariborz Jahanian | 8473b22 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 609 | tok::TokenKind mType, |
| 610 | DeclTy *IDecl, |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 611 | tok::ObjCKeywordKind MethodImplKind) |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 612 | { |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 613 | // Parse the return type. |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 614 | TypeTy *ReturnType = 0; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 615 | ObjCDeclSpec DSRet; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 616 | if (Tok.is(tok::l_paren)) |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 617 | ReturnType = ParseObjCTypeName(DSRet); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 618 | SourceLocation selLoc; |
| 619 | IdentifierInfo *SelIdent = ParseObjCSelector(selLoc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 620 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 621 | if (!SelIdent) { |
| 622 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 623 | // FIXME: this creates a unary selector with a null identifier, is this |
| 624 | // ok?? Maybe we should skip to the next semicolon or something. |
| 625 | } |
| 626 | |
| 627 | // If attributes exist after the method, parse them. |
| 628 | AttributeList *MethodAttrs = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 629 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 630 | MethodAttrs = ParseAttributes(); |
| 631 | |
| 632 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 633 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 8473b22 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 634 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 635 | 0, 0, 0, MethodAttrs, MethodImplKind); |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 636 | } |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 637 | |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 638 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 639 | llvm::SmallVector<Action::TypeTy *, 12> KeyTypes; |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 640 | llvm::SmallVector<ObjCDeclSpec, 12> ArgTypeQuals; |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 641 | llvm::SmallVector<IdentifierInfo *, 12> ArgNames; |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 642 | |
| 643 | Action::TypeTy *TypeInfo; |
| 644 | while (1) { |
| 645 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 646 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 647 | // Each iteration parses a single keyword argument. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 648 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 649 | Diag(Tok, diag::err_expected_colon); |
| 650 | break; |
| 651 | } |
| 652 | ConsumeToken(); // Eat the ':'. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 653 | ObjCDeclSpec DSType; |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 654 | if (Tok.is(tok::l_paren)) { // Parse the argument type. |
| 655 | TypeInfo = ParseObjCTypeName(DSType); |
| 656 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 657 | else |
| 658 | TypeInfo = 0; |
| 659 | KeyTypes.push_back(TypeInfo); |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 660 | ArgTypeQuals.push_back(DSType); |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 661 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 662 | // If attributes exist before the argument name, parse them. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 663 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 664 | ParseAttributes(); // FIXME: pass attributes through. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 665 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 666 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 667 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 668 | break; |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 669 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 670 | ArgNames.push_back(Tok.getIdentifierInfo()); |
| 671 | ConsumeToken(); // Eat the identifier. |
Steve Naroff | f9e80db | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 672 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 673 | // Check for another keyword selector. |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 674 | SourceLocation Loc; |
| 675 | SelIdent = ParseObjCSelector(Loc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 676 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 677 | break; |
| 678 | // We have a selector or a colon, continue parsing. |
Steve Naroff | 09a0c4c | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 679 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 680 | |
Steve Naroff | 29fe746 | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 681 | bool isVariadic = false; |
| 682 | |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 683 | // Parse the (optional) parameter list. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 684 | while (Tok.is(tok::comma)) { |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 685 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 686 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | 29fe746 | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 687 | isVariadic = true; |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 688 | ConsumeToken(); |
| 689 | break; |
| 690 | } |
Steve Naroff | 29fe746 | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 691 | // FIXME: implement this... |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 692 | // Parse the c-style argument declaration-specifier. |
| 693 | DeclSpec DS; |
| 694 | ParseDeclarationSpecifiers(DS); |
| 695 | // Parse the declarator. |
| 696 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 697 | ParseDeclarator(ParmDecl); |
| 698 | } |
| 699 | |
| 700 | // FIXME: Add support for optional parmameter list... |
Fariborz Jahanian | 3dc7cbc | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 701 | // If attributes exist after the method, parse them. |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 702 | AttributeList *MethodAttrs = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 703 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 704 | MethodAttrs = ParseAttributes(); |
| 705 | |
| 706 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 707 | &KeyIdents[0]); |
Steve Naroff | 3774dd9 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 708 | return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 8473b22 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 709 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 2fd0daa | 2007-10-31 23:53:01 +0000 | [diff] [blame] | 710 | &ArgTypeQuals[0], &KeyTypes[0], |
Steve Naroff | 29fe746 | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 711 | &ArgNames[0], MethodAttrs, |
| 712 | MethodImplKind, isVariadic); |
Steve Naroff | 0bbffd8 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 715 | /// objc-protocol-refs: |
| 716 | /// '<' identifier-list '>' |
| 717 | /// |
Steve Naroff | 304ed39 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 718 | bool Parser::ParseObjCProtocolReferences( |
Chris Lattner | e135230 | 2008-04-07 04:56:42 +0000 | [diff] [blame] | 719 | llvm::SmallVectorImpl<IdentifierInfo*> &ProtocolRefs, SourceLocation &endLoc){ |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 720 | assert(Tok.is(tok::less) && "expected <"); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 721 | |
| 722 | ConsumeToken(); // the "<" |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 723 | |
| 724 | while (1) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 725 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 726 | Diag(Tok, diag::err_expected_ident); |
| 727 | SkipUntil(tok::greater); |
| 728 | return true; |
| 729 | } |
| 730 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 731 | ConsumeToken(); |
| 732 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 733 | if (Tok.isNot(tok::comma)) |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 734 | break; |
| 735 | ConsumeToken(); |
| 736 | } |
Fariborz Jahanian | c04aff1 | 2007-10-08 23:06:41 +0000 | [diff] [blame] | 737 | |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 738 | // Consume the '>'. |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 739 | if (Tok.is(tok::greater)) { |
| 740 | endLoc = ConsumeAnyToken(); |
| 741 | return false; |
| 742 | } |
| 743 | Diag(Tok, diag::err_expected_greater); |
| 744 | return true; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | /// objc-class-instance-variables: |
| 748 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 749 | /// |
| 750 | /// objc-instance-variable-decl-list: |
| 751 | /// objc-visibility-spec |
| 752 | /// objc-instance-variable-decl ';' |
| 753 | /// ';' |
| 754 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 755 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 756 | /// objc-instance-variable-decl-list ';' |
| 757 | /// |
| 758 | /// objc-visibility-spec: |
| 759 | /// @private |
| 760 | /// @protected |
| 761 | /// @public |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 762 | /// @package [OBJC2] |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 763 | /// |
| 764 | /// objc-instance-variable-decl: |
| 765 | /// struct-declaration |
| 766 | /// |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 767 | void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, |
| 768 | SourceLocation atLoc) { |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 769 | assert(Tok.is(tok::l_brace) && "expected {"); |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 770 | llvm::SmallVector<DeclTy*, 32> AllIvarDecls; |
Chris Lattner | 3dd8d39 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 771 | llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators; |
| 772 | |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 773 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 774 | |
Fariborz Jahanian | 7c420a7 | 2008-04-29 23:03:51 +0000 | [diff] [blame] | 775 | tok::ObjCKeywordKind visibility = tok::objc_protected; |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 776 | // While we still have something to read, read the instance variables. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 777 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 778 | // Each iteration of this loop reads one objc-instance-variable-decl. |
| 779 | |
| 780 | // Check for extraneous top-level semicolon. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 781 | if (Tok.is(tok::semi)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 782 | Diag(Tok, diag::ext_extra_struct_semi); |
| 783 | ConsumeToken(); |
| 784 | continue; |
| 785 | } |
Chris Lattner | 3dd8d39 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 786 | |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 787 | // Set the default visibility to private. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 788 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 789 | ConsumeToken(); // eat the @ sign |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 790 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 791 | case tok::objc_private: |
| 792 | case tok::objc_public: |
| 793 | case tok::objc_protected: |
| 794 | case tok::objc_package: |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 795 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 796 | ConsumeToken(); |
| 797 | continue; |
| 798 | default: |
| 799 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 800 | continue; |
| 801 | } |
| 802 | } |
Chris Lattner | 3dd8d39 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 803 | |
| 804 | // Parse all the comma separated declarators. |
| 805 | DeclSpec DS; |
| 806 | FieldDeclarators.clear(); |
| 807 | ParseStructDeclaration(DS, FieldDeclarators); |
| 808 | |
| 809 | // Convert them all to fields. |
| 810 | for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) { |
| 811 | FieldDeclarator &FD = FieldDeclarators[i]; |
| 812 | // Install the declarator into interfaceDecl. |
Fariborz Jahanian | 751c617 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 813 | DeclTy *Field = Actions.ActOnIvar(CurScope, |
Chris Lattner | 3dd8d39 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 814 | DS.getSourceRange().getBegin(), |
Fariborz Jahanian | 751c617 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 815 | FD.D, FD.BitfieldSize, visibility); |
Chris Lattner | 3dd8d39 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 816 | AllIvarDecls.push_back(Field); |
Fariborz Jahanian | 3957dae | 2007-09-13 20:56:13 +0000 | [diff] [blame] | 817 | } |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 818 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 819 | if (Tok.is(tok::semi)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 820 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 821 | } else if (Tok.is(tok::r_brace)) { |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 822 | Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list); |
| 823 | break; |
| 824 | } else { |
| 825 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 826 | // Skip to end of block or statement |
| 827 | SkipUntil(tok::r_brace, true, true); |
| 828 | } |
| 829 | } |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 830 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Steve Naroff | 809b4f0 | 2007-10-31 22:11:35 +0000 | [diff] [blame] | 831 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 832 | // for code rewriting tools that need to be aware of the empty list. |
| 833 | Actions.ActOnFields(CurScope, atLoc, interfaceDecl, |
| 834 | &AllIvarDecls[0], AllIvarDecls.size(), |
Fariborz Jahanian | 751c617 | 2008-04-10 23:32:45 +0000 | [diff] [blame] | 835 | LBraceLoc, RBraceLoc); |
Steve Naroff | c447499 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 836 | return; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 837 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 838 | |
| 839 | /// objc-protocol-declaration: |
| 840 | /// objc-protocol-definition |
| 841 | /// objc-protocol-forward-reference |
| 842 | /// |
| 843 | /// objc-protocol-definition: |
| 844 | /// @protocol identifier |
| 845 | /// objc-protocol-refs[opt] |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 846 | /// objc-interface-decl-list |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 847 | /// @end |
| 848 | /// |
| 849 | /// objc-protocol-forward-reference: |
| 850 | /// @protocol identifier-list ';' |
| 851 | /// |
| 852 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 853 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 854 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 855 | Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 856 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 857 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 858 | ConsumeToken(); // the "protocol" identifier |
| 859 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 860 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 861 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
| 862 | return 0; |
| 863 | } |
| 864 | // Save the protocol name, then consume it. |
| 865 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 866 | SourceLocation nameLoc = ConsumeToken(); |
| 867 | |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 868 | llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 869 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 870 | ConsumeToken(); |
Fariborz Jahanian | c716c94 | 2007-09-21 15:40:54 +0000 | [diff] [blame] | 871 | ProtocolRefs.push_back(protocolName); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 872 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 873 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 874 | // Parse the list of forward declarations. |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 875 | ProtocolRefs.push_back(protocolName); |
| 876 | |
| 877 | while (1) { |
| 878 | ConsumeToken(); // the ',' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 879 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 880 | Diag(Tok, diag::err_expected_ident); |
| 881 | SkipUntil(tok::semi); |
| 882 | return 0; |
| 883 | } |
| 884 | ProtocolRefs.push_back(Tok.getIdentifierInfo()); |
| 885 | ConsumeToken(); // the identifier |
| 886 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 887 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 888 | break; |
| 889 | } |
| 890 | // Consume the ';'. |
| 891 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
| 892 | return 0; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 893 | } |
Chris Lattner | 7afba9c | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 894 | if (!ProtocolRefs.empty()) |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 895 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Steve Naroff | b4dfe36 | 2007-10-02 22:39:18 +0000 | [diff] [blame] | 896 | &ProtocolRefs[0], |
| 897 | ProtocolRefs.size()); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 898 | // Last, and definitely not least, parse a protocol declaration. |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 899 | SourceLocation endProtoLoc; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 900 | if (Tok.is(tok::less)) { |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 901 | if (ParseObjCProtocolReferences(ProtocolRefs, endProtoLoc)) |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 902 | return 0; |
| 903 | } |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 904 | |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 905 | DeclTy *ProtoType = Actions.ActOnStartProtocolInterface(AtLoc, |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 906 | protocolName, nameLoc, |
| 907 | &ProtocolRefs[0], |
Steve Naroff | ef20ed3 | 2007-10-30 02:23:23 +0000 | [diff] [blame] | 908 | ProtocolRefs.size(), endProtoLoc); |
Fariborz Jahanian | 63ca8ae | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 909 | ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 910 | |
| 911 | // The @ sign was already consumed by ParseObjCInterfaceDeclList(). |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 912 | if (Tok.isObjCAtKeyword(tok::objc_end)) { |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 913 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | ac20be2 | 2007-10-08 18:53:38 +0000 | [diff] [blame] | 914 | return ProtoType; |
Steve Naroff | 72f17fb | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 915 | } |
| 916 | Diag(Tok, diag::err_objc_missing_end); |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 917 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 918 | } |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 919 | |
| 920 | /// objc-implementation: |
| 921 | /// objc-class-implementation-prologue |
| 922 | /// objc-category-implementation-prologue |
| 923 | /// |
| 924 | /// objc-class-implementation-prologue: |
| 925 | /// @implementation identifier objc-superclass[opt] |
| 926 | /// objc-class-instance-variables[opt] |
| 927 | /// |
| 928 | /// objc-category-implementation-prologue: |
| 929 | /// @implementation identifier ( identifier ) |
| 930 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 931 | Parser::DeclTy *Parser::ParseObjCAtImplementationDeclaration( |
| 932 | SourceLocation atLoc) { |
| 933 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 934 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 935 | ConsumeToken(); // the "implementation" identifier |
| 936 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 937 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 938 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
| 939 | return 0; |
| 940 | } |
| 941 | // We have a class or category name - consume it. |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 942 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 943 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
| 944 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 945 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 946 | // we have a category implementation. |
| 947 | SourceLocation lparenLoc = ConsumeParen(); |
| 948 | SourceLocation categoryLoc, rparenLoc; |
| 949 | IdentifierInfo *categoryId = 0; |
| 950 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 951 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 952 | categoryId = Tok.getIdentifierInfo(); |
| 953 | categoryLoc = ConsumeToken(); |
| 954 | } else { |
| 955 | Diag(Tok, diag::err_expected_ident); // missing category name. |
| 956 | return 0; |
| 957 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 958 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 959 | Diag(Tok, diag::err_expected_rparen); |
| 960 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
| 961 | return 0; |
| 962 | } |
| 963 | rparenLoc = ConsumeParen(); |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 964 | DeclTy *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Fariborz Jahanian | a91aa32 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 965 | atLoc, nameId, nameLoc, categoryId, |
| 966 | categoryLoc); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 967 | ObjCImpDecl = ImplCatType; |
Fariborz Jahanian | 83ddf82 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 968 | return 0; |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 969 | } |
| 970 | // We have a class implementation |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 971 | SourceLocation superClassLoc; |
| 972 | IdentifierInfo *superClassId = 0; |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 973 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 974 | // We have a super class |
| 975 | ConsumeToken(); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 976 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 977 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
| 978 | return 0; |
| 979 | } |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 980 | superClassId = Tok.getIdentifierInfo(); |
| 981 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 982 | } |
Steve Naroff | 415c183 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 983 | DeclTy *ImplClsType = Actions.ActOnStartClassImplementation( |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 984 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | c091b5d | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 985 | superClassId, superClassLoc); |
| 986 | |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 987 | if (Tok.is(tok::l_brace)) // we have ivars |
| 988 | ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, atLoc); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 989 | ObjCImpDecl = ImplClsType; |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 990 | |
Fariborz Jahanian | 83ddf82 | 2007-11-10 20:59:13 +0000 | [diff] [blame] | 991 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 992 | } |
Steve Naroff | 1a7fa7b | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 993 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 994 | Parser::DeclTy *Parser::ParseObjCAtEndDeclaration(SourceLocation atLoc) { |
| 995 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 996 | "ParseObjCAtEndDeclaration(): Expected @end"); |
| 997 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | 1a8dcaf | 2008-01-10 17:58:07 +0000 | [diff] [blame] | 998 | if (ObjCImpDecl) |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 999 | Actions.ActOnAtEnd(atLoc, ObjCImpDecl); |
Fariborz Jahanian | 1a8dcaf | 2008-01-10 17:58:07 +0000 | [diff] [blame] | 1000 | else |
| 1001 | Diag(atLoc, diag::warn_expected_implementation); // missing @implementation |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1002 | return ObjCImpDecl; |
Steve Naroff | fb36788 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1003 | } |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1004 | |
| 1005 | /// compatibility-alias-decl: |
| 1006 | /// @compatibility_alias alias-name class-name ';' |
| 1007 | /// |
| 1008 | Parser::DeclTy *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
| 1009 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1010 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1011 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1012 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1013 | Diag(Tok, diag::err_expected_ident); |
| 1014 | return 0; |
| 1015 | } |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1016 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1017 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1018 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | b62aff3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1019 | Diag(Tok, diag::err_expected_ident); |
| 1020 | return 0; |
| 1021 | } |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1022 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1023 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
| 1024 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 6c30fa6 | 2007-09-04 21:42:12 +0000 | [diff] [blame] | 1025 | Diag(Tok, diag::err_expected_semi_after, "@compatibility_alias"); |
Fariborz Jahanian | 05d212a | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1026 | return 0; |
| 1027 | } |
| 1028 | DeclTy *ClsType = Actions.ActOnCompatiblityAlias(atLoc, |
| 1029 | aliasId, aliasLoc, |
| 1030 | classId, classLoc); |
| 1031 | return ClsType; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1034 | /// property-synthesis: |
| 1035 | /// @synthesize property-ivar-list ';' |
| 1036 | /// |
| 1037 | /// property-ivar-list: |
| 1038 | /// property-ivar |
| 1039 | /// property-ivar-list ',' property-ivar |
| 1040 | /// |
| 1041 | /// property-ivar: |
| 1042 | /// identifier |
| 1043 | /// identifier '=' identifier |
| 1044 | /// |
| 1045 | Parser::DeclTy *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
| 1046 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 1047 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
Fariborz Jahanian | 78f7e31 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1048 | SourceLocation loc = ConsumeToken(); // consume synthesize |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1049 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1050 | Diag(Tok, diag::err_expected_ident); |
| 1051 | return 0; |
| 1052 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1053 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 78f7e31 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1054 | IdentifierInfo *propertyIvar = 0; |
| 1055 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1056 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1057 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1058 | // property '=' ivar-name |
| 1059 | ConsumeToken(); // consume '=' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1060 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1061 | Diag(Tok, diag::err_expected_ident); |
| 1062 | break; |
| 1063 | } |
Fariborz Jahanian | 78f7e31 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1064 | propertyIvar = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1065 | ConsumeToken(); // consume ivar-name |
| 1066 | } |
Fariborz Jahanian | 78f7e31 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1067 | Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, true, ObjCImpDecl, |
| 1068 | propertyId, propertyIvar); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1069 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1070 | break; |
| 1071 | ConsumeToken(); // consume ',' |
| 1072 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1073 | if (Tok.isNot(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1074 | Diag(Tok, diag::err_expected_semi_after, "@synthesize"); |
| 1075 | return 0; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1078 | /// property-dynamic: |
| 1079 | /// @dynamic property-list |
| 1080 | /// |
| 1081 | /// property-list: |
| 1082 | /// identifier |
| 1083 | /// property-list ',' identifier |
| 1084 | /// |
| 1085 | Parser::DeclTy *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
| 1086 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1087 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 1088 | SourceLocation loc = ConsumeToken(); // consume dynamic |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1089 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1090 | Diag(Tok, diag::err_expected_ident); |
| 1091 | return 0; |
| 1092 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1093 | while (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 900e3dc | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1094 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1095 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
| 1096 | Actions.ActOnPropertyImplDecl(atLoc, propertyLoc, false, ObjCImpDecl, |
| 1097 | propertyId, 0); |
| 1098 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1099 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1100 | break; |
| 1101 | ConsumeToken(); // consume ',' |
| 1102 | } |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1103 | if (Tok.isNot(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1104 | Diag(Tok, diag::err_expected_semi_after, "@dynamic"); |
| 1105 | return 0; |
| 1106 | } |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1107 | |
| 1108 | /// objc-throw-statement: |
| 1109 | /// throw expression[opt]; |
| 1110 | /// |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1111 | Parser::StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 1112 | ExprResult Res; |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1113 | ConsumeToken(); // consume throw |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1114 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1115 | Res = ParseExpression(); |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1116 | if (Res.isInvalid) { |
| 1117 | SkipUntil(tok::semi); |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1118 | return true; |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1119 | } |
| 1120 | } |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1121 | ConsumeToken(); // consume ';' |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1122 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.Val); |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Fariborz Jahanian | 993360a | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1125 | /// objc-synchronized-statement: |
Fariborz Jahanian | 5f5d622 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1126 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | 993360a | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1127 | /// |
| 1128 | Parser::StmtResult Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1129 | ConsumeToken(); // consume synchronized |
| 1130 | if (Tok.isNot(tok::l_paren)) { |
| 1131 | Diag (Tok, diag::err_expected_lparen_after, "@synchronized"); |
| 1132 | return true; |
| 1133 | } |
| 1134 | ConsumeParen(); // '(' |
Fariborz Jahanian | 5f5d622 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1135 | ExprResult Res = ParseExpression(); |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1136 | if (Res.isInvalid) { |
| 1137 | SkipUntil(tok::semi); |
| 1138 | return true; |
| 1139 | } |
| 1140 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 5f5d622 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1141 | Diag (Tok, diag::err_expected_lbrace); |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1142 | return true; |
| 1143 | } |
| 1144 | ConsumeParen(); // ')' |
Fariborz Jahanian | 5f5d622 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1145 | if (Tok.isNot(tok::l_brace)) { |
| 1146 | Diag (Tok, diag::err_expected_lbrace); |
| 1147 | return true; |
| 1148 | } |
Steve Naroff | 70337ac | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1149 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1150 | // statements can always hold declarations. |
| 1151 | EnterScope(Scope::DeclScope); |
| 1152 | |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1153 | StmtResult SynchBody = ParseCompoundStatementBody(); |
Steve Naroff | 70337ac | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1154 | |
| 1155 | ExitScope(); |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1156 | if (SynchBody.isInvalid) |
| 1157 | SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 1158 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.Val, SynchBody.Val); |
Fariborz Jahanian | 993360a | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1161 | /// objc-try-catch-statement: |
| 1162 | /// @try compound-statement objc-catch-list[opt] |
| 1163 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1164 | /// |
| 1165 | /// objc-catch-list: |
| 1166 | /// @catch ( parameter-declaration ) compound-statement |
| 1167 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1168 | /// catch-parameter-declaration: |
| 1169 | /// parameter-declaration |
| 1170 | /// '...' [OBJC2] |
| 1171 | /// |
Chris Lattner | 8071239 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1172 | Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1173 | bool catch_or_finally_seen = false; |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1174 | |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1175 | ConsumeToken(); // consume try |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1176 | if (Tok.isNot(tok::l_brace)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1177 | Diag (Tok, diag::err_expected_lbrace); |
Fariborz Jahanian | 7095248 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 1178 | return true; |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1179 | } |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1180 | StmtResult CatchStmts; |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1181 | StmtResult FinallyStmt; |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1182 | StmtResult TryBody = ParseCompoundStatementBody(); |
Fariborz Jahanian | b8bf607 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1183 | if (TryBody.isInvalid) |
| 1184 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Chris Lattner | 8071239 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1185 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1186 | while (Tok.is(tok::at)) { |
Chris Lattner | 8071239 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1187 | // At this point, we need to lookahead to determine if this @ is the start |
| 1188 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1189 | // is an @try or @encode or something else. |
| 1190 | Token AfterAt = GetLookAheadToken(1); |
| 1191 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1192 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1193 | break; |
| 1194 | |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1195 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1196 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1197 | StmtTy *FirstPart = 0; |
| 1198 | ConsumeToken(); // consume catch |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1199 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1200 | ConsumeParen(); |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1201 | EnterScope(Scope::DeclScope); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1202 | if (Tok.isNot(tok::ellipsis)) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1203 | DeclSpec DS; |
| 1204 | ParseDeclarationSpecifiers(DS); |
Steve Naroff | fd8f76c | 2008-06-03 05:36:54 +0000 | [diff] [blame] | 1205 | // For some odd reason, the name of the exception variable is |
| 1206 | // optional. As a result, we need to use PrototypeContext. |
| 1207 | Declarator DeclaratorInfo(DS, Declarator::PrototypeContext); |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1208 | ParseDeclarator(DeclaratorInfo); |
Steve Naroff | fd8f76c | 2008-06-03 05:36:54 +0000 | [diff] [blame] | 1209 | if (DeclaratorInfo.getIdentifier()) { |
| 1210 | DeclTy *aBlockVarDecl = Actions.ActOnDeclarator(CurScope, |
Chris Lattner | a4ff427 | 2008-03-13 06:29:04 +0000 | [diff] [blame] | 1211 | DeclaratorInfo, 0); |
Steve Naroff | fd8f76c | 2008-06-03 05:36:54 +0000 | [diff] [blame] | 1212 | StmtResult stmtResult = |
| 1213 | Actions.ActOnDeclStmt(aBlockVarDecl, |
| 1214 | DS.getSourceRange().getBegin(), |
| 1215 | DeclaratorInfo.getSourceRange().getEnd()); |
| 1216 | FirstPart = stmtResult.isInvalid ? 0 : stmtResult.Val; |
| 1217 | } |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1218 | } else |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1219 | ConsumeToken(); // consume '...' |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1220 | SourceLocation RParenLoc = ConsumeParen(); |
Chris Lattner | 8027be6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1221 | |
| 1222 | StmtResult CatchBody(true); |
| 1223 | if (Tok.is(tok::l_brace)) |
| 1224 | CatchBody = ParseCompoundStatementBody(); |
| 1225 | else |
| 1226 | Diag(Tok, diag::err_expected_lbrace); |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1227 | if (CatchBody.isInvalid) |
| 1228 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1229 | CatchStmts = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, RParenLoc, |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1230 | FirstPart, CatchBody.Val, CatchStmts.Val); |
| 1231 | ExitScope(); |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1232 | } else { |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1233 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after, |
| 1234 | "@catch clause"); |
Fariborz Jahanian | 7095248 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 1235 | return true; |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1236 | } |
| 1237 | catch_or_finally_seen = true; |
Chris Lattner | 8071239 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1238 | } else { |
| 1239 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1240 | ConsumeToken(); // consume finally |
Chris Lattner | 8027be6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1241 | |
| 1242 | StmtResult FinallyBody(true); |
| 1243 | if (Tok.is(tok::l_brace)) |
| 1244 | FinallyBody = ParseCompoundStatementBody(); |
| 1245 | else |
| 1246 | Diag(Tok, diag::err_expected_lbrace); |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1247 | if (FinallyBody.isInvalid) |
| 1248 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1249 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
Fariborz Jahanian | de3abf8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1250 | FinallyBody.Val); |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1251 | catch_or_finally_seen = true; |
| 1252 | break; |
| 1253 | } |
| 1254 | } |
Fariborz Jahanian | b8bf607 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1255 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1256 | Diag(atLoc, diag::err_missing_catch_finally); |
Fariborz Jahanian | b8bf607 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1257 | return true; |
| 1258 | } |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1259 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.Val, CatchStmts.Val, |
Fariborz Jahanian | b8bf607 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1260 | FinallyStmt.Val); |
Fariborz Jahanian | 64b864e | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1261 | } |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1262 | |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1263 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1264 | /// |
Steve Naroff | 18c8338 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1265 | Parser::DeclTy *Parser::ParseObjCMethodDefinition() { |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1266 | DeclTy *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1267 | // parse optional ';' |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1268 | if (Tok.is(tok::semi)) |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1269 | ConsumeToken(); |
| 1270 | |
Steve Naroff | 9191a9e8 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1271 | // We should have an opening brace now. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1272 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | 70f1624 | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1273 | Diag(Tok, diag::err_expected_method_body); |
Steve Naroff | 9191a9e8 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1274 | |
| 1275 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 1276 | SkipUntil(tok::l_brace, true, true); |
| 1277 | |
| 1278 | // If we didn't find the '{', bail out. |
| 1279 | if (Tok.isNot(tok::l_brace)) |
Steve Naroff | 18c8338 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1280 | return 0; |
Fariborz Jahanian | 027c23b | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1281 | } |
Steve Naroff | 9191a9e8 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1282 | SourceLocation BraceLoc = Tok.getLocation(); |
| 1283 | |
| 1284 | // Enter a scope for the method body. |
| 1285 | EnterScope(Scope::FnScope|Scope::DeclScope); |
| 1286 | |
| 1287 | // Tell the actions module that we have entered a method definition with the |
| 1288 | // specified Declarator for the method. |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1289 | Actions.ObjCActOnStartOfMethodDef(CurScope, MDecl); |
Steve Naroff | 9191a9e8 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1290 | |
| 1291 | StmtResult FnBody = ParseCompoundStatementBody(); |
| 1292 | |
| 1293 | // If the function body could not be parsed, make a bogus compoundstmt. |
| 1294 | if (FnBody.isInvalid) |
| 1295 | FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, 0, 0, false); |
| 1296 | |
| 1297 | // Leave the function body scope. |
| 1298 | ExitScope(); |
| 1299 | |
| 1300 | // TODO: Pass argument information. |
Steve Naroff | 99ee430 | 2007-11-11 23:20:51 +0000 | [diff] [blame] | 1301 | Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val); |
Steve Naroff | 18c8338 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1302 | return MDecl; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1303 | } |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1304 | |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1305 | Parser::StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
| 1306 | if (Tok.isObjCAtKeyword(tok::objc_try)) { |
Chris Lattner | 8071239 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1307 | return ParseObjCTryStmt(AtLoc); |
Steve Naroff | c949a46 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1308 | } else if (Tok.isObjCAtKeyword(tok::objc_throw)) |
| 1309 | return ParseObjCThrowStmt(AtLoc); |
| 1310 | else if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
| 1311 | return ParseObjCSynchronizedStmt(AtLoc); |
| 1312 | ExprResult Res = ParseExpressionWithLeadingAt(AtLoc); |
| 1313 | if (Res.isInvalid) { |
| 1314 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 1315 | // doing this opens us up to the possibility of infinite loops if |
| 1316 | // ParseExpression does not consume any tokens. |
| 1317 | SkipUntil(tok::semi); |
| 1318 | return true; |
| 1319 | } |
| 1320 | // Otherwise, eat the semicolon. |
| 1321 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_expr); |
| 1322 | return Actions.ActOnExprStmt(Res.Val); |
| 1323 | } |
| 1324 | |
Steve Naroff | fb9dd75 | 2007-10-15 20:55:58 +0000 | [diff] [blame] | 1325 | Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1326 | |
| 1327 | switch (Tok.getKind()) { |
Chris Lattner | ddd3e63 | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1328 | case tok::string_literal: // primary-expression: string-literal |
| 1329 | case tok::wide_string_literal: |
| 1330 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
| 1331 | default: |
| 1332 | break; |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1336 | case tok::objc_encode: |
| 1337 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
| 1338 | case tok::objc_protocol: |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1339 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1340 | case tok::objc_selector: |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1341 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1342 | default: |
| 1343 | Diag(AtLoc, diag::err_unexpected_at); |
| 1344 | SkipUntil(tok::semi); |
Chris Lattner | fd44db3 | 2008-01-30 21:20:25 +0000 | [diff] [blame] | 1345 | return true; |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1346 | } |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1349 | /// objc-message-expr: |
| 1350 | /// '[' objc-receiver objc-message-args ']' |
| 1351 | /// |
| 1352 | /// objc-receiver: |
| 1353 | /// expression |
| 1354 | /// class-name |
| 1355 | /// type-name |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1356 | Parser::ExprResult Parser::ParseObjCMessageExpression() { |
| 1357 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 1358 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 1359 | |
| 1360 | // Parse receiver |
Chris Lattner | c0587e1 | 2008-01-25 19:25:00 +0000 | [diff] [blame] | 1361 | if (isTokObjCMessageIdentifierReceiver()) { |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1362 | IdentifierInfo *ReceiverName = Tok.getIdentifierInfo(); |
| 1363 | ConsumeToken(); |
| 1364 | return ParseObjCMessageExpressionBody(LBracLoc, ReceiverName, 0); |
| 1365 | } |
| 1366 | |
| 1367 | ExprResult Res = ParseAssignmentExpression(); |
| 1368 | if (Res.isInvalid) { |
| 1369 | Diag(Tok, diag::err_invalid_receiver_to_message); |
Chris Lattner | e69015d | 2008-01-25 19:43:26 +0000 | [diff] [blame] | 1370 | SkipUntil(tok::r_square); |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1371 | return Res; |
| 1372 | } |
| 1373 | return ParseObjCMessageExpressionBody(LBracLoc, 0, Res.Val); |
| 1374 | } |
| 1375 | |
| 1376 | /// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse |
| 1377 | /// the rest of a message expression. |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1378 | /// |
| 1379 | /// objc-message-args: |
| 1380 | /// objc-selector |
| 1381 | /// objc-keywordarg-list |
| 1382 | /// |
| 1383 | /// objc-keywordarg-list: |
| 1384 | /// objc-keywordarg |
| 1385 | /// objc-keywordarg-list objc-keywordarg |
| 1386 | /// |
| 1387 | /// objc-keywordarg: |
| 1388 | /// selector-name[opt] ':' objc-keywordexpr |
| 1389 | /// |
| 1390 | /// objc-keywordexpr: |
| 1391 | /// nonempty-expr-list |
| 1392 | /// |
| 1393 | /// nonempty-expr-list: |
| 1394 | /// assignment-expression |
| 1395 | /// nonempty-expr-list , assignment-expression |
| 1396 | /// |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1397 | Parser::ExprResult |
| 1398 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
| 1399 | IdentifierInfo *ReceiverName, |
| 1400 | ExprTy *ReceiverExpr) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1401 | // Parse objc-selector |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1402 | SourceLocation Loc; |
| 1403 | IdentifierInfo *selIdent = ParseObjCSelector(Loc); |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1404 | |
| 1405 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
| 1406 | llvm::SmallVector<Action::ExprTy *, 12> KeyExprs; |
| 1407 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1408 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1409 | while (1) { |
| 1410 | // Each iteration parses a single keyword argument. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1411 | KeyIdents.push_back(selIdent); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1412 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1413 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1414 | Diag(Tok, diag::err_expected_colon); |
| 1415 | SkipUntil(tok::semi); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1416 | return true; |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1417 | } |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1418 | ConsumeToken(); // Eat the ':'. |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1419 | /// Parse the expression after ':' |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1420 | ExprResult Res = ParseAssignmentExpression(); |
| 1421 | if (Res.isInvalid) { |
| 1422 | SkipUntil(tok::identifier); |
| 1423 | return Res; |
| 1424 | } |
| 1425 | // We have a valid expression. |
Steve Naroff | 4ed9d66 | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 1426 | KeyExprs.push_back(Res.Val); |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1427 | |
| 1428 | // Check for another keyword selector. |
Fariborz Jahanian | 91193f6 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 1429 | selIdent = ParseObjCSelector(Loc); |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1430 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | // We have a selector or a colon, continue parsing. |
| 1433 | } |
| 1434 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1435 | while (Tok.is(tok::comma)) { |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1436 | ConsumeToken(); // Eat the ','. |
| 1437 | /// Parse the expression after ',' |
| 1438 | ExprResult Res = ParseAssignmentExpression(); |
| 1439 | if (Res.isInvalid) { |
| 1440 | SkipUntil(tok::identifier); |
| 1441 | return Res; |
| 1442 | } |
| 1443 | // We have a valid expression. |
| 1444 | KeyExprs.push_back(Res.Val); |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1445 | } |
| 1446 | } else if (!selIdent) { |
| 1447 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 1448 | SkipUntil(tok::semi); |
Fariborz Jahanian | 1fc8224 | 2008-01-02 18:09:46 +0000 | [diff] [blame] | 1449 | return true; |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1450 | } |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1451 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1452 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1453 | Diag(Tok, diag::err_expected_rsquare); |
| 1454 | SkipUntil(tok::semi); |
Fariborz Jahanian | 1fc8224 | 2008-01-02 18:09:46 +0000 | [diff] [blame] | 1455 | return true; |
Fariborz Jahanian | d4462f9 | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 1456 | } |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1457 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1458 | |
Steve Naroff | f9e80db | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 1459 | unsigned nKeys = KeyIdents.size(); |
Chris Lattner | d031a45 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1460 | if (nKeys == 0) |
| 1461 | KeyIdents.push_back(selIdent); |
| 1462 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
| 1463 | |
| 1464 | // We've just parsed a keyword message. |
Steve Naroff | 253118b | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 1465 | if (ReceiverName) |
Fariborz Jahanian | 2ce5dc5 | 2007-11-12 20:13:27 +0000 | [diff] [blame] | 1466 | return Actions.ActOnClassMessage(CurScope, |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1467 | ReceiverName, Sel, LBracLoc, RBracLoc, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1468 | &KeyExprs[0], KeyExprs.size()); |
Chris Lattner | ed27a53 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1469 | return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracLoc, RBracLoc, |
Steve Naroff | 9f176d1 | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 1470 | &KeyExprs[0], KeyExprs.size()); |
Fariborz Jahanian | 1e534dc | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Steve Naroff | 0add5d2 | 2007-11-03 11:27:19 +0000 | [diff] [blame] | 1473 | Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1474 | ExprResult Res = ParseStringLiteralExpression(); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1475 | if (Res.isInvalid) return Res; |
Chris Lattner | ddd3e63 | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1476 | |
| 1477 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 1478 | // expressions. At this point, we know that the only valid thing that starts |
| 1479 | // with '@' is an @"". |
| 1480 | llvm::SmallVector<SourceLocation, 4> AtLocs; |
| 1481 | llvm::SmallVector<ExprTy*, 4> AtStrings; |
| 1482 | AtLocs.push_back(AtLoc); |
| 1483 | AtStrings.push_back(Res.Val); |
| 1484 | |
| 1485 | while (Tok.is(tok::at)) { |
| 1486 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1487 | |
Chris Lattner | ddd3e63 | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1488 | ExprResult Res(true); // Invalid unless there is a string literal. |
| 1489 | if (isTokenStringLiteral()) |
| 1490 | Res = ParseStringLiteralExpression(); |
| 1491 | else |
| 1492 | Diag(Tok, diag::err_objc_concat_string); |
| 1493 | |
| 1494 | if (Res.isInvalid) { |
| 1495 | while (!AtStrings.empty()) { |
| 1496 | Actions.DeleteExpr(AtStrings.back()); |
| 1497 | AtStrings.pop_back(); |
| 1498 | } |
| 1499 | return Res; |
| 1500 | } |
| 1501 | |
| 1502 | AtStrings.push_back(Res.Val); |
| 1503 | } |
Fariborz Jahanian | 1a442d3 | 2007-12-12 23:55:49 +0000 | [diff] [blame] | 1504 | |
Chris Lattner | ddd3e63 | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1505 | return Actions.ParseObjCStringLiteral(&AtLocs[0], &AtStrings[0], |
| 1506 | AtStrings.size()); |
Anders Carlsson | a66cad4 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1507 | } |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1508 | |
| 1509 | /// objc-encode-expression: |
| 1510 | /// @encode ( type-name ) |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1511 | Parser::ExprResult Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 87c329f | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1512 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1513 | |
| 1514 | SourceLocation EncLoc = ConsumeToken(); |
| 1515 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1516 | if (Tok.isNot(tok::l_paren)) { |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1517 | Diag(Tok, diag::err_expected_lparen_after, "@encode"); |
| 1518 | return true; |
| 1519 | } |
| 1520 | |
| 1521 | SourceLocation LParenLoc = ConsumeParen(); |
| 1522 | |
| 1523 | TypeTy *Ty = ParseTypeName(); |
| 1524 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1525 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1526 | |
Chris Lattner | cfd61c8 | 2007-10-16 22:51:17 +0000 | [diff] [blame] | 1527 | return Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, Ty, |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1528 | RParenLoc); |
Anders Carlsson | 8be1d40 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 1529 | } |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1530 | |
| 1531 | /// objc-protocol-expression |
| 1532 | /// @protocol ( protocol-name ) |
| 1533 | |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1534 | Parser::ExprResult Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1535 | { |
| 1536 | SourceLocation ProtoLoc = ConsumeToken(); |
| 1537 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1538 | if (Tok.isNot(tok::l_paren)) { |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1539 | Diag(Tok, diag::err_expected_lparen_after, "@protocol"); |
| 1540 | return true; |
| 1541 | } |
| 1542 | |
| 1543 | SourceLocation LParenLoc = ConsumeParen(); |
| 1544 | |
Chris Lattner | a1d2bb7 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1545 | if (Tok.isNot(tok::identifier)) { |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1546 | Diag(Tok, diag::err_expected_ident); |
| 1547 | return true; |
| 1548 | } |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1549 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1550 | ConsumeToken(); |
| 1551 | |
Anders Carlsson | 92faeb8 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 1552 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1553 | |
Fariborz Jahanian | b391e6e | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 1554 | return Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 1555 | LParenLoc, RParenLoc); |
Anders Carlsson | 2996b4e | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 1556 | } |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1557 | |
| 1558 | /// objc-selector-expression |
| 1559 | /// @selector '(' objc-keyword-selector ')' |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1560 | Parser::ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1561 | { |
| 1562 | SourceLocation SelectorLoc = ConsumeToken(); |
| 1563 | |
| 1564 | if (Tok.isNot(tok::l_paren)) { |
| 1565 | Diag(Tok, diag::err_expected_lparen_after, "@selector"); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1569 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1570 | SourceLocation LParenLoc = ConsumeParen(); |
| 1571 | SourceLocation sLoc; |
| 1572 | IdentifierInfo *SelIdent = ParseObjCSelector(sLoc); |
| 1573 | if (!SelIdent && Tok.isNot(tok::colon)) { |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1574 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
| 1575 | return 0; |
| 1576 | } |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1577 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 6fd8927 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1578 | unsigned nColons = 0; |
| 1579 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1580 | while (1) { |
| 1581 | if (Tok.isNot(tok::colon)) { |
| 1582 | Diag(Tok, diag::err_expected_colon); |
| 1583 | break; |
| 1584 | } |
Chris Lattner | 847f5c1 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1585 | nColons++; |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1586 | ConsumeToken(); // Eat the ':'. |
| 1587 | if (Tok.is(tok::r_paren)) |
| 1588 | break; |
| 1589 | // Check for another keyword selector. |
| 1590 | SourceLocation Loc; |
| 1591 | SelIdent = ParseObjCSelector(Loc); |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1592 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1593 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 1594 | break; |
| 1595 | } |
Steve Naroff | 6fd8927 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1596 | } |
Fariborz Jahanian | 056c6b0 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 1597 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 6fd8927 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 1598 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Fariborz Jahanian | 957448a | 2007-10-16 23:21:02 +0000 | [diff] [blame] | 1599 | return Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, LParenLoc, |
Fariborz Jahanian | f807c20 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 1600 | RParenLoc); |
Gabor Greif | a823dd1 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 1601 | } |