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