Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1 | //===--- ParseTentative.cpp - Ambiguity Resolution Parsing ----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the tentative parsing portions of the Parser |
| 11 | // interfaces, for ambiguity resolution. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Parse/Parser.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 17 | #include "clang/Sema/ParsedTemplate.h" |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
| 20 | /// isCXXDeclarationStatement - C++-specialized function that disambiguates |
| 21 | /// between a declaration or an expression statement, when parsing function |
| 22 | /// bodies. Returns true for declaration, false for expression. |
| 23 | /// |
| 24 | /// declaration-statement: |
| 25 | /// block-declaration |
| 26 | /// |
| 27 | /// block-declaration: |
| 28 | /// simple-declaration |
| 29 | /// asm-definition |
| 30 | /// namespace-alias-definition |
| 31 | /// using-declaration |
| 32 | /// using-directive |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 33 | /// [C++0x] static_assert-declaration |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 34 | /// |
| 35 | /// asm-definition: |
| 36 | /// 'asm' '(' string-literal ')' ';' |
| 37 | /// |
| 38 | /// namespace-alias-definition: |
| 39 | /// 'namespace' identifier = qualified-namespace-specifier ';' |
| 40 | /// |
| 41 | /// using-declaration: |
| 42 | /// 'using' typename[opt] '::'[opt] nested-name-specifier |
| 43 | /// unqualified-id ';' |
| 44 | /// 'using' '::' unqualified-id ; |
| 45 | /// |
| 46 | /// using-directive: |
| 47 | /// 'using' 'namespace' '::'[opt] nested-name-specifier[opt] |
| 48 | /// namespace-name ';' |
| 49 | /// |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 50 | bool Parser::isCXXDeclarationStatement() { |
| 51 | switch (Tok.getKind()) { |
| 52 | // asm-definition |
| 53 | case tok::kw_asm: |
| 54 | // namespace-alias-definition |
| 55 | case tok::kw_namespace: |
| 56 | // using-declaration |
| 57 | // using-directive |
| 58 | case tok::kw_using: |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 59 | // static_assert-declaration |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 60 | case tok::kw_static_assert: |
Peter Collingbourne | c6eb44b | 2011-04-15 00:35:57 +0000 | [diff] [blame] | 61 | case tok::kw__Static_assert: |
Anders Carlsson | 511d7ab | 2009-03-11 16:27:10 +0000 | [diff] [blame] | 62 | return true; |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 63 | // simple-declaration |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 64 | default: |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 65 | return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | /// isCXXSimpleDeclaration - C++-specialized function that disambiguates |
| 70 | /// between a simple-declaration or an expression-statement. |
| 71 | /// If during the disambiguation process a parsing error is encountered, |
| 72 | /// the function returns true to let the declaration parsing code handle it. |
| 73 | /// Returns false if the statement is disambiguated as expression. |
| 74 | /// |
| 75 | /// simple-declaration: |
| 76 | /// decl-specifier-seq init-declarator-list[opt] ';' |
| 77 | /// |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 78 | /// (if AllowForRangeDecl specified) |
| 79 | /// for ( for-range-declaration : for-range-initializer ) statement |
| 80 | /// for-range-declaration: |
| 81 | /// attribute-specifier-seqopt type-specifier-seq declarator |
| 82 | bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 83 | // C++ 6.8p1: |
| 84 | // There is an ambiguity in the grammar involving expression-statements and |
| 85 | // declarations: An expression-statement with a function-style explicit type |
| 86 | // conversion (5.2.3) as its leftmost subexpression can be indistinguishable |
| 87 | // from a declaration where the first declarator starts with a '('. In those |
| 88 | // cases the statement is a declaration. [Note: To disambiguate, the whole |
| 89 | // statement might have to be examined to determine if it is an |
| 90 | // expression-statement or a declaration]. |
| 91 | |
| 92 | // C++ 6.8p3: |
| 93 | // The disambiguation is purely syntactic; that is, the meaning of the names |
| 94 | // occurring in such a statement, beyond whether they are type-names or not, |
| 95 | // is not generally used in or changed by the disambiguation. Class |
| 96 | // templates are instantiated as necessary to determine if a qualified name |
| 97 | // is a type-name. Disambiguation precedes parsing, and a statement |
| 98 | // disambiguated as a declaration may be an ill-formed declaration. |
| 99 | |
| 100 | // We don't have to parse all of the decl-specifier-seq part. There's only |
| 101 | // an ambiguity if the first decl-specifier is |
| 102 | // simple-type-specifier/typename-specifier followed by a '(', which may |
| 103 | // indicate a function-style cast expression. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 104 | // isCXXDeclarationSpecifier will return TPResult::Ambiguous() only in such |
| 105 | // a case. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 106 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 107 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 108 | if (TPR != TPResult::Ambiguous()) |
| 109 | return TPR != TPResult::False(); // Returns true for TPResult::True() or |
| 110 | // TPResult::Error(). |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 111 | |
| 112 | // FIXME: Add statistics about the number of ambiguous statements encountered |
| 113 | // and how they were resolved (number of declarations+number of expressions). |
| 114 | |
| 115 | // Ok, we have a simple-type-specifier/typename-specifier followed by a '('. |
| 116 | // We need tentative parsing... |
| 117 | |
| 118 | TentativeParsingAction PA(*this); |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 119 | TPR = TryParseSimpleDeclaration(AllowForRangeDecl); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 120 | PA.Revert(); |
| 121 | |
| 122 | // In case of an error, let the declaration parsing code handle it. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 123 | if (TPR == TPResult::Error()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 124 | return true; |
| 125 | |
| 126 | // Declarations take precedence over expressions. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 127 | if (TPR == TPResult::Ambiguous()) |
| 128 | TPR = TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 129 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 130 | assert(TPR == TPResult::True() || TPR == TPResult::False()); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 131 | return TPR == TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /// simple-declaration: |
| 135 | /// decl-specifier-seq init-declarator-list[opt] ';' |
| 136 | /// |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 137 | /// (if AllowForRangeDecl specified) |
| 138 | /// for ( for-range-declaration : for-range-initializer ) statement |
| 139 | /// for-range-declaration: |
| 140 | /// attribute-specifier-seqopt type-specifier-seq declarator |
| 141 | /// |
| 142 | Parser::TPResult Parser::TryParseSimpleDeclaration(bool AllowForRangeDecl) { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 143 | // We know that we have a simple-type-specifier/typename-specifier followed |
| 144 | // by a '('. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 145 | assert(isCXXDeclarationSpecifier() == TPResult::Ambiguous()); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 146 | |
| 147 | if (Tok.is(tok::kw_typeof)) |
| 148 | TryParseTypeofSpecifier(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 149 | else { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 150 | ConsumeToken(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 151 | |
| 152 | if (getLang().ObjC1 && Tok.is(tok::less)) |
| 153 | TryParseProtocolQualifiers(); |
| 154 | } |
| 155 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 156 | assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 157 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 158 | TPResult TPR = TryParseInitDeclaratorList(); |
| 159 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 160 | return TPR; |
| 161 | |
Eli Friedman | 9490ab4 | 2011-12-20 01:50:37 +0000 | [diff] [blame] | 162 | if (Tok.isNot(tok::semi) && (!AllowForRangeDecl || Tok.isNot(tok::colon))) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 163 | return TPResult::False(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 164 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 165 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 168 | /// init-declarator-list: |
| 169 | /// init-declarator |
| 170 | /// init-declarator-list ',' init-declarator |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 171 | /// |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 172 | /// init-declarator: |
| 173 | /// declarator initializer[opt] |
| 174 | /// [GNU] declarator simple-asm-expr[opt] attributes[opt] initializer[opt] |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 175 | /// |
| 176 | /// initializer: |
| 177 | /// '=' initializer-clause |
| 178 | /// '(' expression-list ')' |
| 179 | /// |
| 180 | /// initializer-clause: |
| 181 | /// assignment-expression |
| 182 | /// '{' initializer-list ','[opt] '}' |
| 183 | /// '{' '}' |
| 184 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 185 | Parser::TPResult Parser::TryParseInitDeclaratorList() { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 186 | while (1) { |
| 187 | // declarator |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 188 | TPResult TPR = TryParseDeclarator(false/*mayBeAbstract*/); |
| 189 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 190 | return TPR; |
| 191 | |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 192 | // [GNU] simple-asm-expr[opt] attributes[opt] |
| 193 | if (Tok.is(tok::kw_asm) || Tok.is(tok::kw___attribute)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 194 | return TPResult::True(); |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 195 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 196 | // initializer[opt] |
| 197 | if (Tok.is(tok::l_paren)) { |
| 198 | // Parse through the parens. |
| 199 | ConsumeParen(); |
| 200 | if (!SkipUntil(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 201 | return TPResult::Error(); |
Fariborz Jahanian | f459beb | 2010-08-29 17:20:53 +0000 | [diff] [blame] | 202 | } else if (Tok.is(tok::equal) || isTokIdentifier_in()) { |
Douglas Gregor | 06b7080 | 2010-07-15 21:05:01 +0000 | [diff] [blame] | 203 | // MSVC and g++ won't examine the rest of declarators if '=' is |
| 204 | // encountered; they just conclude that we have a declaration. |
| 205 | // EDG parses the initializer completely, which is the proper behavior |
| 206 | // for this case. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 207 | // |
Douglas Gregor | 06b7080 | 2010-07-15 21:05:01 +0000 | [diff] [blame] | 208 | // At present, Clang follows MSVC and g++, since the parser does not have |
| 209 | // the ability to parse an expression fully without recording the |
| 210 | // results of that parse. |
Fariborz Jahanian | f459beb | 2010-08-29 17:20:53 +0000 | [diff] [blame] | 211 | // Also allow 'in' after on objective-c declaration as in: |
| 212 | // for (int (^b)(void) in array). Ideally this should be done in the |
| 213 | // context of parsing for-init-statement of a foreach statement only. But, |
| 214 | // in any other context 'in' is invalid after a declaration and parser |
| 215 | // issues the error regardless of outcome of this decision. |
| 216 | // FIXME. Change if above assumption does not hold. |
Douglas Gregor | 06b7080 | 2010-07-15 21:05:01 +0000 | [diff] [blame] | 217 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | if (Tok.isNot(tok::comma)) |
| 221 | break; |
| 222 | ConsumeToken(); // the comma. |
| 223 | } |
| 224 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 225 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 228 | /// isCXXConditionDeclaration - Disambiguates between a declaration or an |
| 229 | /// expression for a condition of a if/switch/while/for statement. |
| 230 | /// If during the disambiguation process a parsing error is encountered, |
| 231 | /// the function returns true to let the declaration parsing code handle it. |
| 232 | /// |
| 233 | /// condition: |
| 234 | /// expression |
| 235 | /// type-specifier-seq declarator '=' assignment-expression |
| 236 | /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt] |
| 237 | /// '=' assignment-expression |
| 238 | /// |
| 239 | bool Parser::isCXXConditionDeclaration() { |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 240 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 241 | if (TPR != TPResult::Ambiguous()) |
| 242 | return TPR != TPResult::False(); // Returns true for TPResult::True() or |
| 243 | // TPResult::Error(). |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 244 | |
| 245 | // FIXME: Add statistics about the number of ambiguous statements encountered |
| 246 | // and how they were resolved (number of declarations+number of expressions). |
| 247 | |
| 248 | // Ok, we have a simple-type-specifier/typename-specifier followed by a '('. |
| 249 | // We need tentative parsing... |
| 250 | |
| 251 | TentativeParsingAction PA(*this); |
| 252 | |
| 253 | // type-specifier-seq |
| 254 | if (Tok.is(tok::kw_typeof)) |
| 255 | TryParseTypeofSpecifier(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 256 | else { |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 257 | ConsumeToken(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 258 | |
| 259 | if (getLang().ObjC1 && Tok.is(tok::less)) |
| 260 | TryParseProtocolQualifiers(); |
| 261 | } |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 262 | assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 263 | |
| 264 | // declarator |
| 265 | TPR = TryParseDeclarator(false/*mayBeAbstract*/); |
| 266 | |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 267 | // In case of an error, let the declaration parsing code handle it. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 268 | if (TPR == TPResult::Error()) |
| 269 | TPR = TPResult::True(); |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 270 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 271 | if (TPR == TPResult::Ambiguous()) { |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 272 | // '=' |
| 273 | // [GNU] simple-asm-expr[opt] attributes[opt] |
| 274 | if (Tok.is(tok::equal) || |
| 275 | Tok.is(tok::kw_asm) || Tok.is(tok::kw___attribute)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 276 | TPR = TPResult::True(); |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 277 | else |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 278 | TPR = TPResult::False(); |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Argyrios Kyrtzidis | ca35baa | 2008-10-05 15:19:49 +0000 | [diff] [blame] | 281 | PA.Revert(); |
| 282 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 283 | assert(TPR == TPResult::True() || TPR == TPResult::False()); |
| 284 | return TPR == TPResult::True(); |
Argyrios Kyrtzidis | a8a4598 | 2008-10-05 15:03:47 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 287 | /// \brief Determine whether the next set of tokens contains a type-id. |
Douglas Gregor | 8b64259 | 2009-02-10 00:53:15 +0000 | [diff] [blame] | 288 | /// |
| 289 | /// The context parameter states what context we're parsing right |
| 290 | /// now, which affects how this routine copes with the token |
| 291 | /// following the type-id. If the context is TypeIdInParens, we have |
| 292 | /// already parsed the '(' and we will cease lookahead when we hit |
| 293 | /// the corresponding ')'. If the context is |
| 294 | /// TypeIdAsTemplateArgument, we've already parsed the '<' or ',' |
| 295 | /// before this template argument, and will cease lookahead when we |
| 296 | /// hit a '>', '>>' (in C++0x), or ','. Returns true for a type-id |
| 297 | /// and false for an expression. If during the disambiguation |
| 298 | /// process a parsing error is encountered, the function returns |
| 299 | /// true to let the declaration parsing code handle it. |
| 300 | /// |
| 301 | /// type-id: |
| 302 | /// type-specifier-seq abstract-declarator[opt] |
| 303 | /// |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 304 | bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 306 | isAmbiguous = false; |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 307 | |
| 308 | // C++ 8.2p2: |
| 309 | // The ambiguity arising from the similarity between a function-style cast and |
| 310 | // a type-id can occur in different contexts. The ambiguity appears as a |
| 311 | // choice between a function-style cast expression and a declaration of a |
| 312 | // type. The resolution is that any construct that could possibly be a type-id |
| 313 | // in its syntactic context shall be considered a type-id. |
| 314 | |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 315 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 316 | if (TPR != TPResult::Ambiguous()) |
| 317 | return TPR != TPResult::False(); // Returns true for TPResult::True() or |
| 318 | // TPResult::Error(). |
| 319 | |
| 320 | // FIXME: Add statistics about the number of ambiguous statements encountered |
| 321 | // and how they were resolved (number of declarations+number of expressions). |
| 322 | |
| 323 | // Ok, we have a simple-type-specifier/typename-specifier followed by a '('. |
| 324 | // We need tentative parsing... |
| 325 | |
| 326 | TentativeParsingAction PA(*this); |
| 327 | |
| 328 | // type-specifier-seq |
| 329 | if (Tok.is(tok::kw_typeof)) |
| 330 | TryParseTypeofSpecifier(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 331 | else { |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 332 | ConsumeToken(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 333 | |
| 334 | if (getLang().ObjC1 && Tok.is(tok::less)) |
| 335 | TryParseProtocolQualifiers(); |
| 336 | } |
| 337 | |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 338 | assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 339 | |
| 340 | // declarator |
| 341 | TPR = TryParseDeclarator(true/*mayBeAbstract*/, false/*mayHaveIdentifier*/); |
| 342 | |
| 343 | // In case of an error, let the declaration parsing code handle it. |
| 344 | if (TPR == TPResult::Error()) |
| 345 | TPR = TPResult::True(); |
| 346 | |
| 347 | if (TPR == TPResult::Ambiguous()) { |
| 348 | // We are supposed to be inside parens, so if after the abstract declarator |
| 349 | // we encounter a ')' this is a type-id, otherwise it's an expression. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 350 | if (Context == TypeIdInParens && Tok.is(tok::r_paren)) { |
Douglas Gregor | 8b64259 | 2009-02-10 00:53:15 +0000 | [diff] [blame] | 351 | TPR = TPResult::True(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 352 | isAmbiguous = true; |
| 353 | |
Douglas Gregor | 8b64259 | 2009-02-10 00:53:15 +0000 | [diff] [blame] | 354 | // We are supposed to be inside a template argument, so if after |
| 355 | // the abstract declarator we encounter a '>', '>>' (in C++0x), or |
| 356 | // ',', this is a type-id. Otherwise, it's an expression. |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 357 | } else if (Context == TypeIdAsTemplateArgument && |
| 358 | (Tok.is(tok::greater) || Tok.is(tok::comma) || |
| 359 | (getLang().CPlusPlus0x && Tok.is(tok::greatergreater)))) { |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 360 | TPR = TPResult::True(); |
Argyrios Kyrtzidis | f58f45e | 2009-05-22 10:24:42 +0000 | [diff] [blame] | 361 | isAmbiguous = true; |
| 362 | |
| 363 | } else |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 364 | TPR = TPResult::False(); |
| 365 | } |
| 366 | |
| 367 | PA.Revert(); |
| 368 | |
| 369 | assert(TPR == TPResult::True() || TPR == TPResult::False()); |
| 370 | return TPR == TPResult::True(); |
| 371 | } |
| 372 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 373 | /// isCXX0XAttributeSpecifier - returns true if this is a C++0x |
| 374 | /// attribute-specifier. By default, unless in Obj-C++, only a cursory check is |
| 375 | /// performed that will simply return true if a [[ is seen. Currently C++ has no |
| 376 | /// syntactical ambiguities from this check, but it may inhibit error recovery. |
| 377 | /// If CheckClosing is true, a check is made for closing ]] brackets. |
| 378 | /// |
| 379 | /// If given, After is set to the token after the attribute-specifier so that |
| 380 | /// appropriate parsing decisions can be made; it is left untouched if false is |
| 381 | /// returned. |
| 382 | /// |
| 383 | /// FIXME: If an error is in the closing ]] brackets, the program assumes |
| 384 | /// the absence of an attribute-specifier, which can cause very yucky errors |
| 385 | /// to occur. |
| 386 | /// |
| 387 | /// [C++0x] attribute-specifier: |
| 388 | /// '[' '[' attribute-list ']' ']' |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 389 | /// alignment-specifier |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 390 | /// |
| 391 | /// [C++0x] attribute-list: |
| 392 | /// attribute[opt] |
| 393 | /// attribute-list ',' attribute[opt] |
| 394 | /// |
| 395 | /// [C++0x] attribute: |
| 396 | /// attribute-token attribute-argument-clause[opt] |
| 397 | /// |
| 398 | /// [C++0x] attribute-token: |
| 399 | /// identifier |
| 400 | /// attribute-scoped-token |
| 401 | /// |
| 402 | /// [C++0x] attribute-scoped-token: |
| 403 | /// attribute-namespace '::' identifier |
| 404 | /// |
| 405 | /// [C++0x] attribute-namespace: |
| 406 | /// identifier |
| 407 | /// |
| 408 | /// [C++0x] attribute-argument-clause: |
| 409 | /// '(' balanced-token-seq ')' |
| 410 | /// |
| 411 | /// [C++0x] balanced-token-seq: |
| 412 | /// balanced-token |
| 413 | /// balanced-token-seq balanced-token |
| 414 | /// |
| 415 | /// [C++0x] balanced-token: |
| 416 | /// '(' balanced-token-seq ')' |
| 417 | /// '[' balanced-token-seq ']' |
| 418 | /// '{' balanced-token-seq '}' |
| 419 | /// any token but '(', ')', '[', ']', '{', or '}' |
| 420 | bool Parser::isCXX0XAttributeSpecifier (bool CheckClosing, |
| 421 | tok::TokenKind *After) { |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 422 | if (Tok.is(tok::kw_alignas)) |
| 423 | return true; |
| 424 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 425 | if (Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) |
| 426 | return false; |
| 427 | |
| 428 | // No tentative parsing if we don't need to look for ]] |
| 429 | if (!CheckClosing && !getLang().ObjC1) |
| 430 | return true; |
| 431 | |
| 432 | struct TentativeReverter { |
| 433 | TentativeParsingAction PA; |
| 434 | |
| 435 | TentativeReverter (Parser& P) |
| 436 | : PA(P) |
| 437 | {} |
| 438 | ~TentativeReverter () { |
| 439 | PA.Revert(); |
| 440 | } |
| 441 | } R(*this); |
| 442 | |
| 443 | // Opening brackets were checked for above. |
| 444 | ConsumeBracket(); |
| 445 | ConsumeBracket(); |
| 446 | |
| 447 | // SkipUntil will handle balanced tokens, which are guaranteed in attributes. |
| 448 | SkipUntil(tok::r_square, false); |
| 449 | |
| 450 | if (Tok.isNot(tok::r_square)) |
| 451 | return false; |
| 452 | ConsumeBracket(); |
| 453 | |
| 454 | if (After) |
| 455 | *After = Tok.getKind(); |
| 456 | |
| 457 | return true; |
| 458 | } |
| 459 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 460 | /// declarator: |
| 461 | /// direct-declarator |
| 462 | /// ptr-operator declarator |
| 463 | /// |
| 464 | /// direct-declarator: |
| 465 | /// declarator-id |
| 466 | /// direct-declarator '(' parameter-declaration-clause ')' |
| 467 | /// cv-qualifier-seq[opt] exception-specification[opt] |
| 468 | /// direct-declarator '[' constant-expression[opt] ']' |
| 469 | /// '(' declarator ')' |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 470 | /// [GNU] '(' attributes declarator ')' |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 471 | /// |
| 472 | /// abstract-declarator: |
| 473 | /// ptr-operator abstract-declarator[opt] |
| 474 | /// direct-abstract-declarator |
Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 475 | /// ... |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 476 | /// |
| 477 | /// direct-abstract-declarator: |
| 478 | /// direct-abstract-declarator[opt] |
| 479 | /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt] |
| 480 | /// exception-specification[opt] |
| 481 | /// direct-abstract-declarator[opt] '[' constant-expression[opt] ']' |
| 482 | /// '(' abstract-declarator ')' |
| 483 | /// |
| 484 | /// ptr-operator: |
| 485 | /// '*' cv-qualifier-seq[opt] |
| 486 | /// '&' |
| 487 | /// [C++0x] '&&' [TODO] |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 488 | /// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt] |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 489 | /// |
| 490 | /// cv-qualifier-seq: |
| 491 | /// cv-qualifier cv-qualifier-seq[opt] |
| 492 | /// |
| 493 | /// cv-qualifier: |
| 494 | /// 'const' |
| 495 | /// 'volatile' |
| 496 | /// |
| 497 | /// declarator-id: |
Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 498 | /// '...'[opt] id-expression |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 499 | /// |
| 500 | /// id-expression: |
| 501 | /// unqualified-id |
| 502 | /// qualified-id [TODO] |
| 503 | /// |
| 504 | /// unqualified-id: |
| 505 | /// identifier |
| 506 | /// operator-function-id [TODO] |
| 507 | /// conversion-function-id [TODO] |
| 508 | /// '~' class-name [TODO] |
| 509 | /// template-id [TODO] |
| 510 | /// |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 511 | Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract, |
| 512 | bool mayHaveIdentifier) { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 513 | // declarator: |
| 514 | // direct-declarator |
| 515 | // ptr-operator declarator |
| 516 | |
| 517 | while (1) { |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 518 | if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier)) |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 519 | if (TryAnnotateCXXScopeToken(true)) |
| 520 | return TPResult::Error(); |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 521 | |
Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 522 | if (Tok.is(tok::star) || Tok.is(tok::amp) || Tok.is(tok::caret) || |
Douglas Gregor | 69d8316 | 2011-01-20 16:08:06 +0000 | [diff] [blame] | 523 | Tok.is(tok::ampamp) || |
Sebastian Redl | 8edef7c | 2009-01-24 23:29:36 +0000 | [diff] [blame] | 524 | (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 525 | // ptr-operator |
| 526 | ConsumeToken(); |
| 527 | while (Tok.is(tok::kw_const) || |
| 528 | Tok.is(tok::kw_volatile) || |
Chris Lattner | 9af5500 | 2009-03-27 04:18:06 +0000 | [diff] [blame] | 529 | Tok.is(tok::kw_restrict)) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 530 | ConsumeToken(); |
| 531 | } else { |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | // direct-declarator: |
| 537 | // direct-abstract-declarator: |
Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 538 | if (Tok.is(tok::ellipsis)) |
| 539 | ConsumeToken(); |
| 540 | |
Argyrios Kyrtzidis | 1e05421 | 2009-07-21 17:05:03 +0000 | [diff] [blame] | 541 | if ((Tok.is(tok::identifier) || |
| 542 | (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier))) && |
| 543 | mayHaveIdentifier) { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 544 | // declarator-id |
Argyrios Kyrtzidis | 1e05421 | 2009-07-21 17:05:03 +0000 | [diff] [blame] | 545 | if (Tok.is(tok::annot_cxxscope)) |
| 546 | ConsumeToken(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 547 | ConsumeToken(); |
| 548 | } else if (Tok.is(tok::l_paren)) { |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 549 | ConsumeParen(); |
| 550 | if (mayBeAbstract && |
| 551 | (Tok.is(tok::r_paren) || // 'int()' is a function. |
| 552 | Tok.is(tok::ellipsis) || // 'int(...)' is a function. |
| 553 | isDeclarationSpecifier())) { // 'int(int)' is a function. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 554 | // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt] |
| 555 | // exception-specification[opt] |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 556 | TPResult TPR = TryParseFunctionDeclarator(); |
| 557 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 558 | return TPR; |
| 559 | } else { |
| 560 | // '(' declarator ')' |
Argyrios Kyrtzidis | 1ee2c43 | 2008-10-05 14:27:18 +0000 | [diff] [blame] | 561 | // '(' attributes declarator ')' |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 562 | // '(' abstract-declarator ')' |
Chris Lattner | 6229c8e | 2010-09-28 23:35:09 +0000 | [diff] [blame] | 563 | if (Tok.is(tok::kw___attribute) || |
| 564 | Tok.is(tok::kw___declspec) || |
| 565 | Tok.is(tok::kw___cdecl) || |
| 566 | Tok.is(tok::kw___stdcall) || |
| 567 | Tok.is(tok::kw___fastcall) || |
Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 568 | Tok.is(tok::kw___thiscall) || |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 569 | Tok.is(tok::kw___unaligned)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 570 | return TPResult::True(); // attributes indicate declaration |
Argyrios Kyrtzidis | 78c8d80 | 2008-10-05 19:56:22 +0000 | [diff] [blame] | 571 | TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 572 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 573 | return TPR; |
| 574 | if (Tok.isNot(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 575 | return TPResult::False(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 576 | ConsumeParen(); |
| 577 | } |
| 578 | } else if (!mayBeAbstract) { |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 579 | return TPResult::False(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | while (1) { |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 583 | TPResult TPR(TPResult::Ambiguous()); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 584 | |
Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 585 | // abstract-declarator: ... |
| 586 | if (Tok.is(tok::ellipsis)) |
| 587 | ConsumeToken(); |
| 588 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 589 | if (Tok.is(tok::l_paren)) { |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 590 | // Check whether we have a function declarator or a possible ctor-style |
| 591 | // initializer that follows the declarator. Note that ctor-style |
| 592 | // initializers are not possible in contexts where abstract declarators |
| 593 | // are allowed. |
Argyrios Kyrtzidis | e75d849 | 2008-10-17 23:23:35 +0000 | [diff] [blame] | 594 | if (!mayBeAbstract && !isCXXFunctionDeclarator(false/*warnIfAmbiguous*/)) |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 595 | break; |
| 596 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 597 | // direct-declarator '(' parameter-declaration-clause ')' |
| 598 | // cv-qualifier-seq[opt] exception-specification[opt] |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 599 | ConsumeParen(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 600 | TPR = TryParseFunctionDeclarator(); |
| 601 | } else if (Tok.is(tok::l_square)) { |
| 602 | // direct-declarator '[' constant-expression[opt] ']' |
| 603 | // direct-abstract-declarator[opt] '[' constant-expression[opt] ']' |
| 604 | TPR = TryParseBracketDeclarator(); |
| 605 | } else { |
| 606 | break; |
| 607 | } |
| 608 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 609 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 610 | return TPR; |
| 611 | } |
| 612 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 613 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 616 | Parser::TPResult |
| 617 | Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) { |
| 618 | switch (Kind) { |
| 619 | // Obviously starts an expression. |
| 620 | case tok::numeric_constant: |
| 621 | case tok::char_constant: |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 622 | case tok::wide_char_constant: |
| 623 | case tok::utf16_char_constant: |
| 624 | case tok::utf32_char_constant: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 625 | case tok::string_literal: |
| 626 | case tok::wide_string_literal: |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 627 | case tok::utf8_string_literal: |
| 628 | case tok::utf16_string_literal: |
| 629 | case tok::utf32_string_literal: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 630 | case tok::l_square: |
| 631 | case tok::l_paren: |
| 632 | case tok::amp: |
Douglas Gregor | 69d8316 | 2011-01-20 16:08:06 +0000 | [diff] [blame] | 633 | case tok::ampamp: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 634 | case tok::star: |
| 635 | case tok::plus: |
| 636 | case tok::plusplus: |
| 637 | case tok::minus: |
| 638 | case tok::minusminus: |
| 639 | case tok::tilde: |
| 640 | case tok::exclaim: |
| 641 | case tok::kw_sizeof: |
| 642 | case tok::kw___func__: |
| 643 | case tok::kw_const_cast: |
| 644 | case tok::kw_delete: |
| 645 | case tok::kw_dynamic_cast: |
| 646 | case tok::kw_false: |
| 647 | case tok::kw_new: |
| 648 | case tok::kw_operator: |
| 649 | case tok::kw_reinterpret_cast: |
| 650 | case tok::kw_static_cast: |
| 651 | case tok::kw_this: |
| 652 | case tok::kw_throw: |
| 653 | case tok::kw_true: |
| 654 | case tok::kw_typeid: |
| 655 | case tok::kw_alignof: |
| 656 | case tok::kw_noexcept: |
| 657 | case tok::kw_nullptr: |
| 658 | case tok::kw___null: |
| 659 | case tok::kw___alignof: |
| 660 | case tok::kw___builtin_choose_expr: |
| 661 | case tok::kw___builtin_offsetof: |
| 662 | case tok::kw___builtin_types_compatible_p: |
| 663 | case tok::kw___builtin_va_arg: |
| 664 | case tok::kw___imag: |
| 665 | case tok::kw___real: |
| 666 | case tok::kw___FUNCTION__: |
| 667 | case tok::kw___PRETTY_FUNCTION__: |
| 668 | case tok::kw___has_nothrow_assign: |
| 669 | case tok::kw___has_nothrow_copy: |
| 670 | case tok::kw___has_nothrow_constructor: |
| 671 | case tok::kw___has_trivial_assign: |
| 672 | case tok::kw___has_trivial_copy: |
| 673 | case tok::kw___has_trivial_constructor: |
| 674 | case tok::kw___has_trivial_destructor: |
| 675 | case tok::kw___has_virtual_destructor: |
| 676 | case tok::kw___is_abstract: |
| 677 | case tok::kw___is_base_of: |
| 678 | case tok::kw___is_class: |
Douglas Gregor | 9f36113 | 2011-01-27 20:28:01 +0000 | [diff] [blame] | 679 | case tok::kw___is_convertible_to: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 680 | case tok::kw___is_empty: |
| 681 | case tok::kw___is_enum: |
Douglas Gregor | 5e9392b | 2011-12-03 18:14:24 +0000 | [diff] [blame] | 682 | case tok::kw___is_final: |
Chandler Carruth | 4e61ddd | 2011-04-23 10:47:20 +0000 | [diff] [blame] | 683 | case tok::kw___is_literal: |
Chandler Carruth | 3840281 | 2011-04-24 02:49:28 +0000 | [diff] [blame] | 684 | case tok::kw___is_literal_type: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 685 | case tok::kw___is_pod: |
| 686 | case tok::kw___is_polymorphic: |
Chandler Carruth | b7e9589 | 2011-04-23 10:47:28 +0000 | [diff] [blame] | 687 | case tok::kw___is_trivial: |
Sean Hunt | feb375d | 2011-05-13 00:31:07 +0000 | [diff] [blame] | 688 | case tok::kw___is_trivially_copyable: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 689 | case tok::kw___is_union: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 690 | case tok::kw___uuidof: |
| 691 | return TPResult::True(); |
| 692 | |
| 693 | // Obviously starts a type-specifier-seq: |
| 694 | case tok::kw_char: |
| 695 | case tok::kw_const: |
| 696 | case tok::kw_double: |
| 697 | case tok::kw_enum: |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 698 | case tok::kw_half: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 699 | case tok::kw_float: |
| 700 | case tok::kw_int: |
| 701 | case tok::kw_long: |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 702 | case tok::kw___int64: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 703 | case tok::kw_restrict: |
| 704 | case tok::kw_short: |
| 705 | case tok::kw_signed: |
| 706 | case tok::kw_struct: |
| 707 | case tok::kw_union: |
| 708 | case tok::kw_unsigned: |
| 709 | case tok::kw_void: |
| 710 | case tok::kw_volatile: |
| 711 | case tok::kw__Bool: |
| 712 | case tok::kw__Complex: |
| 713 | case tok::kw_class: |
| 714 | case tok::kw_typename: |
| 715 | case tok::kw_wchar_t: |
| 716 | case tok::kw_char16_t: |
| 717 | case tok::kw_char32_t: |
Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 718 | case tok::kw___underlying_type: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 719 | case tok::kw_thread_local: |
| 720 | case tok::kw__Decimal32: |
| 721 | case tok::kw__Decimal64: |
| 722 | case tok::kw__Decimal128: |
| 723 | case tok::kw___thread: |
| 724 | case tok::kw_typeof: |
| 725 | case tok::kw___cdecl: |
| 726 | case tok::kw___stdcall: |
| 727 | case tok::kw___fastcall: |
| 728 | case tok::kw___thiscall: |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 729 | case tok::kw___unaligned: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 730 | case tok::kw___vector: |
| 731 | case tok::kw___pixel: |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 732 | case tok::kw__Atomic: |
Douglas Gregor | a61b3e7 | 2010-12-01 17:42:47 +0000 | [diff] [blame] | 733 | return TPResult::False(); |
| 734 | |
| 735 | default: |
| 736 | break; |
| 737 | } |
| 738 | |
| 739 | return TPResult::Ambiguous(); |
| 740 | } |
| 741 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 742 | /// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a declaration |
| 743 | /// specifier, TPResult::False() if it is not, TPResult::Ambiguous() if it could |
| 744 | /// be either a decl-specifier or a function-style cast, and TPResult::Error() |
| 745 | /// if a parsing error was found and reported. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 746 | /// |
| 747 | /// decl-specifier: |
| 748 | /// storage-class-specifier |
| 749 | /// type-specifier |
| 750 | /// function-specifier |
| 751 | /// 'friend' |
| 752 | /// 'typedef' |
Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 753 | /// [C++0x] 'constexpr' |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 754 | /// [GNU] attributes declaration-specifiers[opt] |
| 755 | /// |
| 756 | /// storage-class-specifier: |
| 757 | /// 'register' |
| 758 | /// 'static' |
| 759 | /// 'extern' |
| 760 | /// 'mutable' |
| 761 | /// 'auto' |
| 762 | /// [GNU] '__thread' |
| 763 | /// |
| 764 | /// function-specifier: |
| 765 | /// 'inline' |
| 766 | /// 'virtual' |
| 767 | /// 'explicit' |
| 768 | /// |
| 769 | /// typedef-name: |
| 770 | /// identifier |
| 771 | /// |
| 772 | /// type-specifier: |
| 773 | /// simple-type-specifier |
| 774 | /// class-specifier |
| 775 | /// enum-specifier |
| 776 | /// elaborated-type-specifier |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 777 | /// typename-specifier |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 778 | /// cv-qualifier |
| 779 | /// |
| 780 | /// simple-type-specifier: |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 781 | /// '::'[opt] nested-name-specifier[opt] type-name |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 782 | /// '::'[opt] nested-name-specifier 'template' |
| 783 | /// simple-template-id [TODO] |
| 784 | /// 'char' |
| 785 | /// 'wchar_t' |
| 786 | /// 'bool' |
| 787 | /// 'short' |
| 788 | /// 'int' |
| 789 | /// 'long' |
| 790 | /// 'signed' |
| 791 | /// 'unsigned' |
| 792 | /// 'float' |
| 793 | /// 'double' |
| 794 | /// 'void' |
| 795 | /// [GNU] typeof-specifier |
| 796 | /// [GNU] '_Complex' |
| 797 | /// [C++0x] 'auto' [TODO] |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 798 | /// [C++0x] 'decltype' ( expression ) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 799 | /// |
| 800 | /// type-name: |
| 801 | /// class-name |
| 802 | /// enum-name |
| 803 | /// typedef-name |
| 804 | /// |
| 805 | /// elaborated-type-specifier: |
| 806 | /// class-key '::'[opt] nested-name-specifier[opt] identifier |
| 807 | /// class-key '::'[opt] nested-name-specifier[opt] 'template'[opt] |
| 808 | /// simple-template-id |
| 809 | /// 'enum' '::'[opt] nested-name-specifier[opt] identifier |
| 810 | /// |
| 811 | /// enum-name: |
| 812 | /// identifier |
| 813 | /// |
| 814 | /// enum-specifier: |
| 815 | /// 'enum' identifier[opt] '{' enumerator-list[opt] '}' |
| 816 | /// 'enum' identifier[opt] '{' enumerator-list ',' '}' |
| 817 | /// |
| 818 | /// class-specifier: |
| 819 | /// class-head '{' member-specification[opt] '}' |
| 820 | /// |
| 821 | /// class-head: |
| 822 | /// class-key identifier[opt] base-clause[opt] |
| 823 | /// class-key nested-name-specifier identifier base-clause[opt] |
| 824 | /// class-key nested-name-specifier[opt] simple-template-id |
| 825 | /// base-clause[opt] |
| 826 | /// |
| 827 | /// class-key: |
| 828 | /// 'class' |
| 829 | /// 'struct' |
| 830 | /// 'union' |
| 831 | /// |
| 832 | /// cv-qualifier: |
| 833 | /// 'const' |
| 834 | /// 'volatile' |
| 835 | /// [GNU] restrict |
| 836 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 837 | Parser::TPResult Parser::isCXXDeclarationSpecifier() { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 838 | switch (Tok.getKind()) { |
Chris Lattner | e584926 | 2009-01-04 23:33:56 +0000 | [diff] [blame] | 839 | case tok::identifier: // foo::bar |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 840 | // Check for need to substitute AltiVec __vector keyword |
| 841 | // for "vector" identifier. |
| 842 | if (TryAltiVecVectorToken()) |
| 843 | return TPResult::True(); |
| 844 | // Fall through. |
Douglas Gregor | d57959a | 2009-03-27 23:10:48 +0000 | [diff] [blame] | 845 | case tok::kw_typename: // typename T::type |
Chris Lattner | e584926 | 2009-01-04 23:33:56 +0000 | [diff] [blame] | 846 | // Annotate typenames and C++ scope specifiers. If we get one, just |
| 847 | // recurse to handle whatever we get. |
| 848 | if (TryAnnotateTypeOrScopeToken()) |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 849 | return TPResult::Error(); |
| 850 | if (Tok.is(tok::identifier)) |
| 851 | return TPResult::False(); |
| 852 | return isCXXDeclarationSpecifier(); |
Chris Lattner | e584926 | 2009-01-04 23:33:56 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 2ee9b40 | 2009-12-19 01:11:05 +0000 | [diff] [blame] | 854 | case tok::coloncolon: { // ::foo::bar |
| 855 | const Token &Next = NextToken(); |
| 856 | if (Next.is(tok::kw_new) || // ::new |
| 857 | Next.is(tok::kw_delete)) // ::delete |
John McCall | ae03cb5 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 858 | return TPResult::False(); |
David Blaikie | 42d6d0c | 2011-12-04 05:04:18 +0000 | [diff] [blame] | 859 | } |
| 860 | // Fall through. |
| 861 | case tok::kw_decltype: |
Chris Lattner | e584926 | 2009-01-04 23:33:56 +0000 | [diff] [blame] | 862 | // Annotate typenames and C++ scope specifiers. If we get one, just |
| 863 | // recurse to handle whatever we get. |
| 864 | if (TryAnnotateTypeOrScopeToken()) |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 865 | return TPResult::Error(); |
| 866 | return isCXXDeclarationSpecifier(); |
Nick Lewycky | 443aac9 | 2012-01-25 01:19:14 +0000 | [diff] [blame] | 867 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 868 | // decl-specifier: |
| 869 | // storage-class-specifier |
| 870 | // type-specifier |
| 871 | // function-specifier |
| 872 | // 'friend' |
| 873 | // 'typedef' |
Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 874 | // 'constexpr' |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 875 | case tok::kw_friend: |
| 876 | case tok::kw_typedef: |
Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 877 | case tok::kw_constexpr: |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 878 | // storage-class-specifier |
| 879 | case tok::kw_register: |
| 880 | case tok::kw_static: |
| 881 | case tok::kw_extern: |
| 882 | case tok::kw_mutable: |
| 883 | case tok::kw_auto: |
| 884 | case tok::kw___thread: |
| 885 | // function-specifier |
| 886 | case tok::kw_inline: |
| 887 | case tok::kw_virtual: |
| 888 | case tok::kw_explicit: |
| 889 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 890 | // Modules |
| 891 | case tok::kw___module_private__: |
| 892 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 893 | // type-specifier: |
| 894 | // simple-type-specifier |
| 895 | // class-specifier |
| 896 | // enum-specifier |
| 897 | // elaborated-type-specifier |
| 898 | // typename-specifier |
| 899 | // cv-qualifier |
| 900 | |
| 901 | // class-specifier |
| 902 | // elaborated-type-specifier |
| 903 | case tok::kw_class: |
| 904 | case tok::kw_struct: |
| 905 | case tok::kw_union: |
| 906 | // enum-specifier |
| 907 | case tok::kw_enum: |
| 908 | // cv-qualifier |
| 909 | case tok::kw_const: |
| 910 | case tok::kw_volatile: |
| 911 | |
| 912 | // GNU |
| 913 | case tok::kw_restrict: |
| 914 | case tok::kw__Complex: |
| 915 | case tok::kw___attribute: |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 916 | return TPResult::True(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Steve Naroff | 7ec5658 | 2009-01-06 17:40:00 +0000 | [diff] [blame] | 918 | // Microsoft |
Steve Naroff | 47f5209 | 2009-01-06 19:34:12 +0000 | [diff] [blame] | 919 | case tok::kw___declspec: |
Steve Naroff | 7ec5658 | 2009-01-06 17:40:00 +0000 | [diff] [blame] | 920 | case tok::kw___cdecl: |
| 921 | case tok::kw___stdcall: |
| 922 | case tok::kw___fastcall: |
Douglas Gregor | f813a2c | 2010-05-18 16:57:00 +0000 | [diff] [blame] | 923 | case tok::kw___thiscall: |
Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 924 | case tok::kw___w64: |
| 925 | case tok::kw___ptr64: |
Francois Pichet | 58fd97a | 2011-08-25 00:36:46 +0000 | [diff] [blame] | 926 | case tok::kw___ptr32: |
Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 927 | case tok::kw___forceinline: |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 928 | case tok::kw___unaligned: |
Eli Friedman | 290eeb0 | 2009-06-08 23:27:34 +0000 | [diff] [blame] | 929 | return TPResult::True(); |
Dawn Perchik | 52fc314 | 2010-09-03 01:29:35 +0000 | [diff] [blame] | 930 | |
| 931 | // Borland |
| 932 | case tok::kw___pascal: |
| 933 | return TPResult::True(); |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 934 | |
| 935 | // AltiVec |
| 936 | case tok::kw___vector: |
| 937 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 938 | |
John McCall | 51e2a5d | 2010-04-30 03:11:01 +0000 | [diff] [blame] | 939 | case tok::annot_template_id: { |
Argyrios Kyrtzidis | 25a7676 | 2011-06-22 06:09:49 +0000 | [diff] [blame] | 940 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
John McCall | 51e2a5d | 2010-04-30 03:11:01 +0000 | [diff] [blame] | 941 | if (TemplateId->Kind != TNK_Type_template) |
| 942 | return TPResult::False(); |
| 943 | CXXScopeSpec SS; |
Douglas Gregor | 059101f | 2011-03-02 00:47:37 +0000 | [diff] [blame] | 944 | AnnotateTemplateIdTokenAsType(); |
John McCall | 51e2a5d | 2010-04-30 03:11:01 +0000 | [diff] [blame] | 945 | assert(Tok.is(tok::annot_typename)); |
| 946 | goto case_typename; |
| 947 | } |
| 948 | |
John McCall | ae03cb5 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 949 | case tok::annot_cxxscope: // foo::bar or ::foo::bar, but already parsed |
| 950 | // We've already annotated a scope; try to annotate a type. |
John McCall | 9ba6166 | 2010-02-26 08:45:28 +0000 | [diff] [blame] | 951 | if (TryAnnotateTypeOrScopeToken()) |
| 952 | return TPResult::Error(); |
Nick Lewycky | 443aac9 | 2012-01-25 01:19:14 +0000 | [diff] [blame] | 953 | if (!Tok.is(tok::annot_typename)) { |
| 954 | // If the next token is an identifier or a type qualifier, then this |
| 955 | // can't possibly be a valid expression either. |
| 956 | if (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier)) { |
| 957 | CXXScopeSpec SS; |
| 958 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 959 | Tok.getAnnotationRange(), |
| 960 | SS); |
| 961 | if (SS.getScopeRep() && SS.getScopeRep()->isDependent()) { |
| 962 | TentativeParsingAction PA(*this); |
| 963 | ConsumeToken(); |
| 964 | ConsumeToken(); |
| 965 | bool isIdentifier = Tok.is(tok::identifier); |
| 966 | TPResult TPR = TPResult::False(); |
| 967 | if (!isIdentifier) |
| 968 | TPR = isCXXDeclarationSpecifier(); |
| 969 | PA.Revert(); |
| 970 | |
| 971 | if (isIdentifier || |
| 972 | TPR == TPResult::True() || TPR == TPResult::Error()) |
| 973 | return TPResult::Error(); |
| 974 | } |
| 975 | } |
John McCall | ae03cb5 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 976 | return TPResult::False(); |
Nick Lewycky | 443aac9 | 2012-01-25 01:19:14 +0000 | [diff] [blame] | 977 | } |
John McCall | ae03cb5 | 2009-12-19 00:35:18 +0000 | [diff] [blame] | 978 | // If that succeeded, fallthrough into the generic simple-type-id case. |
| 979 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 980 | // The ambiguity resides in a simple-type-specifier/typename-specifier |
| 981 | // followed by a '('. The '(' could either be the start of: |
| 982 | // |
| 983 | // direct-declarator: |
| 984 | // '(' declarator ')' |
| 985 | // |
| 986 | // direct-abstract-declarator: |
| 987 | // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt] |
| 988 | // exception-specification[opt] |
| 989 | // '(' abstract-declarator ')' |
| 990 | // |
| 991 | // or part of a function-style cast expression: |
| 992 | // |
| 993 | // simple-type-specifier '(' expression-list[opt] ')' |
| 994 | // |
| 995 | |
| 996 | // simple-type-specifier: |
| 997 | |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 998 | case tok::annot_typename: |
| 999 | case_typename: |
| 1000 | // In Objective-C, we might have a protocol-qualified type. |
| 1001 | if (getLang().ObjC1 && NextToken().is(tok::less)) { |
| 1002 | // Tentatively parse the |
| 1003 | TentativeParsingAction PA(*this); |
| 1004 | ConsumeToken(); // The type token |
| 1005 | |
| 1006 | TPResult TPR = TryParseProtocolQualifiers(); |
| 1007 | bool isFollowedByParen = Tok.is(tok::l_paren); |
| 1008 | |
| 1009 | PA.Revert(); |
| 1010 | |
| 1011 | if (TPR == TPResult::Error()) |
| 1012 | return TPResult::Error(); |
| 1013 | |
| 1014 | if (isFollowedByParen) |
| 1015 | return TPResult::Ambiguous(); |
| 1016 | |
| 1017 | return TPResult::True(); |
| 1018 | } |
| 1019 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1020 | case tok::kw_char: |
| 1021 | case tok::kw_wchar_t: |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1022 | case tok::kw_char16_t: |
| 1023 | case tok::kw_char32_t: |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1024 | case tok::kw_bool: |
| 1025 | case tok::kw_short: |
| 1026 | case tok::kw_int: |
| 1027 | case tok::kw_long: |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 1028 | case tok::kw___int64: |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1029 | case tok::kw_signed: |
| 1030 | case tok::kw_unsigned: |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 1031 | case tok::kw_half: |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1032 | case tok::kw_float: |
| 1033 | case tok::kw_double: |
| 1034 | case tok::kw_void: |
David Blaikie | 5e089fe | 2012-01-24 05:47:35 +0000 | [diff] [blame] | 1035 | case tok::annot_decltype: |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1036 | if (NextToken().is(tok::l_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1037 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1038 | |
Douglas Gregor | 9497a73 | 2010-09-16 01:51:54 +0000 | [diff] [blame] | 1039 | if (isStartOfObjCClassMessageMissingOpenBracket()) |
| 1040 | return TPResult::False(); |
| 1041 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1042 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1043 | |
Anders Carlsson | 6fd634f | 2009-06-24 17:47:40 +0000 | [diff] [blame] | 1044 | // GNU typeof support. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1045 | case tok::kw_typeof: { |
| 1046 | if (NextToken().isNot(tok::l_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1047 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1048 | |
| 1049 | TentativeParsingAction PA(*this); |
| 1050 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1051 | TPResult TPR = TryParseTypeofSpecifier(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1052 | bool isFollowedByParen = Tok.is(tok::l_paren); |
| 1053 | |
| 1054 | PA.Revert(); |
| 1055 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1056 | if (TPR == TPResult::Error()) |
| 1057 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1058 | |
| 1059 | if (isFollowedByParen) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1060 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1061 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1062 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Sean Hunt | db5d44b | 2011-05-19 05:37:45 +0000 | [diff] [blame] | 1065 | // C++0x type traits support |
| 1066 | case tok::kw___underlying_type: |
| 1067 | return TPResult::True(); |
| 1068 | |
Benjamin Kramer | ffbe9b9 | 2011-12-23 17:00:35 +0000 | [diff] [blame] | 1069 | // C11 _Atomic |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1070 | case tok::kw__Atomic: |
| 1071 | return TPResult::True(); |
| 1072 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1073 | default: |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1074 | return TPResult::False(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | /// [GNU] typeof-specifier: |
| 1079 | /// 'typeof' '(' expressions ')' |
| 1080 | /// 'typeof' '(' type-name ')' |
| 1081 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1082 | Parser::TPResult Parser::TryParseTypeofSpecifier() { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1083 | assert(Tok.is(tok::kw_typeof) && "Expected 'typeof'!"); |
| 1084 | ConsumeToken(); |
| 1085 | |
| 1086 | assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 1087 | // Parse through the parens after 'typeof'. |
| 1088 | ConsumeParen(); |
| 1089 | if (!SkipUntil(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1090 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1091 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1092 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1095 | /// [ObjC] protocol-qualifiers: |
| 1096 | //// '<' identifier-list '>' |
| 1097 | Parser::TPResult Parser::TryParseProtocolQualifiers() { |
| 1098 | assert(Tok.is(tok::less) && "Expected '<' for qualifier list"); |
| 1099 | ConsumeToken(); |
| 1100 | do { |
| 1101 | if (Tok.isNot(tok::identifier)) |
| 1102 | return TPResult::Error(); |
| 1103 | ConsumeToken(); |
| 1104 | |
| 1105 | if (Tok.is(tok::comma)) { |
| 1106 | ConsumeToken(); |
| 1107 | continue; |
| 1108 | } |
| 1109 | |
| 1110 | if (Tok.is(tok::greater)) { |
| 1111 | ConsumeToken(); |
| 1112 | return TPResult::Ambiguous(); |
| 1113 | } |
| 1114 | } while (false); |
| 1115 | |
| 1116 | return TPResult::Error(); |
| 1117 | } |
| 1118 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1119 | Parser::TPResult Parser::TryParseDeclarationSpecifier() { |
| 1120 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 1121 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1122 | return TPR; |
| 1123 | |
| 1124 | if (Tok.is(tok::kw_typeof)) |
| 1125 | TryParseTypeofSpecifier(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1126 | else { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1127 | ConsumeToken(); |
Douglas Gregor | 9bd1d8d | 2010-10-21 23:17:00 +0000 | [diff] [blame] | 1128 | |
| 1129 | if (getLang().ObjC1 && Tok.is(tok::less)) |
| 1130 | TryParseProtocolQualifiers(); |
| 1131 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1132 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1133 | assert(Tok.is(tok::l_paren) && "Expected '('!"); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1134 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /// isCXXFunctionDeclarator - Disambiguates between a function declarator or |
| 1138 | /// a constructor-style initializer, when parsing declaration statements. |
| 1139 | /// Returns true for function declarator and false for constructor-style |
| 1140 | /// initializer. |
| 1141 | /// If during the disambiguation process a parsing error is encountered, |
| 1142 | /// the function returns true to let the declaration parsing code handle it. |
| 1143 | /// |
| 1144 | /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt] |
| 1145 | /// exception-specification[opt] |
| 1146 | /// |
Argyrios Kyrtzidis | e75d849 | 2008-10-17 23:23:35 +0000 | [diff] [blame] | 1147 | bool Parser::isCXXFunctionDeclarator(bool warnIfAmbiguous) { |
Argyrios Kyrtzidis | d3dbbb6 | 2008-10-05 21:10:08 +0000 | [diff] [blame] | 1148 | |
| 1149 | // C++ 8.2p1: |
| 1150 | // The ambiguity arising from the similarity between a function-style cast and |
| 1151 | // a declaration mentioned in 6.8 can also occur in the context of a |
| 1152 | // declaration. In that context, the choice is between a function declaration |
| 1153 | // with a redundant set of parentheses around a parameter name and an object |
| 1154 | // declaration with a function-style cast as the initializer. Just as for the |
| 1155 | // ambiguities mentioned in 6.8, the resolution is to consider any construct |
| 1156 | // that could possibly be a declaration a declaration. |
| 1157 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1158 | TentativeParsingAction PA(*this); |
| 1159 | |
| 1160 | ConsumeParen(); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1161 | TPResult TPR = TryParseParameterDeclarationClause(); |
| 1162 | if (TPR == TPResult::Ambiguous() && Tok.isNot(tok::r_paren)) |
| 1163 | TPR = TPResult::False(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1164 | |
Argyrios Kyrtzidis | 259b0d9 | 2008-10-15 23:21:32 +0000 | [diff] [blame] | 1165 | SourceLocation TPLoc = Tok.getLocation(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1166 | PA.Revert(); |
| 1167 | |
| 1168 | // In case of an error, let the declaration parsing code handle it. |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1169 | if (TPR == TPResult::Error()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1170 | return true; |
| 1171 | |
Argyrios Kyrtzidis | 259b0d9 | 2008-10-15 23:21:32 +0000 | [diff] [blame] | 1172 | if (TPR == TPResult::Ambiguous()) { |
| 1173 | // Function declarator has precedence over constructor-style initializer. |
| 1174 | // Emit a warning just in case the author intended a variable definition. |
Argyrios Kyrtzidis | e75d849 | 2008-10-17 23:23:35 +0000 | [diff] [blame] | 1175 | if (warnIfAmbiguous) |
Chris Lattner | ef708fd | 2008-11-18 07:50:21 +0000 | [diff] [blame] | 1176 | Diag(Tok, diag::warn_parens_disambiguated_as_function_decl) |
| 1177 | << SourceRange(Tok.getLocation(), TPLoc); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1178 | return true; |
Argyrios Kyrtzidis | 259b0d9 | 2008-10-15 23:21:32 +0000 | [diff] [blame] | 1179 | } |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1180 | |
| 1181 | return TPR == TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /// parameter-declaration-clause: |
| 1185 | /// parameter-declaration-list[opt] '...'[opt] |
| 1186 | /// parameter-declaration-list ',' '...' |
| 1187 | /// |
| 1188 | /// parameter-declaration-list: |
| 1189 | /// parameter-declaration |
| 1190 | /// parameter-declaration-list ',' parameter-declaration |
| 1191 | /// |
| 1192 | /// parameter-declaration: |
Argyrios Kyrtzidis | 346af03 | 2010-12-08 02:02:46 +0000 | [diff] [blame] | 1193 | /// decl-specifier-seq declarator attributes[opt] |
| 1194 | /// decl-specifier-seq declarator attributes[opt] '=' assignment-expression |
| 1195 | /// decl-specifier-seq abstract-declarator[opt] attributes[opt] |
| 1196 | /// decl-specifier-seq abstract-declarator[opt] attributes[opt] |
| 1197 | /// '=' assignment-expression |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1198 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1199 | Parser::TPResult Parser::TryParseParameterDeclarationClause() { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1200 | |
| 1201 | if (Tok.is(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1202 | return TPResult::True(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1203 | |
| 1204 | // parameter-declaration-list[opt] '...'[opt] |
| 1205 | // parameter-declaration-list ',' '...' |
| 1206 | // |
| 1207 | // parameter-declaration-list: |
| 1208 | // parameter-declaration |
| 1209 | // parameter-declaration-list ',' parameter-declaration |
| 1210 | // |
| 1211 | while (1) { |
| 1212 | // '...'[opt] |
| 1213 | if (Tok.is(tok::ellipsis)) { |
| 1214 | ConsumeToken(); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1215 | return TPResult::True(); // '...' is a sign of a function declarator. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 1218 | ParsedAttributes attrs(AttrFactory); |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 1219 | MaybeParseMicrosoftAttributes(attrs); |
Francois Pichet | 334d47e | 2010-10-11 12:59:39 +0000 | [diff] [blame] | 1220 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1221 | // decl-specifier-seq |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1222 | TPResult TPR = TryParseDeclarationSpecifier(); |
| 1223 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1224 | return TPR; |
| 1225 | |
| 1226 | // declarator |
| 1227 | // abstract-declarator[opt] |
| 1228 | TPR = TryParseDeclarator(true/*mayBeAbstract*/); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1229 | if (TPR != TPResult::Ambiguous()) |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1230 | return TPR; |
| 1231 | |
Argyrios Kyrtzidis | 346af03 | 2010-12-08 02:02:46 +0000 | [diff] [blame] | 1232 | // [GNU] attributes[opt] |
| 1233 | if (Tok.is(tok::kw___attribute)) |
| 1234 | return TPResult::True(); |
| 1235 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1236 | if (Tok.is(tok::equal)) { |
| 1237 | // '=' assignment-expression |
| 1238 | // Parse through assignment-expression. |
Douglas Gregor | a8bc8c9 | 2010-12-23 22:44:42 +0000 | [diff] [blame] | 1239 | tok::TokenKind StopToks[2] ={ tok::comma, tok::r_paren }; |
| 1240 | if (!SkipUntil(StopToks, 2, true/*StopAtSemi*/, true/*DontConsume*/)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1241 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | if (Tok.is(tok::ellipsis)) { |
| 1245 | ConsumeToken(); |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1246 | return TPResult::True(); // '...' is a sign of a function declarator. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | if (Tok.isNot(tok::comma)) |
| 1250 | break; |
| 1251 | ConsumeToken(); // the comma. |
| 1252 | } |
| 1253 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1254 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 1257 | /// TryParseFunctionDeclarator - We parsed a '(' and we want to try to continue |
| 1258 | /// parsing as a function declarator. |
| 1259 | /// If TryParseFunctionDeclarator fully parsed the function declarator, it will |
| 1260 | /// return TPResult::Ambiguous(), otherwise it will return either False() or |
| 1261 | /// Error(). |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1262 | /// |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1263 | /// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt] |
| 1264 | /// exception-specification[opt] |
| 1265 | /// |
| 1266 | /// exception-specification: |
| 1267 | /// 'throw' '(' type-id-list[opt] ')' |
| 1268 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1269 | Parser::TPResult Parser::TryParseFunctionDeclarator() { |
Argyrios Kyrtzidis | d3616a8 | 2008-10-05 23:15:41 +0000 | [diff] [blame] | 1270 | |
| 1271 | // The '(' is already parsed. |
| 1272 | |
| 1273 | TPResult TPR = TryParseParameterDeclarationClause(); |
| 1274 | if (TPR == TPResult::Ambiguous() && Tok.isNot(tok::r_paren)) |
| 1275 | TPR = TPResult::False(); |
| 1276 | |
| 1277 | if (TPR == TPResult::False() || TPR == TPResult::Error()) |
| 1278 | return TPR; |
| 1279 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1280 | // Parse through the parens. |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1281 | if (!SkipUntil(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1282 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1283 | |
| 1284 | // cv-qualifier-seq |
| 1285 | while (Tok.is(tok::kw_const) || |
| 1286 | Tok.is(tok::kw_volatile) || |
| 1287 | Tok.is(tok::kw_restrict) ) |
| 1288 | ConsumeToken(); |
| 1289 | |
Douglas Gregor | e3c7a7c | 2011-01-26 16:50:54 +0000 | [diff] [blame] | 1290 | // ref-qualifier[opt] |
| 1291 | if (Tok.is(tok::amp) || Tok.is(tok::ampamp)) |
| 1292 | ConsumeToken(); |
| 1293 | |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1294 | // exception-specification |
| 1295 | if (Tok.is(tok::kw_throw)) { |
| 1296 | ConsumeToken(); |
| 1297 | if (Tok.isNot(tok::l_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1298 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1299 | |
| 1300 | // Parse through the parens after 'throw'. |
| 1301 | ConsumeParen(); |
| 1302 | if (!SkipUntil(tok::r_paren)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1303 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1304 | } |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 1305 | if (Tok.is(tok::kw_noexcept)) { |
| 1306 | ConsumeToken(); |
| 1307 | // Possibly an expression as well. |
| 1308 | if (Tok.is(tok::l_paren)) { |
| 1309 | // Find the matching rparen. |
| 1310 | ConsumeParen(); |
| 1311 | if (!SkipUntil(tok::r_paren)) |
| 1312 | return TPResult::Error(); |
| 1313 | } |
| 1314 | } |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1315 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1316 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /// '[' constant-expression[opt] ']' |
| 1320 | /// |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1321 | Parser::TPResult Parser::TryParseBracketDeclarator() { |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1322 | ConsumeBracket(); |
| 1323 | if (!SkipUntil(tok::r_square)) |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1324 | return TPResult::Error(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1325 | |
Argyrios Kyrtzidis | b9f3419 | 2008-10-05 18:52:21 +0000 | [diff] [blame] | 1326 | return TPResult::Ambiguous(); |
Argyrios Kyrtzidis | 5404a15 | 2008-10-05 00:06:24 +0000 | [diff] [blame] | 1327 | } |