Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1 | //===--- ParseObjC.cpp - Objective C Parsing ------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Objective-C portions of the Parser interface. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 16 | #include "RAIIObjectsForParser.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/DeclSpec.h" |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 18 | #include "clang/Sema/PrettyDeclStackTrace.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Scope.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | using namespace clang; |
| 22 | |
| 23 | |
Chris Lattner | 891dca6 | 2008-12-08 21:53:24 +0000 | [diff] [blame] | 24 | /// ParseObjCAtDirectives - Handle parts of the external-declaration production: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | /// external-declaration: [C99 6.9] |
| 26 | /// [OBJC] objc-class-definition |
Steve Naroff | 91fa0b7 | 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' |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 32 | Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 35 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 36 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 37 | cutOffParsing(); |
| 38 | return DeclGroupPtrTy(); |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 39 | } |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 40 | |
| 41 | Decl *SingleDecl = 0; |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 42 | switch (Tok.getObjCKeywordID()) { |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 43 | case tok::objc_class: |
| 44 | return ParseObjCAtClassDeclaration(AtLoc); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 45 | break; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 46 | case tok::objc_interface: { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 47 | ParsedAttributes attrs(AttrFactory); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 48 | SingleDecl = ParseObjCAtInterfaceDeclaration(AtLoc, attrs); |
| 49 | break; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 50 | } |
| 51 | case tok::objc_protocol: { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 52 | ParsedAttributes attrs(AttrFactory); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 53 | SingleDecl = ParseObjCAtProtocolDeclaration(AtLoc, attrs); |
| 54 | break; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 55 | } |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 56 | case tok::objc_implementation: |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 57 | SingleDecl = ParseObjCAtImplementationDeclaration(AtLoc); |
| 58 | break; |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 59 | case tok::objc_end: |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 60 | return ParseObjCAtEndDeclaration(AtLoc); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 61 | break; |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 62 | case tok::objc_compatibility_alias: |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 63 | SingleDecl = ParseObjCAtAliasDeclaration(AtLoc); |
| 64 | break; |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 65 | case tok::objc_synthesize: |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 66 | SingleDecl = ParseObjCPropertySynthesize(AtLoc); |
| 67 | break; |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 68 | case tok::objc_dynamic: |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 69 | SingleDecl = ParseObjCPropertyDynamic(AtLoc); |
| 70 | break; |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 71 | default: |
| 72 | Diag(AtLoc, diag::err_unexpected_at); |
| 73 | SkipUntil(tok::semi); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 74 | SingleDecl = 0; |
| 75 | break; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | } |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 77 | return Actions.ConvertDeclToDeclGroup(SingleDecl); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 81 | /// objc-class-declaration: |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 82 | /// '@' 'class' identifier-list ';' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | /// |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 84 | Parser::DeclGroupPtrTy |
| 85 | Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 86 | ConsumeToken(); // the identifier "class" |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 87 | SmallVector<IdentifierInfo *, 8> ClassNames; |
| 88 | SmallVector<SourceLocation, 8> ClassLocs; |
Ted Kremenek | c09cba6 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 89 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 91 | while (1) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 92 | if (Tok.isNot(tok::identifier)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | Diag(Tok, diag::err_expected_ident); |
| 94 | SkipUntil(tok::semi); |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 95 | return Actions.ConvertDeclToDeclGroup(0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 96 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | ClassNames.push_back(Tok.getIdentifierInfo()); |
Ted Kremenek | c09cba6 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 98 | ClassLocs.push_back(Tok.getLocation()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 99 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 101 | if (Tok.isNot(tok::comma)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 102 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 104 | ConsumeToken(); |
| 105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 107 | // Consume the ';'. |
| 108 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class")) |
Fariborz Jahanian | 95ed778 | 2011-08-27 20:50:59 +0000 | [diff] [blame] | 109 | return Actions.ConvertDeclToDeclGroup(0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | c09cba6 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 111 | return Actions.ActOnForwardClassDeclaration(atLoc, ClassNames.data(), |
| 112 | ClassLocs.data(), |
| 113 | ClassNames.size()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 116 | /// |
| 117 | /// objc-interface: |
| 118 | /// objc-class-interface-attributes[opt] objc-class-interface |
| 119 | /// objc-category-interface |
| 120 | /// |
| 121 | /// objc-class-interface: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | /// '@' 'interface' identifier objc-superclass[opt] |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 123 | /// objc-protocol-refs[opt] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | /// objc-class-instance-variables[opt] |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 125 | /// objc-interface-decl-list |
| 126 | /// @end |
| 127 | /// |
| 128 | /// objc-category-interface: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 129 | /// '@' 'interface' identifier '(' identifier[opt] ')' |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 130 | /// objc-protocol-refs[opt] |
| 131 | /// objc-interface-decl-list |
| 132 | /// @end |
| 133 | /// |
| 134 | /// objc-superclass: |
| 135 | /// ':' identifier |
| 136 | /// |
| 137 | /// objc-class-interface-attributes: |
| 138 | /// __attribute__((visibility("default"))) |
| 139 | /// __attribute__((visibility("hidden"))) |
| 140 | /// __attribute__((deprecated)) |
| 141 | /// __attribute__((unavailable)) |
| 142 | /// __attribute__((objc_exception)) - used by NSException on 64-bit |
| 143 | /// |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 144 | Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, |
| 145 | ParsedAttributes &attrs) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 146 | assert(Tok.isObjCAtKeyword(tok::objc_interface) && |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 147 | "ParseObjCAtInterfaceDeclaration(): Expected @interface"); |
| 148 | ConsumeToken(); // the "interface" identifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 150 | // Code completion after '@interface'. |
| 151 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 152 | Actions.CodeCompleteObjCInterfaceDecl(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 153 | cutOffParsing(); |
| 154 | return 0; |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 157 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 158 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 159 | return 0; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 160 | } |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 161 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 162 | // We have a class or category name - consume it. |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 163 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 164 | SourceLocation nameLoc = ConsumeToken(); |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 165 | if (Tok.is(tok::l_paren) && |
| 166 | !isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category. |
Douglas Gregor | 13d05ac | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 167 | SourceLocation LParenLoc = ConsumeParen(); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 168 | SourceLocation categoryLoc, rparenLoc; |
| 169 | IdentifierInfo *categoryId = 0; |
Douglas Gregor | 33ced0b | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 170 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 171 | Actions.CodeCompleteObjCInterfaceCategory(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 172 | cutOffParsing(); |
| 173 | return 0; |
Douglas Gregor | 33ced0b | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Steve Naroff | 527fe23 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 176 | // For ObjC2, the category name is optional (not an error). |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 177 | if (Tok.is(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 178 | categoryId = Tok.getIdentifierInfo(); |
| 179 | categoryLoc = ConsumeToken(); |
Fariborz Jahanian | 05511fa | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 180 | } |
Fariborz Jahanian | 05511fa | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 181 | else if (!getLang().ObjC2) { |
Steve Naroff | 527fe23 | 2007-08-23 19:56:30 +0000 | [diff] [blame] | 182 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 183 | return 0; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 184 | } |
Douglas Gregor | 13d05ac | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 185 | |
| 186 | rparenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 187 | if (rparenLoc.isInvalid()) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 188 | return 0; |
Douglas Gregor | 13d05ac | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 189 | |
| 190 | if (!attrs.empty()) { // categories don't support attributes. |
| 191 | Diag(nameLoc, diag::err_objc_no_attributes_on_category); |
| 192 | attrs.clear(); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 193 | } |
Douglas Gregor | 13d05ac | 2011-09-23 19:19:41 +0000 | [diff] [blame] | 194 | |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 195 | // Next, we need to check for any protocol references. |
| 196 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 197 | SmallVector<Decl *, 8> ProtocolRefs; |
| 198 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 199 | if (Tok.is(tok::less) && |
| 200 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 201 | LAngleLoc, EndProtoLoc)) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 202 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 203 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 204 | Decl *CategoryType = |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 205 | Actions.ActOnStartCategoryInterface(atLoc, |
| 206 | nameId, nameLoc, |
| 207 | categoryId, categoryLoc, |
| 208 | ProtocolRefs.data(), |
| 209 | ProtocolRefs.size(), |
| 210 | ProtocolLocs.data(), |
| 211 | EndProtoLoc); |
Fariborz Jahanian | e6f07f5 | 2011-08-19 18:02:47 +0000 | [diff] [blame] | 212 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 213 | if (Tok.is(tok::l_brace)) |
| 214 | ParseObjCClassInstanceVariables(CategoryType, tok::objc_private, atLoc); |
| 215 | |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 216 | ParseObjCInterfaceDeclList(tok::objc_not_keyword, CategoryType); |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 217 | return CategoryType; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 218 | } |
| 219 | // Parse a class interface. |
| 220 | IdentifierInfo *superClassId = 0; |
| 221 | SourceLocation superClassLoc; |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 222 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 223 | if (Tok.is(tok::colon)) { // a super class is specified. |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 224 | ConsumeToken(); |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 225 | |
| 226 | // Code completion of superclass names. |
| 227 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 228 | Actions.CodeCompleteObjCSuperclass(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 229 | cutOffParsing(); |
| 230 | return 0; |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 233 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 234 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 235 | return 0; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 236 | } |
| 237 | superClassId = Tok.getIdentifierInfo(); |
| 238 | superClassLoc = ConsumeToken(); |
| 239 | } |
| 240 | // Next, we need to check for any protocol references. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 241 | SmallVector<Decl *, 8> ProtocolRefs; |
| 242 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 243 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 244 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 245 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, true, |
| 246 | LAngleLoc, EndProtoLoc)) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 247 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 249 | Decl *ClsType = |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 250 | Actions.ActOnStartClassInterface(atLoc, nameId, nameLoc, |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 251 | superClassId, superClassLoc, |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 252 | ProtocolRefs.data(), ProtocolRefs.size(), |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 253 | ProtocolLocs.data(), |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 254 | EndProtoLoc, attrs.getList()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 255 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 256 | if (Tok.is(tok::l_brace)) |
Fariborz Jahanian | 83c481a | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 257 | ParseObjCClassInstanceVariables(ClsType, tok::objc_protected, atLoc); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 258 | |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 259 | ParseObjCInterfaceDeclList(tok::objc_interface, ClsType); |
Fariborz Jahanian | 5512ba5 | 2010-04-26 21:18:08 +0000 | [diff] [blame] | 260 | return ClsType; |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 261 | } |
| 262 | |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 263 | /// The Objective-C property callback. This should be defined where |
| 264 | /// it's used, but instead it's been lifted to here to support VS2005. |
| 265 | struct Parser::ObjCPropertyCallback : FieldCallback { |
| 266 | Parser &P; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 267 | SmallVectorImpl<Decl *> &Props; |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 268 | ObjCDeclSpec &OCDS; |
| 269 | SourceLocation AtLoc; |
| 270 | tok::ObjCKeywordKind MethodImplKind; |
| 271 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 272 | ObjCPropertyCallback(Parser &P, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 273 | SmallVectorImpl<Decl *> &Props, |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 274 | ObjCDeclSpec &OCDS, SourceLocation AtLoc, |
| 275 | tok::ObjCKeywordKind MethodImplKind) : |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 276 | P(P), Props(Props), OCDS(OCDS), AtLoc(AtLoc), |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 277 | MethodImplKind(MethodImplKind) { |
| 278 | } |
| 279 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 280 | Decl *invoke(FieldDeclarator &FD) { |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 281 | if (FD.D.getIdentifier() == 0) { |
| 282 | P.Diag(AtLoc, diag::err_objc_property_requires_field_name) |
| 283 | << FD.D.getSourceRange(); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 284 | return 0; |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 285 | } |
| 286 | if (FD.BitfieldSize) { |
| 287 | P.Diag(AtLoc, diag::err_objc_property_bitfield) |
| 288 | << FD.D.getSourceRange(); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 289 | return 0; |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | // Install the property declarator into interfaceDecl. |
| 293 | IdentifierInfo *SelName = |
| 294 | OCDS.getGetterName() ? OCDS.getGetterName() : FD.D.getIdentifier(); |
| 295 | |
| 296 | Selector GetterSel = |
| 297 | P.PP.getSelectorTable().getNullarySelector(SelName); |
| 298 | IdentifierInfo *SetterName = OCDS.getSetterName(); |
| 299 | Selector SetterSel; |
| 300 | if (SetterName) |
| 301 | SetterSel = P.PP.getSelectorTable().getSelector(1, &SetterName); |
| 302 | else |
| 303 | SetterSel = SelectorTable::constructSetterName(P.PP.getIdentifierTable(), |
| 304 | P.PP.getSelectorTable(), |
| 305 | FD.D.getIdentifier()); |
| 306 | bool isOverridingProperty = false; |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 307 | Decl *Property = |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 308 | P.Actions.ActOnProperty(P.getCurScope(), AtLoc, FD, OCDS, |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 309 | GetterSel, SetterSel, |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 310 | &isOverridingProperty, |
| 311 | MethodImplKind); |
| 312 | if (!isOverridingProperty) |
| 313 | Props.push_back(Property); |
| 314 | |
| 315 | return Property; |
| 316 | } |
| 317 | }; |
| 318 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 319 | /// objc-interface-decl-list: |
| 320 | /// empty |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 321 | /// objc-interface-decl-list objc-property-decl [OBJC2] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 322 | /// objc-interface-decl-list objc-method-requirement [OBJC2] |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 323 | /// objc-interface-decl-list objc-method-proto ';' |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 324 | /// objc-interface-decl-list declaration |
| 325 | /// objc-interface-decl-list ';' |
| 326 | /// |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 327 | /// objc-method-requirement: [OBJC2] |
| 328 | /// @required |
| 329 | /// @optional |
| 330 | /// |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 331 | void Parser::ParseObjCInterfaceDeclList(tok::ObjCKeywordKind contextKey, |
| 332 | Decl *CDecl) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 333 | SmallVector<Decl *, 32> allMethods; |
| 334 | SmallVector<Decl *, 16> allProperties; |
| 335 | SmallVector<DeclGroupPtrTy, 8> allTUVariables; |
Fariborz Jahanian | 0093359 | 2007-09-18 00:25:23 +0000 | [diff] [blame] | 336 | tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 337 | |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 338 | SourceRange AtEnd; |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 339 | |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 340 | while (1) { |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 341 | // If this is a method prototype, parse it. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 342 | if (Tok.is(tok::minus) || Tok.is(tok::plus)) { |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 343 | Decl *methodPrototype = |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 344 | ParseObjCMethodPrototype(MethodImplKind, false); |
Fariborz Jahanian | 25e077d | 2007-09-17 21:07:36 +0000 | [diff] [blame] | 345 | allMethods.push_back(methodPrototype); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 346 | // Consume the ';' here, since ParseObjCMethodPrototype() is re-used for |
| 347 | // method definitions. |
Chris Lattner | b6d74a1 | 2009-02-15 22:24:30 +0000 | [diff] [blame] | 348 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after_method_proto, |
| 349 | "", tok::semi); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 350 | continue; |
| 351 | } |
Fariborz Jahanian | 05511fa | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 352 | if (Tok.is(tok::l_paren)) { |
| 353 | Diag(Tok, diag::err_expected_minus_or_plus); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 354 | ParseObjCMethodDecl(Tok.getLocation(), |
| 355 | tok::minus, |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 356 | MethodImplKind, false); |
Fariborz Jahanian | 05511fa | 2010-04-02 23:15:40 +0000 | [diff] [blame] | 357 | continue; |
| 358 | } |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 359 | // Ignore excess semicolons. |
| 360 | if (Tok.is(tok::semi)) { |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 361 | ConsumeToken(); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 362 | continue; |
| 363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 364 | |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 365 | // If we got to the end of the file, exit the loop. |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 366 | if (Tok.is(tok::eof)) |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 367 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | |
Douglas Gregor | b6ac245 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 369 | // Code completion within an Objective-C interface. |
| 370 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 371 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 372 | ObjCImpDecl? Sema::PCC_ObjCImplementation |
| 373 | : Sema::PCC_ObjCInterface); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 374 | return cutOffParsing(); |
Douglas Gregor | b6ac245 | 2010-01-13 21:24:21 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 377 | // If we don't have an @ directive, parse it as a function definition. |
| 378 | if (Tok.isNot(tok::at)) { |
Chris Lattner | 1fd8011 | 2009-01-09 04:34:13 +0000 | [diff] [blame] | 379 | // The code below does not consume '}'s because it is afraid of eating the |
| 380 | // end of a namespace. Because of the way this code is structured, an |
| 381 | // erroneous r_brace would cause an infinite loop if not handled here. |
| 382 | if (Tok.is(tok::r_brace)) |
| 383 | break; |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 384 | ParsedAttributes attrs(AttrFactory); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 385 | allTUVariables.push_back(ParseDeclarationOrFunctionDefinition(attrs)); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 386 | continue; |
| 387 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 389 | // Otherwise, we have an @ directive, eat the @. |
| 390 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 391 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 392 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 393 | return cutOffParsing(); |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 394 | break; |
| 395 | } |
| 396 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 397 | tok::ObjCKeywordKind DirectiveKind = Tok.getObjCKeywordID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 399 | if (DirectiveKind == tok::objc_end) { // @end -> terminate list |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 400 | AtEnd.setBegin(AtLoc); |
| 401 | AtEnd.setEnd(Tok.getLocation()); |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 402 | break; |
Douglas Gregor | c3d43b7 | 2010-03-16 06:04:47 +0000 | [diff] [blame] | 403 | } else if (DirectiveKind == tok::objc_not_keyword) { |
| 404 | Diag(Tok, diag::err_objc_unknown_at); |
| 405 | SkipUntil(tok::semi); |
| 406 | continue; |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 407 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 409 | // Eat the identifier. |
| 410 | ConsumeToken(); |
| 411 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 412 | switch (DirectiveKind) { |
| 413 | default: |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 414 | // FIXME: If someone forgets an @end on a protocol, this loop will |
| 415 | // continue to eat up tons of stuff and spew lots of nonsense errors. It |
| 416 | // would probably be better to bail out if we saw an @class or @interface |
| 417 | // or something like that. |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 418 | Diag(AtLoc, diag::err_objc_illegal_interface_qual); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 419 | // Skip until we see an '@' or '}' or ';'. |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 420 | SkipUntil(tok::r_brace, tok::at); |
| 421 | break; |
Fariborz Jahanian | 46d545e | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 422 | |
| 423 | case tok::objc_implementation: |
Fariborz Jahanian | df81c2c | 2010-11-09 20:38:00 +0000 | [diff] [blame] | 424 | case tok::objc_interface: |
Fariborz Jahanian | 46d545e | 2010-11-02 00:44:43 +0000 | [diff] [blame] | 425 | Diag(Tok, diag::err_objc_missing_end); |
| 426 | ConsumeToken(); |
| 427 | break; |
| 428 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 429 | case tok::objc_required: |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 430 | case tok::objc_optional: |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 431 | // This is only valid on protocols. |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 432 | // FIXME: Should this check for ObjC2 being enabled? |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 433 | if (contextKey != tok::objc_protocol) |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 434 | Diag(AtLoc, diag::err_objc_directive_only_in_protocol); |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 435 | else |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 436 | MethodImplKind = DirectiveKind; |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 437 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 439 | case tok::objc_property: |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 440 | if (!getLang().ObjC2) |
Chris Lattner | b321c0c | 2010-12-17 05:40:22 +0000 | [diff] [blame] | 441 | Diag(AtLoc, diag::err_objc_properties_require_objc2); |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 442 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 443 | ObjCDeclSpec OCDS; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 444 | // Parse property attribute list, if any. |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 445 | if (Tok.is(tok::l_paren)) |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 446 | ParseObjCPropertyAttribute(OCDS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 447 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 448 | ObjCPropertyCallback Callback(*this, allProperties, |
John McCall | d001454 | 2009-12-03 22:31:13 +0000 | [diff] [blame] | 449 | OCDS, AtLoc, MethodImplKind); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 450 | |
Chris Lattner | e82a10f | 2008-10-20 05:46:22 +0000 | [diff] [blame] | 451 | // Parse all the comma separated declarators. |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 452 | DeclSpec DS(AttrFactory); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 453 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 454 | |
John McCall | 7da19ea | 2011-03-26 01:53:26 +0000 | [diff] [blame] | 455 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 456 | break; |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 457 | } |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 458 | } |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 459 | |
| 460 | // We break out of the big loop in two cases: when we see @end or when we see |
| 461 | // EOF. In the former case, eat the @end. In the later case, emit an error. |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 462 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 463 | Actions.CodeCompleteObjCAtDirective(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 464 | return cutOffParsing(); |
Douglas Gregor | c464ae8 | 2009-12-07 09:27:33 +0000 | [diff] [blame] | 465 | } else if (Tok.isObjCAtKeyword(tok::objc_end)) |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 466 | ConsumeToken(); // the "end" identifier |
| 467 | else |
| 468 | Diag(Tok, diag::err_objc_missing_end); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Chris Lattner | a2449b2 | 2008-10-20 05:57:40 +0000 | [diff] [blame] | 470 | // Insert collected methods declarations into the @interface object. |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 471 | // This passes in an invalid SourceLocation for AtEndLoc when EOF is hit. |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 472 | Actions.ActOnAtEnd(getCurScope(), AtEnd, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 473 | allMethods.data(), allMethods.size(), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 474 | allProperties.data(), allProperties.size(), |
| 475 | allTUVariables.data(), allTUVariables.size()); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 478 | /// Parse property attribute declarations. |
| 479 | /// |
| 480 | /// property-attr-decl: '(' property-attrlist ')' |
| 481 | /// property-attrlist: |
| 482 | /// property-attribute |
| 483 | /// property-attrlist ',' property-attribute |
| 484 | /// property-attribute: |
| 485 | /// getter '=' identifier |
| 486 | /// setter '=' identifier ':' |
| 487 | /// readonly |
| 488 | /// readwrite |
| 489 | /// assign |
| 490 | /// retain |
| 491 | /// copy |
| 492 | /// nonatomic |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 493 | /// atomic |
| 494 | /// strong |
| 495 | /// weak |
| 496 | /// unsafe_unretained |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 497 | /// |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 498 | void Parser::ParseObjCPropertyAttribute(ObjCDeclSpec &DS) { |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 499 | assert(Tok.getKind() == tok::l_paren); |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 500 | SourceLocation LHSLoc = ConsumeParen(); // consume '(' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 502 | while (1) { |
Steve Naroff | ece8e71 | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 503 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 504 | Actions.CodeCompleteObjCPropertyFlags(getCurScope(), DS); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 505 | return cutOffParsing(); |
Steve Naroff | ece8e71 | 2009-10-08 21:55:05 +0000 | [diff] [blame] | 506 | } |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 507 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | |
Chris Lattner | f6ed855 | 2008-10-20 07:22:18 +0000 | [diff] [blame] | 509 | // If this is not an identifier at all, bail out early. |
| 510 | if (II == 0) { |
| 511 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
| 512 | return; |
| 513 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 514 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 515 | SourceLocation AttrName = ConsumeToken(); // consume last attribute name |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 516 | |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 517 | if (II->isStr("readonly")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 518 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readonly); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 519 | else if (II->isStr("assign")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 520 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_assign); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 521 | else if (II->isStr("unsafe_unretained")) |
| 522 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_unsafe_unretained); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 523 | else if (II->isStr("readwrite")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 524 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_readwrite); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 525 | else if (II->isStr("retain")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 526 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_retain); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 527 | else if (II->isStr("strong")) |
| 528 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_strong); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 529 | else if (II->isStr("copy")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 530 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_copy); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 531 | else if (II->isStr("nonatomic")) |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 532 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_nonatomic); |
Fariborz Jahanian | 45937ae | 2011-06-11 00:45:12 +0000 | [diff] [blame] | 533 | else if (II->isStr("atomic")) |
| 534 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_atomic); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 535 | else if (II->isStr("weak")) |
| 536 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_weak); |
Chris Lattner | 92e62b0 | 2008-11-20 04:42:34 +0000 | [diff] [blame] | 537 | else if (II->isStr("getter") || II->isStr("setter")) { |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 538 | bool IsSetter = II->getNameStart()[0] == 's'; |
| 539 | |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 540 | // getter/setter require extra treatment. |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 541 | unsigned DiagID = IsSetter ? diag::err_objc_expected_equal_for_setter : |
| 542 | diag::err_objc_expected_equal_for_getter; |
| 543 | |
| 544 | if (ExpectAndConsume(tok::equal, DiagID, "", tok::r_paren)) |
Chris Lattner | dd5b5f2 | 2008-10-20 07:00:43 +0000 | [diff] [blame] | 545 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | |
Douglas Gregor | 4ad9685 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 547 | if (Tok.is(tok::code_completion)) { |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 548 | if (IsSetter) |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 549 | Actions.CodeCompleteObjCPropertySetter(getCurScope()); |
Douglas Gregor | 4ad9685 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 550 | else |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 551 | Actions.CodeCompleteObjCPropertyGetter(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 552 | return cutOffParsing(); |
Douglas Gregor | 4ad9685 | 2009-11-19 07:41:15 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 555 | |
| 556 | SourceLocation SelLoc; |
| 557 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(SelLoc); |
| 558 | |
| 559 | if (!SelIdent) { |
| 560 | Diag(Tok, diag::err_objc_expected_selector_for_getter_setter) |
| 561 | << IsSetter; |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 562 | SkipUntil(tok::r_paren); |
| 563 | return; |
| 564 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 566 | if (IsSetter) { |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 567 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_setter); |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 568 | DS.setSetterName(SelIdent); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 569 | |
Fariborz Jahanian | e0097db | 2010-02-15 22:20:11 +0000 | [diff] [blame] | 570 | if (ExpectAndConsume(tok::colon, |
| 571 | diag::err_expected_colon_after_setter_name, "", |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 572 | tok::r_paren)) |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 573 | return; |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 574 | } else { |
| 575 | DS.setPropertyAttributes(ObjCDeclSpec::DQ_PR_getter); |
Anders Carlsson | 42499be | 2010-10-02 17:45:21 +0000 | [diff] [blame] | 576 | DS.setGetterName(SelIdent); |
Chris Lattner | 8ca329c | 2008-10-20 07:24:39 +0000 | [diff] [blame] | 577 | } |
Chris Lattner | e00da7c | 2008-10-20 07:39:53 +0000 | [diff] [blame] | 578 | } else { |
Chris Lattner | a9500f0 | 2008-11-19 07:49:38 +0000 | [diff] [blame] | 579 | Diag(AttrName, diag::err_objc_expected_property_attr) << II; |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 580 | SkipUntil(tok::r_paren); |
| 581 | return; |
Chris Lattner | cd9f4b3 | 2008-10-20 07:15:22 +0000 | [diff] [blame] | 582 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 583 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 584 | if (Tok.isNot(tok::comma)) |
| 585 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 586 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 587 | ConsumeToken(); |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 588 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 589 | |
Chris Lattner | 156b061 | 2008-10-20 07:37:22 +0000 | [diff] [blame] | 590 | MatchRHSPunctuation(tok::r_paren, LHSLoc); |
Fariborz Jahanian | d0f97d1 | 2007-08-31 16:11:31 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 593 | /// objc-method-proto: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 594 | /// objc-instance-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 595 | /// objc-class-method objc-method-decl objc-method-attributes[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 596 | /// |
| 597 | /// objc-instance-method: '-' |
| 598 | /// objc-class-method: '+' |
| 599 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 600 | /// objc-method-attributes: [OBJC2] |
| 601 | /// __attribute__((deprecated)) |
| 602 | /// |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 603 | Decl *Parser::ParseObjCMethodPrototype(tok::ObjCKeywordKind MethodImplKind, |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 604 | bool MethodDefinition) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 605 | assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-"); |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 606 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 607 | tok::TokenKind methodType = Tok.getKind(); |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 608 | SourceLocation mLoc = ConsumeToken(); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 609 | Decl *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind, |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 610 | MethodDefinition); |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 611 | // Since this rule is used for both method declarations and definitions, |
Steve Naroff | 2bd42fa | 2007-09-10 20:51:04 +0000 | [diff] [blame] | 612 | // the caller is (optionally) responsible for consuming the ';'. |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 613 | return MDecl; |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /// objc-selector: |
| 617 | /// identifier |
| 618 | /// one of |
| 619 | /// enum struct union if else while do for switch case default |
| 620 | /// break continue return goto asm sizeof typeof __alignof |
| 621 | /// unsigned long const short volatile signed restrict _Complex |
| 622 | /// in out inout bycopy byref oneway int char float double void _Bool |
| 623 | /// |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 624 | IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) { |
Fariborz Jahanian | be74740 | 2010-09-03 01:26:16 +0000 | [diff] [blame] | 625 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 626 | switch (Tok.getKind()) { |
| 627 | default: |
| 628 | return 0; |
Fariborz Jahanian | afbc681 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 629 | case tok::ampamp: |
| 630 | case tok::ampequal: |
| 631 | case tok::amp: |
| 632 | case tok::pipe: |
| 633 | case tok::tilde: |
| 634 | case tok::exclaim: |
| 635 | case tok::exclaimequal: |
| 636 | case tok::pipepipe: |
| 637 | case tok::pipeequal: |
| 638 | case tok::caret: |
| 639 | case tok::caretequal: { |
Fariborz Jahanian | 3846ca2 | 2010-09-03 18:01:09 +0000 | [diff] [blame] | 640 | std::string ThisTok(PP.getSpelling(Tok)); |
Fariborz Jahanian | afbc681 | 2010-09-03 17:33:04 +0000 | [diff] [blame] | 641 | if (isalpha(ThisTok[0])) { |
| 642 | IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data()); |
| 643 | Tok.setKind(tok::identifier); |
| 644 | SelectorLoc = ConsumeToken(); |
| 645 | return II; |
| 646 | } |
| 647 | return 0; |
| 648 | } |
| 649 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 650 | case tok::identifier: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 651 | case tok::kw_asm: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 652 | case tok::kw_auto: |
Chris Lattner | 9298d96 | 2007-11-15 05:25:19 +0000 | [diff] [blame] | 653 | case tok::kw_bool: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 654 | case tok::kw_break: |
| 655 | case tok::kw_case: |
| 656 | case tok::kw_catch: |
| 657 | case tok::kw_char: |
| 658 | case tok::kw_class: |
| 659 | case tok::kw_const: |
| 660 | case tok::kw_const_cast: |
| 661 | case tok::kw_continue: |
| 662 | case tok::kw_default: |
| 663 | case tok::kw_delete: |
| 664 | case tok::kw_do: |
| 665 | case tok::kw_double: |
| 666 | case tok::kw_dynamic_cast: |
| 667 | case tok::kw_else: |
| 668 | case tok::kw_enum: |
| 669 | case tok::kw_explicit: |
| 670 | case tok::kw_export: |
| 671 | case tok::kw_extern: |
| 672 | case tok::kw_false: |
| 673 | case tok::kw_float: |
| 674 | case tok::kw_for: |
| 675 | case tok::kw_friend: |
| 676 | case tok::kw_goto: |
| 677 | case tok::kw_if: |
| 678 | case tok::kw_inline: |
| 679 | case tok::kw_int: |
| 680 | case tok::kw_long: |
| 681 | case tok::kw_mutable: |
| 682 | case tok::kw_namespace: |
| 683 | case tok::kw_new: |
| 684 | case tok::kw_operator: |
| 685 | case tok::kw_private: |
| 686 | case tok::kw_protected: |
| 687 | case tok::kw_public: |
| 688 | case tok::kw_register: |
| 689 | case tok::kw_reinterpret_cast: |
| 690 | case tok::kw_restrict: |
| 691 | case tok::kw_return: |
| 692 | case tok::kw_short: |
| 693 | case tok::kw_signed: |
| 694 | case tok::kw_sizeof: |
| 695 | case tok::kw_static: |
| 696 | case tok::kw_static_cast: |
| 697 | case tok::kw_struct: |
| 698 | case tok::kw_switch: |
| 699 | case tok::kw_template: |
| 700 | case tok::kw_this: |
| 701 | case tok::kw_throw: |
| 702 | case tok::kw_true: |
| 703 | case tok::kw_try: |
| 704 | case tok::kw_typedef: |
| 705 | case tok::kw_typeid: |
| 706 | case tok::kw_typename: |
| 707 | case tok::kw_typeof: |
| 708 | case tok::kw_union: |
| 709 | case tok::kw_unsigned: |
| 710 | case tok::kw_using: |
| 711 | case tok::kw_virtual: |
| 712 | case tok::kw_void: |
| 713 | case tok::kw_volatile: |
| 714 | case tok::kw_wchar_t: |
| 715 | case tok::kw_while: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 716 | case tok::kw__Bool: |
| 717 | case tok::kw__Complex: |
Anders Carlsson | ef048ef | 2008-08-23 21:00:01 +0000 | [diff] [blame] | 718 | case tok::kw___alignof: |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 719 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 720 | SelectorLoc = ConsumeToken(); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 721 | return II; |
Fariborz Jahanian | d064951 | 2007-09-27 19:52:15 +0000 | [diff] [blame] | 722 | } |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 725 | /// objc-for-collection-in: 'in' |
| 726 | /// |
Fariborz Jahanian | 335a2d4 | 2008-01-04 23:04:08 +0000 | [diff] [blame] | 727 | bool Parser::isTokIdentifier_in() const { |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 728 | // FIXME: May have to do additional look-ahead to only allow for |
| 729 | // valid tokens following an 'in'; such as an identifier, unary operators, |
| 730 | // '[' etc. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | return (getLang().ObjC2 && Tok.is(tok::identifier) && |
Chris Lattner | 5ffb14b | 2008-08-23 02:02:23 +0000 | [diff] [blame] | 732 | Tok.getIdentifierInfo() == ObjCTypeQuals[objc_in]); |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 735 | /// ParseObjCTypeQualifierList - This routine parses the objective-c's type |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 736 | /// qualifier list and builds their bitmask representation in the input |
| 737 | /// argument. |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 738 | /// |
| 739 | /// objc-type-qualifiers: |
| 740 | /// objc-type-qualifier |
| 741 | /// objc-type-qualifiers objc-type-qualifier |
| 742 | /// |
Douglas Gregor | b77cab9 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 743 | void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 744 | Declarator::TheContext Context) { |
| 745 | assert(Context == Declarator::ObjCParameterContext || |
| 746 | Context == Declarator::ObjCResultContext); |
| 747 | |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 748 | while (1) { |
Douglas Gregor | d32b022 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 749 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | b77cab9 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 750 | Actions.CodeCompleteObjCPassingType(getCurScope(), DS, |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 751 | Context == Declarator::ObjCParameterContext); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 752 | return cutOffParsing(); |
Douglas Gregor | d32b022 | 2010-08-24 01:06:58 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 755 | if (Tok.isNot(tok::identifier)) |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 756 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 758 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 759 | for (unsigned i = 0; i != objc_NumQuals; ++i) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 760 | if (II != ObjCTypeQuals[i]) |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 761 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 763 | ObjCDeclSpec::ObjCDeclQualifier Qual; |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 764 | switch (i) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 765 | default: llvm_unreachable("Unknown decl qualifier"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 766 | case objc_in: Qual = ObjCDeclSpec::DQ_In; break; |
| 767 | case objc_out: Qual = ObjCDeclSpec::DQ_Out; break; |
| 768 | case objc_inout: Qual = ObjCDeclSpec::DQ_Inout; break; |
| 769 | case objc_oneway: Qual = ObjCDeclSpec::DQ_Oneway; break; |
| 770 | case objc_bycopy: Qual = ObjCDeclSpec::DQ_Bycopy; break; |
| 771 | case objc_byref: Qual = ObjCDeclSpec::DQ_Byref; break; |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 772 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 773 | DS.setObjCDeclQualifier(Qual); |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 774 | ConsumeToken(); |
| 775 | II = 0; |
| 776 | break; |
| 777 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 778 | |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 779 | // If this wasn't a recognized qualifier, bail out. |
| 780 | if (II) return; |
| 781 | } |
| 782 | } |
| 783 | |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 784 | /// Take all the decl attributes out of the given list and add |
| 785 | /// them to the given attribute set. |
| 786 | static void takeDeclAttributes(ParsedAttributes &attrs, |
| 787 | AttributeList *list) { |
| 788 | while (list) { |
| 789 | AttributeList *cur = list; |
| 790 | list = cur->getNext(); |
| 791 | |
| 792 | if (!cur->isUsedAsTypeAttr()) { |
| 793 | // Clear out the next pointer. We're really completely |
| 794 | // destroying the internal invariants of the declarator here, |
| 795 | // but it doesn't matter because we're done with it. |
| 796 | cur->setNext(0); |
| 797 | attrs.add(cur); |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | /// takeDeclAttributes - Take all the decl attributes from the given |
| 803 | /// declarator and add them to the given list. |
| 804 | static void takeDeclAttributes(ParsedAttributes &attrs, |
| 805 | Declarator &D) { |
| 806 | // First, take ownership of all attributes. |
| 807 | attrs.getPool().takeAllFrom(D.getAttributePool()); |
| 808 | attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool()); |
| 809 | |
| 810 | // Now actually move the attributes over. |
| 811 | takeDeclAttributes(attrs, D.getDeclSpec().getAttributes().getList()); |
| 812 | takeDeclAttributes(attrs, D.getAttributes()); |
| 813 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) |
| 814 | takeDeclAttributes(attrs, |
| 815 | const_cast<AttributeList*>(D.getTypeObject(i).getAttrs())); |
| 816 | } |
| 817 | |
Chris Lattner | e8b724d | 2007-12-12 06:56:32 +0000 | [diff] [blame] | 818 | /// objc-type-name: |
| 819 | /// '(' objc-type-qualifiers[opt] type-name ')' |
| 820 | /// '(' objc-type-qualifiers[opt] ')' |
| 821 | /// |
Douglas Gregor | b77cab9 | 2011-03-08 19:17:54 +0000 | [diff] [blame] | 822 | ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 823 | Declarator::TheContext context, |
| 824 | ParsedAttributes *paramAttrs) { |
| 825 | assert(context == Declarator::ObjCParameterContext || |
| 826 | context == Declarator::ObjCResultContext); |
| 827 | assert((paramAttrs != 0) == (context == Declarator::ObjCParameterContext)); |
| 828 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 829 | assert(Tok.is(tok::l_paren) && "expected ("); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 831 | SourceLocation LParenLoc = ConsumeParen(); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 832 | SourceLocation TypeStartLoc = Tok.getLocation(); |
Fariborz Jahanian | 9735c5e | 2011-08-22 17:59:19 +0000 | [diff] [blame] | 833 | ObjCDeclContextSwitch ObjCDC(*this); |
| 834 | |
Fariborz Jahanian | 19d74e1 | 2007-10-31 21:59:43 +0000 | [diff] [blame] | 835 | // Parse type qualifiers, in, inout, etc. |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 836 | ParseObjCTypeQualifierList(DS, context); |
Steve Naroff | 4fa7afd | 2007-08-22 23:18:22 +0000 | [diff] [blame] | 837 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 838 | ParsedType Ty; |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 839 | if (isTypeSpecifierQualifier()) { |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 840 | // Parse an abstract declarator. |
| 841 | DeclSpec declSpec(AttrFactory); |
| 842 | declSpec.setObjCQualifiers(&DS); |
| 843 | ParseSpecifierQualifierList(declSpec); |
| 844 | Declarator declarator(declSpec, context); |
| 845 | ParseDeclarator(declarator); |
| 846 | |
| 847 | // If that's not invalid, extract a type. |
| 848 | if (!declarator.isInvalidType()) { |
| 849 | TypeResult type = Actions.ActOnTypeName(getCurScope(), declarator); |
| 850 | if (!type.isInvalid()) |
| 851 | Ty = type.get(); |
| 852 | |
| 853 | // If we're parsing a parameter, steal all the decl attributes |
| 854 | // and add them to the decl spec. |
| 855 | if (context == Declarator::ObjCParameterContext) |
| 856 | takeDeclAttributes(*paramAttrs, declarator); |
| 857 | } |
| 858 | } else if (context == Declarator::ObjCResultContext && |
| 859 | Tok.is(tok::identifier)) { |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 860 | if (!Ident_instancetype) |
| 861 | Ident_instancetype = PP.getIdentifierInfo("instancetype"); |
| 862 | |
| 863 | if (Tok.getIdentifierInfo() == Ident_instancetype) { |
| 864 | Ty = Actions.ActOnObjCInstanceType(Tok.getLocation()); |
| 865 | ConsumeToken(); |
| 866 | } |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 867 | } |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 868 | |
Steve Naroff | d7333c2 | 2008-10-21 14:15:04 +0000 | [diff] [blame] | 869 | if (Tok.is(tok::r_paren)) |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 870 | ConsumeParen(); |
| 871 | else if (Tok.getLocation() == TypeStartLoc) { |
| 872 | // If we didn't eat any tokens, then this isn't a type. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 873 | Diag(Tok, diag::err_expected_type); |
Chris Lattner | 4a76b29 | 2008-10-22 03:52:06 +0000 | [diff] [blame] | 874 | SkipUntil(tok::r_paren); |
| 875 | } else { |
| 876 | // Otherwise, we found *something*, but didn't get a ')' in the right |
| 877 | // place. Emit an error then return what we have as the type. |
| 878 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 879 | } |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 880 | return Ty; |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | /// objc-method-decl: |
| 884 | /// objc-selector |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 885 | /// objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 886 | /// objc-type-name objc-selector |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 887 | /// objc-type-name objc-keyword-selector objc-parmlist[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 888 | /// |
| 889 | /// objc-keyword-selector: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | /// objc-keyword-decl |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 891 | /// objc-keyword-selector objc-keyword-decl |
| 892 | /// |
| 893 | /// objc-keyword-decl: |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 894 | /// objc-selector ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 895 | /// objc-selector ':' objc-keyword-attributes[opt] identifier |
| 896 | /// ':' objc-type-name objc-keyword-attributes[opt] identifier |
| 897 | /// ':' objc-keyword-attributes[opt] identifier |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 898 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 899 | /// objc-parmlist: |
| 900 | /// objc-parms objc-ellipsis[opt] |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 901 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 902 | /// objc-parms: |
| 903 | /// objc-parms , parameter-declaration |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 904 | /// |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 905 | /// objc-ellipsis: |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 906 | /// , ... |
| 907 | /// |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 908 | /// objc-keyword-attributes: [OBJC2] |
| 909 | /// __attribute__((unused)) |
| 910 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 911 | Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, |
Douglas Gregor | 2ccccb3 | 2010-08-23 18:23:48 +0000 | [diff] [blame] | 912 | tok::TokenKind mType, |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 913 | tok::ObjCKeywordKind MethodImplKind, |
| 914 | bool MethodDefinition) { |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 915 | ParsingDeclRAIIObject PD(*this); |
| 916 | |
Douglas Gregor | e8f5a17 | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 917 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 918 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 919 | /*ReturnType=*/ ParsedType()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 920 | cutOffParsing(); |
| 921 | return 0; |
Douglas Gregor | e8f5a17 | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 924 | // Parse the return type if present. |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 925 | ParsedType ReturnType; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 926 | ObjCDeclSpec DSRet; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 927 | if (Tok.is(tok::l_paren)) |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 928 | ReturnType = ParseObjCTypeName(DSRet, Declarator::ObjCResultContext, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Ted Kremenek | 9e04935 | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 930 | // If attributes exist before the method, parse them. |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 931 | ParsedAttributes methodAttrs(AttrFactory); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 932 | if (getLang().ObjC2) |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 933 | MaybeParseGNUAttributes(methodAttrs); |
Ted Kremenek | 9e04935 | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 934 | |
Douglas Gregor | e8f5a17 | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 935 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 936 | Actions.CodeCompleteObjCMethodDecl(getCurScope(), mType == tok::minus, |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 937 | ReturnType); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 938 | cutOffParsing(); |
| 939 | return 0; |
Douglas Gregor | e8f5a17 | 2010-04-07 00:21:17 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Ted Kremenek | 9e04935 | 2010-02-18 23:05:16 +0000 | [diff] [blame] | 942 | // Now parse the selector. |
Steve Naroff | bef1185 | 2007-10-26 20:53:56 +0000 | [diff] [blame] | 943 | SourceLocation selLoc; |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 944 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(selLoc); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 945 | |
Steve Naroff | 84c4310 | 2009-02-11 20:43:13 +0000 | [diff] [blame] | 946 | // An unnamed colon is valid. |
| 947 | if (!SelIdent && Tok.isNot(tok::colon)) { // missing selector name. |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 948 | Diag(Tok, diag::err_expected_selector_for_method) |
| 949 | << SourceRange(mLoc, Tok.getLocation()); |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 950 | // Skip until we get a ; or {}. |
| 951 | SkipUntil(tok::r_brace); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 952 | return 0; |
Chris Lattner | e8904e9 | 2008-08-23 01:48:03 +0000 | [diff] [blame] | 953 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 955 | SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 956 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 957 | // If attributes exist after the method, parse them. |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 958 | if (getLang().ObjC2) |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 959 | MaybeParseGNUAttributes(methodAttrs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 961 | Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 962 | Decl *Result |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 963 | = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 964 | mType, DSRet, ReturnType, |
Douglas Gregor | 926df6c | 2011-06-11 01:09:30 +0000 | [diff] [blame] | 965 | selLoc, Sel, 0, |
Fariborz Jahanian | 4f4fd92 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 966 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 967 | methodAttrs.getList(), MethodImplKind, |
| 968 | false, MethodDefinition); |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 969 | PD.complete(Result); |
| 970 | return Result; |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 971 | } |
Steve Naroff | f28b264 | 2007-09-05 23:30:30 +0000 | [diff] [blame] | 972 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 973 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Argyrios Kyrtzidis | 11d7716 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 974 | SmallVector<SourceLocation, 12> KeyLocs; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 975 | SmallVector<Sema::ObjCArgInfo, 12> ArgInfos; |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 976 | ParseScope PrototypeScope(this, |
| 977 | Scope::FunctionPrototypeScope|Scope::DeclScope); |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 978 | |
| 979 | AttributePool allParamAttrs(AttrFactory); |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 980 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 981 | while (1) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 982 | ParsedAttributes paramAttrs(AttrFactory); |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 983 | Sema::ObjCArgInfo ArgInfo; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 985 | // Each iteration parses a single keyword argument. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 986 | if (Tok.isNot(tok::colon)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 987 | Diag(Tok, diag::err_expected_colon); |
| 988 | break; |
| 989 | } |
| 990 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 992 | ArgInfo.Type = ParsedType(); |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 993 | if (Tok.is(tok::l_paren)) // Parse the argument type if present. |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 994 | ArgInfo.Type = ParseObjCTypeName(ArgInfo.DeclSpec, |
| 995 | Declarator::ObjCParameterContext, |
| 996 | ¶mAttrs); |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 997 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 998 | // If attributes exist before the argument name, parse them. |
John McCall | cdda47f | 2011-10-01 09:56:14 +0000 | [diff] [blame] | 999 | // Regardless, collect all the attributes we've parsed so far. |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1000 | ArgInfo.ArgAttrs = 0; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1001 | if (getLang().ObjC2) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1002 | MaybeParseGNUAttributes(paramAttrs); |
| 1003 | ArgInfo.ArgAttrs = paramAttrs.getList(); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1004 | } |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1005 | |
Douglas Gregor | 40ed9a1 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1006 | // Code completion for the next piece of the selector. |
| 1007 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 40ed9a1 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1008 | KeyIdents.push_back(SelIdent); |
| 1009 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1010 | mType == tok::minus, |
| 1011 | /*AtParameterName=*/true, |
| 1012 | ReturnType, |
| 1013 | KeyIdents.data(), |
| 1014 | KeyIdents.size()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1015 | cutOffParsing(); |
| 1016 | return 0; |
Douglas Gregor | 40ed9a1 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1019 | if (Tok.isNot(tok::identifier)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1020 | Diag(Tok, diag::err_expected_ident); // missing argument name. |
| 1021 | break; |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 1022 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1023 | |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1024 | ArgInfo.Name = Tok.getIdentifierInfo(); |
| 1025 | ArgInfo.NameLoc = Tok.getLocation(); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1026 | ConsumeToken(); // Eat the identifier. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1027 | |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1028 | ArgInfos.push_back(ArgInfo); |
| 1029 | KeyIdents.push_back(SelIdent); |
Argyrios Kyrtzidis | 11d7716 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1030 | KeyLocs.push_back(selLoc); |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1031 | |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1032 | // Make sure the attributes persist. |
| 1033 | allParamAttrs.takeAllFrom(paramAttrs.getPool()); |
| 1034 | |
Douglas Gregor | 1f5537a | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1035 | // Code completion for the next piece of the selector. |
| 1036 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 1f5537a | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1037 | Actions.CodeCompleteObjCMethodDeclSelector(getCurScope(), |
| 1038 | mType == tok::minus, |
Douglas Gregor | 40ed9a1 | 2010-07-08 23:37:41 +0000 | [diff] [blame] | 1039 | /*AtParameterName=*/false, |
Douglas Gregor | 1f5537a | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1040 | ReturnType, |
| 1041 | KeyIdents.data(), |
| 1042 | KeyIdents.size()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1043 | cutOffParsing(); |
| 1044 | return 0; |
Douglas Gregor | 1f5537a | 2010-07-08 23:20:03 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1047 | // Check for another keyword selector. |
Argyrios Kyrtzidis | 11d7716 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1048 | SelIdent = ParseObjCSelectorPiece(selLoc); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1049 | if (!SelIdent && Tok.isNot(tok::colon)) |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1050 | break; |
| 1051 | // We have a selector or a colon, continue parsing. |
Steve Naroff | 4985ace | 2007-08-22 18:35:33 +0000 | [diff] [blame] | 1052 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1054 | bool isVariadic = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1056 | // Parse the (optional) parameter list. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1057 | while (Tok.is(tok::comma)) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1058 | ConsumeToken(); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1059 | if (Tok.is(tok::ellipsis)) { |
Steve Naroff | 335eafa | 2007-11-15 12:35:21 +0000 | [diff] [blame] | 1060 | isVariadic = true; |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1061 | ConsumeToken(); |
| 1062 | break; |
| 1063 | } |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1064 | DeclSpec DS(AttrFactory); |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1065 | ParseDeclarationSpecifiers(DS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | // Parse the declarator. |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1067 | Declarator ParmDecl(DS, Declarator::PrototypeContext); |
| 1068 | ParseDeclarator(ParmDecl); |
Fariborz Jahanian | 4f4fd92 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1069 | IdentifierInfo *ParmII = ParmDecl.getIdentifier(); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1070 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDecl); |
Fariborz Jahanian | 4f4fd92 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1071 | CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 1072 | ParmDecl.getIdentifierLoc(), |
| 1073 | Param, |
| 1074 | 0)); |
| 1075 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1076 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Cameron Esfahani | 9c4bb2c | 2010-10-12 00:21:25 +0000 | [diff] [blame] | 1078 | // FIXME: Add support for optional parameter list... |
Fariborz Jahanian | e3a2ca7 | 2007-09-10 20:33:04 +0000 | [diff] [blame] | 1079 | // If attributes exist after the method, parse them. |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1080 | if (getLang().ObjC2) |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1081 | MaybeParseGNUAttributes(methodAttrs); |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1082 | |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1083 | if (KeyIdents.size() == 0) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1084 | return 0; |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1085 | |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 1086 | Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(), |
| 1087 | &KeyIdents[0]); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1088 | Decl *Result |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1089 | = Actions.ActOnMethodDeclaration(getCurScope(), mLoc, Tok.getLocation(), |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1090 | mType, DSRet, ReturnType, |
Argyrios Kyrtzidis | 11d7716 | 2011-10-03 06:36:36 +0000 | [diff] [blame] | 1091 | KeyLocs, Sel, &ArgInfos[0], |
Fariborz Jahanian | 4f4fd92 | 2010-04-08 00:30:06 +0000 | [diff] [blame] | 1092 | CParamInfo.data(), CParamInfo.size(), |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1093 | methodAttrs.getList(), |
Fariborz Jahanian | 90ba78c | 2011-03-12 18:54:30 +0000 | [diff] [blame] | 1094 | MethodImplKind, isVariadic, MethodDefinition); |
Fariborz Jahanian | 7f53253 | 2011-02-09 22:20:01 +0000 | [diff] [blame] | 1095 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 1096 | PD.complete(Result); |
| 1097 | return Result; |
Steve Naroff | 294494e | 2007-08-22 16:35:03 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1100 | /// objc-protocol-refs: |
| 1101 | /// '<' identifier-list '>' |
| 1102 | /// |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1103 | bool Parser:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1104 | ParseObjCProtocolReferences(SmallVectorImpl<Decl *> &Protocols, |
| 1105 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1106 | bool WarnOnDeclarations, |
| 1107 | SourceLocation &LAngleLoc, SourceLocation &EndLoc) { |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1108 | assert(Tok.is(tok::less) && "expected <"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1110 | LAngleLoc = ConsumeToken(); // the "<" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1112 | SmallVector<IdentifierLocPair, 8> ProtocolIdents; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1114 | while (1) { |
Douglas Gregor | 55385fe | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1115 | if (Tok.is(tok::code_completion)) { |
| 1116 | Actions.CodeCompleteObjCProtocolReferences(ProtocolIdents.data(), |
| 1117 | ProtocolIdents.size()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1118 | cutOffParsing(); |
| 1119 | return true; |
Douglas Gregor | 55385fe | 2009-11-18 04:19:12 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1122 | if (Tok.isNot(tok::identifier)) { |
| 1123 | Diag(Tok, diag::err_expected_ident); |
| 1124 | SkipUntil(tok::greater); |
| 1125 | return true; |
| 1126 | } |
| 1127 | ProtocolIdents.push_back(std::make_pair(Tok.getIdentifierInfo(), |
| 1128 | Tok.getLocation())); |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1129 | ProtocolLocs.push_back(Tok.getLocation()); |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1130 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1132 | if (Tok.isNot(tok::comma)) |
| 1133 | break; |
| 1134 | ConsumeToken(); |
| 1135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1137 | // Consume the '>'. |
| 1138 | if (Tok.isNot(tok::greater)) { |
| 1139 | Diag(Tok, diag::err_expected_greater); |
| 1140 | return true; |
| 1141 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1142 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1143 | EndLoc = ConsumeAnyToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1145 | // Convert the list of protocols identifiers into a list of protocol decls. |
| 1146 | Actions.FindProtocolDeclaration(WarnOnDeclarations, |
| 1147 | &ProtocolIdents[0], ProtocolIdents.size(), |
| 1148 | Protocols); |
| 1149 | return false; |
| 1150 | } |
| 1151 | |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1152 | /// \brief Parse the Objective-C protocol qualifiers that follow a typename |
| 1153 | /// in a decl-specifier-seq, starting at the '<'. |
Douglas Gregor | 46f936e | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1154 | bool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1155 | assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); |
| 1156 | assert(getLang().ObjC1 && "Protocol qualifiers only exist in Objective-C"); |
| 1157 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1158 | SmallVector<Decl *, 8> ProtocolDecl; |
| 1159 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Douglas Gregor | 46f936e | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1160 | bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, |
| 1161 | LAngleLoc, EndProtoLoc); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1162 | DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), |
| 1163 | ProtocolLocs.data(), LAngleLoc); |
| 1164 | if (EndProtoLoc.isValid()) |
| 1165 | DS.SetRangeEnd(EndProtoLoc); |
Douglas Gregor | 46f936e | 2010-11-19 17:10:50 +0000 | [diff] [blame] | 1166 | return Result; |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1170 | /// objc-class-instance-variables: |
| 1171 | /// '{' objc-instance-variable-decl-list[opt] '}' |
| 1172 | /// |
| 1173 | /// objc-instance-variable-decl-list: |
| 1174 | /// objc-visibility-spec |
| 1175 | /// objc-instance-variable-decl ';' |
| 1176 | /// ';' |
| 1177 | /// objc-instance-variable-decl-list objc-visibility-spec |
| 1178 | /// objc-instance-variable-decl-list objc-instance-variable-decl ';' |
| 1179 | /// objc-instance-variable-decl-list ';' |
| 1180 | /// |
| 1181 | /// objc-visibility-spec: |
| 1182 | /// @private |
| 1183 | /// @protected |
| 1184 | /// @public |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1185 | /// @package [OBJC2] |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1186 | /// |
| 1187 | /// objc-instance-variable-decl: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1188 | /// struct-declaration |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1189 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1190 | void Parser::ParseObjCClassInstanceVariables(Decl *interfaceDecl, |
Fariborz Jahanian | 83c481a | 2010-02-22 23:04:20 +0000 | [diff] [blame] | 1191 | tok::ObjCKeywordKind visibility, |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1192 | SourceLocation atLoc) { |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1193 | assert(Tok.is(tok::l_brace) && "expected {"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1194 | SmallVector<Decl *, 32> AllIvarDecls; |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1195 | |
Douglas Gregor | 1a0d31a | 2009-01-12 18:45:55 +0000 | [diff] [blame] | 1196 | ParseScope ClassScope(this, Scope::DeclScope|Scope::ClassScope); |
Argyrios Kyrtzidis | 3a38744 | 2011-10-06 23:23:20 +0000 | [diff] [blame] | 1197 | ObjCDeclContextSwitch ObjCDC(*this); |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 1198 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1199 | SourceLocation LBraceLoc = ConsumeBrace(); // the "{" |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1201 | // While we still have something to read, read the instance variables. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1202 | while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1203 | // Each iteration of this loop reads one objc-instance-variable-decl. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1204 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1205 | // Check for extraneous top-level semicolon. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1206 | if (Tok.is(tok::semi)) { |
Douglas Gregor | f13ca06 | 2010-06-16 23:08:59 +0000 | [diff] [blame] | 1207 | Diag(Tok, diag::ext_extra_ivar_semi) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1208 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1209 | ConsumeToken(); |
| 1210 | continue; |
| 1211 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1213 | // Set the default visibility to private. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1214 | if (Tok.is(tok::at)) { // parse objc-visibility-spec |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1215 | ConsumeToken(); // eat the @ sign |
Douglas Gregor | c38c3e1 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1216 | |
| 1217 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1218 | Actions.CodeCompleteObjCAtVisibility(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1219 | return cutOffParsing(); |
Douglas Gregor | c38c3e1 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1222 | switch (Tok.getObjCKeywordID()) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1223 | case tok::objc_private: |
| 1224 | case tok::objc_public: |
| 1225 | case tok::objc_protected: |
| 1226 | case tok::objc_package: |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1227 | visibility = Tok.getObjCKeywordID(); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1228 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1229 | continue; |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1230 | default: |
| 1231 | Diag(Tok, diag::err_objc_illegal_visibility_spec); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1232 | continue; |
| 1233 | } |
| 1234 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1235 | |
Douglas Gregor | c38c3e1 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1236 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1237 | Actions.CodeCompleteOrdinaryName(getCurScope(), |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1238 | Sema::PCC_ObjCInstanceVariableList); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1239 | return cutOffParsing(); |
Douglas Gregor | c38c3e1 | 2010-01-13 21:54:15 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1242 | struct ObjCIvarCallback : FieldCallback { |
| 1243 | Parser &P; |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1244 | Decl *IDecl; |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1245 | tok::ObjCKeywordKind visibility; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1246 | SmallVectorImpl<Decl *> &AllIvarDecls; |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1247 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1248 | ObjCIvarCallback(Parser &P, Decl *IDecl, tok::ObjCKeywordKind V, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1249 | SmallVectorImpl<Decl *> &AllIvarDecls) : |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1250 | P(P), IDecl(IDecl), visibility(V), AllIvarDecls(AllIvarDecls) { |
| 1251 | } |
| 1252 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1253 | Decl *invoke(FieldDeclarator &FD) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1254 | P.Actions.ActOnObjCContainerStartDefinition(IDecl); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1255 | // Install the declarator into the interface decl. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1256 | Decl *Field |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1257 | = P.Actions.ActOnIvar(P.getCurScope(), |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1258 | FD.D.getDeclSpec().getSourceRange().getBegin(), |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1259 | FD.D, FD.BitfieldSize, visibility); |
Fariborz Jahanian | 10af879 | 2011-08-29 17:33:12 +0000 | [diff] [blame] | 1260 | P.Actions.ActOnObjCContainerFinishDefinition(); |
Fariborz Jahanian | 0bd0459 | 2010-04-06 22:43:48 +0000 | [diff] [blame] | 1261 | if (Field) |
| 1262 | AllIvarDecls.push_back(Field); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1263 | return Field; |
| 1264 | } |
| 1265 | } Callback(*this, interfaceDecl, visibility, AllIvarDecls); |
Fariborz Jahanian | d097be8 | 2010-08-23 22:46:52 +0000 | [diff] [blame] | 1266 | |
Chris Lattner | e135942 | 2008-04-10 06:46:29 +0000 | [diff] [blame] | 1267 | // Parse all the comma separated declarators. |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1268 | DeclSpec DS(AttrFactory); |
John McCall | bdd563e | 2009-11-03 02:38:08 +0000 | [diff] [blame] | 1269 | ParseStructDeclaration(DS, Callback); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1270 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1271 | if (Tok.is(tok::semi)) { |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1272 | ConsumeToken(); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1273 | } else { |
| 1274 | Diag(Tok, diag::err_expected_semi_decl_list); |
| 1275 | // Skip to end of block or statement |
| 1276 | SkipUntil(tok::r_brace, true, true); |
| 1277 | } |
| 1278 | } |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1279 | SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1280 | Actions.ActOnObjCContainerStartDefinition(interfaceDecl); |
| 1281 | Actions.ActOnLastBitfield(RBraceLoc, AllIvarDecls); |
Fariborz Jahanian | 10af879 | 2011-08-29 17:33:12 +0000 | [diff] [blame] | 1282 | Actions.ActOnObjCContainerFinishDefinition(); |
Steve Naroff | 8749be5 | 2007-10-31 22:11:35 +0000 | [diff] [blame] | 1283 | // Call ActOnFields() even if we don't have any decls. This is useful |
| 1284 | // for code rewriting tools that need to be aware of the empty list. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1285 | Actions.ActOnFields(getCurScope(), atLoc, interfaceDecl, |
David Blaikie | 77b6de0 | 2011-09-22 02:58:26 +0000 | [diff] [blame] | 1286 | AllIvarDecls, |
Daniel Dunbar | 1bfe1c2 | 2008-10-03 02:03:53 +0000 | [diff] [blame] | 1287 | LBraceLoc, RBraceLoc, 0); |
Steve Naroff | ddbff78 | 2007-08-21 21:17:12 +0000 | [diff] [blame] | 1288 | return; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1289 | } |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1290 | |
| 1291 | /// objc-protocol-declaration: |
| 1292 | /// objc-protocol-definition |
| 1293 | /// objc-protocol-forward-reference |
| 1294 | /// |
| 1295 | /// objc-protocol-definition: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | /// @protocol identifier |
| 1297 | /// objc-protocol-refs[opt] |
| 1298 | /// objc-interface-decl-list |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1299 | /// @end |
| 1300 | /// |
| 1301 | /// objc-protocol-forward-reference: |
| 1302 | /// @protocol identifier-list ';' |
| 1303 | /// |
| 1304 | /// "@protocol identifier ;" should be resolved as "@protocol |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1305 | /// identifier-list ;": objc-interface-decl-list may not start with a |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1306 | /// semicolon in the first alternative if objc-protocol-refs are omitted. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1307 | Decl *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1308 | ParsedAttributes &attrs) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 1309 | assert(Tok.isObjCAtKeyword(tok::objc_protocol) && |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1310 | "ParseObjCAtProtocolDeclaration(): Expected @protocol"); |
| 1311 | ConsumeToken(); // the "protocol" identifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | |
Douglas Gregor | 083128f | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1313 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1314 | Actions.CodeCompleteObjCProtocolDecl(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1315 | cutOffParsing(); |
| 1316 | return 0; |
Douglas Gregor | 083128f | 2009-11-18 04:49:41 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1319 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1320 | Diag(Tok, diag::err_expected_ident); // missing protocol name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1321 | return 0; |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1322 | } |
| 1323 | // Save the protocol name, then consume it. |
| 1324 | IdentifierInfo *protocolName = Tok.getIdentifierInfo(); |
| 1325 | SourceLocation nameLoc = ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1326 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1327 | if (Tok.is(tok::semi)) { // forward declaration of one protocol. |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1328 | IdentifierLocPair ProtoInfo(protocolName, nameLoc); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1329 | ConsumeToken(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, &ProtoInfo, 1, |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1331 | attrs.getList()); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1332 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1333 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1334 | if (Tok.is(tok::comma)) { // list of forward declarations. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1335 | SmallVector<IdentifierLocPair, 8> ProtocolRefs; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1336 | ProtocolRefs.push_back(std::make_pair(protocolName, nameLoc)); |
| 1337 | |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1338 | // Parse the list of forward declarations. |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1339 | while (1) { |
| 1340 | ConsumeToken(); // the ',' |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1341 | if (Tok.isNot(tok::identifier)) { |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1342 | Diag(Tok, diag::err_expected_ident); |
| 1343 | SkipUntil(tok::semi); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1344 | return 0; |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1345 | } |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1346 | ProtocolRefs.push_back(IdentifierLocPair(Tok.getIdentifierInfo(), |
| 1347 | Tok.getLocation())); |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1348 | ConsumeToken(); // the identifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1350 | if (Tok.isNot(tok::comma)) |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1351 | break; |
| 1352 | } |
| 1353 | // Consume the ';'. |
| 1354 | if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol")) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1355 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | |
Steve Naroff | e440eb8 | 2007-10-10 17:32:04 +0000 | [diff] [blame] | 1357 | return Actions.ActOnForwardProtocolDeclaration(AtLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1358 | &ProtocolRefs[0], |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 1359 | ProtocolRefs.size(), |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1360 | attrs.getList()); |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | |
Steve Naroff | 7ef58fd | 2007-08-22 22:17:26 +0000 | [diff] [blame] | 1363 | // Last, and definitely not least, parse a protocol declaration. |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1364 | SourceLocation LAngleLoc, EndProtoLoc; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1365 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1366 | SmallVector<Decl *, 8> ProtocolRefs; |
| 1367 | SmallVector<SourceLocation, 8> ProtocolLocs; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 1368 | if (Tok.is(tok::less) && |
Argyrios Kyrtzidis | 71b0add | 2009-09-29 19:41:44 +0000 | [diff] [blame] | 1369 | ParseObjCProtocolReferences(ProtocolRefs, ProtocolLocs, false, |
| 1370 | LAngleLoc, EndProtoLoc)) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1371 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1373 | Decl *ProtoType = |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 1374 | Actions.ActOnStartProtocolInterface(AtLoc, protocolName, nameLoc, |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1375 | ProtocolRefs.data(), |
| 1376 | ProtocolRefs.size(), |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1377 | ProtocolLocs.data(), |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1378 | EndProtoLoc, attrs.getList()); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1379 | |
Fariborz Jahanian | 2f64cfe | 2011-08-22 21:44:58 +0000 | [diff] [blame] | 1380 | ParseObjCInterfaceDeclList(tok::objc_protocol, ProtoType); |
Chris Lattner | bc662af | 2008-10-20 06:10:06 +0000 | [diff] [blame] | 1381 | return ProtoType; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1382 | } |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1383 | |
| 1384 | /// objc-implementation: |
| 1385 | /// objc-class-implementation-prologue |
| 1386 | /// objc-category-implementation-prologue |
| 1387 | /// |
| 1388 | /// objc-class-implementation-prologue: |
| 1389 | /// @implementation identifier objc-superclass[opt] |
| 1390 | /// objc-class-instance-variables[opt] |
| 1391 | /// |
| 1392 | /// objc-category-implementation-prologue: |
| 1393 | /// @implementation identifier ( identifier ) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1394 | Decl *Parser::ParseObjCAtImplementationDeclaration( |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1395 | SourceLocation atLoc) { |
| 1396 | assert(Tok.isObjCAtKeyword(tok::objc_implementation) && |
| 1397 | "ParseObjCAtImplementationDeclaration(): Expected @implementation"); |
| 1398 | ConsumeToken(); // the "implementation" identifier |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1400 | // Code completion after '@implementation'. |
| 1401 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1402 | Actions.CodeCompleteObjCImplementationDecl(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1403 | cutOffParsing(); |
| 1404 | return 0; |
Douglas Gregor | 3b49aca | 2009-11-18 16:26:39 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1407 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1408 | Diag(Tok, diag::err_expected_ident); // missing class or category name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1409 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1410 | } |
| 1411 | // We have a class or category name - consume it. |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1412 | IdentifierInfo *nameId = Tok.getIdentifierInfo(); |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1413 | SourceLocation nameLoc = ConsumeToken(); // consume class or category name |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | |
| 1415 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1416 | // we have a category implementation. |
Jeffrey Yasskin | dec0984 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1417 | ConsumeParen(); |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1418 | SourceLocation categoryLoc, rparenLoc; |
| 1419 | IdentifierInfo *categoryId = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1420 | |
Douglas Gregor | 33ced0b | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1421 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1422 | Actions.CodeCompleteObjCImplementationCategory(getCurScope(), nameId, nameLoc); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1423 | cutOffParsing(); |
| 1424 | return 0; |
Douglas Gregor | 33ced0b | 2009-11-18 19:08:43 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1427 | if (Tok.is(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1428 | categoryId = Tok.getIdentifierInfo(); |
| 1429 | categoryLoc = ConsumeToken(); |
| 1430 | } else { |
| 1431 | Diag(Tok, diag::err_expected_ident); // missing category name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1432 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | } |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1434 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1435 | Diag(Tok, diag::err_expected_rparen); |
| 1436 | SkipUntil(tok::r_paren, false); // don't stop at ';' |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1437 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1438 | } |
| 1439 | rparenLoc = ConsumeParen(); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1440 | Decl *ImplCatType = Actions.ActOnStartCategoryImplementation( |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1441 | atLoc, nameId, nameLoc, categoryId, |
Fariborz Jahanian | 8f3fde0 | 2007-10-02 16:38:50 +0000 | [diff] [blame] | 1442 | categoryLoc); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1443 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1444 | ObjCImpDecl = ImplCatType; |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1445 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1446 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1447 | } |
| 1448 | // We have a class implementation |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1449 | SourceLocation superClassLoc; |
| 1450 | IdentifierInfo *superClassId = 0; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1451 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1452 | // We have a super class |
| 1453 | ConsumeToken(); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1454 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1455 | Diag(Tok, diag::err_expected_ident); // missing super class name. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1456 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1457 | } |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1458 | superClassId = Tok.getIdentifierInfo(); |
| 1459 | superClassLoc = ConsumeToken(); // Consume super class name |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1460 | } |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1461 | Decl *ImplClsType = Actions.ActOnStartClassImplementation( |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1462 | atLoc, nameId, nameLoc, |
Fariborz Jahanian | ccb4f31 | 2007-09-25 18:38:09 +0000 | [diff] [blame] | 1463 | superClassId, superClassLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1464 | |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1465 | if (Tok.is(tok::l_brace)) // we have ivars |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1466 | ParseObjCClassInstanceVariables(ImplClsType, tok::objc_private, atLoc); |
| 1467 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1468 | ObjCImpDecl = ImplClsType; |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1469 | PendingObjCImpDecl.push_back(ObjCImpDecl); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1470 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1471 | } |
Steve Naroff | 60fccee | 2007-10-29 21:38:07 +0000 | [diff] [blame] | 1472 | |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1473 | Parser::DeclGroupPtrTy |
| 1474 | Parser::ParseObjCAtEndDeclaration(SourceRange atEnd) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1475 | assert(Tok.isObjCAtKeyword(tok::objc_end) && |
| 1476 | "ParseObjCAtEndDeclaration(): Expected @end"); |
| 1477 | ConsumeToken(); // the "end" identifier |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1478 | SmallVector<Decl *, 8> DeclsInGroup; |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 1479 | Actions.DefaultSynthesizeProperties(getCurScope(), ObjCImpDecl); |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1480 | for (size_t i = 0; i < LateParsedObjCMethods.size(); ++i) { |
| 1481 | Decl *D = ParseLexedObjCMethodDefs(*LateParsedObjCMethods[i]); |
| 1482 | DeclsInGroup.push_back(D); |
| 1483 | } |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1484 | DeclsInGroup.push_back(ObjCImpDecl); |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 1485 | |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1486 | if (ObjCImpDecl) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1487 | Actions.ActOnAtEnd(getCurScope(), atEnd); |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1488 | PendingObjCImpDecl.pop_back(); |
Fariborz Jahanian | a6e3ac5 | 2009-03-04 22:30:12 +0000 | [diff] [blame] | 1489 | } |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 1490 | else |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1491 | // missing @implementation |
Fariborz Jahanian | 64089ce | 2011-04-22 22:02:28 +0000 | [diff] [blame] | 1492 | Diag(atEnd.getBegin(), diag::err_expected_implementation); |
Fariborz Jahanian | 8697d30 | 2011-08-31 22:24:06 +0000 | [diff] [blame] | 1493 | |
| 1494 | LateParsedObjCMethods.clear(); |
| 1495 | ObjCImpDecl = 0; |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1496 | return Actions.BuildDeclaratorGroup( |
| 1497 | DeclsInGroup.data(), DeclsInGroup.size(), false); |
Steve Naroff | dac269b | 2007-08-20 21:31:48 +0000 | [diff] [blame] | 1498 | } |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1499 | |
Fariborz Jahanian | 3fe1041 | 2010-07-22 18:24:20 +0000 | [diff] [blame] | 1500 | Parser::DeclGroupPtrTy Parser::FinishPendingObjCActions() { |
| 1501 | Actions.DiagnoseUseOfUnimplementedSelectors(); |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1502 | if (PendingObjCImpDecl.empty()) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1503 | return Actions.ConvertDeclToDeclGroup(0); |
| 1504 | Decl *ImpDecl = PendingObjCImpDecl.pop_back_val(); |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1505 | Actions.ActOnAtEnd(getCurScope(), SourceRange()); |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1506 | return Actions.ConvertDeclToDeclGroup(ImpDecl); |
| 1507 | } |
| 1508 | |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1509 | /// compatibility-alias-decl: |
| 1510 | /// @compatibility_alias alias-name class-name ';' |
| 1511 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1512 | Decl *Parser::ParseObjCAtAliasDeclaration(SourceLocation atLoc) { |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1513 | assert(Tok.isObjCAtKeyword(tok::objc_compatibility_alias) && |
| 1514 | "ParseObjCAtAliasDeclaration(): Expected @compatibility_alias"); |
| 1515 | ConsumeToken(); // consume compatibility_alias |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1516 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1517 | Diag(Tok, diag::err_expected_ident); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1518 | return 0; |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1519 | } |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1520 | IdentifierInfo *aliasId = Tok.getIdentifierInfo(); |
| 1521 | SourceLocation aliasLoc = ConsumeToken(); // consume alias-name |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1522 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1523 | Diag(Tok, diag::err_expected_ident); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1524 | return 0; |
Fariborz Jahanian | e992af0 | 2007-09-04 19:26:51 +0000 | [diff] [blame] | 1525 | } |
Fariborz Jahanian | 243b64b | 2007-10-11 23:42:27 +0000 | [diff] [blame] | 1526 | IdentifierInfo *classId = Tok.getIdentifierInfo(); |
| 1527 | SourceLocation classLoc = ConsumeToken(); // consume class-name; |
Douglas Gregor | e6bf90a | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1528 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 1529 | "@compatibility_alias"); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1530 | return Actions.ActOnCompatiblityAlias(atLoc, aliasId, aliasLoc, |
| 1531 | classId, classLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1534 | /// property-synthesis: |
| 1535 | /// @synthesize property-ivar-list ';' |
| 1536 | /// |
| 1537 | /// property-ivar-list: |
| 1538 | /// property-ivar |
| 1539 | /// property-ivar-list ',' property-ivar |
| 1540 | /// |
| 1541 | /// property-ivar: |
| 1542 | /// identifier |
| 1543 | /// identifier '=' identifier |
| 1544 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1545 | Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1546 | assert(Tok.isObjCAtKeyword(tok::objc_synthesize) && |
| 1547 | "ParseObjCPropertyDynamic(): Expected '@synthesize'"); |
Jeffrey Yasskin | dec0984 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1548 | ConsumeToken(); // consume synthesize |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1549 | |
Douglas Gregor | b328c42 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1550 | while (true) { |
Douglas Gregor | 322328b | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1551 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1552 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1553 | cutOffParsing(); |
| 1554 | return 0; |
Douglas Gregor | 322328b | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Douglas Gregor | b328c42 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1557 | if (Tok.isNot(tok::identifier)) { |
| 1558 | Diag(Tok, diag::err_synthesized_property_name); |
| 1559 | SkipUntil(tok::semi); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1560 | return 0; |
Douglas Gregor | b328c42 | 2009-11-18 19:45:45 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1563 | IdentifierInfo *propertyIvar = 0; |
| 1564 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1565 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1566 | SourceLocation propertyIvarLoc; |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1567 | if (Tok.is(tok::equal)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1568 | // property '=' ivar-name |
| 1569 | ConsumeToken(); // consume '=' |
Douglas Gregor | 322328b | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1570 | |
| 1571 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1572 | Actions.CodeCompleteObjCPropertySynthesizeIvar(getCurScope(), propertyId); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1573 | cutOffParsing(); |
| 1574 | return 0; |
Douglas Gregor | 322328b | 2009-11-18 22:32:06 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1577 | if (Tok.isNot(tok::identifier)) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1578 | Diag(Tok, diag::err_expected_ident); |
| 1579 | break; |
| 1580 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1581 | propertyIvar = Tok.getIdentifierInfo(); |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1582 | propertyIvarLoc = ConsumeToken(); // consume ivar-name |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1583 | } |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1584 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, true, |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1585 | propertyId, propertyIvar, propertyIvarLoc); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1586 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | ConsumeToken(); // consume ',' |
| 1589 | } |
Douglas Gregor | e6bf90a | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1590 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@synthesize"); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1591 | return 0; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1594 | /// property-dynamic: |
| 1595 | /// @dynamic property-list |
| 1596 | /// |
| 1597 | /// property-list: |
| 1598 | /// identifier |
| 1599 | /// property-list ',' identifier |
| 1600 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1601 | Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) { |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1602 | assert(Tok.isObjCAtKeyword(tok::objc_dynamic) && |
| 1603 | "ParseObjCPropertyDynamic(): Expected '@dynamic'"); |
Jeffrey Yasskin | dec0984 | 2011-01-18 02:00:16 +0000 | [diff] [blame] | 1604 | ConsumeToken(); // consume dynamic |
Douglas Gregor | 424b2a5 | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1605 | while (true) { |
| 1606 | if (Tok.is(tok::code_completion)) { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1607 | Actions.CodeCompleteObjCPropertyDefinition(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1608 | cutOffParsing(); |
| 1609 | return 0; |
Douglas Gregor | 424b2a5 | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | if (Tok.isNot(tok::identifier)) { |
| 1613 | Diag(Tok, diag::err_expected_ident); |
| 1614 | SkipUntil(tok::semi); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1615 | return 0; |
Douglas Gregor | 424b2a5 | 2009-11-18 22:56:13 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1618 | IdentifierInfo *propertyId = Tok.getIdentifierInfo(); |
| 1619 | SourceLocation propertyLoc = ConsumeToken(); // consume property name |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1620 | Actions.ActOnPropertyImplDecl(getCurScope(), atLoc, propertyLoc, false, |
Douglas Gregor | a4ffd85 | 2010-11-17 01:03:52 +0000 | [diff] [blame] | 1621 | propertyId, 0, SourceLocation()); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1622 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1623 | if (Tok.isNot(tok::comma)) |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1624 | break; |
| 1625 | ConsumeToken(); // consume ',' |
| 1626 | } |
Douglas Gregor | e6bf90a | 2011-01-05 01:10:06 +0000 | [diff] [blame] | 1627 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@dynamic"); |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1628 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1629 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1630 | |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1631 | /// objc-throw-statement: |
| 1632 | /// throw expression[opt]; |
| 1633 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1634 | StmtResult Parser::ParseObjCThrowStmt(SourceLocation atLoc) { |
| 1635 | ExprResult Res; |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1636 | ConsumeToken(); // consume throw |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1637 | if (Tok.isNot(tok::semi)) { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 1638 | Res = ParseExpression(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1639 | if (Res.isInvalid()) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1640 | SkipUntil(tok::semi); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1641 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1642 | } |
| 1643 | } |
Ted Kremenek | 02418c7 | 2010-04-20 21:21:51 +0000 | [diff] [blame] | 1644 | // consume ';' |
| 1645 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@throw"); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1646 | return Actions.ActOnObjCAtThrowStmt(atLoc, Res.take(), getCurScope()); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1649 | /// objc-synchronized-statement: |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1650 | /// @synchronized '(' expression ')' compound-statement |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1651 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1652 | StmtResult |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1653 | Parser::ParseObjCSynchronizedStmt(SourceLocation atLoc) { |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1654 | ConsumeToken(); // consume synchronized |
| 1655 | if (Tok.isNot(tok::l_paren)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1656 | Diag(Tok, diag::err_expected_lparen_after) << "@synchronized"; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1657 | return StmtError(); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1658 | } |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1659 | |
| 1660 | // The operand is surrounded with parentheses. |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1661 | ConsumeParen(); // '(' |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1662 | ExprResult operand(ParseExpression()); |
| 1663 | |
| 1664 | if (Tok.is(tok::r_paren)) { |
| 1665 | ConsumeParen(); // ')' |
| 1666 | } else { |
| 1667 | if (!operand.isInvalid()) |
| 1668 | Diag(Tok, diag::err_expected_rparen); |
| 1669 | |
| 1670 | // Skip forward until we see a left brace, but don't consume it. |
| 1671 | SkipUntil(tok::l_brace, true, true); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 1672 | } |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Require a compound statement. |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1675 | if (Tok.isNot(tok::l_brace)) { |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1676 | if (!operand.isInvalid()) |
| 1677 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1678 | return StmtError(); |
Fariborz Jahanian | 78a677b | 2008-01-30 17:38:29 +0000 | [diff] [blame] | 1679 | } |
Steve Naroff | 3ac438c | 2008-06-04 20:36:13 +0000 | [diff] [blame] | 1680 | |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1681 | // Check the @synchronized operand now. |
| 1682 | if (!operand.isInvalid()) |
| 1683 | operand = Actions.ActOnObjCAtSynchronizedOperand(atLoc, operand.take()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1684 | |
John McCall | 0752403 | 2011-07-27 21:50:02 +0000 | [diff] [blame] | 1685 | // Parse the compound statement within a new scope. |
| 1686 | ParseScope bodyScope(this, Scope::DeclScope); |
| 1687 | StmtResult body(ParseCompoundStatementBody()); |
| 1688 | bodyScope.Exit(); |
| 1689 | |
| 1690 | // If there was a semantic or parse error earlier with the |
| 1691 | // operand, fail now. |
| 1692 | if (operand.isInvalid()) |
| 1693 | return StmtError(); |
| 1694 | |
| 1695 | if (body.isInvalid()) |
| 1696 | body = Actions.ActOnNullStmt(Tok.getLocation()); |
| 1697 | |
| 1698 | return Actions.ActOnObjCAtSynchronizedStmt(atLoc, operand.get(), body.get()); |
Fariborz Jahanian | c385c90 | 2008-01-29 18:21:32 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1701 | /// objc-try-catch-statement: |
| 1702 | /// @try compound-statement objc-catch-list[opt] |
| 1703 | /// @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 1704 | /// |
| 1705 | /// objc-catch-list: |
| 1706 | /// @catch ( parameter-declaration ) compound-statement |
| 1707 | /// objc-catch-list @catch ( catch-parameter-declaration ) compound-statement |
| 1708 | /// catch-parameter-declaration: |
| 1709 | /// parameter-declaration |
| 1710 | /// '...' [OBJC2] |
| 1711 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1712 | StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1713 | bool catch_or_finally_seen = false; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1714 | |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1715 | ConsumeToken(); // consume try |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1716 | if (Tok.isNot(tok::l_brace)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1717 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1718 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1719 | } |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1720 | StmtVector CatchStmts(Actions); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1721 | StmtResult FinallyStmt; |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1722 | ParseScope TryScope(this, Scope::DeclScope); |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1723 | StmtResult TryBody(ParseCompoundStatementBody()); |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1724 | TryScope.Exit(); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1725 | if (TryBody.isInvalid()) |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1726 | TryBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 1727 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1728 | while (Tok.is(tok::at)) { |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1729 | // At this point, we need to lookahead to determine if this @ is the start |
| 1730 | // of an @catch or @finally. We don't want to consume the @ token if this |
| 1731 | // is an @try or @encode or something else. |
| 1732 | Token AfterAt = GetLookAheadToken(1); |
| 1733 | if (!AfterAt.isObjCAtKeyword(tok::objc_catch) && |
| 1734 | !AfterAt.isObjCAtKeyword(tok::objc_finally)) |
| 1735 | break; |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1736 | |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1737 | SourceLocation AtCatchFinallyLoc = ConsumeToken(); |
Chris Lattner | cb53b36 | 2007-12-27 19:57:00 +0000 | [diff] [blame] | 1738 | if (Tok.isObjCAtKeyword(tok::objc_catch)) { |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1739 | Decl *FirstPart = 0; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1740 | ConsumeToken(); // consume catch |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1741 | if (Tok.is(tok::l_paren)) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1742 | ConsumeParen(); |
Steve Naroff | e21dd6f | 2009-02-11 20:05:44 +0000 | [diff] [blame] | 1743 | ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1744 | if (Tok.isNot(tok::ellipsis)) { |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1745 | DeclSpec DS(AttrFactory); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1746 | ParseDeclarationSpecifiers(DS); |
Argyrios Kyrtzidis | 17b6399 | 2011-07-01 22:22:40 +0000 | [diff] [blame] | 1747 | Declarator ParmDecl(DS, Declarator::ObjCCatchContext); |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1748 | ParseDeclarator(ParmDecl); |
| 1749 | |
Douglas Gregor | 4e6c0d1 | 2010-04-23 23:01:43 +0000 | [diff] [blame] | 1750 | // Inform the actions module about the declarator, so it |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 1751 | // gets added to the current scope. |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1752 | FirstPart = Actions.ActOnObjCExceptionDecl(getCurScope(), ParmDecl); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1753 | } else |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1754 | ConsumeToken(); // consume '...' |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1755 | |
Steve Naroff | 93a2595 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1756 | SourceLocation RParenLoc; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1757 | |
Steve Naroff | 93a2595 | 2009-04-07 22:56:58 +0000 | [diff] [blame] | 1758 | if (Tok.is(tok::r_paren)) |
| 1759 | RParenLoc = ConsumeParen(); |
| 1760 | else // Skip over garbage, until we get to ')'. Eat the ')'. |
| 1761 | SkipUntil(tok::r_paren, true, false); |
| 1762 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1763 | StmtResult CatchBody(true); |
Chris Lattner | c1b3ba5 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1764 | if (Tok.is(tok::l_brace)) |
| 1765 | CatchBody = ParseCompoundStatementBody(); |
| 1766 | else |
| 1767 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1768 | if (CatchBody.isInvalid()) |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 1769 | CatchBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1770 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1771 | StmtResult Catch = Actions.ActOnObjCAtCatchStmt(AtCatchFinallyLoc, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1772 | RParenLoc, |
| 1773 | FirstPart, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1774 | CatchBody.take()); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1775 | if (!Catch.isInvalid()) |
| 1776 | CatchStmts.push_back(Catch.release()); |
| 1777 | |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1778 | } else { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 1779 | Diag(AtCatchFinallyLoc, diag::err_expected_lparen_after) |
| 1780 | << "@catch clause"; |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1781 | return StmtError(); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1782 | } |
| 1783 | catch_or_finally_seen = true; |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1784 | } else { |
| 1785 | assert(Tok.isObjCAtKeyword(tok::objc_finally) && "Lookahead confused?"); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1786 | ConsumeToken(); // consume finally |
Douglas Gregor | 8935b8b | 2008-12-10 06:34:36 +0000 | [diff] [blame] | 1787 | ParseScope FinallyScope(this, Scope::DeclScope); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1788 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1789 | StmtResult FinallyBody(true); |
Chris Lattner | c1b3ba5 | 2008-02-14 19:27:54 +0000 | [diff] [blame] | 1790 | if (Tok.is(tok::l_brace)) |
| 1791 | FinallyBody = ParseCompoundStatementBody(); |
| 1792 | else |
| 1793 | Diag(Tok, diag::err_expected_lbrace); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1794 | if (FinallyBody.isInvalid()) |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 1795 | FinallyBody = Actions.ActOnNullStmt(Tok.getLocation()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1796 | FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc, |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1797 | FinallyBody.take()); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1798 | catch_or_finally_seen = true; |
| 1799 | break; |
| 1800 | } |
| 1801 | } |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1802 | if (!catch_or_finally_seen) { |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1803 | Diag(atLoc, diag::err_missing_catch_finally); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1804 | return StmtError(); |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 1805 | } |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1806 | |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1807 | return Actions.ActOnObjCAtTryStmt(atLoc, TryBody.take(), |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 1808 | move_arg(CatchStmts), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1809 | FinallyStmt.take()); |
Fariborz Jahanian | 397fcc1 | 2007-09-19 19:14:32 +0000 | [diff] [blame] | 1810 | } |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1811 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1812 | /// objc-autoreleasepool-statement: |
| 1813 | /// @autoreleasepool compound-statement |
| 1814 | /// |
| 1815 | StmtResult |
| 1816 | Parser::ParseObjCAutoreleasePoolStmt(SourceLocation atLoc) { |
| 1817 | ConsumeToken(); // consume autoreleasepool |
| 1818 | if (Tok.isNot(tok::l_brace)) { |
| 1819 | Diag(Tok, diag::err_expected_lbrace); |
| 1820 | return StmtError(); |
| 1821 | } |
| 1822 | // Enter a scope to hold everything within the compound stmt. Compound |
| 1823 | // statements can always hold declarations. |
| 1824 | ParseScope BodyScope(this, Scope::DeclScope); |
| 1825 | |
| 1826 | StmtResult AutoreleasePoolBody(ParseCompoundStatementBody()); |
| 1827 | |
| 1828 | BodyScope.Exit(); |
| 1829 | if (AutoreleasePoolBody.isInvalid()) |
| 1830 | AutoreleasePoolBody = Actions.ActOnNullStmt(Tok.getLocation()); |
| 1831 | return Actions.ActOnObjCAutoreleasePoolStmt(atLoc, |
| 1832 | AutoreleasePoolBody.take()); |
| 1833 | } |
| 1834 | |
Steve Naroff | 3536b44 | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 1835 | /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1836 | /// |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1837 | Decl *Parser::ParseObjCMethodDefinition() { |
Fariborz Jahanian | a28948f | 2011-08-22 15:54:49 +0000 | [diff] [blame] | 1838 | Decl *MDecl = ParseObjCMethodPrototype(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 1840 | PrettyDeclStackTraceEntry CrashInfo(Actions, MDecl, Tok.getLocation(), |
| 1841 | "parsing Objective-C method"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1842 | |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1843 | // parse optional ';' |
Fariborz Jahanian | 209a8c2 | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1844 | if (Tok.is(tok::semi)) { |
Ted Kremenek | 496e45e | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1845 | if (ObjCImpDecl) { |
| 1846 | Diag(Tok, diag::warn_semicolon_before_method_body) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 1847 | << FixItHint::CreateRemoval(Tok.getLocation()); |
Ted Kremenek | 496e45e | 2009-11-10 22:55:49 +0000 | [diff] [blame] | 1848 | } |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1849 | ConsumeToken(); |
Fariborz Jahanian | 209a8c2 | 2009-10-20 16:39:13 +0000 | [diff] [blame] | 1850 | } |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1851 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1852 | // We should have an opening brace now. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 1853 | if (Tok.isNot(tok::l_brace)) { |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1854 | Diag(Tok, diag::err_expected_method_body); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1855 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1856 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 1857 | SkipUntil(tok::l_brace, true, true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1858 | |
Steve Naroff | 409be83 | 2007-11-11 19:54:21 +0000 | [diff] [blame] | 1859 | // If we didn't find the '{', bail out. |
| 1860 | if (Tok.isNot(tok::l_brace)) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 1861 | return 0; |
Fariborz Jahanian | ac00b7f | 2007-09-01 00:26:16 +0000 | [diff] [blame] | 1862 | } |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 1863 | // Allow the rest of sema to find private method decl implementations. |
| 1864 | if (MDecl) |
| 1865 | Actions.AddAnyMethodToGlobalPool(MDecl); |
| 1866 | |
| 1867 | // Consume the tokens and store them for later parsing. |
| 1868 | LexedMethod* LM = new LexedMethod(this, MDecl); |
| 1869 | LateParsedObjCMethods.push_back(LM); |
| 1870 | CachedTokens &Toks = LM->Toks; |
| 1871 | // Begin by storing the '{' token. |
| 1872 | Toks.push_back(Tok); |
| 1873 | ConsumeBrace(); |
| 1874 | // Consume everything up to (and including) the matching right brace. |
| 1875 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Steve Naroff | 71c0a95 | 2007-11-13 23:01:27 +0000 | [diff] [blame] | 1876 | return MDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1877 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1878 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1879 | StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) { |
Douglas Gregor | 9a0c85e | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1880 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1881 | Actions.CodeCompleteObjCAtStatement(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1882 | cutOffParsing(); |
Douglas Gregor | 9a0c85e | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1883 | return StmtError(); |
Chris Lattner | 5d80316 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | if (Tok.isObjCAtKeyword(tok::objc_try)) |
Chris Lattner | 6b88450 | 2008-03-10 06:06:04 +0000 | [diff] [blame] | 1887 | return ParseObjCTryStmt(AtLoc); |
Chris Lattner | 5d80316 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1888 | |
| 1889 | if (Tok.isObjCAtKeyword(tok::objc_throw)) |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1890 | return ParseObjCThrowStmt(AtLoc); |
Chris Lattner | 5d80316 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1891 | |
| 1892 | if (Tok.isObjCAtKeyword(tok::objc_synchronized)) |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1893 | return ParseObjCSynchronizedStmt(AtLoc); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 1894 | |
| 1895 | if (Tok.isObjCAtKeyword(tok::objc_autoreleasepool)) |
| 1896 | return ParseObjCAutoreleasePoolStmt(AtLoc); |
Chris Lattner | 5d80316 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1897 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1898 | ExprResult Res(ParseExpressionWithLeadingAt(AtLoc)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 1899 | if (Res.isInvalid()) { |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1900 | // If the expression is invalid, skip ahead to the next semicolon. Not |
| 1901 | // doing this opens us up to the possibility of infinite loops if |
| 1902 | // ParseExpression does not consume any tokens. |
| 1903 | SkipUntil(tok::semi); |
Sebastian Redl | 43bc2a0 | 2008-12-11 20:12:42 +0000 | [diff] [blame] | 1904 | return StmtError(); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1905 | } |
Chris Lattner | 5d80316 | 2009-12-07 16:33:19 +0000 | [diff] [blame] | 1906 | |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1907 | // Otherwise, eat the semicolon. |
Douglas Gregor | 9ba23b4 | 2010-09-07 15:23:11 +0000 | [diff] [blame] | 1908 | ExpectAndConsumeSemi(diag::err_expected_semi_after_expr); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 1909 | return Actions.ActOnExprStmt(Actions.MakeFullExpr(Res.take())); |
Steve Naroff | 64515f3 | 2008-02-05 21:27:35 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1912 | ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1913 | switch (Tok.getKind()) { |
Douglas Gregor | 9a0c85e | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1914 | case tok::code_completion: |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 1915 | Actions.CodeCompleteObjCAtExpression(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 1916 | cutOffParsing(); |
Douglas Gregor | 9a0c85e | 2009-12-07 09:51:25 +0000 | [diff] [blame] | 1917 | return ExprError(); |
| 1918 | |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1919 | case tok::string_literal: // primary-expression: string-literal |
| 1920 | case tok::wide_string_literal: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1921 | return ParsePostfixExpressionSuffix(ParseObjCStringLiteral(AtLoc)); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 1922 | default: |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1923 | if (Tok.getIdentifierInfo() == 0) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1924 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 1925 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1926 | switch (Tok.getIdentifierInfo()->getObjCKeywordID()) { |
| 1927 | case tok::objc_encode: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1928 | return ParsePostfixExpressionSuffix(ParseObjCEncodeExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1929 | case tok::objc_protocol: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1930 | return ParsePostfixExpressionSuffix(ParseObjCProtocolExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1931 | case tok::objc_selector: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1932 | return ParsePostfixExpressionSuffix(ParseObjCSelectorExpression(AtLoc)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1933 | default: |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 1934 | return ExprError(Diag(AtLoc, diag::err_unexpected_at)); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 1935 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1936 | } |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1939 | /// \brirg Parse the receiver of an Objective-C++ message send. |
| 1940 | /// |
| 1941 | /// This routine parses the receiver of a message send in |
| 1942 | /// Objective-C++ either as a type or as an expression. Note that this |
| 1943 | /// routine must not be called to parse a send to 'super', since it |
| 1944 | /// has no way to return such a result. |
| 1945 | /// |
| 1946 | /// \param IsExpr Whether the receiver was parsed as an expression. |
| 1947 | /// |
| 1948 | /// \param TypeOrExpr If the receiver was parsed as an expression (\c |
| 1949 | /// IsExpr is true), the parsed expression. If the receiver was parsed |
| 1950 | /// as a type (\c IsExpr is false), the parsed type. |
| 1951 | /// |
| 1952 | /// \returns True if an error occurred during parsing or semantic |
| 1953 | /// analysis, in which case the arguments do not have valid |
| 1954 | /// values. Otherwise, returns false for a successful parse. |
| 1955 | /// |
| 1956 | /// objc-receiver: [C++] |
| 1957 | /// 'super' [not parsed here] |
| 1958 | /// expression |
| 1959 | /// simple-type-specifier |
| 1960 | /// typename-specifier |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1961 | bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) { |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 1962 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 1963 | |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1964 | if (Tok.is(tok::identifier) || Tok.is(tok::coloncolon) || |
| 1965 | Tok.is(tok::kw_typename) || Tok.is(tok::annot_cxxscope)) |
| 1966 | TryAnnotateTypeOrScopeToken(); |
| 1967 | |
| 1968 | if (!isCXXSimpleTypeSpecifier()) { |
| 1969 | // objc-receiver: |
| 1970 | // expression |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 1971 | ExprResult Receiver = ParseExpression(); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1972 | if (Receiver.isInvalid()) |
| 1973 | return true; |
| 1974 | |
| 1975 | IsExpr = true; |
| 1976 | TypeOrExpr = Receiver.take(); |
| 1977 | return false; |
| 1978 | } |
| 1979 | |
| 1980 | // objc-receiver: |
| 1981 | // typename-specifier |
| 1982 | // simple-type-specifier |
| 1983 | // expression (that starts with one of the above) |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1984 | DeclSpec DS(AttrFactory); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 1985 | ParseCXXSimpleTypeSpecifier(DS); |
| 1986 | |
| 1987 | if (Tok.is(tok::l_paren)) { |
| 1988 | // If we see an opening parentheses at this point, we are |
| 1989 | // actually parsing an expression that starts with a |
| 1990 | // function-style cast, e.g., |
| 1991 | // |
| 1992 | // postfix-expression: |
| 1993 | // simple-type-specifier ( expression-list [opt] ) |
| 1994 | // typename-specifier ( expression-list [opt] ) |
| 1995 | // |
| 1996 | // Parse the remainder of this case, then the (optional) |
| 1997 | // postfix-expression suffix, followed by the (optional) |
| 1998 | // right-hand side of the binary expression. We have an |
| 1999 | // instance method. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2000 | ExprResult Receiver = ParseCXXTypeConstructExpression(DS); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2001 | if (!Receiver.isInvalid()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2002 | Receiver = ParsePostfixExpressionSuffix(Receiver.take()); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2003 | if (!Receiver.isInvalid()) |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2004 | Receiver = ParseRHSOfBinaryExpression(Receiver.take(), prec::Comma); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2005 | if (Receiver.isInvalid()) |
| 2006 | return true; |
| 2007 | |
| 2008 | IsExpr = true; |
| 2009 | TypeOrExpr = Receiver.take(); |
| 2010 | return false; |
| 2011 | } |
| 2012 | |
| 2013 | // We have a class message. Turn the simple-type-specifier or |
| 2014 | // typename-specifier we parsed into a type and parse the |
| 2015 | // remainder of the class message. |
| 2016 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2017 | TypeResult Type = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2018 | if (Type.isInvalid()) |
| 2019 | return true; |
| 2020 | |
| 2021 | IsExpr = false; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2022 | TypeOrExpr = Type.get().getAsOpaquePtr(); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2023 | return false; |
| 2024 | } |
| 2025 | |
Douglas Gregor | 1b730e8 | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2026 | /// \brief Determine whether the parser is currently referring to a an |
| 2027 | /// Objective-C message send, using a simplified heuristic to avoid overhead. |
| 2028 | /// |
| 2029 | /// This routine will only return true for a subset of valid message-send |
| 2030 | /// expressions. |
| 2031 | bool Parser::isSimpleObjCMessageExpression() { |
Chris Lattner | c59cb38 | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 2032 | assert(Tok.is(tok::l_square) && getLang().ObjC1 && |
Douglas Gregor | 1b730e8 | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2033 | "Incorrect start for isSimpleObjCMessageExpression"); |
Douglas Gregor | 1b730e8 | 2010-05-31 14:40:22 +0000 | [diff] [blame] | 2034 | return GetLookAheadToken(1).is(tok::identifier) && |
| 2035 | GetLookAheadToken(2).is(tok::identifier); |
| 2036 | } |
| 2037 | |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 2038 | bool Parser::isStartOfObjCClassMessageMissingOpenBracket() { |
| 2039 | if (!getLang().ObjC1 || !NextToken().is(tok::identifier) || |
| 2040 | InMessageExpression) |
| 2041 | return false; |
| 2042 | |
| 2043 | |
| 2044 | ParsedType Type; |
| 2045 | |
| 2046 | if (Tok.is(tok::annot_typename)) |
| 2047 | Type = getTypeAnnotation(Tok); |
| 2048 | else if (Tok.is(tok::identifier)) |
| 2049 | Type = Actions.getTypeName(*Tok.getIdentifierInfo(), Tok.getLocation(), |
| 2050 | getCurScope()); |
| 2051 | else |
| 2052 | return false; |
| 2053 | |
| 2054 | if (!Type.get().isNull() && Type.get()->isObjCObjectOrInterfaceType()) { |
| 2055 | const Token &AfterNext = GetLookAheadToken(2); |
| 2056 | if (AfterNext.is(tok::colon) || AfterNext.is(tok::r_square)) { |
| 2057 | if (Tok.is(tok::identifier)) |
| 2058 | TryAnnotateTypeOrScopeToken(); |
| 2059 | |
| 2060 | return Tok.is(tok::annot_typename); |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | return false; |
| 2065 | } |
| 2066 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2067 | /// objc-message-expr: |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2068 | /// '[' objc-receiver objc-message-args ']' |
| 2069 | /// |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2070 | /// objc-receiver: [C] |
Chris Lattner | eb483eb | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 2071 | /// 'super' |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2072 | /// expression |
| 2073 | /// class-name |
| 2074 | /// type-name |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2075 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2076 | ExprResult Parser::ParseObjCMessageExpression() { |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2077 | assert(Tok.is(tok::l_square) && "'[' expected"); |
| 2078 | SourceLocation LBracLoc = ConsumeBracket(); // consume '[' |
| 2079 | |
Douglas Gregor | 8e254cf | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 2080 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2081 | Actions.CodeCompleteObjCMessageReceiver(getCurScope()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2082 | cutOffParsing(); |
Douglas Gregor | 8e254cf | 2010-05-27 23:06:34 +0000 | [diff] [blame] | 2083 | return ExprError(); |
| 2084 | } |
| 2085 | |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2086 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2087 | |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2088 | if (getLang().CPlusPlus) { |
| 2089 | // We completely separate the C and C++ cases because C++ requires |
| 2090 | // more complicated (read: slower) parsing. |
| 2091 | |
| 2092 | // Handle send to super. |
| 2093 | // FIXME: This doesn't benefit from the same typo-correction we |
| 2094 | // get in Objective-C. |
| 2095 | if (Tok.is(tok::identifier) && Tok.getIdentifierInfo() == Ident_super && |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2096 | NextToken().isNot(tok::period) && getCurScope()->isInObjcMethodScope()) |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2097 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 2098 | ParsedType(), 0); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2099 | |
| 2100 | // Parse the receiver, which is either a type or an expression. |
| 2101 | bool IsExpr; |
Nick Lewycky | 304b752 | 2010-09-15 18:35:19 +0000 | [diff] [blame] | 2102 | void *TypeOrExpr = NULL; |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2103 | if (ParseObjCXXMessageReceiver(IsExpr, TypeOrExpr)) { |
| 2104 | SkipUntil(tok::r_square); |
| 2105 | return ExprError(); |
| 2106 | } |
| 2107 | |
| 2108 | if (IsExpr) |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2109 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 2110 | ParsedType(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2111 | static_cast<Expr*>(TypeOrExpr)); |
Douglas Gregor | 6aa14d8 | 2010-04-21 22:36:40 +0000 | [diff] [blame] | 2112 | |
| 2113 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2114 | ParsedType::getFromOpaquePtr(TypeOrExpr), |
| 2115 | 0); |
Chris Lattner | c59cb38 | 2010-05-31 18:18:22 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | if (Tok.is(tok::identifier)) { |
Douglas Gregor | 1dbca6e | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2119 | IdentifierInfo *Name = Tok.getIdentifierInfo(); |
| 2120 | SourceLocation NameLoc = Tok.getLocation(); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2121 | ParsedType ReceiverType; |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2122 | switch (Actions.getObjCMessageKind(getCurScope(), Name, NameLoc, |
Douglas Gregor | 1dbca6e | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2123 | Name == Ident_super, |
Douglas Gregor | 1569f95 | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2124 | NextToken().is(tok::period), |
| 2125 | ReceiverType)) { |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2126 | case Sema::ObjCSuperMessage: |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2127 | return ParseObjCMessageExpressionBody(LBracLoc, ConsumeToken(), |
| 2128 | ParsedType(), 0); |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2129 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2130 | case Sema::ObjCClassMessage: |
Douglas Gregor | 1569f95 | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2131 | if (!ReceiverType) { |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2132 | SkipUntil(tok::r_square); |
| 2133 | return ExprError(); |
| 2134 | } |
| 2135 | |
Douglas Gregor | 1569f95 | 2010-04-21 20:38:13 +0000 | [diff] [blame] | 2136 | ConsumeToken(); // the type name |
| 2137 | |
| 2138 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2139 | ReceiverType, 0); |
Douglas Gregor | 1dbca6e | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2140 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2141 | case Sema::ObjCInstanceMessage: |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2142 | // Fall through to parse an expression. |
Douglas Gregor | 1dbca6e | 2010-04-14 02:22:16 +0000 | [diff] [blame] | 2143 | break; |
Fariborz Jahanian | d286992 | 2009-04-08 19:50:10 +0000 | [diff] [blame] | 2144 | } |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2145 | } |
Chris Lattner | eb483eb | 2010-04-11 08:28:14 +0000 | [diff] [blame] | 2146 | |
| 2147 | // Otherwise, an arbitrary expression can be the receiver of a send. |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2148 | ExprResult Res(ParseExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2149 | if (Res.isInvalid()) { |
Chris Lattner | 5c74942 | 2008-01-25 19:43:26 +0000 | [diff] [blame] | 2150 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2151 | return move(Res); |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2152 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2153 | |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2154 | return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), |
| 2155 | ParsedType(), Res.take()); |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2156 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2157 | |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2158 | /// \brief Parse the remainder of an Objective-C message following the |
| 2159 | /// '[' objc-receiver. |
| 2160 | /// |
| 2161 | /// This routine handles sends to super, class messages (sent to a |
| 2162 | /// class name), and instance messages (sent to an object), and the |
| 2163 | /// target is represented by \p SuperLoc, \p ReceiverType, or \p |
| 2164 | /// ReceiverExpr, respectively. Only one of these parameters may have |
| 2165 | /// a valid value. |
| 2166 | /// |
| 2167 | /// \param LBracLoc The location of the opening '['. |
| 2168 | /// |
| 2169 | /// \param SuperLoc If this is a send to 'super', the location of the |
| 2170 | /// 'super' keyword that indicates a send to the superclass. |
| 2171 | /// |
| 2172 | /// \param ReceiverType If this is a class message, the type of the |
| 2173 | /// class we are sending a message to. |
| 2174 | /// |
| 2175 | /// \param ReceiverExpr If this is an instance message, the expression |
| 2176 | /// used to compute the receiver object. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2177 | /// |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2178 | /// objc-message-args: |
| 2179 | /// objc-selector |
| 2180 | /// objc-keywordarg-list |
| 2181 | /// |
| 2182 | /// objc-keywordarg-list: |
| 2183 | /// objc-keywordarg |
| 2184 | /// objc-keywordarg-list objc-keywordarg |
| 2185 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2186 | /// objc-keywordarg: |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2187 | /// selector-name[opt] ':' objc-keywordexpr |
| 2188 | /// |
| 2189 | /// objc-keywordexpr: |
| 2190 | /// nonempty-expr-list |
| 2191 | /// |
| 2192 | /// nonempty-expr-list: |
| 2193 | /// assignment-expression |
| 2194 | /// nonempty-expr-list , assignment-expression |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2195 | /// |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2196 | ExprResult |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2197 | Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc, |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2198 | SourceLocation SuperLoc, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 2199 | ParsedType ReceiverType, |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2200 | ExprArg ReceiverExpr) { |
Douglas Gregor | 0fbda68 | 2010-09-15 14:51:05 +0000 | [diff] [blame] | 2201 | InMessageExpressionRAIIObject InMessage(*this, true); |
| 2202 | |
Steve Naroff | c4df6d2 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2203 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2204 | if (SuperLoc.isValid()) |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2205 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, 0, 0, |
| 2206 | false); |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2207 | else if (ReceiverType) |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2208 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, 0, 0, |
| 2209 | false); |
Steve Naroff | c4df6d2 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2210 | else |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2211 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2212 | 0, 0, false); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2213 | cutOffParsing(); |
| 2214 | return ExprError(); |
Steve Naroff | c4df6d2 | 2009-11-07 02:08:14 +0000 | [diff] [blame] | 2215 | } |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2216 | |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2217 | // Parse objc-selector |
Fariborz Jahanian | 4b6c905 | 2007-10-11 00:55:41 +0000 | [diff] [blame] | 2218 | SourceLocation Loc; |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2219 | IdentifierInfo *selIdent = ParseObjCSelectorPiece(Loc); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2220 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2221 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2222 | SmallVector<SourceLocation, 12> KeyLocs; |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2223 | ExprVector KeyExprs(Actions); |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2224 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2225 | if (Tok.is(tok::colon)) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2226 | while (1) { |
| 2227 | // Each iteration parses a single keyword argument. |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2228 | KeyIdents.push_back(selIdent); |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2229 | KeyLocs.push_back(Loc); |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2230 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2231 | if (Tok.isNot(tok::colon)) { |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2232 | Diag(Tok, diag::err_expected_colon); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2233 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2234 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2235 | // the enclosing expression. |
| 2236 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2237 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2238 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2239 | |
Steve Naroff | 68d331a | 2007-09-27 14:38:14 +0000 | [diff] [blame] | 2240 | ConsumeToken(); // Eat the ':'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2241 | /// Parse the expression after ':' |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2242 | |
| 2243 | if (Tok.is(tok::code_completion)) { |
| 2244 | if (SuperLoc.isValid()) |
| 2245 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
| 2246 | KeyIdents.data(), |
| 2247 | KeyIdents.size(), |
| 2248 | /*AtArgumentEpression=*/true); |
| 2249 | else if (ReceiverType) |
| 2250 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
| 2251 | KeyIdents.data(), |
| 2252 | KeyIdents.size(), |
| 2253 | /*AtArgumentEpression=*/true); |
| 2254 | else |
| 2255 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
| 2256 | KeyIdents.data(), |
| 2257 | KeyIdents.size(), |
| 2258 | /*AtArgumentEpression=*/true); |
| 2259 | |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2260 | cutOffParsing(); |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2261 | return ExprError(); |
| 2262 | } |
| 2263 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2264 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2265 | if (Res.isInvalid()) { |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2266 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2267 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2268 | // the enclosing expression. |
| 2269 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2270 | return move(Res); |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2271 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2272 | |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2273 | // We have a valid expression. |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2274 | KeyExprs.push_back(Res.release()); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2275 | |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2276 | // Code completion after each argument. |
| 2277 | if (Tok.is(tok::code_completion)) { |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2278 | if (SuperLoc.isValid()) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2279 | Actions.CodeCompleteObjCSuperMessage(getCurScope(), SuperLoc, |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2280 | KeyIdents.data(), |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2281 | KeyIdents.size(), |
| 2282 | /*AtArgumentEpression=*/false); |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2283 | else if (ReceiverType) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2284 | Actions.CodeCompleteObjCClassMessage(getCurScope(), ReceiverType, |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2285 | KeyIdents.data(), |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2286 | KeyIdents.size(), |
| 2287 | /*AtArgumentEpression=*/false); |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2288 | else |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2289 | Actions.CodeCompleteObjCInstanceMessage(getCurScope(), ReceiverExpr, |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2290 | KeyIdents.data(), |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2291 | KeyIdents.size(), |
| 2292 | /*AtArgumentEpression=*/false); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2293 | cutOffParsing(); |
Douglas Gregor | 70c5ac7 | 2010-09-20 23:34:21 +0000 | [diff] [blame] | 2294 | return ExprError(); |
Douglas Gregor | d3c6854 | 2009-11-19 01:08:35 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Steve Naroff | 37387c9 | 2007-09-17 20:25:27 +0000 | [diff] [blame] | 2297 | // Check for another keyword selector. |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2298 | selIdent = ParseObjCSelectorPiece(Loc); |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2299 | if (!selIdent && Tok.isNot(tok::colon)) |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2300 | break; |
| 2301 | // We have a selector or a colon, continue parsing. |
| 2302 | } |
| 2303 | // Parse the, optional, argument list, comma separated. |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2304 | while (Tok.is(tok::comma)) { |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2305 | ConsumeToken(); // Eat the ','. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2306 | /// Parse the expression after ',' |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2307 | ExprResult Res(ParseAssignmentExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2308 | if (Res.isInvalid()) { |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2309 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2310 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2311 | // the enclosing expression. |
| 2312 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2313 | return move(Res); |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2314 | } |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2315 | |
Steve Naroff | 49f109c | 2007-11-15 13:05:42 +0000 | [diff] [blame] | 2316 | // We have a valid expression. |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2317 | KeyExprs.push_back(Res.release()); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2318 | } |
| 2319 | } else if (!selIdent) { |
| 2320 | Diag(Tok, diag::err_expected_ident); // missing selector name. |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2321 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2322 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2323 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2324 | // the enclosing expression. |
| 2325 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2326 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2327 | } |
Fariborz Jahanian | 809872e | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2328 | |
Chris Lattner | df19526 | 2007-10-09 17:51:17 +0000 | [diff] [blame] | 2329 | if (Tok.isNot(tok::r_square)) { |
Fariborz Jahanian | 809872e | 2010-03-31 20:22:35 +0000 | [diff] [blame] | 2330 | if (Tok.is(tok::identifier)) |
| 2331 | Diag(Tok, diag::err_expected_colon); |
| 2332 | else |
| 2333 | Diag(Tok, diag::err_expected_rsquare); |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2334 | // We must manually skip to a ']', otherwise the expression skipper will |
| 2335 | // stop at the ']' when it skips to the ';'. We want it to skip beyond |
| 2336 | // the enclosing expression. |
| 2337 | SkipUntil(tok::r_square); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2338 | return ExprError(); |
Fariborz Jahanian | a65ff6c | 2007-09-05 23:08:20 +0000 | [diff] [blame] | 2339 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2340 | |
Chris Lattner | 699b661 | 2008-01-25 18:59:06 +0000 | [diff] [blame] | 2341 | SourceLocation RBracLoc = ConsumeBracket(); // consume ']' |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2342 | |
Steve Naroff | 29238a0 | 2007-10-05 18:42:47 +0000 | [diff] [blame] | 2343 | unsigned nKeys = KeyIdents.size(); |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2344 | if (nKeys == 0) { |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2345 | KeyIdents.push_back(selIdent); |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2346 | KeyLocs.push_back(Loc); |
| 2347 | } |
Chris Lattner | ff38491 | 2007-10-07 02:00:24 +0000 | [diff] [blame] | 2348 | Selector Sel = PP.getSelectorTable().getSelector(nKeys, &KeyIdents[0]); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2349 | |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2350 | if (SuperLoc.isValid()) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2351 | return Actions.ActOnSuperMessage(getCurScope(), SuperLoc, Sel, |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2352 | LBracLoc, KeyLocs, RBracLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2353 | MultiExprArg(Actions, |
| 2354 | KeyExprs.take(), |
| 2355 | KeyExprs.size())); |
Douglas Gregor | 2725ca8 | 2010-04-21 19:57:20 +0000 | [diff] [blame] | 2356 | else if (ReceiverType) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 2357 | return Actions.ActOnClassMessage(getCurScope(), ReceiverType, Sel, |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2358 | LBracLoc, KeyLocs, RBracLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2359 | MultiExprArg(Actions, |
| 2360 | KeyExprs.take(), |
| 2361 | KeyExprs.size())); |
John McCall | 9ae2f07 | 2010-08-23 23:25:46 +0000 | [diff] [blame] | 2362 | return Actions.ActOnInstanceMessage(getCurScope(), ReceiverExpr, Sel, |
Argyrios Kyrtzidis | 9513762 | 2011-10-03 06:36:17 +0000 | [diff] [blame] | 2363 | LBracLoc, KeyLocs, RBracLoc, |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 2364 | MultiExprArg(Actions, |
| 2365 | KeyExprs.take(), |
| 2366 | KeyExprs.size())); |
Fariborz Jahanian | 0ccb27d | 2007-09-05 19:52:07 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2369 | ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) { |
| 2370 | ExprResult Res(ParseStringLiteralExpression()); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2371 | if (Res.isInvalid()) return move(Res); |
| 2372 | |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2373 | // @"foo" @"bar" is a valid concatenated string. Eat any subsequent string |
| 2374 | // expressions. At this point, we know that the only valid thing that starts |
| 2375 | // with '@' is an @"". |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2376 | SmallVector<SourceLocation, 4> AtLocs; |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 2377 | ExprVector AtStrings(Actions); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2378 | AtLocs.push_back(AtLoc); |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2379 | AtStrings.push_back(Res.release()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2380 | |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2381 | while (Tok.is(tok::at)) { |
| 2382 | AtLocs.push_back(ConsumeToken()); // eat the @. |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2383 | |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 2384 | // Invalid unless there is a string literal. |
Chris Lattner | 97cf6eb | 2009-02-18 05:56:09 +0000 | [diff] [blame] | 2385 | if (!isTokenStringLiteral()) |
| 2386 | return ExprError(Diag(Tok, diag::err_objc_concat_string)); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2387 | |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2388 | ExprResult Lit(ParseStringLiteralExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2389 | if (Lit.isInvalid()) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2390 | return move(Lit); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 2391 | |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 2392 | AtStrings.push_back(Lit.release()); |
Chris Lattner | b3a99cd | 2007-12-12 01:04:12 +0000 | [diff] [blame] | 2393 | } |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2394 | |
| 2395 | return Owned(Actions.ParseObjCStringLiteral(&AtLocs[0], AtStrings.take(), |
| 2396 | AtStrings.size())); |
Anders Carlsson | 5508518 | 2007-08-21 17:43:55 +0000 | [diff] [blame] | 2397 | } |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2398 | |
| 2399 | /// objc-encode-expression: |
| 2400 | /// @encode ( type-name ) |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2401 | ExprResult |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2402 | Parser::ParseObjCEncodeExpression(SourceLocation AtLoc) { |
Steve Naroff | 861cf3e | 2007-08-23 18:16:40 +0000 | [diff] [blame] | 2403 | assert(Tok.isObjCAtKeyword(tok::objc_encode) && "Not an @encode expression!"); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2404 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2405 | SourceLocation EncLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2406 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2407 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2408 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@encode"); |
| 2409 | |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2410 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2411 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2412 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2413 | |
Anders Carlsson | 4988ae3 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2414 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2415 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2416 | if (Ty.isInvalid()) |
| 2417 | return ExprError(); |
| 2418 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2419 | return Owned(Actions.ParseObjCEncodeExpression(AtLoc, EncLoc, LParenLoc, |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 2420 | Ty.get(), RParenLoc)); |
Anders Carlsson | f9bcf01 | 2007-08-22 15:14:15 +0000 | [diff] [blame] | 2421 | } |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2422 | |
| 2423 | /// objc-protocol-expression |
| 2424 | /// @protocol ( protocol-name ) |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2425 | ExprResult |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2426 | Parser::ParseObjCProtocolExpression(SourceLocation AtLoc) { |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2427 | SourceLocation ProtoLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2428 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2429 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2430 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@protocol"); |
| 2431 | |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2432 | SourceLocation LParenLoc = ConsumeParen(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2433 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2434 | if (Tok.isNot(tok::identifier)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2435 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2436 | |
Fariborz Jahanian | 390d50a | 2007-10-17 16:58:11 +0000 | [diff] [blame] | 2437 | IdentifierInfo *protocolId = Tok.getIdentifierInfo(); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2438 | ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2439 | |
Anders Carlsson | 4988ae3 | 2007-08-23 15:31:37 +0000 | [diff] [blame] | 2440 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2441 | |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2442 | return Owned(Actions.ParseObjCProtocolExpression(protocolId, AtLoc, ProtoLoc, |
| 2443 | LParenLoc, RParenLoc)); |
Anders Carlsson | 29b2cb1 | 2007-08-23 15:25:28 +0000 | [diff] [blame] | 2444 | } |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2445 | |
| 2446 | /// objc-selector-expression |
| 2447 | /// @selector '(' objc-keyword-selector ')' |
John McCall | 60d7b3a | 2010-08-24 06:29:42 +0000 | [diff] [blame] | 2448 | ExprResult Parser::ParseObjCSelectorExpression(SourceLocation AtLoc) { |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2449 | SourceLocation SelectorLoc = ConsumeToken(); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2450 | |
Chris Lattner | 4fef81d | 2008-08-05 06:19:09 +0000 | [diff] [blame] | 2451 | if (Tok.isNot(tok::l_paren)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2452 | return ExprError(Diag(Tok, diag::err_expected_lparen_after) << "@selector"); |
| 2453 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2454 | SmallVector<IdentifierInfo *, 12> KeyIdents; |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2455 | SourceLocation LParenLoc = ConsumeParen(); |
| 2456 | SourceLocation sLoc; |
Douglas Gregor | 458433d | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2457 | |
| 2458 | if (Tok.is(tok::code_completion)) { |
| 2459 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2460 | KeyIdents.size()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2461 | cutOffParsing(); |
Douglas Gregor | 458433d | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2462 | return ExprError(); |
| 2463 | } |
| 2464 | |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2465 | IdentifierInfo *SelIdent = ParseObjCSelectorPiece(sLoc); |
Chris Lattner | 5add754 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2466 | if (!SelIdent && // missing selector name. |
| 2467 | Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2468 | return ExprError(Diag(Tok, diag::err_expected_ident)); |
| 2469 | |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2470 | KeyIdents.push_back(SelIdent); |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2471 | unsigned nColons = 0; |
| 2472 | if (Tok.isNot(tok::r_paren)) { |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2473 | while (1) { |
Chris Lattner | 5add754 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2474 | if (Tok.is(tok::coloncolon)) { // Handle :: in C++. |
| 2475 | ++nColons; |
| 2476 | KeyIdents.push_back(0); |
| 2477 | } else if (Tok.isNot(tok::colon)) |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2478 | return ExprError(Diag(Tok, diag::err_expected_colon)); |
| 2479 | |
Chris Lattner | 5add754 | 2010-08-27 22:32:41 +0000 | [diff] [blame] | 2480 | ++nColons; |
Chris Lattner | 3b3e1a9 | 2011-03-26 18:11:38 +0000 | [diff] [blame] | 2481 | ConsumeToken(); // Eat the ':' or '::'. |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2482 | if (Tok.is(tok::r_paren)) |
| 2483 | break; |
Douglas Gregor | 458433d | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2484 | |
| 2485 | if (Tok.is(tok::code_completion)) { |
| 2486 | Actions.CodeCompleteObjCSelector(getCurScope(), KeyIdents.data(), |
| 2487 | KeyIdents.size()); |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 2488 | cutOffParsing(); |
Douglas Gregor | 458433d | 2010-08-26 15:07:07 +0000 | [diff] [blame] | 2489 | return ExprError(); |
| 2490 | } |
| 2491 | |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2492 | // Check for another keyword selector. |
| 2493 | SourceLocation Loc; |
Chris Lattner | 2fc5c24 | 2009-04-11 18:13:45 +0000 | [diff] [blame] | 2494 | SelIdent = ParseObjCSelectorPiece(Loc); |
Fariborz Jahanian | b62f681 | 2007-10-16 20:40:23 +0000 | [diff] [blame] | 2495 | KeyIdents.push_back(SelIdent); |
Chris Lattner | 3b3e1a9 | 2011-03-26 18:11:38 +0000 | [diff] [blame] | 2496 | if (!SelIdent && Tok.isNot(tok::colon) && Tok.isNot(tok::coloncolon)) |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2497 | break; |
| 2498 | } |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2499 | } |
Fariborz Jahanian | a0818e3 | 2007-10-15 23:39:13 +0000 | [diff] [blame] | 2500 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Steve Naroff | 887407e | 2007-12-05 22:21:29 +0000 | [diff] [blame] | 2501 | Selector Sel = PP.getSelectorTable().getSelector(nColons, &KeyIdents[0]); |
Sebastian Redl | 1d92296 | 2008-12-13 15:32:12 +0000 | [diff] [blame] | 2502 | return Owned(Actions.ParseObjCSelectorExpression(Sel, AtLoc, SelectorLoc, |
| 2503 | LParenLoc, RParenLoc)); |
Gabor Greif | 58065b2 | 2007-10-19 15:38:32 +0000 | [diff] [blame] | 2504 | } |
Fariborz Jahanian | 140ab23 | 2011-08-31 17:37:55 +0000 | [diff] [blame] | 2505 | |
| 2506 | Decl *Parser::ParseLexedObjCMethodDefs(LexedMethod &LM) { |
| 2507 | |
| 2508 | assert(!LM.Toks.empty() && "ParseLexedObjCMethodDef - Empty body!"); |
| 2509 | // Append the current token at the end of the new token stream so that it |
| 2510 | // doesn't get lost. |
| 2511 | LM.Toks.push_back(Tok); |
| 2512 | PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); |
| 2513 | |
| 2514 | // MDecl might be null due to error in method prototype, etc. |
| 2515 | Decl *MDecl = LM.D; |
| 2516 | // Consume the previously pushed token. |
| 2517 | ConsumeAnyToken(); |
| 2518 | |
| 2519 | assert(Tok.is(tok::l_brace) && "Inline objective-c method not starting with '{'"); |
| 2520 | SourceLocation BraceLoc = Tok.getLocation(); |
| 2521 | // Enter a scope for the method body. |
| 2522 | ParseScope BodyScope(this, |
| 2523 | Scope::ObjCMethodScope|Scope::FnScope|Scope::DeclScope); |
| 2524 | |
| 2525 | // Tell the actions module that we have entered a method definition with the |
| 2526 | // specified Declarator for the method. |
| 2527 | Actions.ActOnStartOfObjCMethodDef(getCurScope(), MDecl); |
| 2528 | |
| 2529 | if (PP.isCodeCompletionEnabled()) { |
| 2530 | if (trySkippingFunctionBodyForCodeCompletion()) { |
| 2531 | BodyScope.Exit(); |
| 2532 | return Actions.ActOnFinishFunctionBody(MDecl, 0); |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | StmtResult FnBody(ParseCompoundStatementBody()); |
| 2537 | |
| 2538 | // If the function body could not be parsed, make a bogus compoundstmt. |
| 2539 | if (FnBody.isInvalid()) |
| 2540 | FnBody = Actions.ActOnCompoundStmt(BraceLoc, BraceLoc, |
| 2541 | MultiStmtArg(Actions), false); |
| 2542 | |
| 2543 | // Leave the function body scope. |
| 2544 | BodyScope.Exit(); |
| 2545 | |
| 2546 | return Actions.ActOnFinishFunctionBody(MDecl, FnBody.take()); |
| 2547 | } |