Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===// |
| 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 Expression parsing implementation for C++. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 16 | #include "clang/Parse/DeclSpec.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 19 | /// ParseOptionalCXXScopeSpecifier - Parse global scope or |
| 20 | /// nested-name-specifier if present. Returns true if a nested-name-specifier |
| 21 | /// was parsed from the token stream. Note that this routine will not parse |
| 22 | /// ::new or ::delete, it will just leave them in the token stream. |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 23 | /// |
| 24 | /// '::'[opt] nested-name-specifier |
| 25 | /// '::' |
| 26 | /// |
| 27 | /// nested-name-specifier: |
| 28 | /// type-name '::' |
| 29 | /// namespace-name '::' |
| 30 | /// nested-name-specifier identifier '::' |
| 31 | /// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO] |
| 32 | /// |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 33 | bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS) { |
Argyrios Kyrtzidis | 4bdd91c | 2008-11-26 21:41:52 +0000 | [diff] [blame] | 34 | assert(getLang().CPlusPlus && |
Chris Lattner | 7452c6f | 2009-01-05 01:24:05 +0000 | [diff] [blame] | 35 | "Call sites of this function should be guarded by checking for C++"); |
Argyrios Kyrtzidis | 4bdd91c | 2008-11-26 21:41:52 +0000 | [diff] [blame] | 36 | |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 37 | if (Tok.is(tok::annot_cxxscope)) { |
Douglas Gregor | 3507369 | 2009-03-26 23:56:24 +0000 | [diff] [blame] | 38 | SS.setScopeRep(Tok.getAnnotationValue()); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 39 | SS.setRange(Tok.getAnnotationRange()); |
| 40 | ConsumeToken(); |
Argyrios Kyrtzidis | 4bdd91c | 2008-11-26 21:41:52 +0000 | [diff] [blame] | 41 | return true; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 42 | } |
Chris Lattner | e607e80 | 2009-01-04 21:14:15 +0000 | [diff] [blame] | 43 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 44 | bool HasScopeSpecifier = false; |
| 45 | |
Chris Lattner | 5b45473 | 2009-01-05 03:55:46 +0000 | [diff] [blame] | 46 | if (Tok.is(tok::coloncolon)) { |
| 47 | // ::new and ::delete aren't nested-name-specifiers. |
| 48 | tok::TokenKind NextKind = NextToken().getKind(); |
| 49 | if (NextKind == tok::kw_new || NextKind == tok::kw_delete) |
| 50 | return false; |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 52 | // '::' - Global scope qualifier. |
Chris Lattner | 357089d | 2009-01-05 02:07:19 +0000 | [diff] [blame] | 53 | SourceLocation CCLoc = ConsumeToken(); |
Chris Lattner | 357089d | 2009-01-05 02:07:19 +0000 | [diff] [blame] | 54 | SS.setBeginLoc(CCLoc); |
Douglas Gregor | 3507369 | 2009-03-26 23:56:24 +0000 | [diff] [blame] | 55 | SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc)); |
Chris Lattner | 357089d | 2009-01-05 02:07:19 +0000 | [diff] [blame] | 56 | SS.setEndLoc(CCLoc); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 57 | HasScopeSpecifier = true; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 60 | while (true) { |
| 61 | // nested-name-specifier: |
Chris Lattner | 77cf72a | 2009-06-26 03:47:46 +0000 | [diff] [blame^] | 62 | // nested-name-specifier 'template'[opt] simple-template-id '::' |
| 63 | |
| 64 | // Parse the optional 'template' keyword, then make sure we have |
| 65 | // 'identifier <' after it. |
| 66 | if (Tok.is(tok::kw_template)) { |
| 67 | SourceLocation TemplateKWLoc = ConsumeToken(); |
| 68 | |
| 69 | if (Tok.isNot(tok::identifier)) { |
| 70 | Diag(Tok.getLocation(), |
| 71 | diag::err_id_after_template_in_nested_name_spec) |
| 72 | << SourceRange(TemplateKWLoc); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | if (NextToken().isNot(tok::less)) { |
| 77 | Diag(NextToken().getLocation(), |
| 78 | diag::err_less_after_template_name_in_nested_name_spec) |
| 79 | << Tok.getIdentifierInfo()->getName() |
| 80 | << SourceRange(TemplateKWLoc, Tok.getLocation()); |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | TemplateTy Template |
| 85 | = Actions.ActOnDependentTemplateName(TemplateKWLoc, |
| 86 | *Tok.getIdentifierInfo(), |
| 87 | Tok.getLocation(), SS); |
| 88 | AnnotateTemplateIdToken(Template, TNK_Dependent_template_name, |
| 89 | &SS, TemplateKWLoc, false); |
| 90 | continue; |
| 91 | } |
| 92 | |
| 93 | // nested-name-specifier: |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 94 | // type-name '::' |
| 95 | // namespace-name '::' |
| 96 | // nested-name-specifier identifier '::' |
| 97 | if (Tok.is(tok::identifier) && NextToken().is(tok::coloncolon)) { |
| 98 | // We have an identifier followed by a '::'. Lookup this name |
| 99 | // as the name in a nested-name-specifier. |
| 100 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 101 | SourceLocation IdLoc = ConsumeToken(); |
| 102 | assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); |
| 103 | SourceLocation CCLoc = ConsumeToken(); |
| 104 | |
| 105 | if (!HasScopeSpecifier) { |
| 106 | SS.setBeginLoc(IdLoc); |
| 107 | HasScopeSpecifier = true; |
| 108 | } |
| 109 | |
| 110 | if (SS.isInvalid()) |
| 111 | continue; |
| 112 | |
Douglas Gregor | 3507369 | 2009-03-26 23:56:24 +0000 | [diff] [blame] | 113 | SS.setScopeRep( |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 114 | Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II)); |
| 115 | SS.setEndLoc(CCLoc); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 116 | continue; |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 117 | } |
Chris Lattner | 67b9e83 | 2009-06-26 03:45:46 +0000 | [diff] [blame] | 118 | |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 119 | // nested-name-specifier: |
| 120 | // type-name '::' |
Chris Lattner | 67b9e83 | 2009-06-26 03:45:46 +0000 | [diff] [blame] | 121 | if (Tok.is(tok::identifier) && NextToken().is(tok::less)) { |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 122 | TemplateTy Template; |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 123 | TemplateNameKind TNK = Actions.isTemplateName(*Tok.getIdentifierInfo(), |
| 124 | CurScope, Template, &SS); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 125 | if (TNK) { |
| 126 | // We have found a template name, so annotate this this token |
| 127 | // with a template-id annotation. We do not permit the |
| 128 | // template-id to be translated into a type annotation, |
| 129 | // because some clients (e.g., the parsing of class template |
| 130 | // specializations) still want to see the original template-id |
| 131 | // token. |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 132 | AnnotateTemplateIdToken(Template, TNK, &SS, SourceLocation(), false); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 133 | continue; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) { |
| 138 | // We have |
| 139 | // |
| 140 | // simple-template-id '::' |
| 141 | // |
| 142 | // So we need to check whether the simple-template-id is of the |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 143 | // right kind (it should name a type or be dependent), and then |
| 144 | // convert it into a type within the nested-name-specifier. |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 145 | TemplateIdAnnotation *TemplateId |
| 146 | = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue()); |
| 147 | |
Douglas Gregor | c45c232 | 2009-03-31 00:43:58 +0000 | [diff] [blame] | 148 | if (TemplateId->Kind == TNK_Type_template || |
| 149 | TemplateId->Kind == TNK_Dependent_template_name) { |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 150 | AnnotateTemplateIdTokenAsType(&SS); |
Douglas Gregor | 3f5b61c | 2009-05-14 00:28:11 +0000 | [diff] [blame] | 151 | SS.setScopeRep(0); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 152 | |
| 153 | assert(Tok.is(tok::annot_typename) && |
| 154 | "AnnotateTemplateIdTokenAsType isn't working"); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 155 | Token TypeToken = Tok; |
| 156 | ConsumeToken(); |
| 157 | assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!"); |
| 158 | SourceLocation CCLoc = ConsumeToken(); |
| 159 | |
| 160 | if (!HasScopeSpecifier) { |
| 161 | SS.setBeginLoc(TypeToken.getLocation()); |
| 162 | HasScopeSpecifier = true; |
| 163 | } |
Douglas Gregor | 31a19b6 | 2009-04-01 21:51:26 +0000 | [diff] [blame] | 164 | |
| 165 | if (TypeToken.getAnnotationValue()) |
| 166 | SS.setScopeRep( |
| 167 | Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, |
| 168 | TypeToken.getAnnotationValue(), |
| 169 | TypeToken.getAnnotationRange(), |
| 170 | CCLoc)); |
| 171 | else |
| 172 | SS.setScopeRep(0); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 173 | SS.setEndLoc(CCLoc); |
| 174 | continue; |
Chris Lattner | 67b9e83 | 2009-06-26 03:45:46 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | assert(false && "FIXME: Only type template names supported here"); |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | // We don't have any tokens that form the beginning of a |
| 181 | // nested-name-specifier, so we're done. |
| 182 | break; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 183 | } |
Douglas Gregor | 39a8de1 | 2009-02-25 19:37:18 +0000 | [diff] [blame] | 184 | |
| 185 | return HasScopeSpecifier; |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /// ParseCXXIdExpression - Handle id-expression. |
| 189 | /// |
| 190 | /// id-expression: |
| 191 | /// unqualified-id |
| 192 | /// qualified-id |
| 193 | /// |
| 194 | /// unqualified-id: |
| 195 | /// identifier |
| 196 | /// operator-function-id |
| 197 | /// conversion-function-id [TODO] |
| 198 | /// '~' class-name [TODO] |
| 199 | /// template-id [TODO] |
| 200 | /// |
| 201 | /// qualified-id: |
| 202 | /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 203 | /// '::' identifier |
| 204 | /// '::' operator-function-id |
| 205 | /// '::' template-id [TODO] |
| 206 | /// |
| 207 | /// nested-name-specifier: |
| 208 | /// type-name '::' |
| 209 | /// namespace-name '::' |
| 210 | /// nested-name-specifier identifier '::' |
| 211 | /// nested-name-specifier 'template'[opt] simple-template-id '::' [TODO] |
| 212 | /// |
| 213 | /// NOTE: The standard specifies that, for qualified-id, the parser does not |
| 214 | /// expect: |
| 215 | /// |
| 216 | /// '::' conversion-function-id |
| 217 | /// '::' '~' class-name |
| 218 | /// |
| 219 | /// This may cause a slight inconsistency on diagnostics: |
| 220 | /// |
| 221 | /// class C {}; |
| 222 | /// namespace A {} |
| 223 | /// void f() { |
| 224 | /// :: A :: ~ C(); // Some Sema error about using destructor with a |
| 225 | /// // namespace. |
| 226 | /// :: ~ C(); // Some Parser error like 'unexpected ~'. |
| 227 | /// } |
| 228 | /// |
| 229 | /// We simplify the parser a bit and make it work like: |
| 230 | /// |
| 231 | /// qualified-id: |
| 232 | /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 233 | /// '::' unqualified-id |
| 234 | /// |
| 235 | /// That way Sema can handle and report similar errors for namespaces and the |
| 236 | /// global scope. |
| 237 | /// |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 238 | /// The isAddressOfOperand parameter indicates that this id-expression is a |
| 239 | /// direct operand of the address-of operator. This is, besides member contexts, |
| 240 | /// the only place where a qualified-id naming a non-static class member may |
| 241 | /// appear. |
| 242 | /// |
| 243 | Parser::OwningExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) { |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 244 | // qualified-id: |
| 245 | // '::'[opt] nested-name-specifier 'template'[opt] unqualified-id |
| 246 | // '::' unqualified-id |
| 247 | // |
| 248 | CXXScopeSpec SS; |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 249 | ParseOptionalCXXScopeSpecifier(SS); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 250 | |
| 251 | // unqualified-id: |
| 252 | // identifier |
| 253 | // operator-function-id |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 254 | // conversion-function-id |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 255 | // '~' class-name [TODO] |
| 256 | // template-id [TODO] |
| 257 | // |
| 258 | switch (Tok.getKind()) { |
| 259 | default: |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 260 | return ExprError(Diag(Tok, diag::err_expected_unqualified_id)); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 261 | |
| 262 | case tok::identifier: { |
| 263 | // Consume the identifier so that we can see if it is followed by a '('. |
| 264 | IdentifierInfo &II = *Tok.getIdentifierInfo(); |
| 265 | SourceLocation L = ConsumeToken(); |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 266 | return Actions.ActOnIdentifierExpr(CurScope, L, II, Tok.is(tok::l_paren), |
| 267 | &SS, isAddressOfOperand); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | case tok::kw_operator: { |
| 271 | SourceLocation OperatorLoc = Tok.getLocation(); |
Chris Lattner | 7452c6f | 2009-01-05 01:24:05 +0000 | [diff] [blame] | 272 | if (OverloadedOperatorKind Op = TryParseOperatorFunctionId()) |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 273 | return Actions.ActOnCXXOperatorFunctionIdExpr( |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 274 | CurScope, OperatorLoc, Op, Tok.is(tok::l_paren), SS, |
| 275 | isAddressOfOperand); |
Chris Lattner | 7452c6f | 2009-01-05 01:24:05 +0000 | [diff] [blame] | 276 | if (TypeTy *Type = ParseConversionFunctionId()) |
Sebastian Redl | cd965b9 | 2009-01-18 18:53:16 +0000 | [diff] [blame] | 277 | return Actions.ActOnCXXConversionFunctionExpr(CurScope, OperatorLoc, Type, |
Sebastian Redl | ebc07d5 | 2009-02-03 20:19:35 +0000 | [diff] [blame] | 278 | Tok.is(tok::l_paren), SS, |
| 279 | isAddressOfOperand); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 280 | |
Douglas Gregor | 2def483 | 2008-11-17 20:34:05 +0000 | [diff] [blame] | 281 | // We already complained about a bad conversion-function-id, |
| 282 | // above. |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 283 | return ExprError(); |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | } // switch. |
| 287 | |
| 288 | assert(0 && "The switch was supposed to take care everything."); |
| 289 | } |
| 290 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 291 | /// ParseCXXCasts - This handles the various ways to cast expressions to another |
| 292 | /// type. |
| 293 | /// |
| 294 | /// postfix-expression: [C++ 5.2p1] |
| 295 | /// 'dynamic_cast' '<' type-name '>' '(' expression ')' |
| 296 | /// 'static_cast' '<' type-name '>' '(' expression ')' |
| 297 | /// 'reinterpret_cast' '<' type-name '>' '(' expression ')' |
| 298 | /// 'const_cast' '<' type-name '>' '(' expression ')' |
| 299 | /// |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 300 | Parser::OwningExprResult Parser::ParseCXXCasts() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 301 | tok::TokenKind Kind = Tok.getKind(); |
| 302 | const char *CastName = 0; // For error messages |
| 303 | |
| 304 | switch (Kind) { |
| 305 | default: assert(0 && "Unknown C++ cast!"); abort(); |
| 306 | case tok::kw_const_cast: CastName = "const_cast"; break; |
| 307 | case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break; |
| 308 | case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break; |
| 309 | case tok::kw_static_cast: CastName = "static_cast"; break; |
| 310 | } |
| 311 | |
| 312 | SourceLocation OpLoc = ConsumeToken(); |
| 313 | SourceLocation LAngleBracketLoc = Tok.getLocation(); |
| 314 | |
| 315 | if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName)) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 316 | return ExprError(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 317 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 318 | TypeResult CastTy = ParseTypeName(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 319 | SourceLocation RAngleBracketLoc = Tok.getLocation(); |
| 320 | |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 321 | if (ExpectAndConsume(tok::greater, diag::err_expected_greater)) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 322 | return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << "<"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 323 | |
| 324 | SourceLocation LParenLoc = Tok.getLocation(), RParenLoc; |
| 325 | |
Argyrios Kyrtzidis | 21e7ad2 | 2009-05-22 10:23:16 +0000 | [diff] [blame] | 326 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, CastName)) |
| 327 | return ExprError(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 328 | |
Argyrios Kyrtzidis | 21e7ad2 | 2009-05-22 10:23:16 +0000 | [diff] [blame] | 329 | OwningExprResult Result = ParseExpression(); |
| 330 | |
| 331 | // Match the ')'. |
| 332 | if (Result.isInvalid()) |
| 333 | SkipUntil(tok::r_paren); |
| 334 | |
| 335 | if (Tok.is(tok::r_paren)) |
| 336 | RParenLoc = ConsumeParen(); |
| 337 | else |
| 338 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 339 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 340 | if (!Result.isInvalid() && !CastTy.isInvalid()) |
Douglas Gregor | 49badde | 2008-10-27 19:41:14 +0000 | [diff] [blame] | 341 | Result = Actions.ActOnCXXNamedCast(OpLoc, Kind, |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 342 | LAngleBracketLoc, CastTy.get(), |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 343 | RAngleBracketLoc, |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 344 | LParenLoc, move(Result), RParenLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 345 | |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 346 | return move(Result); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 349 | /// ParseCXXTypeid - This handles the C++ typeid expression. |
| 350 | /// |
| 351 | /// postfix-expression: [C++ 5.2p1] |
| 352 | /// 'typeid' '(' expression ')' |
| 353 | /// 'typeid' '(' type-id ')' |
| 354 | /// |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 355 | Parser::OwningExprResult Parser::ParseCXXTypeid() { |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 356 | assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!"); |
| 357 | |
| 358 | SourceLocation OpLoc = ConsumeToken(); |
| 359 | SourceLocation LParenLoc = Tok.getLocation(); |
| 360 | SourceLocation RParenLoc; |
| 361 | |
| 362 | // typeid expressions are always parenthesized. |
| 363 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
| 364 | "typeid")) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 365 | return ExprError(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 366 | |
Sebastian Redl | 15faa7f | 2008-12-09 20:22:58 +0000 | [diff] [blame] | 367 | OwningExprResult Result(Actions); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 368 | |
| 369 | if (isTypeIdInParens()) { |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 370 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 371 | |
| 372 | // Match the ')'. |
| 373 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 374 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 375 | if (Ty.isInvalid()) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 376 | return ExprError(); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 377 | |
| 378 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true, |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 379 | Ty.get(), RParenLoc); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 380 | } else { |
Douglas Gregor | e0762c9 | 2009-06-19 23:52:42 +0000 | [diff] [blame] | 381 | // C++0x [expr.typeid]p3: |
| 382 | // When typeid is applied to an expression other than an lvalue of a |
| 383 | // polymorphic class type [...] The expression is an unevaluated |
| 384 | // operand (Clause 5). |
| 385 | // |
| 386 | // Note that we can't tell whether the expression is an lvalue of a |
| 387 | // polymorphic class type until after we've parsed the expression, so |
Douglas Gregor | ac7610d | 2009-06-22 20:57:11 +0000 | [diff] [blame] | 388 | // we the expression is potentially potentially evaluated. |
| 389 | EnterExpressionEvaluationContext Unevaluated(Actions, |
| 390 | Action::PotentiallyPotentiallyEvaluated); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 391 | Result = ParseExpression(); |
| 392 | |
| 393 | // Match the ')'. |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 394 | if (Result.isInvalid()) |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 395 | SkipUntil(tok::r_paren); |
| 396 | else { |
| 397 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 398 | |
| 399 | Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false, |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 400 | Result.release(), RParenLoc); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 404 | return move(Result); |
Sebastian Redl | c42e118 | 2008-11-11 11:37:55 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 407 | /// ParseCXXBoolLiteral - This handles the C++ Boolean literals. |
| 408 | /// |
| 409 | /// boolean-literal: [C++ 2.13.5] |
| 410 | /// 'true' |
| 411 | /// 'false' |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 412 | Parser::OwningExprResult Parser::ParseCXXBoolLiteral() { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 413 | tok::TokenKind Kind = Tok.getKind(); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 414 | return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 415 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 416 | |
| 417 | /// ParseThrowExpression - This handles the C++ throw expression. |
| 418 | /// |
| 419 | /// throw-expression: [C++ 15] |
| 420 | /// 'throw' assignment-expression[opt] |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 421 | Parser::OwningExprResult Parser::ParseThrowExpression() { |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 422 | assert(Tok.is(tok::kw_throw) && "Not throw!"); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 423 | SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token. |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 424 | |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 425 | // If the current token isn't the start of an assignment-expression, |
| 426 | // then the expression is not present. This handles things like: |
| 427 | // "C ? throw : (void)42", which is crazy but legal. |
| 428 | switch (Tok.getKind()) { // FIXME: move this predicate somewhere common. |
| 429 | case tok::semi: |
| 430 | case tok::r_paren: |
| 431 | case tok::r_square: |
| 432 | case tok::r_brace: |
| 433 | case tok::colon: |
| 434 | case tok::comma: |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 435 | return Actions.ActOnCXXThrow(ThrowLoc, ExprArg(Actions)); |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 436 | |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 437 | default: |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 438 | OwningExprResult Expr(ParseAssignmentExpression()); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 439 | if (Expr.isInvalid()) return move(Expr); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 440 | return Actions.ActOnCXXThrow(ThrowLoc, move(Expr)); |
Chris Lattner | 2a2819a | 2008-04-06 06:02:23 +0000 | [diff] [blame] | 441 | } |
Chris Lattner | 50dd289 | 2008-02-26 00:51:44 +0000 | [diff] [blame] | 442 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 443 | |
| 444 | /// ParseCXXThis - This handles the C++ 'this' pointer. |
| 445 | /// |
| 446 | /// C++ 9.3.2: In the body of a non-static member function, the keyword this is |
| 447 | /// a non-lvalue expression whose value is the address of the object for which |
| 448 | /// the function is called. |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 449 | Parser::OwningExprResult Parser::ParseCXXThis() { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 450 | assert(Tok.is(tok::kw_this) && "Not 'this'!"); |
| 451 | SourceLocation ThisLoc = ConsumeToken(); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 452 | return Actions.ActOnCXXThis(ThisLoc); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 453 | } |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 454 | |
| 455 | /// ParseCXXTypeConstructExpression - Parse construction of a specified type. |
| 456 | /// Can be interpreted either as function-style casting ("int(x)") |
| 457 | /// or class type construction ("ClassType(x,y,z)") |
| 458 | /// or creation of a value-initialized type ("int()"). |
| 459 | /// |
| 460 | /// postfix-expression: [C++ 5.2p1] |
| 461 | /// simple-type-specifier '(' expression-list[opt] ')' [C++ 5.2.3] |
| 462 | /// typename-specifier '(' expression-list[opt] ')' [TODO] |
| 463 | /// |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 464 | Parser::OwningExprResult |
| 465 | Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) { |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 466 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 467 | TypeTy *TypeRep = Actions.ActOnTypeName(CurScope, DeclaratorInfo).get(); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 468 | |
| 469 | assert(Tok.is(tok::l_paren) && "Expected '('!"); |
| 470 | SourceLocation LParenLoc = ConsumeParen(); |
| 471 | |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 472 | ExprVector Exprs(Actions); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 473 | CommaLocsTy CommaLocs; |
| 474 | |
| 475 | if (Tok.isNot(tok::r_paren)) { |
| 476 | if (ParseExpressionList(Exprs, CommaLocs)) { |
| 477 | SkipUntil(tok::r_paren); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 478 | return ExprError(); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | // Match the ')'. |
| 483 | SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 484 | |
| 485 | assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&& |
| 486 | "Unexpected number of commas!"); |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 487 | return Actions.ActOnCXXTypeConstructExpr(DS.getSourceRange(), TypeRep, |
| 488 | LParenLoc, move_arg(Exprs), |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 489 | CommaLocs.data(), RParenLoc); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 492 | /// ParseCXXCondition - if/switch/while/for condition expression. |
| 493 | /// |
| 494 | /// condition: |
| 495 | /// expression |
| 496 | /// type-specifier-seq declarator '=' assignment-expression |
| 497 | /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] |
| 498 | /// '=' assignment-expression |
| 499 | /// |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 500 | Parser::OwningExprResult Parser::ParseCXXCondition() { |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 501 | if (!isCXXConditionDeclaration()) |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 502 | return ParseExpression(); // expression |
| 503 | |
| 504 | SourceLocation StartLoc = Tok.getLocation(); |
| 505 | |
| 506 | // type-specifier-seq |
| 507 | DeclSpec DS; |
| 508 | ParseSpecifierQualifierList(DS); |
| 509 | |
| 510 | // declarator |
| 511 | Declarator DeclaratorInfo(DS, Declarator::ConditionContext); |
| 512 | ParseDeclarator(DeclaratorInfo); |
| 513 | |
| 514 | // simple-asm-expr[opt] |
| 515 | if (Tok.is(tok::kw_asm)) { |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 516 | SourceLocation Loc; |
| 517 | OwningExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 518 | if (AsmLabel.isInvalid()) { |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 519 | SkipUntil(tok::semi); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 520 | return ExprError(); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 521 | } |
Sebastian Redl | effa8d1 | 2008-12-10 00:02:53 +0000 | [diff] [blame] | 522 | DeclaratorInfo.setAsmLabel(AsmLabel.release()); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 523 | DeclaratorInfo.SetRangeEnd(Loc); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | // If attributes are present, parse them. |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 527 | if (Tok.is(tok::kw___attribute)) { |
| 528 | SourceLocation Loc; |
| 529 | AttributeList *AttrList = ParseAttributes(&Loc); |
| 530 | DeclaratorInfo.AddAttributes(AttrList, Loc); |
| 531 | } |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 532 | |
| 533 | // '=' assignment-expression |
| 534 | if (Tok.isNot(tok::equal)) |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 535 | return ExprError(Diag(Tok, diag::err_expected_equal_after_declarator)); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 536 | SourceLocation EqualLoc = ConsumeToken(); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 537 | OwningExprResult AssignExpr(ParseAssignmentExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 538 | if (AssignExpr.isInvalid()) |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 539 | return ExprError(); |
| 540 | |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 541 | return Actions.ActOnCXXConditionDeclarationExpr(CurScope, StartLoc, |
| 542 | DeclaratorInfo,EqualLoc, |
| 543 | move(AssignExpr)); |
Argyrios Kyrtzidis | 71b914b | 2008-09-09 20:38:47 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 546 | /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers. |
| 547 | /// This should only be called when the current token is known to be part of |
| 548 | /// simple-type-specifier. |
| 549 | /// |
| 550 | /// simple-type-specifier: |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 551 | /// '::'[opt] nested-name-specifier[opt] type-name |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 552 | /// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO] |
| 553 | /// char |
| 554 | /// wchar_t |
| 555 | /// bool |
| 556 | /// short |
| 557 | /// int |
| 558 | /// long |
| 559 | /// signed |
| 560 | /// unsigned |
| 561 | /// float |
| 562 | /// double |
| 563 | /// void |
| 564 | /// [GNU] typeof-specifier |
| 565 | /// [C++0x] auto [TODO] |
| 566 | /// |
| 567 | /// type-name: |
| 568 | /// class-name |
| 569 | /// enum-name |
| 570 | /// typedef-name |
| 571 | /// |
| 572 | void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) { |
| 573 | DS.SetRangeStart(Tok.getLocation()); |
| 574 | const char *PrevSpec; |
| 575 | SourceLocation Loc = Tok.getLocation(); |
| 576 | |
| 577 | switch (Tok.getKind()) { |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 578 | case tok::identifier: // foo::bar |
| 579 | case tok::coloncolon: // ::foo::bar |
| 580 | assert(0 && "Annotation token should already be formed!"); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 581 | default: |
| 582 | assert(0 && "Not a simple-type-specifier token!"); |
| 583 | abort(); |
Chris Lattner | 55a7cef | 2009-01-05 00:13:00 +0000 | [diff] [blame] | 584 | |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 585 | // type-name |
Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 586 | case tok::annot_typename: { |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 587 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 588 | Tok.getAnnotationValue()); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 589 | break; |
| 590 | } |
| 591 | |
| 592 | // builtin types |
| 593 | case tok::kw_short: |
| 594 | DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec); |
| 595 | break; |
| 596 | case tok::kw_long: |
| 597 | DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec); |
| 598 | break; |
| 599 | case tok::kw_signed: |
| 600 | DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec); |
| 601 | break; |
| 602 | case tok::kw_unsigned: |
| 603 | DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec); |
| 604 | break; |
| 605 | case tok::kw_void: |
| 606 | DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec); |
| 607 | break; |
| 608 | case tok::kw_char: |
| 609 | DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec); |
| 610 | break; |
| 611 | case tok::kw_int: |
| 612 | DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec); |
| 613 | break; |
| 614 | case tok::kw_float: |
| 615 | DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec); |
| 616 | break; |
| 617 | case tok::kw_double: |
| 618 | DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec); |
| 619 | break; |
| 620 | case tok::kw_wchar_t: |
| 621 | DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec); |
| 622 | break; |
| 623 | case tok::kw_bool: |
| 624 | DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec); |
| 625 | break; |
| 626 | |
| 627 | // GNU typeof support. |
| 628 | case tok::kw_typeof: |
| 629 | ParseTypeofSpecifier(DS); |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 630 | DS.Finish(Diags, PP); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 631 | return; |
| 632 | } |
Chris Lattner | b31757b | 2009-01-06 05:06:21 +0000 | [diff] [blame] | 633 | if (Tok.is(tok::annot_typename)) |
Argyrios Kyrtzidis | eb83ecd | 2008-11-08 16:45:02 +0000 | [diff] [blame] | 634 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 635 | else |
| 636 | DS.SetRangeEnd(Tok.getLocation()); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 637 | ConsumeToken(); |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 638 | DS.Finish(Diags, PP); |
Argyrios Kyrtzidis | 987a14b | 2008-08-22 15:38:55 +0000 | [diff] [blame] | 639 | } |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 640 | |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 641 | /// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++ |
| 642 | /// [dcl.name]), which is a non-empty sequence of type-specifiers, |
| 643 | /// e.g., "const short int". Note that the DeclSpec is *not* finished |
| 644 | /// by parsing the type-specifier-seq, because these sequences are |
| 645 | /// typically followed by some form of declarator. Returns true and |
| 646 | /// emits diagnostics if this is not a type-specifier-seq, false |
| 647 | /// otherwise. |
| 648 | /// |
| 649 | /// type-specifier-seq: [C++ 8.1] |
| 650 | /// type-specifier type-specifier-seq[opt] |
| 651 | /// |
| 652 | bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) { |
| 653 | DS.SetRangeStart(Tok.getLocation()); |
| 654 | const char *PrevSpec = 0; |
| 655 | int isInvalid = 0; |
| 656 | |
| 657 | // Parse one or more of the type specifiers. |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 658 | if (!ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec)) { |
Chris Lattner | 1ab3b96 | 2008-11-18 07:48:38 +0000 | [diff] [blame] | 659 | Diag(Tok, diag::err_operator_missing_type_specifier); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 660 | return true; |
| 661 | } |
Chris Lattner | 7a0ab5f | 2009-01-06 06:59:53 +0000 | [diff] [blame] | 662 | |
Ted Kremenek | b8006e5 | 2009-01-06 19:17:58 +0000 | [diff] [blame] | 663 | while (ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec)) ; |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 664 | |
| 665 | return false; |
| 666 | } |
| 667 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 668 | /// TryParseOperatorFunctionId - Attempts to parse a C++ overloaded |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 669 | /// operator name (C++ [over.oper]). If successful, returns the |
| 670 | /// predefined identifier that corresponds to that overloaded |
| 671 | /// operator. Otherwise, returns NULL and does not consume any tokens. |
| 672 | /// |
| 673 | /// operator-function-id: [C++ 13.5] |
| 674 | /// 'operator' operator |
| 675 | /// |
| 676 | /// operator: one of |
| 677 | /// new delete new[] delete[] |
| 678 | /// + - * / % ^ & | ~ |
| 679 | /// ! = < > += -= *= /= %= |
| 680 | /// ^= &= |= << >> >>= <<= == != |
| 681 | /// <= >= && || ++ -- , ->* -> |
| 682 | /// () [] |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 683 | OverloadedOperatorKind |
| 684 | Parser::TryParseOperatorFunctionId(SourceLocation *EndLoc) { |
Argyrios Kyrtzidis | 9057a81 | 2008-11-07 15:54:02 +0000 | [diff] [blame] | 685 | assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 686 | SourceLocation Loc; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 687 | |
| 688 | OverloadedOperatorKind Op = OO_None; |
| 689 | switch (NextToken().getKind()) { |
| 690 | case tok::kw_new: |
| 691 | ConsumeToken(); // 'operator' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 692 | Loc = ConsumeToken(); // 'new' |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 693 | if (Tok.is(tok::l_square)) { |
| 694 | ConsumeBracket(); // '[' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 695 | Loc = Tok.getLocation(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 696 | ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); // ']' |
| 697 | Op = OO_Array_New; |
| 698 | } else { |
| 699 | Op = OO_New; |
| 700 | } |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 701 | if (EndLoc) |
| 702 | *EndLoc = Loc; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 703 | return Op; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 704 | |
| 705 | case tok::kw_delete: |
| 706 | ConsumeToken(); // 'operator' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 707 | Loc = ConsumeToken(); // 'delete' |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 708 | if (Tok.is(tok::l_square)) { |
| 709 | ConsumeBracket(); // '[' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 710 | Loc = Tok.getLocation(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 711 | ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); // ']' |
| 712 | Op = OO_Array_Delete; |
| 713 | } else { |
| 714 | Op = OO_Delete; |
| 715 | } |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 716 | if (EndLoc) |
| 717 | *EndLoc = Loc; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 718 | return Op; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 719 | |
Douglas Gregor | 02bcd4c | 2008-11-10 13:38:07 +0000 | [diff] [blame] | 720 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 721 | case tok::Token: Op = OO_##Name; break; |
Douglas Gregor | 02bcd4c | 2008-11-10 13:38:07 +0000 | [diff] [blame] | 722 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 723 | #include "clang/Basic/OperatorKinds.def" |
| 724 | |
| 725 | case tok::l_paren: |
| 726 | ConsumeToken(); // 'operator' |
| 727 | ConsumeParen(); // '(' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 728 | Loc = Tok.getLocation(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 729 | ExpectAndConsume(tok::r_paren, diag::err_expected_rparen); // ')' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 730 | if (EndLoc) |
| 731 | *EndLoc = Loc; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 732 | return OO_Call; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 733 | |
| 734 | case tok::l_square: |
| 735 | ConsumeToken(); // 'operator' |
| 736 | ConsumeBracket(); // '[' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 737 | Loc = Tok.getLocation(); |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 738 | ExpectAndConsume(tok::r_square, diag::err_expected_rsquare); // ']' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 739 | if (EndLoc) |
| 740 | *EndLoc = Loc; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 741 | return OO_Subscript; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 742 | |
| 743 | default: |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 744 | return OO_None; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Douglas Gregor | 43c7bad | 2008-11-17 16:14:12 +0000 | [diff] [blame] | 747 | ConsumeToken(); // 'operator' |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 748 | Loc = ConsumeAnyToken(); // the operator itself |
| 749 | if (EndLoc) |
| 750 | *EndLoc = Loc; |
Douglas Gregor | e94ca9e4 | 2008-11-18 14:39:36 +0000 | [diff] [blame] | 751 | return Op; |
Douglas Gregor | 1cd1b1e | 2008-11-06 22:13:31 +0000 | [diff] [blame] | 752 | } |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 753 | |
| 754 | /// ParseConversionFunctionId - Parse a C++ conversion-function-id, |
| 755 | /// which expresses the name of a user-defined conversion operator |
| 756 | /// (C++ [class.conv.fct]p1). Returns the type that this operator is |
| 757 | /// specifying a conversion for, or NULL if there was an error. |
| 758 | /// |
| 759 | /// conversion-function-id: [C++ 12.3.2] |
| 760 | /// operator conversion-type-id |
| 761 | /// |
| 762 | /// conversion-type-id: |
| 763 | /// type-specifier-seq conversion-declarator[opt] |
| 764 | /// |
| 765 | /// conversion-declarator: |
| 766 | /// ptr-operator conversion-declarator[opt] |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 767 | Parser::TypeTy *Parser::ParseConversionFunctionId(SourceLocation *EndLoc) { |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 768 | assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword"); |
| 769 | ConsumeToken(); // 'operator' |
| 770 | |
| 771 | // Parse the type-specifier-seq. |
| 772 | DeclSpec DS; |
| 773 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 774 | return 0; |
| 775 | |
| 776 | // Parse the conversion-declarator, which is merely a sequence of |
| 777 | // ptr-operators. |
| 778 | Declarator D(DS, Declarator::TypeNameContext); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 779 | ParseDeclaratorInternal(D, /*DirectDeclParser=*/0); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 780 | if (EndLoc) |
| 781 | *EndLoc = D.getSourceRange().getEnd(); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 782 | |
| 783 | // Finish up the type. |
| 784 | Action::TypeResult Result = Actions.ActOnTypeName(CurScope, D); |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 785 | if (Result.isInvalid()) |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 786 | return 0; |
| 787 | else |
Douglas Gregor | 5ac8aff | 2009-01-26 22:44:13 +0000 | [diff] [blame] | 788 | return Result.get(); |
Douglas Gregor | 2f1bc52 | 2008-11-07 20:08:42 +0000 | [diff] [blame] | 789 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 790 | |
| 791 | /// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate |
| 792 | /// memory in a typesafe manner and call constructors. |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 793 | /// |
| 794 | /// This method is called to parse the new expression after the optional :: has |
| 795 | /// been already parsed. If the :: was present, "UseGlobal" is true and "Start" |
| 796 | /// is its location. Otherwise, "Start" is the location of the 'new' token. |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 797 | /// |
| 798 | /// new-expression: |
| 799 | /// '::'[opt] 'new' new-placement[opt] new-type-id |
| 800 | /// new-initializer[opt] |
| 801 | /// '::'[opt] 'new' new-placement[opt] '(' type-id ')' |
| 802 | /// new-initializer[opt] |
| 803 | /// |
| 804 | /// new-placement: |
| 805 | /// '(' expression-list ')' |
| 806 | /// |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 807 | /// new-type-id: |
| 808 | /// type-specifier-seq new-declarator[opt] |
| 809 | /// |
| 810 | /// new-declarator: |
| 811 | /// ptr-operator new-declarator[opt] |
| 812 | /// direct-new-declarator |
| 813 | /// |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 814 | /// new-initializer: |
| 815 | /// '(' expression-list[opt] ')' |
| 816 | /// [C++0x] braced-init-list [TODO] |
| 817 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 818 | Parser::OwningExprResult |
| 819 | Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) { |
| 820 | assert(Tok.is(tok::kw_new) && "expected 'new' token"); |
| 821 | ConsumeToken(); // Consume 'new' |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 822 | |
| 823 | // A '(' now can be a new-placement or the '(' wrapping the type-id in the |
| 824 | // second form of new-expression. It can't be a new-type-id. |
| 825 | |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 826 | ExprVector PlacementArgs(Actions); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 827 | SourceLocation PlacementLParen, PlacementRParen; |
| 828 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 829 | bool ParenTypeId; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 830 | DeclSpec DS; |
| 831 | Declarator DeclaratorInfo(DS, Declarator::TypeNameContext); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 832 | if (Tok.is(tok::l_paren)) { |
| 833 | // If it turns out to be a placement, we change the type location. |
| 834 | PlacementLParen = ConsumeParen(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 835 | if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) { |
| 836 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 837 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 838 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 839 | |
| 840 | PlacementRParen = MatchRHSPunctuation(tok::r_paren, PlacementLParen); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 841 | if (PlacementRParen.isInvalid()) { |
| 842 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 843 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 844 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 845 | |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 846 | if (PlacementArgs.empty()) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 847 | // Reset the placement locations. There was no placement. |
| 848 | PlacementLParen = PlacementRParen = SourceLocation(); |
| 849 | ParenTypeId = true; |
| 850 | } else { |
| 851 | // We still need the type. |
| 852 | if (Tok.is(tok::l_paren)) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 853 | SourceLocation LParen = ConsumeParen(); |
| 854 | ParseSpecifierQualifierList(DS); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 855 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 856 | ParseDeclarator(DeclaratorInfo); |
| 857 | MatchRHSPunctuation(tok::r_paren, LParen); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 858 | ParenTypeId = true; |
| 859 | } else { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 860 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 861 | DeclaratorInfo.setInvalidType(true); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 862 | else { |
| 863 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 864 | ParseDeclaratorInternal(DeclaratorInfo, |
| 865 | &Parser::ParseDirectNewDeclarator); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 866 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 867 | ParenTypeId = false; |
| 868 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 869 | } |
| 870 | } else { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 871 | // A new-type-id is a simplified type-id, where essentially the |
| 872 | // direct-declarator is replaced by a direct-new-declarator. |
| 873 | if (ParseCXXTypeSpecifierSeq(DS)) |
| 874 | DeclaratorInfo.setInvalidType(true); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 875 | else { |
| 876 | DeclaratorInfo.SetSourceRange(DS.getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 877 | ParseDeclaratorInternal(DeclaratorInfo, |
| 878 | &Parser::ParseDirectNewDeclarator); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 879 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 880 | ParenTypeId = false; |
| 881 | } |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 882 | if (DeclaratorInfo.isInvalidType()) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 883 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 884 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 885 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 886 | |
Sebastian Redl | a55e52c | 2008-11-25 22:21:31 +0000 | [diff] [blame] | 887 | ExprVector ConstructorArgs(Actions); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 888 | SourceLocation ConstructorLParen, ConstructorRParen; |
| 889 | |
| 890 | if (Tok.is(tok::l_paren)) { |
| 891 | ConstructorLParen = ConsumeParen(); |
| 892 | if (Tok.isNot(tok::r_paren)) { |
| 893 | CommaLocsTy CommaLocs; |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 894 | if (ParseExpressionList(ConstructorArgs, CommaLocs)) { |
| 895 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 896 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 897 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 898 | } |
| 899 | ConstructorRParen = MatchRHSPunctuation(tok::r_paren, ConstructorLParen); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 900 | if (ConstructorRParen.isInvalid()) { |
| 901 | SkipUntil(tok::semi, /*StopAtSemi=*/true, /*DontConsume=*/true); |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 902 | return ExprError(); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 903 | } |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 906 | return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen, |
| 907 | move_arg(PlacementArgs), PlacementRParen, |
| 908 | ParenTypeId, DeclaratorInfo, ConstructorLParen, |
| 909 | move_arg(ConstructorArgs), ConstructorRParen); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 912 | /// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be |
| 913 | /// passed to ParseDeclaratorInternal. |
| 914 | /// |
| 915 | /// direct-new-declarator: |
| 916 | /// '[' expression ']' |
| 917 | /// direct-new-declarator '[' constant-expression ']' |
| 918 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 919 | void Parser::ParseDirectNewDeclarator(Declarator &D) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 920 | // Parse the array dimensions. |
| 921 | bool first = true; |
| 922 | while (Tok.is(tok::l_square)) { |
| 923 | SourceLocation LLoc = ConsumeBracket(); |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 924 | OwningExprResult Size(first ? ParseExpression() |
| 925 | : ParseConstantExpression()); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 926 | if (Size.isInvalid()) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 927 | // Recover |
| 928 | SkipUntil(tok::r_square); |
| 929 | return; |
| 930 | } |
| 931 | first = false; |
| 932 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 933 | SourceLocation RLoc = MatchRHSPunctuation(tok::r_square, LLoc); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 934 | D.AddTypeInfo(DeclaratorChunk::getArray(0, /*static=*/false, /*star=*/false, |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 935 | Size.release(), LLoc), |
| 936 | RLoc); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 937 | |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 938 | if (RLoc.isInvalid()) |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 939 | return; |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | /// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id. |
| 944 | /// This ambiguity appears in the syntax of the C++ new operator. |
| 945 | /// |
| 946 | /// new-expression: |
| 947 | /// '::'[opt] 'new' new-placement[opt] '(' type-id ')' |
| 948 | /// new-initializer[opt] |
| 949 | /// |
| 950 | /// new-placement: |
| 951 | /// '(' expression-list ')' |
| 952 | /// |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 953 | bool Parser::ParseExpressionListOrTypeId(ExprListTy &PlacementArgs, |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 954 | Declarator &D) { |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 955 | // The '(' was already consumed. |
| 956 | if (isTypeIdInParens()) { |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 957 | ParseSpecifierQualifierList(D.getMutableDeclSpec()); |
Sebastian Redl | ab197ba | 2009-02-09 18:23:29 +0000 | [diff] [blame] | 958 | D.SetSourceRange(D.getDeclSpec().getSourceRange()); |
Sebastian Redl | cee63fb | 2008-12-02 14:43:59 +0000 | [diff] [blame] | 959 | ParseDeclarator(D); |
Chris Lattner | eaaebc7 | 2009-04-25 08:06:05 +0000 | [diff] [blame] | 960 | return D.isInvalidType(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | // It's not a type, it has to be an expression list. |
| 964 | // Discard the comma locations - ActOnCXXNew has enough parameters. |
| 965 | CommaLocsTy CommaLocs; |
| 966 | return ParseExpressionList(PlacementArgs, CommaLocs); |
| 967 | } |
| 968 | |
| 969 | /// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used |
| 970 | /// to free memory allocated by new. |
| 971 | /// |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 972 | /// This method is called to parse the 'delete' expression after the optional |
| 973 | /// '::' has been already parsed. If the '::' was present, "UseGlobal" is true |
| 974 | /// and "Start" is its location. Otherwise, "Start" is the location of the |
| 975 | /// 'delete' token. |
| 976 | /// |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 977 | /// delete-expression: |
| 978 | /// '::'[opt] 'delete' cast-expression |
| 979 | /// '::'[opt] 'delete' '[' ']' cast-expression |
Chris Lattner | 59232d3 | 2009-01-04 21:25:24 +0000 | [diff] [blame] | 980 | Parser::OwningExprResult |
| 981 | Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) { |
| 982 | assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword"); |
| 983 | ConsumeToken(); // Consume 'delete' |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 984 | |
| 985 | // Array delete? |
| 986 | bool ArrayDelete = false; |
| 987 | if (Tok.is(tok::l_square)) { |
| 988 | ArrayDelete = true; |
| 989 | SourceLocation LHS = ConsumeBracket(); |
| 990 | SourceLocation RHS = MatchRHSPunctuation(tok::r_square, LHS); |
| 991 | if (RHS.isInvalid()) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 992 | return ExprError(); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Sebastian Redl | 2f7ece7 | 2008-12-11 21:36:32 +0000 | [diff] [blame] | 995 | OwningExprResult Operand(ParseCastExpression(false)); |
Sebastian Redl | 0e9eabc | 2008-12-09 13:15:23 +0000 | [diff] [blame] | 996 | if (Operand.isInvalid()) |
Sebastian Redl | 20df9b7 | 2008-12-11 22:51:44 +0000 | [diff] [blame] | 997 | return move(Operand); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 998 | |
Sebastian Redl | f53597f | 2009-03-15 17:47:39 +0000 | [diff] [blame] | 999 | return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, move(Operand)); |
Sebastian Redl | 4c5d320 | 2008-11-21 19:14:01 +0000 | [diff] [blame] | 1000 | } |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1001 | |
| 1002 | static UnaryTypeTrait UnaryTypeTraitFromTokKind(tok::TokenKind kind) |
| 1003 | { |
| 1004 | switch(kind) { |
| 1005 | default: assert(false && "Not a known unary type trait."); |
| 1006 | case tok::kw___has_nothrow_assign: return UTT_HasNothrowAssign; |
| 1007 | case tok::kw___has_nothrow_copy: return UTT_HasNothrowCopy; |
| 1008 | case tok::kw___has_nothrow_constructor: return UTT_HasNothrowConstructor; |
| 1009 | case tok::kw___has_trivial_assign: return UTT_HasTrivialAssign; |
| 1010 | case tok::kw___has_trivial_copy: return UTT_HasTrivialCopy; |
| 1011 | case tok::kw___has_trivial_constructor: return UTT_HasTrivialConstructor; |
| 1012 | case tok::kw___has_trivial_destructor: return UTT_HasTrivialDestructor; |
| 1013 | case tok::kw___has_virtual_destructor: return UTT_HasVirtualDestructor; |
| 1014 | case tok::kw___is_abstract: return UTT_IsAbstract; |
| 1015 | case tok::kw___is_class: return UTT_IsClass; |
| 1016 | case tok::kw___is_empty: return UTT_IsEmpty; |
| 1017 | case tok::kw___is_enum: return UTT_IsEnum; |
| 1018 | case tok::kw___is_pod: return UTT_IsPOD; |
| 1019 | case tok::kw___is_polymorphic: return UTT_IsPolymorphic; |
| 1020 | case tok::kw___is_union: return UTT_IsUnion; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | /// ParseUnaryTypeTrait - Parse the built-in unary type-trait |
| 1025 | /// pseudo-functions that allow implementation of the TR1/C++0x type traits |
| 1026 | /// templates. |
| 1027 | /// |
| 1028 | /// primary-expression: |
| 1029 | /// [GNU] unary-type-trait '(' type-id ')' |
| 1030 | /// |
| 1031 | Parser::OwningExprResult Parser::ParseUnaryTypeTrait() |
| 1032 | { |
| 1033 | UnaryTypeTrait UTT = UnaryTypeTraitFromTokKind(Tok.getKind()); |
| 1034 | SourceLocation Loc = ConsumeToken(); |
| 1035 | |
| 1036 | SourceLocation LParen = Tok.getLocation(); |
| 1037 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen)) |
| 1038 | return ExprError(); |
| 1039 | |
| 1040 | // FIXME: Error reporting absolutely sucks! If the this fails to parse a type |
| 1041 | // there will be cryptic errors about mismatched parentheses and missing |
| 1042 | // specifiers. |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1043 | TypeResult Ty = ParseTypeName(); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1044 | |
| 1045 | SourceLocation RParen = MatchRHSPunctuation(tok::r_paren, LParen); |
| 1046 | |
Douglas Gregor | 809070a | 2009-02-18 17:45:20 +0000 | [diff] [blame] | 1047 | if (Ty.isInvalid()) |
| 1048 | return ExprError(); |
| 1049 | |
| 1050 | return Actions.ActOnUnaryTypeTrait(UTT, Loc, LParen, Ty.get(), RParen); |
Sebastian Redl | 64b45f7 | 2009-01-05 20:52:13 +0000 | [diff] [blame] | 1051 | } |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1052 | |
| 1053 | /// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a |
| 1054 | /// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate |
| 1055 | /// based on the context past the parens. |
| 1056 | Parser::OwningExprResult |
| 1057 | Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType, |
| 1058 | TypeTy *&CastTy, |
| 1059 | SourceLocation LParenLoc, |
| 1060 | SourceLocation &RParenLoc) { |
| 1061 | assert(getLang().CPlusPlus && "Should only be called for C++!"); |
| 1062 | assert(ExprType == CastExpr && "Compound literals are not ambiguous!"); |
| 1063 | assert(isTypeIdInParens() && "Not a type-id!"); |
| 1064 | |
| 1065 | OwningExprResult Result(Actions, true); |
| 1066 | CastTy = 0; |
| 1067 | |
| 1068 | // We need to disambiguate a very ugly part of the C++ syntax: |
| 1069 | // |
| 1070 | // (T())x; - type-id |
| 1071 | // (T())*x; - type-id |
| 1072 | // (T())/x; - expression |
| 1073 | // (T()); - expression |
| 1074 | // |
| 1075 | // The bad news is that we cannot use the specialized tentative parser, since |
| 1076 | // it can only verify that the thing inside the parens can be parsed as |
| 1077 | // type-id, it is not useful for determining the context past the parens. |
| 1078 | // |
| 1079 | // The good news is that the parser can disambiguate this part without |
Argyrios Kyrtzidis | a558a89 | 2009-05-22 15:12:46 +0000 | [diff] [blame] | 1080 | // making any unnecessary Action calls. |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1081 | // |
| 1082 | // It uses a scheme similar to parsing inline methods. The parenthesized |
| 1083 | // tokens are cached, the context that follows is determined (possibly by |
| 1084 | // parsing a cast-expression), and then we re-introduce the cached tokens |
| 1085 | // into the token stream and parse them appropriately. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1086 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1087 | ParenParseOption ParseAs; |
| 1088 | CachedTokens Toks; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1089 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1090 | // Store the tokens of the parentheses. We will parse them after we determine |
| 1091 | // the context that follows them. |
| 1092 | if (!ConsumeAndStoreUntil(tok::r_paren, tok::unknown, Toks, tok::semi)) { |
| 1093 | // We didn't find the ')' we expected. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1094 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 1095 | return ExprError(); |
| 1096 | } |
| 1097 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1098 | if (Tok.is(tok::l_brace)) { |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1099 | ParseAs = CompoundLiteral; |
| 1100 | } else { |
| 1101 | bool NotCastExpr; |
Eli Friedman | b53f08a | 2009-05-25 19:41:42 +0000 | [diff] [blame] | 1102 | // FIXME: Special-case ++ and --: "(S())++;" is not a cast-expression |
| 1103 | if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) { |
| 1104 | NotCastExpr = true; |
| 1105 | } else { |
| 1106 | // Try parsing the cast-expression that may follow. |
| 1107 | // If it is not a cast-expression, NotCastExpr will be true and no token |
| 1108 | // will be consumed. |
| 1109 | Result = ParseCastExpression(false/*isUnaryExpression*/, |
| 1110 | false/*isAddressofOperand*/, |
| 1111 | NotCastExpr); |
| 1112 | } |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1113 | |
| 1114 | // If we parsed a cast-expression, it's really a type-id, otherwise it's |
| 1115 | // an expression. |
| 1116 | ParseAs = NotCastExpr ? SimpleExpr : CastExpr; |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1119 | // The current token should go after the cached tokens. |
| 1120 | Toks.push_back(Tok); |
| 1121 | // Re-enter the stored parenthesized tokens into the token stream, so we may |
| 1122 | // parse them now. |
| 1123 | PP.EnterTokenStream(Toks.data(), Toks.size(), |
| 1124 | true/*DisableMacroExpansion*/, false/*OwnsTokens*/); |
| 1125 | // Drop the current token and bring the first cached one. It's the same token |
| 1126 | // as when we entered this function. |
| 1127 | ConsumeAnyToken(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1128 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1129 | if (ParseAs >= CompoundLiteral) { |
| 1130 | TypeResult Ty = ParseTypeName(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1131 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1132 | // Match the ')'. |
| 1133 | if (Tok.is(tok::r_paren)) |
| 1134 | RParenLoc = ConsumeParen(); |
| 1135 | else |
| 1136 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1137 | |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1138 | if (ParseAs == CompoundLiteral) { |
| 1139 | ExprType = CompoundLiteral; |
| 1140 | return ParseCompoundLiteralExpression(Ty.get(), LParenLoc, RParenLoc); |
| 1141 | } |
| 1142 | |
| 1143 | // We parsed '(' type-id ')' and the thing after it wasn't a '{'. |
| 1144 | assert(ParseAs == CastExpr); |
| 1145 | |
| 1146 | if (Ty.isInvalid()) |
| 1147 | return ExprError(); |
| 1148 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1149 | CastTy = Ty.get(); |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1150 | |
| 1151 | // Result is what ParseCastExpression returned earlier. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1152 | if (!Result.isInvalid()) |
| 1153 | Result = Actions.ActOnCastExpr(LParenLoc, CastTy, RParenLoc,move(Result)); |
| 1154 | return move(Result); |
| 1155 | } |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1156 | |
| 1157 | // Not a compound literal, and not followed by a cast-expression. |
| 1158 | assert(ParseAs == SimpleExpr); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1159 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1160 | ExprType = SimpleExpr; |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1161 | Result = ParseExpression(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1162 | if (!Result.isInvalid() && Tok.is(tok::r_paren)) |
| 1163 | Result = Actions.ActOnParenExpr(LParenLoc, Tok.getLocation(), move(Result)); |
| 1164 | |
| 1165 | // Match the ')'. |
| 1166 | if (Result.isInvalid()) { |
| 1167 | SkipUntil(tok::r_paren); |
| 1168 | return ExprError(); |
| 1169 | } |
Argyrios Kyrtzidis | f40882a | 2009-05-22 21:09:47 +0000 | [diff] [blame] | 1170 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 1171 | if (Tok.is(tok::r_paren)) |
| 1172 | RParenLoc = ConsumeParen(); |
| 1173 | else |
| 1174 | MatchRHSPunctuation(tok::r_paren, LParenLoc); |
| 1175 | |
| 1176 | return move(Result); |
| 1177 | } |