blob: eb6e93540566ef7b0449d6b81d4a5a6db422812b [file] [log] [blame]
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +00001//===--- 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 Lattner500d3292009-01-29 05:15:15 +000016#include "clang/Parse/ParseDiagnostic.h"
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000017using namespace clang;
18
19/// isCXXDeclarationStatement - C++-specialized function that disambiguates
20/// between a declaration or an expression statement, when parsing function
21/// bodies. Returns true for declaration, false for expression.
22///
23/// declaration-statement:
24/// block-declaration
25///
26/// block-declaration:
27/// simple-declaration
28/// asm-definition
29/// namespace-alias-definition
30/// using-declaration
31/// using-directive
Anders Carlsson511d7ab2009-03-11 16:27:10 +000032/// [C++0x] static_assert-declaration
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000033///
34/// asm-definition:
35/// 'asm' '(' string-literal ')' ';'
36///
37/// namespace-alias-definition:
38/// 'namespace' identifier = qualified-namespace-specifier ';'
39///
40/// using-declaration:
41/// 'using' typename[opt] '::'[opt] nested-name-specifier
42/// unqualified-id ';'
43/// 'using' '::' unqualified-id ;
44///
45/// using-directive:
46/// 'using' 'namespace' '::'[opt] nested-name-specifier[opt]
47/// namespace-name ';'
48///
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000049bool Parser::isCXXDeclarationStatement() {
50 switch (Tok.getKind()) {
51 // asm-definition
52 case tok::kw_asm:
53 // namespace-alias-definition
54 case tok::kw_namespace:
55 // using-declaration
56 // using-directive
57 case tok::kw_using:
58 return true;
Anders Carlsson511d7ab2009-03-11 16:27:10 +000059 case tok::kw_static_assert:
60 // static_assert-declaration
61 return true;
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +000062 default:
63 // simple-declaration
64 return isCXXSimpleDeclaration();
65 }
66}
67
68/// isCXXSimpleDeclaration - C++-specialized function that disambiguates
69/// between a simple-declaration or an expression-statement.
70/// If during the disambiguation process a parsing error is encountered,
71/// the function returns true to let the declaration parsing code handle it.
72/// Returns false if the statement is disambiguated as expression.
73///
74/// simple-declaration:
75/// decl-specifier-seq init-declarator-list[opt] ';'
76///
77bool Parser::isCXXSimpleDeclaration() {
78 // C++ 6.8p1:
79 // There is an ambiguity in the grammar involving expression-statements and
80 // declarations: An expression-statement with a function-style explicit type
81 // conversion (5.2.3) as its leftmost subexpression can be indistinguishable
82 // from a declaration where the first declarator starts with a '('. In those
83 // cases the statement is a declaration. [Note: To disambiguate, the whole
84 // statement might have to be examined to determine if it is an
85 // expression-statement or a declaration].
86
87 // C++ 6.8p3:
88 // The disambiguation is purely syntactic; that is, the meaning of the names
89 // occurring in such a statement, beyond whether they are type-names or not,
90 // is not generally used in or changed by the disambiguation. Class
91 // templates are instantiated as necessary to determine if a qualified name
92 // is a type-name. Disambiguation precedes parsing, and a statement
93 // disambiguated as a declaration may be an ill-formed declaration.
94
95 // We don't have to parse all of the decl-specifier-seq part. There's only
96 // an ambiguity if the first decl-specifier is
97 // simple-type-specifier/typename-specifier followed by a '(', which may
98 // indicate a function-style cast expression.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +000099 // isCXXDeclarationSpecifier will return TPResult::Ambiguous() only in such
100 // a case.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000101
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000102 TPResult TPR = isCXXDeclarationSpecifier();
103 if (TPR != TPResult::Ambiguous())
104 return TPR != TPResult::False(); // Returns true for TPResult::True() or
105 // TPResult::Error().
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000106
107 // FIXME: Add statistics about the number of ambiguous statements encountered
108 // and how they were resolved (number of declarations+number of expressions).
109
110 // Ok, we have a simple-type-specifier/typename-specifier followed by a '('.
111 // We need tentative parsing...
112
113 TentativeParsingAction PA(*this);
114
115 TPR = TryParseSimpleDeclaration();
116 SourceLocation TentativeParseLoc = Tok.getLocation();
117
118 PA.Revert();
119
120 // In case of an error, let the declaration parsing code handle it.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000121 if (TPR == TPResult::Error())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000122 return true;
123
124 // Declarations take precedence over expressions.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000125 if (TPR == TPResult::Ambiguous())
126 TPR = TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000127
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000128 assert(TPR == TPResult::True() || TPR == TPResult::False());
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000129 return TPR == TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000130}
131
132/// simple-declaration:
133/// decl-specifier-seq init-declarator-list[opt] ';'
134///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000135Parser::TPResult Parser::TryParseSimpleDeclaration() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000136 // We know that we have a simple-type-specifier/typename-specifier followed
137 // by a '('.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000138 assert(isCXXDeclarationSpecifier() == TPResult::Ambiguous());
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000139
140 if (Tok.is(tok::kw_typeof))
141 TryParseTypeofSpecifier();
142 else
143 ConsumeToken();
144
145 assert(Tok.is(tok::l_paren) && "Expected '('");
146
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000147 TPResult TPR = TryParseInitDeclaratorList();
148 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000149 return TPR;
150
151 if (Tok.isNot(tok::semi))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000152 return TPResult::False();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000153
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000154 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000155}
156
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000157/// init-declarator-list:
158/// init-declarator
159/// init-declarator-list ',' init-declarator
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000160///
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000161/// init-declarator:
162/// declarator initializer[opt]
163/// [GNU] declarator simple-asm-expr[opt] attributes[opt] initializer[opt]
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000164///
165/// initializer:
166/// '=' initializer-clause
167/// '(' expression-list ')'
168///
169/// initializer-clause:
170/// assignment-expression
171/// '{' initializer-list ','[opt] '}'
172/// '{' '}'
173///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000174Parser::TPResult Parser::TryParseInitDeclaratorList() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000175 // GCC only examines the first declarator for disambiguation:
176 // i.e:
177 // int(x), ++x; // GCC regards it as ill-formed declaration.
178 //
179 // Comeau and MSVC will regard the above statement as correct expression.
180 // Clang examines all of the declarators and also regards the above statement
181 // as correct expression.
182
183 while (1) {
184 // declarator
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000185 TPResult TPR = TryParseDeclarator(false/*mayBeAbstract*/);
186 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000187 return TPR;
188
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000189 // [GNU] simple-asm-expr[opt] attributes[opt]
190 if (Tok.is(tok::kw_asm) || Tok.is(tok::kw___attribute))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000191 return TPResult::True();
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000192
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000193 // initializer[opt]
194 if (Tok.is(tok::l_paren)) {
195 // Parse through the parens.
196 ConsumeParen();
197 if (!SkipUntil(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000198 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000199 } else if (Tok.is(tok::equal)) {
200 // MSVC won't examine the rest of declarators if '=' is encountered, it
201 // will conclude that it is a declaration.
202 // Comeau and Clang will examine the rest of declarators.
203 // Note that "int(x) = {0}, ++x;" will be interpreted as ill-formed
204 // expression.
205 //
206 // Parse through the initializer-clause.
207 SkipUntil(tok::comma, true/*StopAtSemi*/, true/*DontConsume*/);
208 }
209
210 if (Tok.isNot(tok::comma))
211 break;
212 ConsumeToken(); // the comma.
213 }
214
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000215 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000216}
217
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000218/// isCXXConditionDeclaration - Disambiguates between a declaration or an
219/// expression for a condition of a if/switch/while/for statement.
220/// If during the disambiguation process a parsing error is encountered,
221/// the function returns true to let the declaration parsing code handle it.
222///
223/// condition:
224/// expression
225/// type-specifier-seq declarator '=' assignment-expression
226/// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
227/// '=' assignment-expression
228///
229bool Parser::isCXXConditionDeclaration() {
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000230 TPResult TPR = isCXXDeclarationSpecifier();
231 if (TPR != TPResult::Ambiguous())
232 return TPR != TPResult::False(); // Returns true for TPResult::True() or
233 // TPResult::Error().
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000234
235 // FIXME: Add statistics about the number of ambiguous statements encountered
236 // and how they were resolved (number of declarations+number of expressions).
237
238 // Ok, we have a simple-type-specifier/typename-specifier followed by a '('.
239 // We need tentative parsing...
240
241 TentativeParsingAction PA(*this);
242
243 // type-specifier-seq
244 if (Tok.is(tok::kw_typeof))
245 TryParseTypeofSpecifier();
246 else
247 ConsumeToken();
248 assert(Tok.is(tok::l_paren) && "Expected '('");
249
250 // declarator
251 TPR = TryParseDeclarator(false/*mayBeAbstract*/);
252
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000253 // In case of an error, let the declaration parsing code handle it.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000254 if (TPR == TPResult::Error())
255 TPR = TPResult::True();
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000256
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000257 if (TPR == TPResult::Ambiguous()) {
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000258 // '='
259 // [GNU] simple-asm-expr[opt] attributes[opt]
260 if (Tok.is(tok::equal) ||
261 Tok.is(tok::kw_asm) || Tok.is(tok::kw___attribute))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000262 TPR = TPResult::True();
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000263 else
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000264 TPR = TPResult::False();
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000265 }
266
Argyrios Kyrtzidisca35baa2008-10-05 15:19:49 +0000267 PA.Revert();
268
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000269 assert(TPR == TPResult::True() || TPR == TPResult::False());
270 return TPR == TPResult::True();
Argyrios Kyrtzidisa8a45982008-10-05 15:03:47 +0000271}
272
Mike Stump1eb44332009-09-09 15:08:12 +0000273 /// \brief Determine whether the next set of tokens contains a type-id.
Douglas Gregor8b642592009-02-10 00:53:15 +0000274 ///
275 /// The context parameter states what context we're parsing right
276 /// now, which affects how this routine copes with the token
277 /// following the type-id. If the context is TypeIdInParens, we have
278 /// already parsed the '(' and we will cease lookahead when we hit
279 /// the corresponding ')'. If the context is
280 /// TypeIdAsTemplateArgument, we've already parsed the '<' or ','
281 /// before this template argument, and will cease lookahead when we
282 /// hit a '>', '>>' (in C++0x), or ','. Returns true for a type-id
283 /// and false for an expression. If during the disambiguation
284 /// process a parsing error is encountered, the function returns
285 /// true to let the declaration parsing code handle it.
286 ///
287 /// type-id:
288 /// type-specifier-seq abstract-declarator[opt]
289 ///
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000290bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) {
Mike Stump1eb44332009-09-09 15:08:12 +0000291
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000292 isAmbiguous = false;
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +0000293
294 // C++ 8.2p2:
295 // The ambiguity arising from the similarity between a function-style cast and
296 // a type-id can occur in different contexts. The ambiguity appears as a
297 // choice between a function-style cast expression and a declaration of a
298 // type. The resolution is that any construct that could possibly be a type-id
299 // in its syntactic context shall be considered a type-id.
300
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +0000301 TPResult TPR = isCXXDeclarationSpecifier();
302 if (TPR != TPResult::Ambiguous())
303 return TPR != TPResult::False(); // Returns true for TPResult::True() or
304 // TPResult::Error().
305
306 // FIXME: Add statistics about the number of ambiguous statements encountered
307 // and how they were resolved (number of declarations+number of expressions).
308
309 // Ok, we have a simple-type-specifier/typename-specifier followed by a '('.
310 // We need tentative parsing...
311
312 TentativeParsingAction PA(*this);
313
314 // type-specifier-seq
315 if (Tok.is(tok::kw_typeof))
316 TryParseTypeofSpecifier();
317 else
318 ConsumeToken();
319 assert(Tok.is(tok::l_paren) && "Expected '('");
320
321 // declarator
322 TPR = TryParseDeclarator(true/*mayBeAbstract*/, false/*mayHaveIdentifier*/);
323
324 // In case of an error, let the declaration parsing code handle it.
325 if (TPR == TPResult::Error())
326 TPR = TPResult::True();
327
328 if (TPR == TPResult::Ambiguous()) {
329 // We are supposed to be inside parens, so if after the abstract declarator
330 // we encounter a ')' this is a type-id, otherwise it's an expression.
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000331 if (Context == TypeIdInParens && Tok.is(tok::r_paren)) {
Douglas Gregor8b642592009-02-10 00:53:15 +0000332 TPR = TPResult::True();
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000333 isAmbiguous = true;
334
Douglas Gregor8b642592009-02-10 00:53:15 +0000335 // We are supposed to be inside a template argument, so if after
336 // the abstract declarator we encounter a '>', '>>' (in C++0x), or
337 // ',', this is a type-id. Otherwise, it's an expression.
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000338 } else if (Context == TypeIdAsTemplateArgument &&
339 (Tok.is(tok::greater) || Tok.is(tok::comma) ||
340 (getLang().CPlusPlus0x && Tok.is(tok::greatergreater)))) {
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +0000341 TPR = TPResult::True();
Argyrios Kyrtzidisf58f45e2009-05-22 10:24:42 +0000342 isAmbiguous = true;
343
344 } else
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +0000345 TPR = TPResult::False();
346 }
347
348 PA.Revert();
349
350 assert(TPR == TPResult::True() || TPR == TPResult::False());
351 return TPR == TPResult::True();
352}
353
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000354/// declarator:
355/// direct-declarator
356/// ptr-operator declarator
357///
358/// direct-declarator:
359/// declarator-id
360/// direct-declarator '(' parameter-declaration-clause ')'
361/// cv-qualifier-seq[opt] exception-specification[opt]
362/// direct-declarator '[' constant-expression[opt] ']'
363/// '(' declarator ')'
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000364/// [GNU] '(' attributes declarator ')'
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000365///
366/// abstract-declarator:
367/// ptr-operator abstract-declarator[opt]
368/// direct-abstract-declarator
369///
370/// direct-abstract-declarator:
371/// direct-abstract-declarator[opt]
372/// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
373/// exception-specification[opt]
374/// direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
375/// '(' abstract-declarator ')'
376///
377/// ptr-operator:
378/// '*' cv-qualifier-seq[opt]
379/// '&'
380/// [C++0x] '&&' [TODO]
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000381/// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt]
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000382///
383/// cv-qualifier-seq:
384/// cv-qualifier cv-qualifier-seq[opt]
385///
386/// cv-qualifier:
387/// 'const'
388/// 'volatile'
389///
390/// declarator-id:
391/// id-expression
392///
393/// id-expression:
394/// unqualified-id
395/// qualified-id [TODO]
396///
397/// unqualified-id:
398/// identifier
399/// operator-function-id [TODO]
400/// conversion-function-id [TODO]
401/// '~' class-name [TODO]
402/// template-id [TODO]
403///
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +0000404Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract,
405 bool mayHaveIdentifier) {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000406 // declarator:
407 // direct-declarator
408 // ptr-operator declarator
409
410 while (1) {
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000411 if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier))
Douglas Gregor495c35d2009-08-25 22:51:20 +0000412 TryAnnotateCXXScopeToken(true);
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000413
Chris Lattner9af55002009-03-27 04:18:06 +0000414 if (Tok.is(tok::star) || Tok.is(tok::amp) || Tok.is(tok::caret) ||
Sebastian Redl8edef7c2009-01-24 23:29:36 +0000415 (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000416 // ptr-operator
417 ConsumeToken();
418 while (Tok.is(tok::kw_const) ||
419 Tok.is(tok::kw_volatile) ||
Chris Lattner9af55002009-03-27 04:18:06 +0000420 Tok.is(tok::kw_restrict))
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000421 ConsumeToken();
422 } else {
423 break;
424 }
425 }
426
427 // direct-declarator:
428 // direct-abstract-declarator:
429
Argyrios Kyrtzidis1e054212009-07-21 17:05:03 +0000430 if ((Tok.is(tok::identifier) ||
431 (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier))) &&
432 mayHaveIdentifier) {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000433 // declarator-id
Argyrios Kyrtzidis1e054212009-07-21 17:05:03 +0000434 if (Tok.is(tok::annot_cxxscope))
435 ConsumeToken();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000436 ConsumeToken();
437 } else if (Tok.is(tok::l_paren)) {
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000438 ConsumeParen();
439 if (mayBeAbstract &&
440 (Tok.is(tok::r_paren) || // 'int()' is a function.
441 Tok.is(tok::ellipsis) || // 'int(...)' is a function.
442 isDeclarationSpecifier())) { // 'int(int)' is a function.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000443 // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
444 // exception-specification[opt]
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000445 TPResult TPR = TryParseFunctionDeclarator();
446 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000447 return TPR;
448 } else {
449 // '(' declarator ')'
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000450 // '(' attributes declarator ')'
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000451 // '(' abstract-declarator ')'
Argyrios Kyrtzidis1ee2c432008-10-05 14:27:18 +0000452 if (Tok.is(tok::kw___attribute))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000453 return TPResult::True(); // attributes indicate declaration
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +0000454 TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier);
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000455 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000456 return TPR;
457 if (Tok.isNot(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000458 return TPResult::False();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000459 ConsumeParen();
460 }
461 } else if (!mayBeAbstract) {
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000462 return TPResult::False();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000463 }
464
465 while (1) {
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000466 TPResult TPR(TPResult::Ambiguous());
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000467
468 if (Tok.is(tok::l_paren)) {
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000469 // Check whether we have a function declarator or a possible ctor-style
470 // initializer that follows the declarator. Note that ctor-style
471 // initializers are not possible in contexts where abstract declarators
472 // are allowed.
Argyrios Kyrtzidise75d8492008-10-17 23:23:35 +0000473 if (!mayBeAbstract && !isCXXFunctionDeclarator(false/*warnIfAmbiguous*/))
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000474 break;
475
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000476 // direct-declarator '(' parameter-declaration-clause ')'
477 // cv-qualifier-seq[opt] exception-specification[opt]
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000478 ConsumeParen();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000479 TPR = TryParseFunctionDeclarator();
480 } else if (Tok.is(tok::l_square)) {
481 // direct-declarator '[' constant-expression[opt] ']'
482 // direct-abstract-declarator[opt] '[' constant-expression[opt] ']'
483 TPR = TryParseBracketDeclarator();
484 } else {
485 break;
486 }
487
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000488 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000489 return TPR;
490 }
491
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000492 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000493}
494
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000495/// isCXXDeclarationSpecifier - Returns TPResult::True() if it is a declaration
496/// specifier, TPResult::False() if it is not, TPResult::Ambiguous() if it could
497/// be either a decl-specifier or a function-style cast, and TPResult::Error()
498/// if a parsing error was found and reported.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000499///
500/// decl-specifier:
501/// storage-class-specifier
502/// type-specifier
503/// function-specifier
504/// 'friend'
505/// 'typedef'
506/// [GNU] attributes declaration-specifiers[opt]
507///
508/// storage-class-specifier:
509/// 'register'
510/// 'static'
511/// 'extern'
512/// 'mutable'
513/// 'auto'
514/// [GNU] '__thread'
515///
516/// function-specifier:
517/// 'inline'
518/// 'virtual'
519/// 'explicit'
520///
521/// typedef-name:
522/// identifier
523///
524/// type-specifier:
525/// simple-type-specifier
526/// class-specifier
527/// enum-specifier
528/// elaborated-type-specifier
Douglas Gregord57959a2009-03-27 23:10:48 +0000529/// typename-specifier
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000530/// cv-qualifier
531///
532/// simple-type-specifier:
Douglas Gregord57959a2009-03-27 23:10:48 +0000533/// '::'[opt] nested-name-specifier[opt] type-name
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000534/// '::'[opt] nested-name-specifier 'template'
535/// simple-template-id [TODO]
536/// 'char'
537/// 'wchar_t'
538/// 'bool'
539/// 'short'
540/// 'int'
541/// 'long'
542/// 'signed'
543/// 'unsigned'
544/// 'float'
545/// 'double'
546/// 'void'
547/// [GNU] typeof-specifier
548/// [GNU] '_Complex'
549/// [C++0x] 'auto' [TODO]
Anders Carlsson6fd634f2009-06-24 17:47:40 +0000550/// [C++0x] 'decltype' ( expression )
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000551///
552/// type-name:
553/// class-name
554/// enum-name
555/// typedef-name
556///
557/// elaborated-type-specifier:
558/// class-key '::'[opt] nested-name-specifier[opt] identifier
559/// class-key '::'[opt] nested-name-specifier[opt] 'template'[opt]
560/// simple-template-id
561/// 'enum' '::'[opt] nested-name-specifier[opt] identifier
562///
563/// enum-name:
564/// identifier
565///
566/// enum-specifier:
567/// 'enum' identifier[opt] '{' enumerator-list[opt] '}'
568/// 'enum' identifier[opt] '{' enumerator-list ',' '}'
569///
570/// class-specifier:
571/// class-head '{' member-specification[opt] '}'
572///
573/// class-head:
574/// class-key identifier[opt] base-clause[opt]
575/// class-key nested-name-specifier identifier base-clause[opt]
576/// class-key nested-name-specifier[opt] simple-template-id
577/// base-clause[opt]
578///
579/// class-key:
580/// 'class'
581/// 'struct'
582/// 'union'
583///
584/// cv-qualifier:
585/// 'const'
586/// 'volatile'
587/// [GNU] restrict
588///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000589Parser::TPResult Parser::isCXXDeclarationSpecifier() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000590 switch (Tok.getKind()) {
Chris Lattnere5849262009-01-04 23:33:56 +0000591 case tok::identifier: // foo::bar
Douglas Gregord57959a2009-03-27 23:10:48 +0000592 case tok::kw_typename: // typename T::type
Chris Lattnere5849262009-01-04 23:33:56 +0000593 // Annotate typenames and C++ scope specifiers. If we get one, just
594 // recurse to handle whatever we get.
595 if (TryAnnotateTypeOrScopeToken())
596 return isCXXDeclarationSpecifier();
597 // Otherwise, not a typename.
598 return TPResult::False();
599
600 case tok::coloncolon: // ::foo::bar
601 if (NextToken().is(tok::kw_new) || // ::new
602 NextToken().is(tok::kw_delete)) // ::delete
603 return TPResult::False();
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Chris Lattnere5849262009-01-04 23:33:56 +0000605 // Annotate typenames and C++ scope specifiers. If we get one, just
606 // recurse to handle whatever we get.
607 if (TryAnnotateTypeOrScopeToken())
608 return isCXXDeclarationSpecifier();
609 // Otherwise, not a typename.
610 return TPResult::False();
Mike Stump1eb44332009-09-09 15:08:12 +0000611
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000612 // decl-specifier:
613 // storage-class-specifier
614 // type-specifier
615 // function-specifier
616 // 'friend'
617 // 'typedef'
618
619 case tok::kw_friend:
620 case tok::kw_typedef:
621 // storage-class-specifier
622 case tok::kw_register:
623 case tok::kw_static:
624 case tok::kw_extern:
625 case tok::kw_mutable:
626 case tok::kw_auto:
627 case tok::kw___thread:
628 // function-specifier
629 case tok::kw_inline:
630 case tok::kw_virtual:
631 case tok::kw_explicit:
632
633 // type-specifier:
634 // simple-type-specifier
635 // class-specifier
636 // enum-specifier
637 // elaborated-type-specifier
638 // typename-specifier
639 // cv-qualifier
640
641 // class-specifier
642 // elaborated-type-specifier
643 case tok::kw_class:
644 case tok::kw_struct:
645 case tok::kw_union:
646 // enum-specifier
647 case tok::kw_enum:
648 // cv-qualifier
649 case tok::kw_const:
650 case tok::kw_volatile:
651
652 // GNU
653 case tok::kw_restrict:
654 case tok::kw__Complex:
655 case tok::kw___attribute:
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000656 return TPResult::True();
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Steve Naroff7ec56582009-01-06 17:40:00 +0000658 // Microsoft
Steve Naroff47f52092009-01-06 19:34:12 +0000659 case tok::kw___declspec:
Steve Naroff7ec56582009-01-06 17:40:00 +0000660 case tok::kw___cdecl:
661 case tok::kw___stdcall:
662 case tok::kw___fastcall:
Eli Friedman290eeb02009-06-08 23:27:34 +0000663 case tok::kw___w64:
664 case tok::kw___ptr64:
665 case tok::kw___forceinline:
666 return TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000667
668 // The ambiguity resides in a simple-type-specifier/typename-specifier
669 // followed by a '('. The '(' could either be the start of:
670 //
671 // direct-declarator:
672 // '(' declarator ')'
673 //
674 // direct-abstract-declarator:
675 // '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
676 // exception-specification[opt]
677 // '(' abstract-declarator ')'
678 //
679 // or part of a function-style cast expression:
680 //
681 // simple-type-specifier '(' expression-list[opt] ')'
682 //
683
684 // simple-type-specifier:
685
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000686 case tok::kw_char:
687 case tok::kw_wchar_t:
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000688 case tok::kw_char16_t:
689 case tok::kw_char32_t:
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000690 case tok::kw_bool:
691 case tok::kw_short:
692 case tok::kw_int:
693 case tok::kw_long:
694 case tok::kw_signed:
695 case tok::kw_unsigned:
696 case tok::kw_float:
697 case tok::kw_double:
698 case tok::kw_void:
Chris Lattnerb31757b2009-01-06 05:06:21 +0000699 case tok::annot_typename:
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000700 if (NextToken().is(tok::l_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000701 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000702
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000703 return TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000704
Anders Carlsson6fd634f2009-06-24 17:47:40 +0000705 // GNU typeof support.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000706 case tok::kw_typeof: {
707 if (NextToken().isNot(tok::l_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000708 return TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000709
710 TentativeParsingAction PA(*this);
711
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000712 TPResult TPR = TryParseTypeofSpecifier();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000713 bool isFollowedByParen = Tok.is(tok::l_paren);
714
715 PA.Revert();
716
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000717 if (TPR == TPResult::Error())
718 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000719
720 if (isFollowedByParen)
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000721 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000722
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000723 return TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000724 }
725
Anders Carlsson6fd634f2009-06-24 17:47:40 +0000726 // C++0x decltype support.
727 case tok::kw_decltype:
728 return TPResult::True();
729
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000730 default:
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000731 return TPResult::False();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000732 }
733}
734
735/// [GNU] typeof-specifier:
736/// 'typeof' '(' expressions ')'
737/// 'typeof' '(' type-name ')'
738///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000739Parser::TPResult Parser::TryParseTypeofSpecifier() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000740 assert(Tok.is(tok::kw_typeof) && "Expected 'typeof'!");
741 ConsumeToken();
742
743 assert(Tok.is(tok::l_paren) && "Expected '('");
744 // Parse through the parens after 'typeof'.
745 ConsumeParen();
746 if (!SkipUntil(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000747 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000748
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000749 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000750}
751
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000752Parser::TPResult Parser::TryParseDeclarationSpecifier() {
753 TPResult TPR = isCXXDeclarationSpecifier();
754 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000755 return TPR;
756
757 if (Tok.is(tok::kw_typeof))
758 TryParseTypeofSpecifier();
759 else
760 ConsumeToken();
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000762 assert(Tok.is(tok::l_paren) && "Expected '('!");
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000763 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000764}
765
766/// isCXXFunctionDeclarator - Disambiguates between a function declarator or
767/// a constructor-style initializer, when parsing declaration statements.
768/// Returns true for function declarator and false for constructor-style
769/// initializer.
770/// If during the disambiguation process a parsing error is encountered,
771/// the function returns true to let the declaration parsing code handle it.
772///
773/// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
774/// exception-specification[opt]
775///
Argyrios Kyrtzidise75d8492008-10-17 23:23:35 +0000776bool Parser::isCXXFunctionDeclarator(bool warnIfAmbiguous) {
Argyrios Kyrtzidisd3dbbb62008-10-05 21:10:08 +0000777
778 // C++ 8.2p1:
779 // The ambiguity arising from the similarity between a function-style cast and
780 // a declaration mentioned in 6.8 can also occur in the context of a
781 // declaration. In that context, the choice is between a function declaration
782 // with a redundant set of parentheses around a parameter name and an object
783 // declaration with a function-style cast as the initializer. Just as for the
784 // ambiguities mentioned in 6.8, the resolution is to consider any construct
785 // that could possibly be a declaration a declaration.
786
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000787 TentativeParsingAction PA(*this);
788
789 ConsumeParen();
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000790 TPResult TPR = TryParseParameterDeclarationClause();
791 if (TPR == TPResult::Ambiguous() && Tok.isNot(tok::r_paren))
792 TPR = TPResult::False();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000793
Argyrios Kyrtzidis259b0d92008-10-15 23:21:32 +0000794 SourceLocation TPLoc = Tok.getLocation();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000795 PA.Revert();
796
797 // In case of an error, let the declaration parsing code handle it.
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000798 if (TPR == TPResult::Error())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000799 return true;
800
Argyrios Kyrtzidis259b0d92008-10-15 23:21:32 +0000801 if (TPR == TPResult::Ambiguous()) {
802 // Function declarator has precedence over constructor-style initializer.
803 // Emit a warning just in case the author intended a variable definition.
Argyrios Kyrtzidise75d8492008-10-17 23:23:35 +0000804 if (warnIfAmbiguous)
Chris Lattneref708fd2008-11-18 07:50:21 +0000805 Diag(Tok, diag::warn_parens_disambiguated_as_function_decl)
806 << SourceRange(Tok.getLocation(), TPLoc);
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000807 return true;
Argyrios Kyrtzidis259b0d92008-10-15 23:21:32 +0000808 }
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000809
810 return TPR == TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000811}
812
813/// parameter-declaration-clause:
814/// parameter-declaration-list[opt] '...'[opt]
815/// parameter-declaration-list ',' '...'
816///
817/// parameter-declaration-list:
818/// parameter-declaration
819/// parameter-declaration-list ',' parameter-declaration
820///
821/// parameter-declaration:
822/// decl-specifier-seq declarator
823/// decl-specifier-seq declarator '=' assignment-expression
824/// decl-specifier-seq abstract-declarator[opt]
825/// decl-specifier-seq abstract-declarator[opt] '=' assignment-expression
826///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000827Parser::TPResult Parser::TryParseParameterDeclarationClause() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000828
829 if (Tok.is(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000830 return TPResult::True();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000831
832 // parameter-declaration-list[opt] '...'[opt]
833 // parameter-declaration-list ',' '...'
834 //
835 // parameter-declaration-list:
836 // parameter-declaration
837 // parameter-declaration-list ',' parameter-declaration
838 //
839 while (1) {
840 // '...'[opt]
841 if (Tok.is(tok::ellipsis)) {
842 ConsumeToken();
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000843 return TPResult::True(); // '...' is a sign of a function declarator.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000844 }
845
846 // decl-specifier-seq
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000847 TPResult TPR = TryParseDeclarationSpecifier();
848 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000849 return TPR;
850
851 // declarator
852 // abstract-declarator[opt]
853 TPR = TryParseDeclarator(true/*mayBeAbstract*/);
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000854 if (TPR != TPResult::Ambiguous())
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000855 return TPR;
856
857 if (Tok.is(tok::equal)) {
858 // '=' assignment-expression
859 // Parse through assignment-expression.
860 tok::TokenKind StopToks[3] ={ tok::comma, tok::ellipsis, tok::r_paren };
861 if (!SkipUntil(StopToks, 3, true/*StopAtSemi*/, true/*DontConsume*/))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000862 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000863 }
864
865 if (Tok.is(tok::ellipsis)) {
866 ConsumeToken();
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000867 return TPResult::True(); // '...' is a sign of a function declarator.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000868 }
869
870 if (Tok.isNot(tok::comma))
871 break;
872 ConsumeToken(); // the comma.
873 }
874
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000875 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000876}
877
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000878/// TryParseFunctionDeclarator - We parsed a '(' and we want to try to continue
879/// parsing as a function declarator.
880/// If TryParseFunctionDeclarator fully parsed the function declarator, it will
881/// return TPResult::Ambiguous(), otherwise it will return either False() or
882/// Error().
Mike Stump1eb44332009-09-09 15:08:12 +0000883///
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000884/// '(' parameter-declaration-clause ')' cv-qualifier-seq[opt]
885/// exception-specification[opt]
886///
887/// exception-specification:
888/// 'throw' '(' type-id-list[opt] ')'
889///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000890Parser::TPResult Parser::TryParseFunctionDeclarator() {
Argyrios Kyrtzidisd3616a82008-10-05 23:15:41 +0000891
892 // The '(' is already parsed.
893
894 TPResult TPR = TryParseParameterDeclarationClause();
895 if (TPR == TPResult::Ambiguous() && Tok.isNot(tok::r_paren))
896 TPR = TPResult::False();
897
898 if (TPR == TPResult::False() || TPR == TPResult::Error())
899 return TPR;
900
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000901 // Parse through the parens.
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000902 if (!SkipUntil(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000903 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000904
905 // cv-qualifier-seq
906 while (Tok.is(tok::kw_const) ||
907 Tok.is(tok::kw_volatile) ||
908 Tok.is(tok::kw_restrict) )
909 ConsumeToken();
910
911 // exception-specification
912 if (Tok.is(tok::kw_throw)) {
913 ConsumeToken();
914 if (Tok.isNot(tok::l_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000915 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000916
917 // Parse through the parens after 'throw'.
918 ConsumeParen();
919 if (!SkipUntil(tok::r_paren))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000920 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000921 }
922
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000923 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000924}
925
926/// '[' constant-expression[opt] ']'
927///
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000928Parser::TPResult Parser::TryParseBracketDeclarator() {
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000929 ConsumeBracket();
930 if (!SkipUntil(tok::r_square))
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000931 return TPResult::Error();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000932
Argyrios Kyrtzidisb9f34192008-10-05 18:52:21 +0000933 return TPResult::Ambiguous();
Argyrios Kyrtzidis5404a152008-10-05 00:06:24 +0000934}