Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1 | //===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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 | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C portions of the Parser interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 60f3622 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 16 | #include "RAIIObjectsForParser.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/DeclSpec.h" |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 18 | #include "clang/Sema/PrettyDeclStackTrace.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Scope.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
| 23 | |
Chris Lattner | 3a90716 | 2008-12-08 21:53:24 +0000 | [diff] [blame] | 24 | /// ParseObjCAtDirectives - Handle parts of the external-declaration production: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 25 | /// external-declaration: [C99 6.9] |
| 26 | /// [OBJC] objc-class-definition |
Steve Naroff | e093339 | 2007-10-29 21:39:29 +0000 | [diff] [blame] | 27 | /// [OBJC] objc-class-declaration |
| 28 | /// [OBJC] objc-alias-declaration |
| 29 | /// [OBJC] objc-protocol-definition |
| 30 | /// [OBJC] objc-method-definition |
| 31 | /// [OBJC] '@' 'end' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 32 | Decl *Parser::ParseObjCAtDirectives() { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 33 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 35 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 36 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 37 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 40 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 41 | case tok::objc_class: |
| 42 | return ParseObjCAtClassDeclaration(AtLoc); |
| 43 | case tok::objc_interface: |
| 44 | return ParseObjCAtInterfaceDeclaration(AtLoc); |
| 45 | case tok::objc_protocol: |
| 46 | return ParseObjCAtProtocolDeclaration(AtLoc); |
| 47 | case tok::objc_implementation: |
| 48 | return ParseObjCAtImplementationDeclaration(AtLoc); |
| 49 | case tok::objc_end: |
| 50 | return ParseObjCAtEndDeclaration(AtLoc); |
| 51 | case tok::objc_compatibility_alias: |
| 52 | return ParseObjCAtAliasDeclaration(AtLoc); |
| 53 | case tok::objc_synthesize: |
| 54 | return ParseObjCPropertySynthesize(AtLoc); |
| 55 | case tok::objc_dynamic: |
| 56 | return ParseObjCPropertyDynamic(AtLoc); |
| 57 | default: |
| 58 | Diag(AtLoc, diag::err_unexpected_at); |
| 59 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 60 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
| 64 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 65 | /// objc-class-declaration: |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 66 | /// '@' 'class' identifier-list ';' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 67 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 68 | Decl *Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 69 | ConsumeToken(); // the identifier "class" |
Chris Lattner | 23b7eb6 | 2007-06-15 23:05:46 +0000 | [diff] [blame] | 70 | llvm::SmallVector<IdentifierInfo *, 8> ClassNames; |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 71 | llvm::SmallVector<SourceLocation, 8> ClassLocs; |
| 72 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 74 | while (1) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 75 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | bd63892 | 2006-11-10 05:19:25 +0000 | [diff] [blame] | 76 | Diag(Tok, diag::err_expected_ident); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 77 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 78 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 79 | } |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 80 | ClassNames.push_back(Tok.getIdentifierInfo()); |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 81 | ClassLocs.push_back(Tok.getLocation()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 82 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 84 | if (Tok.isNot(tok::comma)) |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 85 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 86 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 87 | ConsumeToken(); |
| 88 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 89 | |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 90 | // Consume the ';'. |
| 91 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 92 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 93 | |
Ted Kremenek | a26da85 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 94 | return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), |
| 95 | ClassLocs.data(), |
| 96 | ClassNames.size()); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 99 | /// |
| 100 | /// objc-interface: |
| 101 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 102 | /// objc-category-interface |
| 103 | /// |
| 104 | /// objc-class-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | /// '@' 'interface' identifier objc-superclass[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 106 | /// objc-protocol-refs[opt] |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | /// objc-class-instance-variables[opt] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 108 | /// objc-interface-decl-list |
| 109 | /// @end |
| 110 | /// |
| 111 | /// objc-category-interface: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 112 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 113 | /// objc-protocol-refs[opt] |
| 114 | /// objc-interface-decl-list |
| 115 | /// @end |
| 116 | /// |
| 117 | /// objc-superclass: |
| 118 | /// ':' identifier |
| 119 | /// |
| 120 | /// objc-class-interface-attributes: |
| 121 | /// __attribute__((visibility("default"))) |
| 122 | /// __attribute__((visibility("hidden"))) |
| 123 | /// __attribute__((deprecated)) |
| 124 | /// __attribute__((unavailable)) |
| 125 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 126 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 127 | Decl *Parser::ParseObjCAtInterfaceDeclaration( |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 128 | SourceLocation atLoc, AttributeList *attrList) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 129 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 130 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 131 | ConsumeToken(); // the "interface" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 133 | // Code completion after '@interface'. |
| 134 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 135 | Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 136 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 139 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 140 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 141 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 142 | } |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 143 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 144 | // We have a class or category name - consume it. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 145 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 146 | SourceLocation nameLoc = ConsumeToken(); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 147 | if (Tok.is(tok::l_paren) && |
| 148 | !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 149 | SourceLocation lparenLoc = ConsumeParen(); |
| 150 | SourceLocation categoryLoc, rparenLoc; |
| 151 | IdentifierInfo *categoryId = 0; |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 152 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 153 | Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 154 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Steve Naroff | 4e1f80d | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 157 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 158 | if (Tok.is(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 159 | categoryId = Tok.getIdentifierInfo(); |
| 160 | categoryLoc = ConsumeToken(); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 161 | } |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 162 | else if (!getLang().ObjC2) { |
Steve Naroff | 4e1f80d | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 163 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 164 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 165 | } |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 166 | if (Tok.isNot(tok::r_paren)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 167 | Diag(Tok, diag::err_expected_rparen); |
| 168 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 169 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 170 | } |
| 171 | rparenLoc = ConsumeParen(); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 172 | // Next, we need to check for any protocol references. |
| 173 | SourceLocation LAngleLoc, EndProtoLoc; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 174 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 175 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
| 176 | if (Tok.is(tok::less) && |
| 177 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 178 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 179 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 181 | if (attrList) // categories don't support attributes. |
| 182 | Diag(Tok, diag::err_objc_no_attributes_on_category); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 184 | Decl *CategoryType = |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 185 | Actions.ActOnStartCategoryInterface(atLoc, |
| 186 | nameId, nameLoc, |
| 187 | categoryId, categoryLoc, |
| 188 | ProtocolRefs.data(), |
| 189 | ProtocolRefs.size(), |
| 190 | ProtocolLocs.data(), |
| 191 | EndProtoLoc); |
| 192 | if (Tok.is(tok::l_brace)) |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 193 | ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, |
| 194 | atLoc); |
| 195 | |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 196 | ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword); |
| 197 | return CategoryType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 198 | } |
| 199 | // Parse a class interface. |
| 200 | IdentifierInfo *superClassId = 0; |
| 201 | SourceLocation superClassLoc; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 202 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 203 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 204 | ConsumeToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 205 | |
| 206 | // Code completion of superclass names. |
| 207 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 208 | Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 209 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 212 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 213 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 214 | return 0; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 215 | } |
| 216 | superClassId = Tok.getIdentifierInfo(); |
| 217 | superClassLoc = ConsumeToken(); |
| 218 | } |
| 219 | // Next, we need to check for any protocol references. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 220 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 221 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
| 222 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 223 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 224 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
| 225 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 226 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 227 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 228 | Decl *ClsType = |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 230 | superClassId, superClassLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 231 | ProtocolRefs.data(), ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 232 | ProtocolLocs.data(), |
Chris Lattner | df59f5a | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 233 | EndProtoLoc, attrList); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 235 | if (Tok.is(tok::l_brace)) |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 236 | ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 237 | |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 238 | ParseObjCInterfaceDeclList(ClsType, tok::objc_interface); |
Fariborz Jahanian | 65654df | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 239 | return ClsType; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 240 | } |
| 241 | |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 242 | /// The Objective-C property callback. This should be defined where |
| 243 | /// it's used, but instead it's been lifted to here to support VS2005. |
| 244 | struct Parser::ObjCPropertyCallback : FieldCallback { |
| 245 | Parser &P; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 246 | Decl *IDecl; |
| 247 | llvm::SmallVectorImpl<Decl *> &Props; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 248 | ObjCDeclSpec &OCDS; |
| 249 | SourceLocation AtLoc; |
| 250 | tok::ObjCKeywordKind MethodImplKind; |
| 251 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 252 | ObjCPropertyCallback(Parser &P, Decl *IDecl, |
| 253 | llvm::SmallVectorImpl<Decl *> &Props, |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 254 | ObjCDeclSpec &OCDS, SourceLocation AtLoc, |
| 255 | tok::ObjCKeywordKind MethodImplKind) : |
| 256 | P(P), IDecl(IDecl), Props(Props), OCDS(OCDS), AtLoc(AtLoc), |
| 257 | MethodImplKind(MethodImplKind) { |
| 258 | } |
| 259 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 260 | Decl *invoke(FieldDeclarator &FD) { |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 261 | if (FD.D.getIdentifier() == 0) { |
| 262 | P.Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 263 | << FD.D.getSourceRange(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 264 | return 0; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 265 | } |
| 266 | if (FD.BitfieldSize) { |
| 267 | P.Diag(AtLoc, diag::err_objc_property_bitfield) |
| 268 | << FD.D.getSourceRange(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 269 | return 0; |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | // Install the property declarator into interfaceDecl. |
| 273 | IdentifierInfo *SelName = |
| 274 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 275 | |
| 276 | Selector GetterSel = |
| 277 | P.PP.getSelectorTable().getNullarySelector(SelName); |
| 278 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 279 | Selector SetterSel; |
| 280 | if (SetterName) |
| 281 | SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); |
| 282 | else |
| 283 | SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), |
| 284 | P.PP.getSelectorTable(), |
| 285 | FD.D.getIdentifier()); |
| 286 | bool isOverridingProperty = false; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 287 | Decl *Property = |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 288 | P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 289 | GetterSel, SetterSel, IDecl, |
| 290 | &isOverridingProperty, |
| 291 | MethodImplKind); |
| 292 | if (!isOverridingProperty) |
| 293 | Props.push_back(Property); |
| 294 | |
| 295 | return Property; |
| 296 | } |
| 297 | }; |
| 298 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 299 | /// objc-interface-decl-list: |
| 300 | /// empty |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 301 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 302 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 303 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 304 | /// objc-interface-decl-list declaration |
| 305 | /// objc-interface-decl-list ';' |
| 306 | /// |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 307 | /// objc-method-requirement: [OBJC2] |
| 308 | /// @required |
| 309 | /// @optional |
| 310 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 311 | void Parser::ParseObjCInterfaceDeclList(Decl *interfaceDecl, |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 312 | tok::ObjCKeywordKind contextKey) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 313 | llvm::SmallVector<Decl *, 32> allMethods; |
| 314 | llvm::SmallVector<Decl *, 16> allProperties; |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 315 | llvm::SmallVector<DeclGroupPtrTy, 8> allTUVariables; |
Fariborz Jahanian | 0c74e9d | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 316 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 317 | |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 318 | SourceRange AtEnd; |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 319 | |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 320 | while (1) { |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 321 | // If this is a method prototype, parse it. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 322 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 323 | Decl *methodPrototype = |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 324 | ParseObjCMethodPrototype(interfaceDecl, MethodImplKind); |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 325 | allMethods.push_back(methodPrototype); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 326 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 327 | // method definitions. |
Chris Lattner | 8510b90 | 2009-02-15 22:24:30 +0000 | [diff] [blame] | 328 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, |
| 329 | "", tok::semi); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 330 | continue; |
| 331 | } |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 332 | if (Tok.is(tok::l_paren)) { |
| 333 | Diag(Tok, diag::err_expected_minus_or_plus); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 334 | ParseObjCMethodDecl(Tok.getLocation(), |
| 335 | tok::minus, |
| 336 | interfaceDecl, |
| 337 | MethodImplKind); |
Fariborz Jahanian | d077f71 | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 338 | continue; |
| 339 | } |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 340 | // Ignore excess semicolons. |
| 341 | if (Tok.is(tok::semi)) { |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 342 | ConsumeToken(); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 343 | continue; |
| 344 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 345 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 346 | // If we got to the end of the file, exit the loop. |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 347 | if (Tok.is(tok::eof)) |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 348 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 350 | // Code completion within an Objective-C interface. |
| 351 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 352 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 353 | ObjCImpDecl? Sema::PCC_ObjCImplementation |
| 354 | : Sema::PCC_ObjCInterface); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 355 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f193416 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 358 | // If we don't have an @ directive, parse it as a function definition. |
| 359 | if (Tok.isNot(tok::at)) { |
Chris Lattner | c7c9ab7 | 2009-01-09 04:34:13 +0000 | [diff] [blame] | 360 | // The code below does not consume '}'s because it is afraid of eating the |
| 361 | // end of a namespace. Because of the way this code is structured, an |
| 362 | // erroneous r_brace would cause an infinite loop if not handled here. |
| 363 | if (Tok.is(tok::r_brace)) |
| 364 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 366 | // FIXME: as the name implies, this rule allows function definitions. |
| 367 | // We could pass a flag or check for functions during semantic analysis. |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 368 | allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(0)); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 369 | continue; |
| 370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 372 | // Otherwise, we have an @ directive, eat the @. |
| 373 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 374 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 375 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 376 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 377 | break; |
| 378 | } |
| 379 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 380 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 382 | if (DirectiveKind == tok::objc_end) { // @end -> terminate list |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 383 | AtEnd.setBegin(AtLoc); |
| 384 | AtEnd.setEnd(Tok.getLocation()); |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 385 | break; |
Douglas Gregor | 00a0cf7 | 2010-03-16 06:04:47 +0000 | [diff] [blame] | 386 | } else if (DirectiveKind == tok::objc_not_keyword) { |
| 387 | Diag(Tok, diag::err_objc_unknown_at); |
| 388 | SkipUntil(tok::semi); |
| 389 | continue; |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 390 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 391 | |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 392 | // Eat the identifier. |
| 393 | ConsumeToken(); |
| 394 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 395 | switch (DirectiveKind) { |
| 396 | default: |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 397 | // FIXME: If someone forgets an @end on a protocol, this loop will |
| 398 | // continue to eat up tons of stuff and spew lots of nonsense errors. It |
| 399 | // would probably be better to bail out if we saw an @class or @interface |
| 400 | // or something like that. |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 401 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 402 | // Skip until we see an '@' or '}' or ';'. |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 403 | SkipUntil(tok::r_brace, tok::at); |
| 404 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 406 | case tok::objc_required: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 407 | case tok::objc_optional: |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 408 | // This is only valid on protocols. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 409 | // FIXME: Should this check for ObjC2 being enabled? |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 410 | if (contextKey != tok::objc_protocol) |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 411 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 412 | else |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 413 | MethodImplKind = DirectiveKind; |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 414 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 416 | case tok::objc_property: |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 417 | if (!getLang().ObjC2) |
| 418 | Diag(AtLoc, diag::err_objc_propertoes_require_objc2); |
| 419 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 420 | ObjCDeclSpec OCDS; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | // Parse property attribute list, if any. |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 422 | if (Tok.is(tok::l_paren)) |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 423 | ParseObjCPropertyAttribute(OCDS, interfaceDecl, |
| 424 | allMethods.data(), allMethods.size()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | |
John McCall | 064d77b | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 426 | ObjCPropertyCallback Callback(*this, interfaceDecl, allProperties, |
| 427 | OCDS, AtLoc, MethodImplKind); |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 428 | |
Chris Lattner | 038a3e3 | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 429 | // Parse all the comma separated declarators. |
| 430 | DeclSpec DS; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 431 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 432 | |
Chris Lattner | e0d3fe9 | 2008-10-20 06:15:13 +0000 | [diff] [blame] | 433 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list, "", |
| 434 | tok::at); |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 435 | break; |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 436 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 437 | } |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 438 | |
| 439 | // We break out of the big loop in two cases: when we see @end or when we see |
| 440 | // EOF. In the former case, eat the @end. In the later case, emit an error. |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 441 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 442 | Actions.CodeCompleteObjCAtDirective(getCurScope(), ObjCImpDecl, true); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 443 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f48706c | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 444 | } else if (Tok.isObjCAtKeyword(tok::objc_end)) |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 445 | ConsumeToken(); // the "end" identifier |
| 446 | else |
| 447 | Diag(Tok, diag::err_objc_missing_end); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | |
Chris Lattner | bb8cc18 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 449 | // Insert collected methods declarations into the @interface object. |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 450 | // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 451 | Actions.ActOnAtEnd(getCurScope(), AtEnd, interfaceDecl, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | allMethods.data(), allMethods.size(), |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 453 | allProperties.data(), allProperties.size(), |
| 454 | allTUVariables.data(), allTUVariables.size()); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 457 | /// Parse property attribute declarations. |
| 458 | /// |
| 459 | /// property-attr-decl: '(' property-attrlist ')' |
| 460 | /// property-attrlist: |
| 461 | /// property-attribute |
| 462 | /// property-attrlist ',' property-attribute |
| 463 | /// property-attribute: |
| 464 | /// getter '=' identifier |
| 465 | /// setter '=' identifier ':' |
| 466 | /// readonly |
| 467 | /// readwrite |
| 468 | /// assign |
| 469 | /// retain |
| 470 | /// copy |
| 471 | /// nonatomic |
| 472 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 473 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS, Decl *ClassDecl, |
| 474 | Decl **Methods, |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 475 | unsigned NumMethods) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 476 | assert(Tok.getKind() == tok::l_paren); |
Chris Lattner | 43c76c3 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 477 | SourceLocation LHSLoc = ConsumeParen(); // consume '(' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 479 | while (1) { |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 480 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 481 | Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 482 | ConsumeCodeCompletionToken(); |
Steve Naroff | 936354c | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 483 | } |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 484 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 485 | |
Chris Lattner | 7661923 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 486 | // If this is not an identifier at all, bail out early. |
| 487 | if (II == 0) { |
| 488 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
| 489 | return; |
| 490 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 492 | SourceLocation AttrName = ConsumeToken(); // consume last attribute name |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 493 | |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 494 | if (II->isStr("readonly")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 495 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 496 | else if (II->isStr("assign")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 497 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 498 | else if (II->isStr("readwrite")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 499 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 500 | else if (II->isStr("retain")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 501 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 502 | else if (II->isStr("copy")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 503 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 504 | else if (II->isStr("nonatomic")) |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 505 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Chris Lattner | 68e4868 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 506 | else if (II->isStr("getter") || II->isStr("setter")) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 507 | bool IsSetter = II->getNameStart()[0] == 's'; |
| 508 | |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 509 | // getter/setter require extra treatment. |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 510 | unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : |
| 511 | diag::err_objc_expected_equal_for_getter; |
| 512 | |
| 513 | if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) |
Chris Lattner | 43c76c3 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 514 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 516 | if (Tok.is(tok::code_completion)) { |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 517 | if (IsSetter) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 518 | Actions.CodeCompleteObjCPropertySetter(getCurScope(), ClassDecl, |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 519 | Methods, NumMethods); |
| 520 | else |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 521 | Actions.CodeCompleteObjCPropertyGetter(getCurScope(), ClassDecl, |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 522 | Methods, NumMethods); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 523 | ConsumeCodeCompletionToken(); |
Douglas Gregor | c8537c5 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 526 | |
| 527 | SourceLocation SelLoc; |
| 528 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); |
| 529 | |
| 530 | if (!SelIdent) { |
| 531 | Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) |
| 532 | << IsSetter; |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 533 | SkipUntil(tok::r_paren); |
| 534 | return; |
| 535 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 536 | |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 537 | if (IsSetter) { |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 538 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 539 | DS.setSetterName(SelIdent); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 540 | |
Fariborz Jahanian | 8efe0ec | 2010-02-15 22:20:11 +0000 | [diff] [blame] | 541 | if (ExpectAndConsume(tok::colon, |
| 542 | diag::err_expected_colon_after_setter_name, "", |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 543 | tok::r_paren)) |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 544 | return; |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 545 | } else { |
| 546 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
Anders Carlsson | fe15a78 | 2010-10-02 17:45:21 +0000 | [diff] [blame^] | 547 | DS.setGetterName(SelIdent); |
Chris Lattner | beca770 | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 548 | } |
Chris Lattner | 825bca1 | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 549 | } else { |
Chris Lattner | 406c096 | 2008-11-19 07:49:38 +0000 | [diff] [blame] | 550 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 551 | SkipUntil(tok::r_paren); |
| 552 | return; |
Chris Lattner | 64b1f2f | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 553 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 554 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 555 | if (Tok.isNot(tok::comma)) |
| 556 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 557 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 558 | ConsumeToken(); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 559 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 560 | |
Chris Lattner | 1db3354 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 561 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
Fariborz Jahanian | 9fca6df | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 564 | /// objc-method-proto: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 566 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 567 | /// |
| 568 | /// objc-instance-method: '-' |
| 569 | /// objc-class-method: '+' |
| 570 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 571 | /// objc-method-attributes: [OBJC2] |
| 572 | /// __attribute__((deprecated)) |
| 573 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 574 | Decl *Parser::ParseObjCMethodPrototype(Decl *IDecl, |
| 575 | tok::ObjCKeywordKind MethodImplKind) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 576 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 577 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 579 | SourceLocation mLoc = ConsumeToken(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 580 | Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, IDecl,MethodImplKind); |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 581 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | acb1e74 | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 582 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 583 | return MDecl; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /// objc-selector: |
| 587 | /// identifier |
| 588 | /// one of |
| 589 | /// enum struct union if else while do for switch case default |
| 590 | /// break continue return goto asm sizeof typeof __alignof |
| 591 | /// unsigned long const short volatile signed restrict _Complex |
| 592 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 593 | /// |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 594 | IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { |
Fariborz Jahanian | 0389df4a | 2010-09-03 01:26:16 +0000 | [diff] [blame] | 595 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 596 | switch (Tok.getKind()) { |
| 597 | default: |
| 598 | return 0; |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 599 | case tok::ampamp: |
| 600 | case tok::ampequal: |
| 601 | case tok::amp: |
| 602 | case tok::pipe: |
| 603 | case tok::tilde: |
| 604 | case tok::exclaim: |
| 605 | case tok::exclaimequal: |
| 606 | case tok::pipepipe: |
| 607 | case tok::pipeequal: |
| 608 | case tok::caret: |
| 609 | case tok::caretequal: { |
Fariborz Jahanian | dadfc1c | 2010-09-03 18:01:09 +0000 | [diff] [blame] | 610 | std::string ThisTok(PP.getSpelling(Tok)); |
Fariborz Jahanian | 9e42a95 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 611 | if (isalpha(ThisTok[0])) { |
| 612 | IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); |
| 613 | Tok.setKind(tok::identifier); |
| 614 | SelectorLoc = ConsumeToken(); |
| 615 | return II; |
| 616 | } |
| 617 | return 0; |
| 618 | } |
| 619 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 620 | case tok::identifier: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 621 | case tok::kw_asm: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 622 | case tok::kw_auto: |
Chris Lattner | bb31a42 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 623 | case tok::kw_bool: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 624 | case tok::kw_break: |
| 625 | case tok::kw_case: |
| 626 | case tok::kw_catch: |
| 627 | case tok::kw_char: |
| 628 | case tok::kw_class: |
| 629 | case tok::kw_const: |
| 630 | case tok::kw_const_cast: |
| 631 | case tok::kw_continue: |
| 632 | case tok::kw_default: |
| 633 | case tok::kw_delete: |
| 634 | case tok::kw_do: |
| 635 | case tok::kw_double: |
| 636 | case tok::kw_dynamic_cast: |
| 637 | case tok::kw_else: |
| 638 | case tok::kw_enum: |
| 639 | case tok::kw_explicit: |
| 640 | case tok::kw_export: |
| 641 | case tok::kw_extern: |
| 642 | case tok::kw_false: |
| 643 | case tok::kw_float: |
| 644 | case tok::kw_for: |
| 645 | case tok::kw_friend: |
| 646 | case tok::kw_goto: |
| 647 | case tok::kw_if: |
| 648 | case tok::kw_inline: |
| 649 | case tok::kw_int: |
| 650 | case tok::kw_long: |
| 651 | case tok::kw_mutable: |
| 652 | case tok::kw_namespace: |
| 653 | case tok::kw_new: |
| 654 | case tok::kw_operator: |
| 655 | case tok::kw_private: |
| 656 | case tok::kw_protected: |
| 657 | case tok::kw_public: |
| 658 | case tok::kw_register: |
| 659 | case tok::kw_reinterpret_cast: |
| 660 | case tok::kw_restrict: |
| 661 | case tok::kw_return: |
| 662 | case tok::kw_short: |
| 663 | case tok::kw_signed: |
| 664 | case tok::kw_sizeof: |
| 665 | case tok::kw_static: |
| 666 | case tok::kw_static_cast: |
| 667 | case tok::kw_struct: |
| 668 | case tok::kw_switch: |
| 669 | case tok::kw_template: |
| 670 | case tok::kw_this: |
| 671 | case tok::kw_throw: |
| 672 | case tok::kw_true: |
| 673 | case tok::kw_try: |
| 674 | case tok::kw_typedef: |
| 675 | case tok::kw_typeid: |
| 676 | case tok::kw_typename: |
| 677 | case tok::kw_typeof: |
| 678 | case tok::kw_union: |
| 679 | case tok::kw_unsigned: |
| 680 | case tok::kw_using: |
| 681 | case tok::kw_virtual: |
| 682 | case tok::kw_void: |
| 683 | case tok::kw_volatile: |
| 684 | case tok::kw_wchar_t: |
| 685 | case tok::kw_while: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 686 | case tok::kw__Bool: |
| 687 | case tok::kw__Complex: |
Anders Carlsson | f93f56a | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 688 | case tok::kw___alignof: |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 689 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 690 | SelectorLoc = ConsumeToken(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 691 | return II; |
Fariborz Jahanian | fa80e80 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 692 | } |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 695 | /// objc-for-collection-in: 'in' |
| 696 | /// |
Fariborz Jahanian | 3622e59 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 697 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 732b8c2 | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 698 | // FIXME: May have to do additional look-ahead to only allow for |
| 699 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 700 | // '[' etc. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | return (getLang().ObjC2 && Tok.is(tok::identifier) && |
Chris Lattner | ce90ef5 | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 702 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
Fariborz Jahanian | 8361552 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 705 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 706 | /// qualifier list and builds their bitmask representation in the input |
| 707 | /// argument. |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 708 | /// |
| 709 | /// objc-type-qualifiers: |
| 710 | /// objc-type-qualifier |
| 711 | /// objc-type-qualifiers objc-type-qualifier |
| 712 | /// |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 713 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, bool IsParameter) { |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 714 | while (1) { |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 715 | if (Tok.is(tok::code_completion)) { |
| 716 | Actions.CodeCompleteObjCPassingType(getCurScope(), DS); |
| 717 | ConsumeCodeCompletionToken(); |
| 718 | } |
| 719 | |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 720 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 721 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 722 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 723 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 724 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 725 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 726 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 727 | |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 728 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 729 | switch (i) { |
| 730 | default: assert(0 && "Unknown decl qualifier"); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 731 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 732 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 733 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 734 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 735 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 736 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 737 | } |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 738 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 739 | ConsumeToken(); |
| 740 | II = 0; |
| 741 | break; |
| 742 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | |
Chris Lattner | 61511e1 | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 744 | // If this wasn't a recognized qualifier, bail out. |
| 745 | if (II) return; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /// objc-type-name: |
| 750 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 751 | /// '(' objc-type-qualifiers[opt] ')' |
| 752 | /// |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 753 | ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, bool IsParameter) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 754 | assert(Tok.is(tok::l_paren) && "expected ("); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 756 | SourceLocation LParenLoc = ConsumeParen(); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 757 | SourceLocation TypeStartLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Fariborz Jahanian | d822d68 | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 759 | // Parse type qualifiers, in, inout, etc. |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 760 | ParseObjCTypeQualifierList(DS, IsParameter); |
Steve Naroff | 7e901fd | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 761 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 762 | ParsedType Ty; |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 763 | if (isTypeSpecifierQualifier()) { |
| 764 | TypeResult TypeSpec = ParseTypeName(); |
| 765 | if (!TypeSpec.isInvalid()) |
| 766 | Ty = TypeSpec.get(); |
| 767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | |
Steve Naroff | 90255b4 | 2008-10-21 14:15:04 +0000 | [diff] [blame] | 769 | if (Tok.is(tok::r_paren)) |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 770 | ConsumeParen(); |
| 771 | else if (Tok.getLocation() == TypeStartLoc) { |
| 772 | // If we didn't eat any tokens, then this isn't a type. |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 773 | Diag(Tok, diag::err_expected_type); |
Chris Lattner | b795443 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 774 | SkipUntil(tok::r_paren); |
| 775 | } else { |
| 776 | // Otherwise, we found *something*, but didn't get a ')' in the right |
| 777 | // place. Emit an error then return what we have as the type. |
| 778 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 779 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 780 | return Ty; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /// objc-method-decl: |
| 784 | /// objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 785 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 786 | /// objc-type-name objc-selector |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 787 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 788 | /// |
| 789 | /// objc-keyword-selector: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | /// objc-keyword-decl |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 791 | /// objc-keyword-selector objc-keyword-decl |
| 792 | /// |
| 793 | /// objc-keyword-decl: |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 794 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 795 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 796 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 797 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 798 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 799 | /// objc-parmlist: |
| 800 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 801 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 802 | /// objc-parms: |
| 803 | /// objc-parms , parameter-declaration |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 804 | /// |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 805 | /// objc-ellipsis: |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 806 | /// , ... |
| 807 | /// |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 808 | /// objc-keyword-attributes: [OBJC2] |
| 809 | /// __attribute__((unused)) |
| 810 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 811 | Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Douglas Gregor | c49f5b2 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 812 | tok::TokenKind mType, |
| 813 | Decl *IDecl, |
| 814 | tok::ObjCKeywordKind MethodImplKind) { |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 815 | ParsingDeclRAIIObject PD(*this); |
| 816 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 817 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 818 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 819 | /*ReturnType=*/ ParsedType(), IDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 820 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 823 | // Parse the return type if present. |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 824 | ParsedType ReturnType; |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 825 | ObjCDeclSpec DSRet; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 826 | if (Tok.is(tok::l_paren)) |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 827 | ReturnType = ParseObjCTypeName(DSRet, false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 828 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 829 | // If attributes exist before the method, parse them. |
| 830 | llvm::OwningPtr<AttributeList> MethodAttrs; |
| 831 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
| 832 | MethodAttrs.reset(ParseGNUAttributes()); |
| 833 | |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 834 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 835 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 836 | ReturnType, IDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 837 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 636a61e | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 840 | // Now parse the selector. |
Steve Naroff | 161a92b | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 841 | SourceLocation selLoc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 842 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 843 | |
Steve Naroff | 7a54c0d | 2009-02-11 20:43:13 +0000 | [diff] [blame] | 844 | // An unnamed colon is valid. |
| 845 | if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 846 | Diag(Tok, diag::err_expected_selector_for_method) |
| 847 | << SourceRange(mLoc, Tok.getLocation()); |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 848 | // Skip until we get a ; or {}. |
| 849 | SkipUntil(tok::r_brace); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 850 | return 0; |
Chris Lattner | 2ebb178 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 851 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 853 | llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 854 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 855 | // If attributes exist after the method, parse them. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 856 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 857 | MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), |
| 858 | ParseGNUAttributes())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 860 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 861 | Decl *Result |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 862 | = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | b560517 | 2007-11-09 19:52:12 +0000 | [diff] [blame] | 863 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 864 | 0, |
| 865 | CParamInfo.data(), CParamInfo.size(), |
| 866 | MethodAttrs.get(), |
Ted Kremenek | bc76c72 | 2009-05-04 17:04:30 +0000 | [diff] [blame] | 867 | MethodImplKind); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 868 | PD.complete(Result); |
| 869 | return Result; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 870 | } |
Steve Naroff | ca85d1d | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 871 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 872 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 873 | llvm::SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 874 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 875 | while (1) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 876 | Sema::ObjCArgInfo ArgInfo; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 877 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 878 | // Each iteration parses a single keyword argument. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 879 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 880 | Diag(Tok, diag::err_expected_colon); |
| 881 | break; |
| 882 | } |
| 883 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 885 | ArgInfo.Type = ParsedType(); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 886 | if (Tok.is(tok::l_paren)) // Parse the argument type if present. |
Douglas Gregor | 99fa264 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 887 | ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, true); |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 888 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 889 | // If attributes exist before the argument name, parse them. |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 890 | ArgInfo.ArgAttrs = 0; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 891 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Alexis Hunt | 96d5c76 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 892 | ArgInfo.ArgAttrs = ParseGNUAttributes(); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 893 | |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 894 | // Code completion for the next piece of the selector. |
| 895 | if (Tok.is(tok::code_completion)) { |
| 896 | ConsumeCodeCompletionToken(); |
| 897 | KeyIdents.push_back(SelIdent); |
| 898 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 899 | mType == tok::minus, |
| 900 | /*AtParameterName=*/true, |
| 901 | ReturnType, |
| 902 | KeyIdents.data(), |
| 903 | KeyIdents.size()); |
| 904 | KeyIdents.pop_back(); |
| 905 | break; |
| 906 | } |
| 907 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 908 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 909 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 910 | break; |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 911 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 913 | ArgInfo.Name = Tok.getIdentifierInfo(); |
| 914 | ArgInfo.NameLoc = Tok.getLocation(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 915 | ConsumeToken(); // Eat the identifier. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | |
Chris Lattner | d8626fd | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 917 | ArgInfos.push_back(ArgInfo); |
| 918 | KeyIdents.push_back(SelIdent); |
| 919 | |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 920 | // Code completion for the next piece of the selector. |
| 921 | if (Tok.is(tok::code_completion)) { |
| 922 | ConsumeCodeCompletionToken(); |
| 923 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 924 | mType == tok::minus, |
Douglas Gregor | 4587969 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 925 | /*AtParameterName=*/false, |
Douglas Gregor | 95887f9 | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 926 | ReturnType, |
| 927 | KeyIdents.data(), |
| 928 | KeyIdents.size()); |
| 929 | break; |
| 930 | } |
| 931 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 932 | // Check for another keyword selector. |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 933 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 934 | SelIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 935 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 936 | break; |
| 937 | // We have a selector or a colon, continue parsing. |
Steve Naroff | f1bc45b | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 938 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 940 | bool isVariadic = false; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 941 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 942 | // Parse the (optional) parameter list. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 943 | while (Tok.is(tok::comma)) { |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 944 | ConsumeToken(); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 945 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 946 | isVariadic = true; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 947 | ConsumeToken(); |
| 948 | break; |
| 949 | } |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 950 | DeclSpec DS; |
| 951 | ParseDeclarationSpecifiers(DS); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 952 | // Parse the declarator. |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 953 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 954 | ParseDeclarator(ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 955 | IdentifierInfo *ParmII = ParmDecl.getIdentifier(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 956 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 957 | CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 958 | ParmDecl.getIdentifierLoc(), |
| 959 | Param, |
| 960 | 0)); |
| 961 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 962 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 963 | |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 964 | // FIXME: Add support for optional parmameter list... |
Fariborz Jahanian | 33d0374 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 965 | // If attributes exist after the method, parse them. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | if (getLang().ObjC2 && Tok.is(tok::kw___attribute)) |
Ted Kremenek | 66f2d6b | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 967 | MethodAttrs.reset(addAttributeLists(MethodAttrs.take(), |
| 968 | ParseGNUAttributes())); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | |
Fariborz Jahanian | 6e9e4f3 | 2009-06-24 17:00:18 +0000 | [diff] [blame] | 970 | if (KeyIdents.size() == 0) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 971 | return 0; |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 972 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 973 | &KeyIdents[0]); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 974 | Decl *Result |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 975 | = Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(), |
Fariborz Jahanian | 6e9e4f3 | 2009-06-24 17:00:18 +0000 | [diff] [blame] | 976 | mType, IDecl, DSRet, ReturnType, Sel, |
Fariborz Jahanian | 6046209 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 977 | &ArgInfos[0], |
| 978 | CParamInfo.data(), CParamInfo.size(), |
Ted Kremenek | c162e8e | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 979 | MethodAttrs.get(), |
Steve Naroff | d8ea1ac | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 980 | MethodImplKind, isVariadic); |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 981 | PD.complete(Result); |
Ted Kremenek | c162e8e | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 982 | |
| 983 | // Delete referenced AttributeList objects. |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 984 | for (llvm::SmallVectorImpl<Sema::ObjCArgInfo>::iterator |
Ted Kremenek | c162e8e | 2010-02-11 02:19:13 +0000 | [diff] [blame] | 985 | I = ArgInfos.begin(), E = ArgInfos.end(); I != E; ++I) |
| 986 | delete I->ArgAttrs; |
| 987 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 988 | return Result; |
Steve Naroff | 99264b4 | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 991 | /// objc-protocol-refs: |
| 992 | /// '<' identifier-list '>' |
| 993 | /// |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 994 | bool Parser:: |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 995 | ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 996 | llvm::SmallVectorImpl<SourceLocation> &ProtocolLocs, |
| 997 | bool WarnOnDeclarations, |
| 998 | SourceLocation &LAngleLoc, SourceLocation &EndLoc) { |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 999 | assert(Tok.is(tok::less) && "expected <"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1001 | LAngleLoc = ConsumeToken(); // the "<" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1003 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1005 | while (1) { |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1006 | if (Tok.is(tok::code_completion)) { |
| 1007 | Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), |
| 1008 | ProtocolIdents.size()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1009 | ConsumeCodeCompletionToken(); |
Douglas Gregor | baf6961 | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1012 | if (Tok.isNot(tok::identifier)) { |
| 1013 | Diag(Tok, diag::err_expected_ident); |
| 1014 | SkipUntil(tok::greater); |
| 1015 | return true; |
| 1016 | } |
| 1017 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 1018 | Tok.getLocation())); |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1019 | ProtocolLocs.push_back(Tok.getLocation()); |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1020 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1021 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1022 | if (Tok.isNot(tok::comma)) |
| 1023 | break; |
| 1024 | ConsumeToken(); |
| 1025 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1026 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1027 | // Consume the '>'. |
| 1028 | if (Tok.isNot(tok::greater)) { |
| 1029 | Diag(Tok, diag::err_expected_greater); |
| 1030 | return true; |
| 1031 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1032 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1033 | EndLoc = ConsumeAnyToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1034 | |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1035 | // Convert the list of protocols identifiers into a list of protocol decls. |
| 1036 | Actions.FindProtocolDeclaration(WarnOnDeclarations, |
| 1037 | &ProtocolIdents[0], ProtocolIdents.size(), |
| 1038 | Protocols); |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1042 | /// objc-class-instance-variables: |
| 1043 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 1044 | /// |
| 1045 | /// objc-instance-variable-decl-list: |
| 1046 | /// objc-visibility-spec |
| 1047 | /// objc-instance-variable-decl ';' |
| 1048 | /// ';' |
| 1049 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 1050 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 1051 | /// objc-instance-variable-decl-list ';' |
| 1052 | /// |
| 1053 | /// objc-visibility-spec: |
| 1054 | /// @private |
| 1055 | /// @protected |
| 1056 | /// @public |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1057 | /// @package [OBJC2] |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1058 | /// |
| 1059 | /// objc-instance-variable-decl: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | /// struct-declaration |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1061 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1062 | void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1063 | tok::ObjCKeywordKind visibility, |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1064 | SourceLocation atLoc) { |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1065 | assert(Tok.is(tok::l_brace) && "expected {"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1066 | llvm::SmallVector<Decl *, 32> AllIvarDecls; |
Chris Lattner | a12405b | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | 45a33ec | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 1068 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
Douglas Gregor | 82ac25e | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 1069 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1070 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1072 | // While we still have something to read, read the instance variables. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1073 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1074 | // Each iteration of this loop reads one objc-instance-variable-decl. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1076 | // Check for extraneous top-level semicolon. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1077 | if (Tok.is(tok::semi)) { |
Douglas Gregor | 13d0568 | 2010-06-16 23:08:59 +0000 | [diff] [blame] | 1078 | Diag(Tok, diag::ext_extra_ivar_semi) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1079 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1080 | ConsumeToken(); |
| 1081 | continue; |
| 1082 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1083 | |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1084 | // Set the default visibility to private. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1085 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1086 | ConsumeToken(); // eat the @ sign |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1087 | |
| 1088 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1089 | Actions.CodeCompleteObjCAtVisibility(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1090 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1093 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1094 | case tok::objc_private: |
| 1095 | case tok::objc_public: |
| 1096 | case tok::objc_protected: |
| 1097 | case tok::objc_package: |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1098 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1099 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | continue; |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1101 | default: |
| 1102 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1103 | continue; |
| 1104 | } |
| 1105 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1107 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1108 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1109 | Sema::PCC_ObjCInstanceVariableList); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1110 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 48d4625 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1113 | struct ObjCIvarCallback : FieldCallback { |
| 1114 | Parser &P; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1115 | Decl *IDecl; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1116 | tok::ObjCKeywordKind visibility; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1117 | llvm::SmallVectorImpl<Decl *> &AllIvarDecls; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1118 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1119 | ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, |
| 1120 | llvm::SmallVectorImpl<Decl *> &AllIvarDecls) : |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1121 | P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { |
| 1122 | } |
| 1123 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1124 | Decl *invoke(FieldDeclarator &FD) { |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1125 | // Install the declarator into the interface decl. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1126 | Decl *Field |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1127 | = P.Actions.ActOnIvar(P.getCurScope(), |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1128 | FD.D.getDeclSpec().getSourceRange().getBegin(), |
| 1129 | IDecl, FD.D, FD.BitfieldSize, visibility); |
Fariborz Jahanian | 6a0a2e0 | 2010-04-06 22:43:48 +0000 | [diff] [blame] | 1130 | if (Field) |
| 1131 | AllIvarDecls.push_back(Field); |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1132 | return Field; |
| 1133 | } |
| 1134 | } Callback(*this, interfaceDecl, visibility, AllIvarDecls); |
Fariborz Jahanian | 616d3e7 | 2010-08-23 22:46:52 +0000 | [diff] [blame] | 1135 | |
Chris Lattner | a12405b | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1136 | // Parse all the comma separated declarators. |
| 1137 | DeclSpec DS; |
John McCall | cfefb6d | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1138 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1140 | if (Tok.is(tok::semi)) { |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1141 | ConsumeToken(); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1142 | } else { |
| 1143 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1144 | // Skip to end of block or statement |
| 1145 | SkipUntil(tok::r_brace, true, true); |
| 1146 | } |
| 1147 | } |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1148 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Fariborz Jahanian | 616d3e7 | 2010-08-23 22:46:52 +0000 | [diff] [blame] | 1149 | Actions.ActOnLastBitfield(RBraceLoc, interfaceDecl, AllIvarDecls); |
Steve Naroff | 9c4fddd | 2007-10-31 22:11:35 +0000 | [diff] [blame] | 1150 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 1151 | // for code rewriting tools that need to be aware of the empty list. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1152 | Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1153 | AllIvarDecls.data(), AllIvarDecls.size(), |
Daniel Dunbar | 15619c7 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 1154 | LBraceLoc, RBraceLoc, 0); |
Steve Naroff | 00433d3 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1155 | return; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1156 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1157 | |
| 1158 | /// objc-protocol-declaration: |
| 1159 | /// objc-protocol-definition |
| 1160 | /// objc-protocol-forward-reference |
| 1161 | /// |
| 1162 | /// objc-protocol-definition: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | /// @protocol identifier |
| 1164 | /// objc-protocol-refs[opt] |
| 1165 | /// objc-interface-decl-list |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1166 | /// @end |
| 1167 | /// |
| 1168 | /// objc-protocol-forward-reference: |
| 1169 | /// @protocol identifier-list ';' |
| 1170 | /// |
| 1171 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1172 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1173 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1174 | Decl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
Chris Lattner | 83f095c | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1175 | AttributeList *attrList) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1176 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1177 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 1178 | ConsumeToken(); // the "protocol" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1180 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1181 | Actions.CodeCompleteObjCProtocolDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1182 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5b4671c | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1185 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1186 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1187 | return 0; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1188 | } |
| 1189 | // Save the protocol name, then consume it. |
| 1190 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 1191 | SourceLocation nameLoc = ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1193 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1194 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1195 | ConsumeToken(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1196 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, |
Fariborz Jahanian | 1470e93 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1197 | attrList); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1198 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1200 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1201 | llvm::SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
| 1202 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 1203 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1204 | // Parse the list of forward declarations. |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1205 | while (1) { |
| 1206 | ConsumeToken(); // the ',' |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1207 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1208 | Diag(Tok, diag::err_expected_ident); |
| 1209 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1210 | return 0; |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1211 | } |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1212 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 1213 | Tok.getLocation())); |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1214 | ConsumeToken(); // the identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1216 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | } |
| 1219 | // Consume the ';'. |
| 1220 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1221 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | |
Steve Naroff | 93eb5f1 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1223 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1224 | &ProtocolRefs[0], |
Fariborz Jahanian | 1470e93 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1225 | ProtocolRefs.size(), |
| 1226 | attrList); |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1227 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1228 | |
Steve Naroff | 0b6a01a | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1229 | // Last, and definitely not least, parse a protocol declaration. |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1230 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1231 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1232 | llvm::SmallVector<Decl *, 8> ProtocolRefs; |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1233 | llvm::SmallVector<SourceLocation, 8> ProtocolLocs; |
Chris Lattner | d7352d6 | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1234 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | fc1f9e4 | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1235 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, |
| 1236 | LAngleLoc, EndProtoLoc)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1237 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1239 | Decl *ProtoType = |
Chris Lattner | 3bbae00 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1240 | Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1241 | ProtocolRefs.data(), |
| 1242 | ProtocolRefs.size(), |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1243 | ProtocolLocs.data(), |
Daniel Dunbar | 26e2ab4 | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 1244 | EndProtoLoc, attrList); |
Fariborz Jahanian | 39d641f | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 1245 | ParseObjCInterfaceDeclList(ProtoType, tok::objc_protocol); |
Chris Lattner | da9fb15 | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 1246 | return ProtoType; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1247 | } |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1248 | |
| 1249 | /// objc-implementation: |
| 1250 | /// objc-class-implementation-prologue |
| 1251 | /// objc-category-implementation-prologue |
| 1252 | /// |
| 1253 | /// objc-class-implementation-prologue: |
| 1254 | /// @implementation identifier objc-superclass[opt] |
| 1255 | /// objc-class-instance-variables[opt] |
| 1256 | /// |
| 1257 | /// objc-category-implementation-prologue: |
| 1258 | /// @implementation identifier ( identifier ) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1259 | Decl *Parser::ParseObjCAtImplementationDeclaration( |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1260 | SourceLocation atLoc) { |
| 1261 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 1262 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 1263 | ConsumeToken(); // the "implementation" identifier |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1265 | // Code completion after '@implementation'. |
| 1266 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1267 | Actions.CodeCompleteObjCImplementationDecl(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1268 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 49c22a7 | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1271 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1272 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1273 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1274 | } |
| 1275 | // We have a class or category name - consume it. |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1276 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1277 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | |
| 1279 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1280 | // we have a category implementation. |
| 1281 | SourceLocation lparenLoc = ConsumeParen(); |
| 1282 | SourceLocation categoryLoc, rparenLoc; |
| 1283 | IdentifierInfo *categoryId = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1284 | |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1285 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1286 | Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1287 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d34fd3 | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1290 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1291 | categoryId = Tok.getIdentifierInfo(); |
| 1292 | categoryLoc = ConsumeToken(); |
| 1293 | } else { |
| 1294 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1295 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | } |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1297 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1298 | Diag(Tok, diag::err_expected_rparen); |
| 1299 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1300 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1301 | } |
| 1302 | rparenLoc = ConsumeParen(); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1303 | Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | atLoc, nameId, nameLoc, categoryId, |
Fariborz Jahanian | 89b8ef9 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1305 | categoryLoc); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1306 | ObjCImpDecl = ImplCatType; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1307 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1308 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1309 | } |
| 1310 | // We have a class implementation |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1311 | SourceLocation superClassLoc; |
| 1312 | IdentifierInfo *superClassId = 0; |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1313 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1314 | // We have a super class |
| 1315 | ConsumeToken(); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1316 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1317 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1318 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1319 | } |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1320 | superClassId = Tok.getIdentifierInfo(); |
| 1321 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1322 | } |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1323 | Decl *ImplClsType = Actions.ActOnStartClassImplementation( |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1324 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | bfe13c5 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1325 | superClassId, superClassLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1327 | if (Tok.is(tok::l_brace)) // we have ivars |
Fariborz Jahanian | 4c172c6 | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1328 | ParseObjCClassInstanceVariables(ImplClsType/*FIXME*/, |
Fariborz Jahanian | a9effb5 | 2010-03-22 19:04:14 +0000 | [diff] [blame] | 1329 | tok::objc_private, atLoc); |
Ted Kremenek | 1b0ea82 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1330 | ObjCImpDecl = ImplClsType; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1331 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
| 1332 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1333 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1334 | } |
Steve Naroff | 33a1e80 | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1335 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1336 | Decl *Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1337 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 1338 | "ParseObjCAtEndDeclaration(): Expected @end"); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1339 | Decl *Result = ObjCImpDecl; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1340 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1341 | if (ObjCImpDecl) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1342 | Actions.ActOnAtEnd(getCurScope(), atEnd, ObjCImpDecl); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1343 | ObjCImpDecl = 0; |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1344 | PendingObjCImpDecl.pop_back(); |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1345 | } |
Ted Kremenek | c7c6431 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1346 | else { |
| 1347 | // missing @implementation |
| 1348 | Diag(atEnd.getBegin(), diag::warn_expected_implementation); |
| 1349 | } |
Fariborz Jahanian | b8d091c | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1350 | return Result; |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1351 | } |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1352 | |
Fariborz Jahanian | 6e7e8cc | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 1353 | Parser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { |
| 1354 | Actions.DiagnoseUseOfUnimplementedSelectors(); |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1355 | if (PendingObjCImpDecl.empty()) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1356 | return Actions.ConvertDeclToDeclGroup(0); |
| 1357 | Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1358 | Actions.ActOnAtEnd(getCurScope(), SourceRange(), ImpDecl); |
Fariborz Jahanian | 9290ede | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1359 | return Actions.ConvertDeclToDeclGroup(ImpDecl); |
| 1360 | } |
| 1361 | |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1362 | /// compatibility-alias-decl: |
| 1363 | /// @compatibility_alias alias-name class-name ';' |
| 1364 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1365 | Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1366 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1367 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1368 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1369 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1370 | Diag(Tok, diag::err_expected_ident); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1371 | return 0; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1372 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1373 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1374 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1375 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1376 | Diag(Tok, diag::err_expected_ident); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1377 | return 0; |
Fariborz Jahanian | d8e12d3 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1378 | } |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1379 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1380 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
| 1381 | if (Tok.isNot(tok::semi)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1382 | Diag(Tok, diag::err_expected_semi_after) << "@compatibility_alias"; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1383 | return 0; |
Fariborz Jahanian | 49c6425 | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1384 | } |
Chris Lattner | 83f095c | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1385 | return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, |
| 1386 | classId, classLoc); |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1389 | /// property-synthesis: |
| 1390 | /// @synthesize property-ivar-list ';' |
| 1391 | /// |
| 1392 | /// property-ivar-list: |
| 1393 | /// property-ivar |
| 1394 | /// property-ivar-list ',' property-ivar |
| 1395 | /// |
| 1396 | /// property-ivar: |
| 1397 | /// identifier |
| 1398 | /// identifier '=' identifier |
| 1399 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1400 | Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1401 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 1402 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1403 | SourceLocation loc = ConsumeToken(); // consume synthesize |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1404 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1405 | while (true) { |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1406 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1407 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1408 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1411 | if (Tok.isNot(tok::identifier)) { |
| 1412 | Diag(Tok, diag::err_synthesized_property_name); |
| 1413 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1414 | return 0; |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1417 | IdentifierInfo *propertyIvar = 0; |
| 1418 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1419 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1420 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1421 | // property '=' ivar-name |
| 1422 | ConsumeToken(); // consume '=' |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1423 | |
| 1424 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1425 | Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId, |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1426 | ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1427 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 5d64988 | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1428 | } |
| 1429 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1430 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1431 | Diag(Tok, diag::err_expected_ident); |
| 1432 | break; |
| 1433 | } |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1434 | propertyIvar = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1435 | ConsumeToken(); // consume ivar-name |
| 1436 | } |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1437 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, ObjCImpDecl, |
Fariborz Jahanian | ffe97a3 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1438 | propertyId, propertyIvar); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1439 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | ConsumeToken(); // consume ',' |
| 1442 | } |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1443 | if (Tok.isNot(tok::semi)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1444 | Diag(Tok, diag::err_expected_semi_after) << "@synthesize"; |
Douglas Gregor | 88e72a0 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1445 | SkipUntil(tok::semi); |
| 1446 | } |
Fariborz Jahanian | 9523911 | 2009-11-06 21:48:47 +0000 | [diff] [blame] | 1447 | else |
| 1448 | ConsumeToken(); // consume ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1449 | return 0; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1452 | /// property-dynamic: |
| 1453 | /// @dynamic property-list |
| 1454 | /// |
| 1455 | /// property-list: |
| 1456 | /// identifier |
| 1457 | /// property-list ',' identifier |
| 1458 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1459 | Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1460 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1461 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
| 1462 | SourceLocation loc = ConsumeToken(); // consume dynamic |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1463 | while (true) { |
| 1464 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1465 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1466 | ConsumeCodeCompletionToken(); |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | if (Tok.isNot(tok::identifier)) { |
| 1470 | Diag(Tok, diag::err_expected_ident); |
| 1471 | SkipUntil(tok::semi); |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1472 | return 0; |
Douglas Gregor | 52e78bd | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1475 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1476 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1477 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, ObjCImpDecl, |
Fariborz Jahanian | f2a7d7c | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1478 | propertyId, 0); |
| 1479 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1480 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1481 | break; |
| 1482 | ConsumeToken(); // consume ',' |
| 1483 | } |
Fariborz Jahanian | b5795c0 | 2010-04-14 20:52:42 +0000 | [diff] [blame] | 1484 | if (Tok.isNot(tok::semi)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1485 | Diag(Tok, diag::err_expected_semi_after) << "@dynamic"; |
Fariborz Jahanian | b5795c0 | 2010-04-14 20:52:42 +0000 | [diff] [blame] | 1486 | SkipUntil(tok::semi); |
| 1487 | } |
| 1488 | else |
| 1489 | ConsumeToken(); // consume ';' |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1490 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1491 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1492 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1493 | /// objc-throw-statement: |
| 1494 | /// throw expression[opt]; |
| 1495 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1496 | StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 1497 | ExprResult Res; |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1498 | ConsumeToken(); // consume throw |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1499 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | adfbbc3 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1500 | Res = ParseExpression(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1501 | if (Res.isInvalid()) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1502 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1503 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
Ted Kremenek | 15a81e5 | 2010-04-20 21:21:51 +0000 | [diff] [blame] | 1506 | // consume ';' |
| 1507 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1508 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1511 | /// objc-synchronized-statement: |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1512 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1513 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1514 | StmtResult |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1515 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1516 | ConsumeToken(); // consume synchronized |
| 1517 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1518 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1519 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1520 | } |
| 1521 | ConsumeParen(); // '(' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1522 | ExprResult Res(ParseExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1523 | if (Res.isInvalid()) { |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1524 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1525 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1526 | } |
| 1527 | if (Tok.isNot(tok::r_paren)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1528 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1529 | return StmtError(); |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1530 | } |
| 1531 | ConsumeParen(); // ')' |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1532 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1533 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1534 | return StmtError(); |
Fariborz Jahanian | 049fa58 | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1535 | } |
Steve Naroff | d9c2607 | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1536 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1537 | // statements can always hold declarations. |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1538 | ParseScope BodyScope(this, Scope::DeclScope); |
Steve Naroff | d9c2607 | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1539 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1540 | StmtResult SynchBody(ParseCompoundStatementBody()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1541 | |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1542 | BodyScope.Exit(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1543 | if (SynchBody.isInvalid()) |
Fariborz Jahanian | 48085b8 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1544 | SynchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1545 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, Res.take(), SynchBody.take()); |
Fariborz Jahanian | f89ca38 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1548 | /// objc-try-catch-statement: |
| 1549 | /// @try compound-statement objc-catch-list[opt] |
| 1550 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1551 | /// |
| 1552 | /// objc-catch-list: |
| 1553 | /// @catch ( parameter-declaration ) compound-statement |
| 1554 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1555 | /// catch-parameter-declaration: |
| 1556 | /// parameter-declaration |
| 1557 | /// '...' [OBJC2] |
| 1558 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1559 | StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1560 | bool catch_or_finally_seen = false; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1561 | |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1562 | ConsumeToken(); // consume try |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1563 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1564 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1565 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1566 | } |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1567 | StmtVector CatchStmts(Actions); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1568 | StmtResult FinallyStmt; |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1569 | ParseScope TryScope(this, Scope::DeclScope); |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1570 | StmtResult TryBody(ParseCompoundStatementBody()); |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1571 | TryScope.Exit(); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1572 | if (TryBody.isInvalid()) |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1573 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1574 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1575 | while (Tok.is(tok::at)) { |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1576 | // At this point, we need to lookahead to determine if this @ is the start |
| 1577 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1578 | // is an @try or @encode or something else. |
| 1579 | Token AfterAt = GetLookAheadToken(1); |
| 1580 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1581 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1582 | break; |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1583 | |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1584 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | 5e530bc | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1585 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1586 | Decl *FirstPart = 0; |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1587 | ConsumeToken(); // consume catch |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1588 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1589 | ConsumeParen(); |
Steve Naroff | 5ee2c02 | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1590 | ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1591 | if (Tok.isNot(tok::ellipsis)) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1592 | DeclSpec DS; |
| 1593 | ParseDeclarationSpecifiers(DS); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1594 | // For some odd reason, the name of the exception variable is |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1595 | // optional. As a result, we need to use "PrototypeContext", because |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1596 | // we must accept either 'declarator' or 'abstract-declarator' here. |
| 1597 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 1598 | ParseDeclarator(ParmDecl); |
| 1599 | |
Douglas Gregor | e11ee11 | 2010-04-23 23:01:43 +0000 | [diff] [blame] | 1600 | // Inform the actions module about the declarator, so it |
Steve Naroff | 371b8fb | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1601 | // gets added to the current scope. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1602 | FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1603 | } else |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1604 | ConsumeToken(); // consume '...' |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1605 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1606 | SourceLocation RParenLoc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1607 | |
Steve Naroff | 65a0089 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1608 | if (Tok.is(tok::r_paren)) |
| 1609 | RParenLoc = ConsumeParen(); |
| 1610 | else // Skip over garbage, until we get to ')'. Eat the ')'. |
| 1611 | SkipUntil(tok::r_paren, true, false); |
| 1612 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1613 | StmtResult CatchBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1614 | if (Tok.is(tok::l_brace)) |
| 1615 | CatchBody = ParseCompoundStatementBody(); |
| 1616 | else |
| 1617 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1618 | if (CatchBody.isInvalid()) |
Fariborz Jahanian | 9e63b98 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1619 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1620 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1621 | StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1622 | RParenLoc, |
| 1623 | FirstPart, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1624 | CatchBody.take()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1625 | if (!Catch.isInvalid()) |
| 1626 | CatchStmts.push_back(Catch.release()); |
| 1627 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1628 | } else { |
Chris Lattner | 6d29c10 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1629 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 1630 | << "@catch clause"; |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1631 | return StmtError(); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1632 | } |
| 1633 | catch_or_finally_seen = true; |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1634 | } else { |
| 1635 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1636 | ConsumeToken(); // consume finally |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1637 | ParseScope FinallyScope(this, Scope::DeclScope); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1638 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1639 | StmtResult FinallyBody(true); |
Chris Lattner | 99a59b6 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1640 | if (Tok.is(tok::l_brace)) |
| 1641 | FinallyBody = ParseCompoundStatementBody(); |
| 1642 | else |
| 1643 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1644 | if (FinallyBody.isInvalid()) |
Fariborz Jahanian | 71234d8 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1645 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1646 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1647 | FinallyBody.take()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1648 | catch_or_finally_seen = true; |
| 1649 | break; |
| 1650 | } |
| 1651 | } |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1652 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1653 | Diag(atLoc, diag::err_missing_catch_finally); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1654 | return StmtError(); |
Fariborz Jahanian | f859ef2 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1655 | } |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1656 | |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1657 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1658 | move_arg(CatchStmts), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1659 | FinallyStmt.take()); |
Fariborz Jahanian | 62fd2b4 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1660 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1661 | |
Steve Naroff | 09bf815 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1662 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1663 | /// |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1664 | Decl *Parser::ParseObjCMethodDefinition() { |
| 1665 | Decl *MDecl = ParseObjCMethodPrototype(ObjCImpDecl); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1667 | PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), |
| 1668 | "parsing Objective-C method"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1669 | |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1670 | // parse optional ';' |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1671 | if (Tok.is(tok::semi)) { |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1672 | if (ObjCImpDecl) { |
| 1673 | Diag(Tok, diag::warn_semicolon_before_method_body) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1674 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Ted Kremenek | 0b61a80 | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1675 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1676 | ConsumeToken(); |
Fariborz Jahanian | 040d75d | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1677 | } |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1678 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1679 | // We should have an opening brace now. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1680 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | 83777fe | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1681 | Diag(Tok, diag::err_expected_method_body); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1683 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 1684 | SkipUntil(tok::l_brace, true, true); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1685 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1686 | // If we didn't find the '{', bail out. |
| 1687 | if (Tok.isNot(tok::l_brace)) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1688 | return 0; |
Fariborz Jahanian | 53cacae | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1689 | } |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1690 | SourceLocation BraceLoc = Tok.getLocation(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1691 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1692 | // Enter a scope for the method body. |
Chris Lattner | c2ebb03 | 2010-04-12 05:38:43 +0000 | [diff] [blame] | 1693 | ParseScope BodyScope(this, |
| 1694 | Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1695 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1696 | // Tell the actions module that we have entered a method definition with the |
Steve Naroff | 542cd5d | 2008-07-25 17:57:26 +0000 | [diff] [blame] | 1697 | // specified Declarator for the method. |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1698 | Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); |
Sebastian Redl | 042ad95 | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1699 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1700 | StmtResult FnBody(ParseCompoundStatementBody()); |
Sebastian Redl | 042ad95 | 2008-12-11 19:30:53 +0000 | [diff] [blame] | 1701 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1702 | // If the function body could not be parsed, make a bogus compoundstmt. |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1703 | if (FnBody.isInvalid()) |
Sebastian Redl | 52f03ba | 2008-12-21 12:04:03 +0000 | [diff] [blame] | 1704 | FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, |
| 1705 | MultiStmtArg(Actions), false); |
Sebastian Redl | c675bab | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1706 | |
Steve Naroff | b94d7f6 | 2009-03-02 22:00:56 +0000 | [diff] [blame] | 1707 | // TODO: Pass argument information. |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1708 | Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1709 | |
Steve Naroff | bb87572 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1710 | // Leave the function body scope. |
Douglas Gregor | 7307d6c | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1711 | BodyScope.Exit(); |
Sebastian Redl | c675bab | 2008-12-13 16:23:55 +0000 | [diff] [blame] | 1712 | |
Steve Naroff | 7b8fa47 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1713 | return MDecl; |
Chris Lattner | da59c2f | 2006-11-05 02:08:13 +0000 | [diff] [blame] | 1714 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1715 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1716 | StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1717 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1718 | Actions.CodeCompleteObjCAtStatement(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1719 | ConsumeCodeCompletionToken(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1720 | return StmtError(); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | if (Tok.isObjCAtKeyword(tok::objc_try)) |
Chris Lattner | 3e46832 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1724 | return ParseObjCTryStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1725 | |
| 1726 | if (Tok.isObjCAtKeyword(tok::objc_throw)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1727 | return ParseObjCThrowStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1728 | |
| 1729 | if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1730 | return ParseObjCSynchronizedStmt(AtLoc); |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1731 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1732 | ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1733 | if (Res.isInvalid()) { |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1734 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 1735 | // doing this opens us up to the possibility of infinite loops if |
| 1736 | // ParseExpression does not consume any tokens. |
| 1737 | SkipUntil(tok::semi); |
Sebastian Redl | bab9a4b | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1738 | return StmtError(); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1739 | } |
Chris Lattner | 3ababf5 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1740 | |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1741 | // Otherwise, eat the semicolon. |
Douglas Gregor | 45d6bdf | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 1742 | ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1743 | return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); |
Steve Naroff | e601679 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1746 | ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1747 | switch (Tok.getKind()) { |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1748 | case tok::code_completion: |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1749 | Actions.CodeCompleteObjCAtExpression(getCurScope()); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 1750 | ConsumeCodeCompletionToken(); |
Douglas Gregor | bc7c5e4 | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1751 | return ExprError(); |
| 1752 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1753 | case tok::string_literal: // primary-expression: string-literal |
| 1754 | case tok::wide_string_literal: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1755 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1756 | default: |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1757 | if (Tok.getIdentifierInfo() == 0) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1758 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Sebastian Redl | 59b5e51 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1759 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1760 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 1761 | case tok::objc_encode: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1762 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1763 | case tok::objc_protocol: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1764 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1765 | case tok::objc_selector: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1766 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1767 | default: |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1768 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1769 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1770 | } |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1773 | /// \brirg Parse the receiver of an Objective-C++ message send. |
| 1774 | /// |
| 1775 | /// This routine parses the receiver of a message send in |
| 1776 | /// Objective-C++ either as a type or as an expression. Note that this |
| 1777 | /// routine must not be called to parse a send to 'super', since it |
| 1778 | /// has no way to return such a result. |
| 1779 | /// |
| 1780 | /// \param IsExpr Whether the receiver was parsed as an expression. |
| 1781 | /// |
| 1782 | /// \param TypeOrExpr If the receiver was parsed as an expression (\c |
| 1783 | /// IsExpr is true), the parsed expression. If the receiver was parsed |
| 1784 | /// as a type (\c IsExpr is false), the parsed type. |
| 1785 | /// |
| 1786 | /// \returns True if an error occurred during parsing or semantic |
| 1787 | /// analysis, in which case the arguments do not have valid |
| 1788 | /// values. Otherwise, returns false for a successful parse. |
| 1789 | /// |
| 1790 | /// objc-receiver: [C++] |
| 1791 | /// 'super' [not parsed here] |
| 1792 | /// expression |
| 1793 | /// simple-type-specifier |
| 1794 | /// typename-specifier |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1795 | bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 1796 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 1797 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1798 | if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || |
| 1799 | Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) |
| 1800 | TryAnnotateTypeOrScopeToken(); |
| 1801 | |
| 1802 | if (!isCXXSimpleTypeSpecifier()) { |
| 1803 | // objc-receiver: |
| 1804 | // expression |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1805 | ExprResult Receiver = ParseExpression(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1806 | if (Receiver.isInvalid()) |
| 1807 | return true; |
| 1808 | |
| 1809 | IsExpr = true; |
| 1810 | TypeOrExpr = Receiver.take(); |
| 1811 | return false; |
| 1812 | } |
| 1813 | |
| 1814 | // objc-receiver: |
| 1815 | // typename-specifier |
| 1816 | // simple-type-specifier |
| 1817 | // expression (that starts with one of the above) |
| 1818 | DeclSpec DS; |
| 1819 | ParseCXXSimpleTypeSpecifier(DS); |
| 1820 | |
| 1821 | if (Tok.is(tok::l_paren)) { |
| 1822 | // If we see an opening parentheses at this point, we are |
| 1823 | // actually parsing an expression that starts with a |
| 1824 | // function-style cast, e.g., |
| 1825 | // |
| 1826 | // postfix-expression: |
| 1827 | // simple-type-specifier ( expression-list [opt] ) |
| 1828 | // typename-specifier ( expression-list [opt] ) |
| 1829 | // |
| 1830 | // Parse the remainder of this case, then the (optional) |
| 1831 | // postfix-expression suffix, followed by the (optional) |
| 1832 | // right-hand side of the binary expression. We have an |
| 1833 | // instance method. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1834 | ExprResult Receiver = ParseCXXTypeConstructExpression(DS); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1835 | if (!Receiver.isInvalid()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1836 | Receiver = ParsePostfixExpressionSuffix(Receiver.take()); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1837 | if (!Receiver.isInvalid()) |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1838 | Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1839 | if (Receiver.isInvalid()) |
| 1840 | return true; |
| 1841 | |
| 1842 | IsExpr = true; |
| 1843 | TypeOrExpr = Receiver.take(); |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | // We have a class message. Turn the simple-type-specifier or |
| 1848 | // typename-specifier we parsed into a type and parse the |
| 1849 | // remainder of the class message. |
| 1850 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1851 | TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1852 | if (Type.isInvalid()) |
| 1853 | return true; |
| 1854 | |
| 1855 | IsExpr = false; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1856 | TypeOrExpr = Type.get().getAsOpaquePtr(); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1857 | return false; |
| 1858 | } |
| 1859 | |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1860 | /// \brief Determine whether the parser is currently referring to a an |
| 1861 | /// Objective-C message send, using a simplified heuristic to avoid overhead. |
| 1862 | /// |
| 1863 | /// This routine will only return true for a subset of valid message-send |
| 1864 | /// expressions. |
| 1865 | bool Parser::isSimpleObjCMessageExpression() { |
Chris Lattner | 47054fb | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 1866 | assert(Tok.is(tok::l_square) && getLang().ObjC1 && |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1867 | "Incorrect start for isSimpleObjCMessageExpression"); |
Douglas Gregor | 990ccac | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 1868 | return GetLookAheadToken(1).is(tok::identifier) && |
| 1869 | GetLookAheadToken(2).is(tok::identifier); |
| 1870 | } |
| 1871 | |
Douglas Gregor | abf4a3e | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1872 | bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { |
| 1873 | if (!getLang().ObjC1 || !NextToken().is(tok::identifier) || |
| 1874 | InMessageExpression) |
| 1875 | return false; |
| 1876 | |
| 1877 | |
| 1878 | ParsedType Type; |
| 1879 | |
| 1880 | if (Tok.is(tok::annot_typename)) |
| 1881 | Type = getTypeAnnotation(Tok); |
| 1882 | else if (Tok.is(tok::identifier)) |
| 1883 | Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), |
| 1884 | getCurScope()); |
| 1885 | else |
| 1886 | return false; |
| 1887 | |
| 1888 | if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { |
| 1889 | const Token &AfterNext = GetLookAheadToken(2); |
| 1890 | if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { |
| 1891 | if (Tok.is(tok::identifier)) |
| 1892 | TryAnnotateTypeOrScopeToken(); |
| 1893 | |
| 1894 | return Tok.is(tok::annot_typename); |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | return false; |
| 1899 | } |
| 1900 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1901 | /// objc-message-expr: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1902 | /// '[' objc-receiver objc-message-args ']' |
| 1903 | /// |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1904 | /// objc-receiver: [C] |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 1905 | /// 'super' |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 1906 | /// expression |
| 1907 | /// class-name |
| 1908 | /// type-name |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1909 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1910 | ExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1911 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 1912 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 1913 | |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 1914 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1915 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
Douglas Gregor | a817a19 | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 1916 | ConsumeCodeCompletionToken(); |
| 1917 | SkipUntil(tok::r_square); |
| 1918 | return ExprError(); |
| 1919 | } |
| 1920 | |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 1921 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 1922 | |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1923 | if (getLang().CPlusPlus) { |
| 1924 | // We completely separate the C and C++ cases because C++ requires |
| 1925 | // more complicated (read: slower) parsing. |
| 1926 | |
| 1927 | // Handle send to super. |
| 1928 | // FIXME: This doesn't benefit from the same typo-correction we |
| 1929 | // get in Objective-C. |
| 1930 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1931 | NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1932 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 1933 | ParsedType(), 0); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1934 | |
| 1935 | // Parse the receiver, which is either a type or an expression. |
| 1936 | bool IsExpr; |
Nick Lewycky | 970aed9 | 2010-09-15 18:35:19 +0000 | [diff] [blame] | 1937 | void *TypeOrExpr = NULL; |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1938 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
| 1939 | SkipUntil(tok::r_square); |
| 1940 | return ExprError(); |
| 1941 | } |
| 1942 | |
| 1943 | if (IsExpr) |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1944 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 1945 | ParsedType(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1946 | static_cast<Expr*>(TypeOrExpr)); |
Douglas Gregor | 8d4de67 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1947 | |
| 1948 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1949 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
| 1950 | 0); |
Chris Lattner | 47054fb | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1954 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 1955 | SourceLocation NameLoc = Tok.getLocation(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1956 | ParsedType ReceiverType; |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1957 | switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1958 | Name == Ident_super, |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1959 | NextToken().is(tok::period), |
| 1960 | ReceiverType)) { |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1961 | case Sema::ObjCSuperMessage: |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1962 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 1963 | ParsedType(), 0); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1964 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1965 | case Sema::ObjCClassMessage: |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1966 | if (!ReceiverType) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1967 | SkipUntil(tok::r_square); |
| 1968 | return ExprError(); |
| 1969 | } |
| 1970 | |
Douglas Gregor | e5798dc | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 1971 | ConsumeToken(); // the type name |
| 1972 | |
| 1973 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1974 | ReceiverType, 0); |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1975 | |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1976 | case Sema::ObjCInstanceMessage: |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1977 | // Fall through to parse an expression. |
Douglas Gregor | a148a1d | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 1978 | break; |
Fariborz Jahanian | fc58ca4 | 2009-04-08 19:50:10 +0000 | [diff] [blame] | 1979 | } |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1980 | } |
Chris Lattner | a36ec42 | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 1981 | |
| 1982 | // Otherwise, an arbitrary expression can be the receiver of a send. |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1983 | ExprResult Res(ParseExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1984 | if (Res.isInvalid()) { |
Chris Lattner | 77927cc | 2008-01-25 19:43:26 +0000 | [diff] [blame] | 1985 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1986 | return move(Res); |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1987 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1988 | |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1989 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 1990 | ParsedType(), Res.take()); |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 1991 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1992 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 1993 | /// \brief Parse the remainder of an Objective-C message following the |
| 1994 | /// '[' objc-receiver. |
| 1995 | /// |
| 1996 | /// This routine handles sends to super, class messages (sent to a |
| 1997 | /// class name), and instance messages (sent to an object), and the |
| 1998 | /// target is represented by \p SuperLoc, \p ReceiverType, or \p |
| 1999 | /// ReceiverExpr, respectively. Only one of these parameters may have |
| 2000 | /// a valid value. |
| 2001 | /// |
| 2002 | /// \param LBracLoc The location of the opening '['. |
| 2003 | /// |
| 2004 | /// \param SuperLoc If this is a send to 'super', the location of the |
| 2005 | /// 'super' keyword that indicates a send to the superclass. |
| 2006 | /// |
| 2007 | /// \param ReceiverType If this is a class message, the type of the |
| 2008 | /// class we are sending a message to. |
| 2009 | /// |
| 2010 | /// \param ReceiverExpr If this is an instance message, the expression |
| 2011 | /// used to compute the receiver object. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | /// |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2013 | /// objc-message-args: |
| 2014 | /// objc-selector |
| 2015 | /// objc-keywordarg-list |
| 2016 | /// |
| 2017 | /// objc-keywordarg-list: |
| 2018 | /// objc-keywordarg |
| 2019 | /// objc-keywordarg-list objc-keywordarg |
| 2020 | /// |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2021 | /// objc-keywordarg: |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2022 | /// selector-name[opt] ':' objc-keywordexpr |
| 2023 | /// |
| 2024 | /// objc-keywordexpr: |
| 2025 | /// nonempty-expr-list |
| 2026 | /// |
| 2027 | /// nonempty-expr-list: |
| 2028 | /// assignment-expression |
| 2029 | /// nonempty-expr-list , assignment-expression |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2030 | /// |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2031 | ExprResult |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2032 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2033 | SourceLocation SuperLoc, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2034 | ParsedType ReceiverType, |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2035 | ExprArg ReceiverExpr) { |
Douglas Gregor | e9bba4f | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2036 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2037 | |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2038 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2039 | if (SuperLoc.isValid()) |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2040 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, |
| 2041 | false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2042 | else if (ReceiverType) |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2043 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, |
| 2044 | false); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2045 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2046 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2047 | 0, 0, false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 2048 | ConsumeCodeCompletionToken(); |
Steve Naroff | eae6503 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2049 | } |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2050 | |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2051 | // Parse objc-selector |
Fariborz Jahanian | 70e8f10 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 2052 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2053 | IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2054 | |
Anders Carlsson | 978f08d | 2009-02-14 18:21:46 +0000 | [diff] [blame] | 2055 | SourceLocation SelectorLoc = Loc; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2056 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2057 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2058 | ExprVector KeyExprs(Actions); |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2059 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2060 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2061 | while (1) { |
| 2062 | // Each iteration parses a single keyword argument. |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2063 | KeyIdents.push_back(selIdent); |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2064 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2065 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2066 | Diag(Tok, diag::err_expected_colon); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2067 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2068 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2069 | // the enclosing expression. |
| 2070 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2071 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2072 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2073 | |
Steve Naroff | f73590d | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2074 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2075 | /// Parse the expression after ':' |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2076 | |
| 2077 | if (Tok.is(tok::code_completion)) { |
| 2078 | if (SuperLoc.isValid()) |
| 2079 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
| 2080 | KeyIdents.data(), |
| 2081 | KeyIdents.size(), |
| 2082 | /*AtArgumentEpression=*/true); |
| 2083 | else if (ReceiverType) |
| 2084 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
| 2085 | KeyIdents.data(), |
| 2086 | KeyIdents.size(), |
| 2087 | /*AtArgumentEpression=*/true); |
| 2088 | else |
| 2089 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 2090 | KeyIdents.data(), |
| 2091 | KeyIdents.size(), |
| 2092 | /*AtArgumentEpression=*/true); |
| 2093 | |
| 2094 | ConsumeCodeCompletionToken(); |
| 2095 | SkipUntil(tok::r_square); |
| 2096 | return ExprError(); |
| 2097 | } |
| 2098 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2099 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2100 | if (Res.isInvalid()) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2101 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2102 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2103 | // the enclosing expression. |
| 2104 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2105 | return move(Res); |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2106 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2107 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2108 | // We have a valid expression. |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2109 | KeyExprs.push_back(Res.release()); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2110 | |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2111 | // Code completion after each argument. |
| 2112 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2113 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2114 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2115 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2116 | KeyIdents.size(), |
| 2117 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2118 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2119 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2120 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2121 | KeyIdents.size(), |
| 2122 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2123 | else |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2124 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2125 | KeyIdents.data(), |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2126 | KeyIdents.size(), |
| 2127 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 6da3db4 | 2010-05-25 05:58:43 +0000 | [diff] [blame] | 2128 | ConsumeCodeCompletionToken(); |
Douglas Gregor | f86e4da | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2129 | SkipUntil(tok::r_square); |
| 2130 | return ExprError(); |
Douglas Gregor | 1b605f7 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
Steve Naroff | 486760a | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2133 | // Check for another keyword selector. |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2134 | selIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2135 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2136 | break; |
| 2137 | // We have a selector or a colon, continue parsing. |
| 2138 | } |
| 2139 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2140 | while (Tok.is(tok::comma)) { |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2141 | ConsumeToken(); // Eat the ','. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2142 | /// Parse the expression after ',' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2143 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2144 | if (Res.isInvalid()) { |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2145 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2146 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2147 | // the enclosing expression. |
| 2148 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2149 | return move(Res); |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2150 | } |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2151 | |
Steve Naroff | e3ffc2f | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2152 | // We have a valid expression. |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2153 | KeyExprs.push_back(Res.release()); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2154 | } |
| 2155 | } else if (!selIdent) { |
| 2156 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2157 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2158 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2159 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2160 | // the enclosing expression. |
| 2161 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2162 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2163 | } |
Fariborz Jahanian | 083712f | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2164 | |
Chris Lattner | 0ef1352 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2165 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | 083712f | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2166 | if (Tok.is(tok::identifier)) |
| 2167 | Diag(Tok, diag::err_expected_colon); |
| 2168 | else |
| 2169 | Diag(Tok, diag::err_expected_rsquare); |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2170 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2171 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2172 | // the enclosing expression. |
| 2173 | SkipUntil(tok::r_square); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2174 | return ExprError(); |
Fariborz Jahanian | bd25f7d | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2175 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2176 | |
Chris Lattner | 8f69706 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2177 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2178 | |
Steve Naroff | e61bfa8 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 2179 | unsigned nKeys = KeyIdents.size(); |
Chris Lattner | 5700fab | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2180 | if (nKeys == 0) |
| 2181 | KeyIdents.push_back(selIdent); |
| 2182 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2183 | |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2184 | if (SuperLoc.isValid()) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2185 | return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2186 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2187 | MultiExprArg(Actions, |
| 2188 | KeyExprs.take(), |
| 2189 | KeyExprs.size())); |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2190 | else if (ReceiverType) |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2191 | return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2192 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2193 | MultiExprArg(Actions, |
| 2194 | KeyExprs.take(), |
| 2195 | KeyExprs.size())); |
John McCall | b268a28 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2196 | return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, |
Douglas Gregor | 0c78ad9 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2197 | LBracLoc, SelectorLoc, RBracLoc, |
John McCall | faf5fb4 | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2198 | MultiExprArg(Actions, |
| 2199 | KeyExprs.take(), |
| 2200 | KeyExprs.size())); |
Fariborz Jahanian | 7db004d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2203 | ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
| 2204 | ExprResult Res(ParseStringLiteralExpression()); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2205 | if (Res.isInvalid()) return move(Res); |
| 2206 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2207 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 2208 | // expressions. At this point, we know that the only valid thing that starts |
| 2209 | // with '@' is an @"". |
| 2210 | llvm::SmallVector<SourceLocation, 4> AtLocs; |
Sebastian Redl | 511ed55 | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2211 | ExprVector AtStrings(Actions); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2212 | AtLocs.push_back(AtLoc); |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2213 | AtStrings.push_back(Res.release()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2214 | |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2215 | while (Tok.is(tok::at)) { |
| 2216 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2217 | |
Sebastian Redl | c13f268 | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 2218 | // Invalid unless there is a string literal. |
Chris Lattner | d3b5d5d | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 2219 | if (!isTokenStringLiteral()) |
| 2220 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2221 | |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2222 | ExprResult Lit(ParseStringLiteralExpression()); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2223 | if (Lit.isInvalid()) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2224 | return move(Lit); |
Sebastian Redl | 17f2c7d | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2225 | |
Sebastian Redl | d9f7b1c | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2226 | AtStrings.push_back(Lit.release()); |
Chris Lattner | e002fbe | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2227 | } |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2228 | |
| 2229 | return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), |
| 2230 | AtStrings.size())); |
Anders Carlsson | 76f4a90 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2231 | } |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2232 | |
| 2233 | /// objc-encode-expression: |
| 2234 | /// @encode ( type-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2235 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2236 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 7c34817 | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 2237 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2238 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2239 | SourceLocation EncLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2240 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2241 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2242 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 2243 | |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2244 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2245 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2246 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2247 | |
Anders Carlsson | cb8f832 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2248 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2249 | |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2250 | if (Ty.isInvalid()) |
| 2251 | return ExprError(); |
| 2252 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2253 | return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, |
Douglas Gregor | 220cac5 | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2254 | Ty.get(), RParenLoc)); |
Anders Carlsson | c5a81eb | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2255 | } |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2256 | |
| 2257 | /// objc-protocol-expression |
| 2258 | /// @protocol ( protocol-name ) |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2259 | ExprResult |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2260 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2261 | SourceLocation ProtoLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2262 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2263 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2264 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 2265 | |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2266 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2267 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2268 | if (Tok.isNot(tok::identifier)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2269 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2270 | |
Fariborz Jahanian | a32aaef | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2271 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2272 | ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2273 | |
Anders Carlsson | cb8f832 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2274 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2275 | |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2276 | return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 2277 | LParenLoc, RParenLoc)); |
Anders Carlsson | e01493d | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2278 | } |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2279 | |
| 2280 | /// objc-selector-expression |
| 2281 | /// @selector '(' objc-keyword-selector ')' |
John McCall | dadc575 | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2282 | ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2283 | SourceLocation SelectorLoc = ConsumeToken(); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2284 | |
Chris Lattner | 197a301 | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2285 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2286 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 2287 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2288 | llvm::SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2289 | SourceLocation LParenLoc = ConsumeParen(); |
| 2290 | SourceLocation sLoc; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2291 | |
| 2292 | if (Tok.is(tok::code_completion)) { |
| 2293 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2294 | KeyIdents.size()); |
| 2295 | ConsumeCodeCompletionToken(); |
| 2296 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2297 | return ExprError(); |
| 2298 | } |
| 2299 | |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2300 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2301 | if (!SelIdent && // missing selector name. |
| 2302 | Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2303 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2304 | |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2305 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2306 | unsigned nColons = 0; |
| 2307 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2308 | while (1) { |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2309 | if (Tok.is(tok::coloncolon)) { // Handle :: in C++. |
| 2310 | ++nColons; |
| 2311 | KeyIdents.push_back(0); |
| 2312 | } else if (Tok.isNot(tok::colon)) |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2313 | return ExprError(Diag(Tok, diag::err_expected_colon)); |
| 2314 | |
Chris Lattner | 1ba6445 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2315 | ++nColons; |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2316 | ConsumeToken(); // Eat the ':'. |
| 2317 | if (Tok.is(tok::r_paren)) |
| 2318 | break; |
Douglas Gregor | 67c692c | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2319 | |
| 2320 | if (Tok.is(tok::code_completion)) { |
| 2321 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2322 | KeyIdents.size()); |
| 2323 | ConsumeCodeCompletionToken(); |
| 2324 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 2325 | return ExprError(); |
| 2326 | } |
| 2327 | |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2328 | // Check for another keyword selector. |
| 2329 | SourceLocation Loc; |
Chris Lattner | 4f472a3 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2330 | SelIdent = ParseObjCSelectorPiece(Loc); |
Fariborz Jahanian | 4bef462 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2331 | KeyIdents.push_back(SelIdent); |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2332 | if (!SelIdent && Tok.isNot(tok::colon)) |
| 2333 | break; |
| 2334 | } |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2335 | } |
Fariborz Jahanian | 76a9427 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2336 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 152dd81 | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2337 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Sebastian Redl | cb6e2c6 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2338 | return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 2339 | LParenLoc, RParenLoc)); |
Gabor Greif | 24032f1 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 2340 | } |