blob: 00e441412f42526bc805e0bc3b7c5a07cff81cb6 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- ParseDecl.cpp - Declaration Parsing ------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Declaration portions of the Parser interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
15#include "clang/Parse/DeclSpec.h"
Chris Lattnera7549902007-08-26 06:24:45 +000016#include "clang/Parse/Scope.h"
Chris Lattner4b009652007-07-25 00:24:17 +000017#include "llvm/ADT/SmallSet.h"
18using namespace clang;
19
20//===----------------------------------------------------------------------===//
21// C99 6.7: Declarations.
22//===----------------------------------------------------------------------===//
23
24/// ParseTypeName
25/// type-name: [C99 6.7.6]
26/// specifier-qualifier-list abstract-declarator[opt]
27Parser::TypeTy *Parser::ParseTypeName() {
28 // Parse the common declaration-specifiers piece.
29 DeclSpec DS;
30 ParseSpecifierQualifierList(DS);
31
32 // Parse the abstract-declarator, if present.
33 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
34 ParseDeclarator(DeclaratorInfo);
35
Steve Naroff0acc9c92007-09-15 18:49:24 +000036 return Actions.ActOnTypeName(CurScope, DeclaratorInfo).Val;
Chris Lattner4b009652007-07-25 00:24:17 +000037}
38
39/// ParseAttributes - Parse a non-empty attributes list.
40///
41/// [GNU] attributes:
42/// attribute
43/// attributes attribute
44///
45/// [GNU] attribute:
46/// '__attribute__' '(' '(' attribute-list ')' ')'
47///
48/// [GNU] attribute-list:
49/// attrib
50/// attribute_list ',' attrib
51///
52/// [GNU] attrib:
53/// empty
54/// attrib-name
55/// attrib-name '(' identifier ')'
56/// attrib-name '(' identifier ',' nonempty-expr-list ')'
57/// attrib-name '(' argument-expression-list [C99 6.5.2] ')'
58///
59/// [GNU] attrib-name:
60/// identifier
61/// typespec
62/// typequal
63/// storageclass
64///
65/// FIXME: The GCC grammar/code for this construct implies we need two
66/// token lookahead. Comment from gcc: "If they start with an identifier
67/// which is followed by a comma or close parenthesis, then the arguments
68/// start with that identifier; otherwise they are an expression list."
69///
70/// At the moment, I am not doing 2 token lookahead. I am also unaware of
71/// any attributes that don't work (based on my limited testing). Most
72/// attributes are very simple in practice. Until we find a bug, I don't see
73/// a pressing need to implement the 2 token lookahead.
74
75AttributeList *Parser::ParseAttributes() {
Chris Lattner34a01ad2007-10-09 17:33:22 +000076 assert(Tok.is(tok::kw___attribute) && "Not an attribute list!");
Chris Lattner4b009652007-07-25 00:24:17 +000077
78 AttributeList *CurrAttr = 0;
79
Chris Lattner34a01ad2007-10-09 17:33:22 +000080 while (Tok.is(tok::kw___attribute)) {
Chris Lattner4b009652007-07-25 00:24:17 +000081 ConsumeToken();
82 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
83 "attribute")) {
84 SkipUntil(tok::r_paren, true); // skip until ) or ;
85 return CurrAttr;
86 }
87 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "(")) {
88 SkipUntil(tok::r_paren, true); // skip until ) or ;
89 return CurrAttr;
90 }
91 // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
Chris Lattner34a01ad2007-10-09 17:33:22 +000092 while (Tok.is(tok::identifier) || isDeclarationSpecifier() ||
93 Tok.is(tok::comma)) {
Chris Lattner4b009652007-07-25 00:24:17 +000094
Chris Lattner34a01ad2007-10-09 17:33:22 +000095 if (Tok.is(tok::comma)) {
Chris Lattner4b009652007-07-25 00:24:17 +000096 // allows for empty/non-empty attributes. ((__vector_size__(16),,,,))
97 ConsumeToken();
98 continue;
99 }
100 // we have an identifier or declaration specifier (const, int, etc.)
101 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
102 SourceLocation AttrNameLoc = ConsumeToken();
103
104 // check if we have a "paramterized" attribute
Chris Lattner34a01ad2007-10-09 17:33:22 +0000105 if (Tok.is(tok::l_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000106 ConsumeParen(); // ignore the left paren loc for now
107
Chris Lattner34a01ad2007-10-09 17:33:22 +0000108 if (Tok.is(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000109 IdentifierInfo *ParmName = Tok.getIdentifierInfo();
110 SourceLocation ParmLoc = ConsumeToken();
111
Chris Lattner34a01ad2007-10-09 17:33:22 +0000112 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000113 // __attribute__(( mode(byte) ))
114 ConsumeParen(); // ignore the right paren loc for now
115 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
116 ParmName, ParmLoc, 0, 0, CurrAttr);
Chris Lattner34a01ad2007-10-09 17:33:22 +0000117 } else if (Tok.is(tok::comma)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000118 ConsumeToken();
119 // __attribute__(( format(printf, 1, 2) ))
120 llvm::SmallVector<ExprTy*, 8> ArgExprs;
121 bool ArgExprsOk = true;
122
123 // now parse the non-empty comma separated list of expressions
124 while (1) {
125 ExprResult ArgExpr = ParseAssignmentExpression();
126 if (ArgExpr.isInvalid) {
127 ArgExprsOk = false;
128 SkipUntil(tok::r_paren);
129 break;
130 } else {
131 ArgExprs.push_back(ArgExpr.Val);
132 }
Chris Lattner34a01ad2007-10-09 17:33:22 +0000133 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +0000134 break;
135 ConsumeToken(); // Eat the comma, move to the next argument
136 }
Chris Lattner34a01ad2007-10-09 17:33:22 +0000137 if (ArgExprsOk && Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000138 ConsumeParen(); // ignore the right paren loc for now
139 CurrAttr = new AttributeList(AttrName, AttrNameLoc, ParmName,
140 ParmLoc, &ArgExprs[0], ArgExprs.size(), CurrAttr);
141 }
142 }
143 } else { // not an identifier
144 // parse a possibly empty comma separated list of expressions
Chris Lattner34a01ad2007-10-09 17:33:22 +0000145 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000146 // __attribute__(( nonnull() ))
147 ConsumeParen(); // ignore the right paren loc for now
148 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
149 0, SourceLocation(), 0, 0, CurrAttr);
150 } else {
151 // __attribute__(( aligned(16) ))
152 llvm::SmallVector<ExprTy*, 8> ArgExprs;
153 bool ArgExprsOk = true;
154
155 // now parse the list of expressions
156 while (1) {
157 ExprResult ArgExpr = ParseAssignmentExpression();
158 if (ArgExpr.isInvalid) {
159 ArgExprsOk = false;
160 SkipUntil(tok::r_paren);
161 break;
162 } else {
163 ArgExprs.push_back(ArgExpr.Val);
164 }
Chris Lattner34a01ad2007-10-09 17:33:22 +0000165 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +0000166 break;
167 ConsumeToken(); // Eat the comma, move to the next argument
168 }
169 // Match the ')'.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000170 if (ArgExprsOk && Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000171 ConsumeParen(); // ignore the right paren loc for now
172 CurrAttr = new AttributeList(AttrName, AttrNameLoc, 0,
173 SourceLocation(), &ArgExprs[0], ArgExprs.size(),
174 CurrAttr);
175 }
176 }
177 }
178 } else {
179 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
180 0, SourceLocation(), 0, 0, CurrAttr);
181 }
182 }
183 if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
184 SkipUntil(tok::r_paren, false);
185 if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
186 SkipUntil(tok::r_paren, false);
187 }
188 return CurrAttr;
189}
190
191/// ParseDeclaration - Parse a full 'declaration', which consists of
192/// declaration-specifiers, some number of declarators, and a semicolon.
193/// 'Context' should be a Declarator::TheContext value.
Chris Lattnerf7b2e552007-08-25 06:57:03 +0000194///
195/// declaration: [C99 6.7]
196/// block-declaration ->
197/// simple-declaration
198/// others [FIXME]
199/// [C++] namespace-definition
200/// others... [FIXME]
201///
Chris Lattner4b009652007-07-25 00:24:17 +0000202Parser::DeclTy *Parser::ParseDeclaration(unsigned Context) {
Chris Lattnerf7b2e552007-08-25 06:57:03 +0000203 switch (Tok.getKind()) {
204 case tok::kw_namespace:
205 return ParseNamespace(Context);
206 default:
207 return ParseSimpleDeclaration(Context);
208 }
209}
210
211/// simple-declaration: [C99 6.7: declaration] [C++ 7p1: dcl.dcl]
212/// declaration-specifiers init-declarator-list[opt] ';'
213///[C90/C++]init-declarator-list ';' [TODO]
214/// [OMP] threadprivate-directive [TODO]
215Parser::DeclTy *Parser::ParseSimpleDeclaration(unsigned Context) {
Chris Lattner4b009652007-07-25 00:24:17 +0000216 // Parse the common declaration-specifiers piece.
217 DeclSpec DS;
218 ParseDeclarationSpecifiers(DS);
219
220 // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
221 // declaration-specifiers init-declarator-list[opt] ';'
Chris Lattner34a01ad2007-10-09 17:33:22 +0000222 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000223 ConsumeToken();
224 return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
225 }
226
227 Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context);
228 ParseDeclarator(DeclaratorInfo);
229
230 return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
231}
232
Chris Lattnerf7b2e552007-08-25 06:57:03 +0000233
Chris Lattner4b009652007-07-25 00:24:17 +0000234/// ParseInitDeclaratorListAfterFirstDeclarator - Parse 'declaration' after
235/// parsing 'declaration-specifiers declarator'. This method is split out this
236/// way to handle the ambiguity between top-level function-definitions and
237/// declarations.
238///
Chris Lattner4b009652007-07-25 00:24:17 +0000239/// init-declarator-list: [C99 6.7]
240/// init-declarator
241/// init-declarator-list ',' init-declarator
242/// init-declarator: [C99 6.7]
243/// declarator
244/// declarator '=' initializer
245/// [GNU] declarator simple-asm-expr[opt] attributes[opt]
246/// [GNU] declarator simple-asm-expr[opt] attributes[opt] '=' initializer
247///
248Parser::DeclTy *Parser::
249ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
250
251 // Declarators may be grouped together ("int X, *Y, Z();"). Provide info so
252 // that they can be chained properly if the actions want this.
253 Parser::DeclTy *LastDeclInGroup = 0;
254
255 // At this point, we know that it is not a function definition. Parse the
256 // rest of the init-declarator-list.
257 while (1) {
258 // If a simple-asm-expr is present, parse it.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000259 if (Tok.is(tok::kw_asm))
Chris Lattner4b009652007-07-25 00:24:17 +0000260 ParseSimpleAsm();
261
262 // If attributes are present, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000263 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000264 D.AddAttributes(ParseAttributes());
Steve Naroff6a0e2092007-09-12 14:07:44 +0000265
266 // Inform the current actions module that we just parsed this declarator.
267 // FIXME: pass asm & attributes.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000268 LastDeclInGroup = Actions.ActOnDeclarator(CurScope, D, LastDeclInGroup);
Steve Naroff6a0e2092007-09-12 14:07:44 +0000269
Chris Lattner4b009652007-07-25 00:24:17 +0000270 // Parse declarator '=' initializer.
271 ExprResult Init;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000272 if (Tok.is(tok::equal)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000273 ConsumeToken();
274 Init = ParseInitializer();
275 if (Init.isInvalid) {
276 SkipUntil(tok::semi);
277 return 0;
278 }
Steve Naroff6a0e2092007-09-12 14:07:44 +0000279 Actions.AddInitializerToDecl(LastDeclInGroup, Init.Val);
Chris Lattner4b009652007-07-25 00:24:17 +0000280 }
281
Chris Lattner4b009652007-07-25 00:24:17 +0000282 // If we don't have a comma, it is either the end of the list (a ';') or an
283 // error, bail out.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000284 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +0000285 break;
286
287 // Consume the comma.
288 ConsumeToken();
289
290 // Parse the next declarator.
291 D.clear();
292 ParseDeclarator(D);
293 }
294
Chris Lattner34a01ad2007-10-09 17:33:22 +0000295 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000296 ConsumeToken();
297 return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
298 }
299
300 Diag(Tok, diag::err_parse_error);
301 // Skip to end of block or statement
Chris Lattnerf491b412007-08-21 18:36:18 +0000302 SkipUntil(tok::r_brace, true, true);
Chris Lattner34a01ad2007-10-09 17:33:22 +0000303 if (Tok.is(tok::semi))
Chris Lattner4b009652007-07-25 00:24:17 +0000304 ConsumeToken();
305 return 0;
306}
307
308/// ParseSpecifierQualifierList
309/// specifier-qualifier-list:
310/// type-specifier specifier-qualifier-list[opt]
311/// type-qualifier specifier-qualifier-list[opt]
312/// [GNU] attributes specifier-qualifier-list[opt]
313///
314void Parser::ParseSpecifierQualifierList(DeclSpec &DS) {
315 /// specifier-qualifier-list is a subset of declaration-specifiers. Just
316 /// parse declaration-specifiers and complain about extra stuff.
317 ParseDeclarationSpecifiers(DS);
318
319 // Validate declspec for type-name.
320 unsigned Specs = DS.getParsedSpecifiers();
321 if (Specs == DeclSpec::PQ_None)
322 Diag(Tok, diag::err_typename_requires_specqual);
323
324 // Issue diagnostic and remove storage class if present.
325 if (Specs & DeclSpec::PQ_StorageClassSpecifier) {
326 if (DS.getStorageClassSpecLoc().isValid())
327 Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass);
328 else
329 Diag(DS.getThreadSpecLoc(), diag::err_typename_invalid_storageclass);
330 DS.ClearStorageClassSpecs();
331 }
332
333 // Issue diagnostic and remove function specfier if present.
334 if (Specs & DeclSpec::PQ_FunctionSpecifier) {
335 Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec);
336 DS.ClearFunctionSpecs();
337 }
338}
339
340/// ParseDeclarationSpecifiers
341/// declaration-specifiers: [C99 6.7]
342/// storage-class-specifier declaration-specifiers[opt]
343/// type-specifier declaration-specifiers[opt]
344/// type-qualifier declaration-specifiers[opt]
345/// [C99] function-specifier declaration-specifiers[opt]
346/// [GNU] attributes declaration-specifiers[opt]
347///
348/// storage-class-specifier: [C99 6.7.1]
349/// 'typedef'
350/// 'extern'
351/// 'static'
352/// 'auto'
353/// 'register'
354/// [GNU] '__thread'
355/// type-specifier: [C99 6.7.2]
356/// 'void'
357/// 'char'
358/// 'short'
359/// 'int'
360/// 'long'
361/// 'float'
362/// 'double'
363/// 'signed'
364/// 'unsigned'
365/// struct-or-union-specifier
366/// enum-specifier
367/// typedef-name
368/// [C++] 'bool'
369/// [C99] '_Bool'
370/// [C99] '_Complex'
371/// [C99] '_Imaginary' // Removed in TC2?
372/// [GNU] '_Decimal32'
373/// [GNU] '_Decimal64'
374/// [GNU] '_Decimal128'
Steve Naroff4c255ab2007-07-31 23:56:32 +0000375/// [GNU] typeof-specifier
Chris Lattner4b009652007-07-25 00:24:17 +0000376/// [OBJC] class-name objc-protocol-refs[opt] [TODO]
Steve Naroffa8ee2262007-08-22 23:18:22 +0000377/// [OBJC] typedef-name objc-protocol-refs[opt] [TODO]
Chris Lattner4b009652007-07-25 00:24:17 +0000378/// type-qualifier:
379/// 'const'
380/// 'volatile'
381/// [C99] 'restrict'
382/// function-specifier: [C99 6.7.4]
383/// [C99] 'inline'
384///
385void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) {
386 DS.Range.setBegin(Tok.getLocation());
387 while (1) {
388 int isInvalid = false;
389 const char *PrevSpec = 0;
390 SourceLocation Loc = Tok.getLocation();
391
392 switch (Tok.getKind()) {
393 // typedef-name
394 case tok::identifier:
395 // This identifier can only be a typedef name if we haven't already seen
396 // a type-specifier. Without this check we misparse:
397 // typedef int X; struct Y { short X; }; as 'short int'.
398 if (!DS.hasTypeSpecifier()) {
399 // It has to be available as a typedef too!
400 if (void *TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(),
401 CurScope)) {
402 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typedef, Loc, PrevSpec,
403 TypeRep);
Steve Naroffa8ee2262007-08-22 23:18:22 +0000404 if (isInvalid)
405 break;
406 else { // FIXME: restrict this to "id" and ObjC classnames.
407 DS.Range.setEnd(Tok.getLocation());
408 ConsumeToken(); // The identifier
Chris Lattner34a01ad2007-10-09 17:33:22 +0000409 if (Tok.is(tok::less)) {
Steve Naroff304ed392007-09-05 23:30:30 +0000410 llvm::SmallVector<IdentifierInfo *, 8> ProtocolRefs;
411 ParseObjCProtocolReferences(ProtocolRefs);
Steve Naroff415c1832007-10-10 17:32:04 +0000412 Actions.ActOnFindProtocolDeclaration(Loc,
Fariborz Jahaniana096e1d2007-10-05 21:01:53 +0000413 &ProtocolRefs[0],
414 ProtocolRefs.size());
Steve Naroff304ed392007-09-05 23:30:30 +0000415 }
Steve Naroffa8ee2262007-08-22 23:18:22 +0000416 continue;
417 }
Chris Lattner4b009652007-07-25 00:24:17 +0000418 }
419 }
420 // FALL THROUGH.
421 default:
422 // If this is not a declaration specifier token, we're done reading decl
423 // specifiers. First verify that DeclSpec's are consistent.
424 DS.Finish(Diags, getLang());
425 return;
426
427 // GNU attributes support.
428 case tok::kw___attribute:
429 DS.AddAttributes(ParseAttributes());
430 continue;
431
432 // storage-class-specifier
433 case tok::kw_typedef:
434 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec);
435 break;
436 case tok::kw_extern:
437 if (DS.isThreadSpecified())
438 Diag(Tok, diag::ext_thread_before, "extern");
439 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec);
440 break;
441 case tok::kw_static:
442 if (DS.isThreadSpecified())
443 Diag(Tok, diag::ext_thread_before, "static");
444 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec);
445 break;
446 case tok::kw_auto:
447 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec);
448 break;
449 case tok::kw_register:
450 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
451 break;
452 case tok::kw___thread:
453 isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec)*2;
454 break;
455
456 // type-specifiers
457 case tok::kw_short:
458 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec);
459 break;
460 case tok::kw_long:
461 if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
462 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec);
463 else
464 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec);
465 break;
466 case tok::kw_signed:
467 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec);
468 break;
469 case tok::kw_unsigned:
470 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec);
471 break;
472 case tok::kw__Complex:
473 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec);
474 break;
475 case tok::kw__Imaginary:
476 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec);
477 break;
478 case tok::kw_void:
479 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec);
480 break;
481 case tok::kw_char:
482 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec);
483 break;
484 case tok::kw_int:
485 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec);
486 break;
487 case tok::kw_float:
488 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec);
489 break;
490 case tok::kw_double:
491 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
492 break;
493 case tok::kw_bool: // [C++ 2.11p1]
494 case tok::kw__Bool:
495 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
496 break;
497 case tok::kw__Decimal32:
498 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec);
499 break;
500 case tok::kw__Decimal64:
501 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec);
502 break;
503 case tok::kw__Decimal128:
504 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec);
505 break;
506
507 case tok::kw_struct:
508 case tok::kw_union:
509 ParseStructUnionSpecifier(DS);
510 continue;
511 case tok::kw_enum:
512 ParseEnumSpecifier(DS);
513 continue;
514
Steve Naroff7cbb1462007-07-31 12:34:36 +0000515 // GNU typeof support.
516 case tok::kw_typeof:
517 ParseTypeofSpecifier(DS);
518 continue;
519
Chris Lattner4b009652007-07-25 00:24:17 +0000520 // type-qualifier
521 case tok::kw_const:
522 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
523 getLang())*2;
524 break;
525 case tok::kw_volatile:
526 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
527 getLang())*2;
528 break;
529 case tok::kw_restrict:
530 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
531 getLang())*2;
532 break;
533
534 // function-specifier
535 case tok::kw_inline:
536 isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec);
537 break;
538 }
539 // If the specifier combination wasn't legal, issue a diagnostic.
540 if (isInvalid) {
541 assert(PrevSpec && "Method did not return previous specifier!");
542 if (isInvalid == 1) // Error.
543 Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec);
544 else // extwarn.
545 Diag(Tok, diag::ext_duplicate_declspec, PrevSpec);
546 }
547 DS.Range.setEnd(Tok.getLocation());
548 ConsumeToken();
549 }
550}
551
552/// ParseTag - Parse "struct-or-union-or-class-or-enum identifier[opt]", where
553/// the first token has already been read and has been turned into an instance
554/// of DeclSpec::TST (TagType). This returns true if there is an error parsing,
555/// otherwise it returns false and fills in Decl.
556bool Parser::ParseTag(DeclTy *&Decl, unsigned TagType, SourceLocation StartLoc){
557 AttributeList *Attr = 0;
558 // If attributes exist after tag, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000559 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000560 Attr = ParseAttributes();
561
562 // Must have either 'struct name' or 'struct {...}'.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000563 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000564 Diag(Tok, diag::err_expected_ident_lbrace);
565
566 // Skip the rest of this declarator, up until the comma or semicolon.
567 SkipUntil(tok::comma, true);
568 return true;
569 }
570
571 // If an identifier is present, consume and remember it.
572 IdentifierInfo *Name = 0;
573 SourceLocation NameLoc;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000574 if (Tok.is(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000575 Name = Tok.getIdentifierInfo();
576 NameLoc = ConsumeToken();
577 }
578
579 // There are three options here. If we have 'struct foo;', then this is a
580 // forward declaration. If we have 'struct foo {...' then this is a
581 // definition. Otherwise we have something like 'struct foo xyz', a reference.
582 //
583 // This is needed to handle stuff like this right (C99 6.7.2.3p11):
584 // struct foo {..}; void bar() { struct foo; } <- new foo in bar.
585 // struct foo {..}; void bar() { struct foo x; } <- use of old foo.
586 //
587 Action::TagKind TK;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000588 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000589 TK = Action::TK_Definition;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000590 else if (Tok.is(tok::semi))
Chris Lattner4b009652007-07-25 00:24:17 +0000591 TK = Action::TK_Declaration;
592 else
593 TK = Action::TK_Reference;
Steve Naroff0acc9c92007-09-15 18:49:24 +0000594 Decl = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, Name, NameLoc, Attr);
Chris Lattner4b009652007-07-25 00:24:17 +0000595 return false;
596}
597
598
599/// ParseStructUnionSpecifier
600/// struct-or-union-specifier: [C99 6.7.2.1]
601/// struct-or-union identifier[opt] '{' struct-contents '}'
602/// struct-or-union identifier
603/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents
604/// '}' attributes[opt]
605/// [GNU] struct-or-union attributes[opt] identifier
606/// struct-or-union:
607/// 'struct'
608/// 'union'
609///
610void Parser::ParseStructUnionSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +0000611 assert((Tok.is(tok::kw_struct) || Tok.is(tok::kw_union)) &&
612 "Not a struct/union specifier");
Chris Lattner4b009652007-07-25 00:24:17 +0000613 DeclSpec::TST TagType =
Chris Lattner34a01ad2007-10-09 17:33:22 +0000614 Tok.is(tok::kw_union) ? DeclSpec::TST_union : DeclSpec::TST_struct;
Chris Lattner4b009652007-07-25 00:24:17 +0000615 SourceLocation StartLoc = ConsumeToken();
616
617 // Parse the tag portion of this.
618 DeclTy *TagDecl;
619 if (ParseTag(TagDecl, TagType, StartLoc))
620 return;
621
622 // If there is a body, parse it and inform the actions module.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000623 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000624 ParseStructUnionBody(StartLoc, TagType, TagDecl);
625
626 const char *PrevSpec = 0;
627 if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, TagDecl))
628 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
629}
630
Steve Naroffa9adf112007-08-20 22:28:22 +0000631/// ParseStructDeclaration
Chris Lattner4b009652007-07-25 00:24:17 +0000632/// struct-declaration:
633/// specifier-qualifier-list struct-declarator-list ';'
634/// [GNU] __extension__ struct-declaration
635/// [GNU] specifier-qualifier-list ';'
636/// struct-declarator-list:
637/// struct-declarator
638/// struct-declarator-list ',' struct-declarator
639/// [GNU] struct-declarator-list ',' attributes[opt] struct-declarator
640/// struct-declarator:
641/// declarator
642/// [GNU] declarator attributes[opt]
643/// declarator[opt] ':' constant-expression
644/// [GNU] declarator[opt] ':' constant-expression attributes[opt]
645///
Steve Naroffa9adf112007-08-20 22:28:22 +0000646void Parser::ParseStructDeclaration(DeclTy *TagDecl,
Steve Naroffc02f4a92007-08-28 16:31:47 +0000647 llvm::SmallVectorImpl<DeclTy*> &FieldDecls) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000648 // FIXME: When __extension__ is specified, disable extension diagnostics.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000649 if (Tok.is(tok::kw___extension__))
Steve Naroffa9adf112007-08-20 22:28:22 +0000650 ConsumeToken();
651
652 // Parse the common specifier-qualifiers-list piece.
653 DeclSpec DS;
654 SourceLocation SpecQualLoc = Tok.getLocation();
655 ParseSpecifierQualifierList(DS);
656 // TODO: Does specifier-qualifier list correctly check that *something* is
657 // specified?
658
659 // If there are no declarators, issue a warning.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000660 if (Tok.is(tok::semi)) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000661 Diag(SpecQualLoc, diag::w_no_declarators);
662 ConsumeToken();
663 return;
664 }
665
666 // Read struct-declarators until we find the semicolon.
667 Declarator DeclaratorInfo(DS, Declarator::MemberContext);
668
669 while (1) {
670 /// struct-declarator: declarator
671 /// struct-declarator: declarator[opt] ':' constant-expression
Chris Lattner34a01ad2007-10-09 17:33:22 +0000672 if (Tok.isNot(tok::colon))
Steve Naroffa9adf112007-08-20 22:28:22 +0000673 ParseDeclarator(DeclaratorInfo);
674
675 ExprTy *BitfieldSize = 0;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000676 if (Tok.is(tok::colon)) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000677 ConsumeToken();
678 ExprResult Res = ParseConstantExpression();
679 if (Res.isInvalid) {
680 SkipUntil(tok::semi, true, true);
681 } else {
682 BitfieldSize = Res.Val;
683 }
684 }
685
686 // If attributes exist after the declarator, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000687 if (Tok.is(tok::kw___attribute))
Steve Naroffa9adf112007-08-20 22:28:22 +0000688 DeclaratorInfo.AddAttributes(ParseAttributes());
689
690 // Install the declarator into the current TagDecl.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000691 DeclTy *Field = Actions.ActOnField(CurScope, TagDecl, SpecQualLoc,
Steve Naroffa9adf112007-08-20 22:28:22 +0000692 DeclaratorInfo, BitfieldSize);
693 FieldDecls.push_back(Field);
694
695 // If we don't have a comma, it is either the end of the list (a ';')
696 // or an error, bail out.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000697 if (Tok.isNot(tok::comma))
Steve Naroffa9adf112007-08-20 22:28:22 +0000698 break;
699
700 // Consume the comma.
701 ConsumeToken();
702
703 // Parse the next declarator.
704 DeclaratorInfo.clear();
705
706 // Attributes are only allowed on the second declarator.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000707 if (Tok.is(tok::kw___attribute))
Steve Naroffa9adf112007-08-20 22:28:22 +0000708 DeclaratorInfo.AddAttributes(ParseAttributes());
709 }
710 return;
711}
712
713/// ParseStructUnionBody
714/// struct-contents:
715/// struct-declaration-list
716/// [EXT] empty
717/// [GNU] "struct-declaration-list" without terminatoring ';'
718/// struct-declaration-list:
719/// struct-declaration
720/// struct-declaration-list struct-declaration
721/// [OBC] '@' 'defs' '(' class-name ')' [TODO]
722///
Chris Lattner4b009652007-07-25 00:24:17 +0000723void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
724 unsigned TagType, DeclTy *TagDecl) {
725 SourceLocation LBraceLoc = ConsumeBrace();
726
727 // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in
728 // C++.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000729 if (Tok.is(tok::r_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000730 Diag(Tok, diag::ext_empty_struct_union_enum,
731 DeclSpec::getSpecifierName((DeclSpec::TST)TagType));
732
733 llvm::SmallVector<DeclTy*, 32> FieldDecls;
734
735 // While we still have something to read, read the declarations in the struct.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000736 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000737 // Each iteration of this loop reads one struct-declaration.
738
739 // Check for extraneous top-level semicolon.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000740 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000741 Diag(Tok, diag::ext_extra_struct_semi);
742 ConsumeToken();
743 continue;
744 }
Steve Naroffa9adf112007-08-20 22:28:22 +0000745 ParseStructDeclaration(TagDecl, FieldDecls);
Chris Lattner4b009652007-07-25 00:24:17 +0000746
Chris Lattner34a01ad2007-10-09 17:33:22 +0000747 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000748 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +0000749 } else if (Tok.is(tok::r_brace)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000750 Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list);
751 break;
752 } else {
753 Diag(Tok, diag::err_expected_semi_decl_list);
754 // Skip to end of block or statement
755 SkipUntil(tok::r_brace, true, true);
756 }
757 }
758
759 MatchRHSPunctuation(tok::r_brace, LBraceLoc);
760
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000761 Actions.ActOnFields(CurScope,
762 RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
Chris Lattner4b009652007-07-25 00:24:17 +0000763
764 AttributeList *AttrList = 0;
765 // If attributes exist after struct contents, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000766 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000767 AttrList = ParseAttributes(); // FIXME: where should I put them?
768}
769
770
771/// ParseEnumSpecifier
772/// enum-specifier: [C99 6.7.2.2]
773/// 'enum' identifier[opt] '{' enumerator-list '}'
774/// [C99] 'enum' identifier[opt] '{' enumerator-list ',' '}'
775/// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt]
776/// '}' attributes[opt]
777/// 'enum' identifier
778/// [GNU] 'enum' attributes[opt] identifier
779void Parser::ParseEnumSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +0000780 assert(Tok.is(tok::kw_enum) && "Not an enum specifier");
Chris Lattner4b009652007-07-25 00:24:17 +0000781 SourceLocation StartLoc = ConsumeToken();
782
783 // Parse the tag portion of this.
784 DeclTy *TagDecl;
785 if (ParseTag(TagDecl, DeclSpec::TST_enum, StartLoc))
786 return;
787
Chris Lattner34a01ad2007-10-09 17:33:22 +0000788 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000789 ParseEnumBody(StartLoc, TagDecl);
790
791 // TODO: semantic analysis on the declspec for enums.
792 const char *PrevSpec = 0;
793 if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, TagDecl))
794 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
795}
796
797/// ParseEnumBody - Parse a {} enclosed enumerator-list.
798/// enumerator-list:
799/// enumerator
800/// enumerator-list ',' enumerator
801/// enumerator:
802/// enumeration-constant
803/// enumeration-constant '=' constant-expression
804/// enumeration-constant:
805/// identifier
806///
807void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) {
808 SourceLocation LBraceLoc = ConsumeBrace();
809
Chris Lattnerc9a92452007-08-27 17:24:30 +0000810 // C does not allow an empty enumerator-list, C++ does [dcl.enum].
Chris Lattner34a01ad2007-10-09 17:33:22 +0000811 if (Tok.is(tok::r_brace) && !getLang().CPlusPlus)
Chris Lattner4b009652007-07-25 00:24:17 +0000812 Diag(Tok, diag::ext_empty_struct_union_enum, "enum");
813
814 llvm::SmallVector<DeclTy*, 32> EnumConstantDecls;
815
816 DeclTy *LastEnumConstDecl = 0;
817
818 // Parse the enumerator-list.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000819 while (Tok.is(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000820 IdentifierInfo *Ident = Tok.getIdentifierInfo();
821 SourceLocation IdentLoc = ConsumeToken();
822
823 SourceLocation EqualLoc;
824 ExprTy *AssignedVal = 0;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000825 if (Tok.is(tok::equal)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000826 EqualLoc = ConsumeToken();
827 ExprResult Res = ParseConstantExpression();
828 if (Res.isInvalid)
829 SkipUntil(tok::comma, tok::r_brace, true, true);
830 else
831 AssignedVal = Res.Val;
832 }
833
834 // Install the enumerator constant into EnumDecl.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000835 DeclTy *EnumConstDecl = Actions.ActOnEnumConstant(CurScope, EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000836 LastEnumConstDecl,
837 IdentLoc, Ident,
838 EqualLoc, AssignedVal);
839 EnumConstantDecls.push_back(EnumConstDecl);
840 LastEnumConstDecl = EnumConstDecl;
841
Chris Lattner34a01ad2007-10-09 17:33:22 +0000842 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +0000843 break;
844 SourceLocation CommaLoc = ConsumeToken();
845
Chris Lattner34a01ad2007-10-09 17:33:22 +0000846 if (Tok.isNot(tok::identifier) && !getLang().C99)
Chris Lattner4b009652007-07-25 00:24:17 +0000847 Diag(CommaLoc, diag::ext_c99_enumerator_list_comma);
848 }
849
850 // Eat the }.
851 MatchRHSPunctuation(tok::r_brace, LBraceLoc);
852
Steve Naroff0acc9c92007-09-15 18:49:24 +0000853 Actions.ActOnEnumBody(StartLoc, EnumDecl, &EnumConstantDecls[0],
Chris Lattner4b009652007-07-25 00:24:17 +0000854 EnumConstantDecls.size());
855
856 DeclTy *AttrList = 0;
857 // If attributes exist after the identifier list, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000858 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000859 AttrList = ParseAttributes(); // FIXME: where do they do?
860}
861
862/// isTypeSpecifierQualifier - Return true if the current token could be the
863/// start of a specifier-qualifier-list.
864bool Parser::isTypeSpecifierQualifier() const {
865 switch (Tok.getKind()) {
866 default: return false;
867 // GNU attributes support.
868 case tok::kw___attribute:
Steve Naroff7cbb1462007-07-31 12:34:36 +0000869 // GNU typeof support.
870 case tok::kw_typeof:
871
Chris Lattner4b009652007-07-25 00:24:17 +0000872 // type-specifiers
873 case tok::kw_short:
874 case tok::kw_long:
875 case tok::kw_signed:
876 case tok::kw_unsigned:
877 case tok::kw__Complex:
878 case tok::kw__Imaginary:
879 case tok::kw_void:
880 case tok::kw_char:
881 case tok::kw_int:
882 case tok::kw_float:
883 case tok::kw_double:
884 case tok::kw__Bool:
885 case tok::kw__Decimal32:
886 case tok::kw__Decimal64:
887 case tok::kw__Decimal128:
888
889 // struct-or-union-specifier
890 case tok::kw_struct:
891 case tok::kw_union:
892 // enum-specifier
893 case tok::kw_enum:
894
895 // type-qualifier
896 case tok::kw_const:
897 case tok::kw_volatile:
898 case tok::kw_restrict:
899 return true;
900
901 // typedef-name
902 case tok::identifier:
903 return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000904 }
905}
906
907/// isDeclarationSpecifier() - Return true if the current token is part of a
908/// declaration specifier.
909bool Parser::isDeclarationSpecifier() const {
910 switch (Tok.getKind()) {
911 default: return false;
912 // storage-class-specifier
913 case tok::kw_typedef:
914 case tok::kw_extern:
915 case tok::kw_static:
916 case tok::kw_auto:
917 case tok::kw_register:
918 case tok::kw___thread:
919
920 // type-specifiers
921 case tok::kw_short:
922 case tok::kw_long:
923 case tok::kw_signed:
924 case tok::kw_unsigned:
925 case tok::kw__Complex:
926 case tok::kw__Imaginary:
927 case tok::kw_void:
928 case tok::kw_char:
929 case tok::kw_int:
930 case tok::kw_float:
931 case tok::kw_double:
932 case tok::kw__Bool:
933 case tok::kw__Decimal32:
934 case tok::kw__Decimal64:
935 case tok::kw__Decimal128:
936
937 // struct-or-union-specifier
938 case tok::kw_struct:
939 case tok::kw_union:
940 // enum-specifier
941 case tok::kw_enum:
942
943 // type-qualifier
944 case tok::kw_const:
945 case tok::kw_volatile:
946 case tok::kw_restrict:
Steve Naroff7cbb1462007-07-31 12:34:36 +0000947
Chris Lattner4b009652007-07-25 00:24:17 +0000948 // function-specifier
949 case tok::kw_inline:
Chris Lattnere35d2582007-08-09 16:40:21 +0000950
Chris Lattnerb707a7a2007-08-09 17:01:07 +0000951 // GNU typeof support.
952 case tok::kw_typeof:
953
954 // GNU attributes.
Chris Lattnere35d2582007-08-09 16:40:21 +0000955 case tok::kw___attribute:
Chris Lattner4b009652007-07-25 00:24:17 +0000956 return true;
957
958 // typedef-name
959 case tok::identifier:
960 return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000961 }
962}
963
964
965/// ParseTypeQualifierListOpt
966/// type-qualifier-list: [C99 6.7.5]
967/// type-qualifier
968/// [GNU] attributes
969/// type-qualifier-list type-qualifier
970/// [GNU] type-qualifier-list attributes
971///
972void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) {
973 while (1) {
974 int isInvalid = false;
975 const char *PrevSpec = 0;
976 SourceLocation Loc = Tok.getLocation();
977
978 switch (Tok.getKind()) {
979 default:
980 // If this is not a type-qualifier token, we're done reading type
981 // qualifiers. First verify that DeclSpec's are consistent.
982 DS.Finish(Diags, getLang());
983 return;
984 case tok::kw_const:
985 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
986 getLang())*2;
987 break;
988 case tok::kw_volatile:
989 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
990 getLang())*2;
991 break;
992 case tok::kw_restrict:
993 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
994 getLang())*2;
995 break;
996 case tok::kw___attribute:
997 DS.AddAttributes(ParseAttributes());
998 continue; // do *not* consume the next token!
999 }
1000
1001 // If the specifier combination wasn't legal, issue a diagnostic.
1002 if (isInvalid) {
1003 assert(PrevSpec && "Method did not return previous specifier!");
1004 if (isInvalid == 1) // Error.
1005 Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec);
1006 else // extwarn.
1007 Diag(Tok, diag::ext_duplicate_declspec, PrevSpec);
1008 }
1009 ConsumeToken();
1010 }
1011}
1012
1013
1014/// ParseDeclarator - Parse and verify a newly-initialized declarator.
1015///
1016void Parser::ParseDeclarator(Declarator &D) {
1017 /// This implements the 'declarator' production in the C grammar, then checks
1018 /// for well-formedness and issues diagnostics.
1019 ParseDeclaratorInternal(D);
1020
1021 // TODO: validate D.
1022
1023}
1024
1025/// ParseDeclaratorInternal
1026/// declarator: [C99 6.7.5]
1027/// pointer[opt] direct-declarator
1028/// [C++] '&' declarator [C++ 8p4, dcl.decl]
1029/// [GNU] '&' restrict[opt] attributes[opt] declarator
1030///
1031/// pointer: [C99 6.7.5]
1032/// '*' type-qualifier-list[opt]
1033/// '*' type-qualifier-list[opt] pointer
1034///
1035void Parser::ParseDeclaratorInternal(Declarator &D) {
1036 tok::TokenKind Kind = Tok.getKind();
1037
1038 // Not a pointer or C++ reference.
1039 if (Kind != tok::star && !(Kind == tok::amp && getLang().CPlusPlus))
1040 return ParseDirectDeclarator(D);
1041
1042 // Otherwise, '*' -> pointer or '&' -> reference.
1043 SourceLocation Loc = ConsumeToken(); // Eat the * or &.
1044
1045 if (Kind == tok::star) {
1046 // Is a pointer
1047 DeclSpec DS;
1048
1049 ParseTypeQualifierListOpt(DS);
1050
1051 // Recursively parse the declarator.
1052 ParseDeclaratorInternal(D);
1053
1054 // Remember that we parsed a pointer type, and remember the type-quals.
1055 D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc));
1056 } else {
1057 // Is a reference
1058 DeclSpec DS;
1059
1060 // C++ 8.3.2p1: cv-qualified references are ill-formed except when the
1061 // cv-qualifiers are introduced through the use of a typedef or of a
1062 // template type argument, in which case the cv-qualifiers are ignored.
1063 //
1064 // [GNU] Retricted references are allowed.
1065 // [GNU] Attributes on references are allowed.
1066 ParseTypeQualifierListOpt(DS);
1067
1068 if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) {
1069 if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
1070 Diag(DS.getConstSpecLoc(),
1071 diag::err_invalid_reference_qualifier_application,
1072 "const");
1073 if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile)
1074 Diag(DS.getVolatileSpecLoc(),
1075 diag::err_invalid_reference_qualifier_application,
1076 "volatile");
1077 }
1078
1079 // Recursively parse the declarator.
1080 ParseDeclaratorInternal(D);
1081
1082 // Remember that we parsed a reference type. It doesn't have type-quals.
1083 D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc));
1084 }
1085}
1086
1087/// ParseDirectDeclarator
1088/// direct-declarator: [C99 6.7.5]
1089/// identifier
1090/// '(' declarator ')'
1091/// [GNU] '(' attributes declarator ')'
1092/// [C90] direct-declarator '[' constant-expression[opt] ']'
1093/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
1094/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
1095/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
1096/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
1097/// direct-declarator '(' parameter-type-list ')'
1098/// direct-declarator '(' identifier-list[opt] ')'
1099/// [GNU] direct-declarator '(' parameter-forward-declarations
1100/// parameter-type-list[opt] ')'
1101///
1102void Parser::ParseDirectDeclarator(Declarator &D) {
1103 // Parse the first direct-declarator seen.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001104 if (Tok.is(tok::identifier) && D.mayHaveIdentifier()) {
Chris Lattner4b009652007-07-25 00:24:17 +00001105 assert(Tok.getIdentifierInfo() && "Not an identifier?");
1106 D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1107 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +00001108 } else if (Tok.is(tok::l_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001109 // direct-declarator: '(' declarator ')'
1110 // direct-declarator: '(' attributes declarator ')'
1111 // Example: 'char (*X)' or 'int (*XX)(void)'
1112 ParseParenDeclarator(D);
1113 } else if (D.mayOmitIdentifier()) {
1114 // This could be something simple like "int" (in which case the declarator
1115 // portion is empty), if an abstract-declarator is allowed.
1116 D.SetIdentifier(0, Tok.getLocation());
1117 } else {
1118 // Expected identifier or '('.
1119 Diag(Tok, diag::err_expected_ident_lparen);
1120 D.SetIdentifier(0, Tok.getLocation());
1121 }
1122
1123 assert(D.isPastIdentifier() &&
1124 "Haven't past the location of the identifier yet?");
1125
1126 while (1) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001127 if (Tok.is(tok::l_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001128 ParseParenDeclarator(D);
Chris Lattner34a01ad2007-10-09 17:33:22 +00001129 } else if (Tok.is(tok::l_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001130 ParseBracketDeclarator(D);
1131 } else {
1132 break;
1133 }
1134 }
1135}
1136
1137/// ParseParenDeclarator - We parsed the declarator D up to a paren. This may
1138/// either be before the identifier (in which case these are just grouping
1139/// parens for precedence) or it may be after the identifier, in which case
1140/// these are function arguments.
1141///
1142/// This method also handles this portion of the grammar:
1143/// parameter-type-list: [C99 6.7.5]
1144/// parameter-list
1145/// parameter-list ',' '...'
1146///
1147/// parameter-list: [C99 6.7.5]
1148/// parameter-declaration
1149/// parameter-list ',' parameter-declaration
1150///
1151/// parameter-declaration: [C99 6.7.5]
1152/// declaration-specifiers declarator
1153/// [GNU] declaration-specifiers declarator attributes
1154/// declaration-specifiers abstract-declarator[opt]
1155/// [GNU] declaration-specifiers abstract-declarator[opt] attributes
1156///
1157/// identifier-list: [C99 6.7.5]
1158/// identifier
1159/// identifier-list ',' identifier
1160///
1161void Parser::ParseParenDeclarator(Declarator &D) {
1162 SourceLocation StartLoc = ConsumeParen();
1163
1164 // If we haven't past the identifier yet (or where the identifier would be
1165 // stored, if this is an abstract declarator), then this is probably just
1166 // grouping parens.
1167 if (!D.isPastIdentifier()) {
1168 // Okay, this is probably a grouping paren. However, if this could be an
1169 // abstract-declarator, then this could also be the start of function
1170 // arguments (consider 'void()').
1171 bool isGrouping;
1172
1173 if (!D.mayOmitIdentifier()) {
1174 // If this can't be an abstract-declarator, this *must* be a grouping
1175 // paren, because we haven't seen the identifier yet.
1176 isGrouping = true;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001177 } else if (Tok.is(tok::r_paren) || // 'int()' is a function.
Chris Lattner4b009652007-07-25 00:24:17 +00001178 isDeclarationSpecifier()) { // 'int(int)' is a function.
1179 // This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is
1180 // considered to be a type, not a K&R identifier-list.
1181 isGrouping = false;
1182 } else {
1183 // Otherwise, this is a grouping paren, e.g. 'int (*X)' or 'int(X)'.
1184 isGrouping = true;
1185 }
1186
1187 // If this is a grouping paren, handle:
1188 // direct-declarator: '(' declarator ')'
1189 // direct-declarator: '(' attributes declarator ')'
1190 if (isGrouping) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001191 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +00001192 D.AddAttributes(ParseAttributes());
1193
1194 ParseDeclaratorInternal(D);
1195 // Match the ')'.
1196 MatchRHSPunctuation(tok::r_paren, StartLoc);
1197 return;
1198 }
1199
1200 // Okay, if this wasn't a grouping paren, it must be the start of a function
1201 // argument list. Recognize that this declarator will never have an
1202 // identifier (and remember where it would have been), then fall through to
1203 // the handling of argument lists.
1204 D.SetIdentifier(0, Tok.getLocation());
1205 }
1206
1207 // Okay, this is the parameter list of a function definition, or it is an
1208 // identifier list of a K&R-style function.
1209 bool IsVariadic;
1210 bool HasPrototype;
1211 bool ErrorEmitted = false;
1212
1213 // Build up an array of information about the parsed arguments.
1214 llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1215 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
1216
Chris Lattner34a01ad2007-10-09 17:33:22 +00001217 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001218 // int() -> no prototype, no '...'.
1219 IsVariadic = false;
1220 HasPrototype = false;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001221 } else if (Tok.is(tok::identifier) &&
Chris Lattner4b009652007-07-25 00:24:17 +00001222 // K&R identifier lists can't have typedefs as identifiers, per
1223 // C99 6.7.5.3p11.
1224 !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
1225 // Identifier list. Note that '(' identifier-list ')' is only allowed for
1226 // normal declarators, not for abstract-declarators.
1227 assert(D.isPastIdentifier() && "Identifier (if present) must be passed!");
1228
1229 // If there was no identifier specified, either we are in an
1230 // abstract-declarator, or we are in a parameter declarator which was found
1231 // to be abstract. In abstract-declarators, identifier lists are not valid,
1232 // diagnose this.
1233 if (!D.getIdentifier())
1234 Diag(Tok, diag::ext_ident_list_in_param);
1235
1236 // Remember this identifier in ParamInfo.
1237 ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
1238 Tok.getLocation(), 0));
1239
1240 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +00001241 while (Tok.is(tok::comma)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001242 // Eat the comma.
1243 ConsumeToken();
1244
Chris Lattner34a01ad2007-10-09 17:33:22 +00001245 if (Tok.isNot(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001246 Diag(Tok, diag::err_expected_ident);
1247 ErrorEmitted = true;
1248 break;
1249 }
1250
1251 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
1252
1253 // Verify that the argument identifier has not already been mentioned.
1254 if (!ParamsSoFar.insert(ParmII)) {
1255 Diag(Tok.getLocation(), diag::err_param_redefinition,ParmII->getName());
1256 ParmII = 0;
1257 }
1258
1259 // Remember this identifier in ParamInfo.
1260 if (ParmII)
1261 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
1262 Tok.getLocation(), 0));
1263
1264 // Eat the identifier.
1265 ConsumeToken();
1266 }
1267
1268 // K&R 'prototype'.
1269 IsVariadic = false;
1270 HasPrototype = false;
1271 } else {
1272 // Finally, a normal, non-empty parameter type list.
1273
1274 // Enter function-declaration scope, limiting any declarators for struct
1275 // tags to the function prototype scope.
1276 // FIXME: is this needed?
Chris Lattnera7549902007-08-26 06:24:45 +00001277 EnterScope(Scope::DeclScope);
Chris Lattner4b009652007-07-25 00:24:17 +00001278
1279 IsVariadic = false;
1280 while (1) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001281 if (Tok.is(tok::ellipsis)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001282 IsVariadic = true;
1283
1284 // Check to see if this is "void(...)" which is not allowed.
1285 if (ParamInfo.empty()) {
1286 // Otherwise, parse parameter type list. If it starts with an
1287 // ellipsis, diagnose the malformed function.
1288 Diag(Tok, diag::err_ellipsis_first_arg);
1289 IsVariadic = false; // Treat this like 'void()'.
1290 }
1291
1292 // Consume the ellipsis.
1293 ConsumeToken();
1294 break;
1295 }
1296
1297 // Parse the declaration-specifiers.
1298 DeclSpec DS;
1299 ParseDeclarationSpecifiers(DS);
1300
1301 // Parse the declarator. This is "PrototypeContext", because we must
1302 // accept either 'declarator' or 'abstract-declarator' here.
1303 Declarator ParmDecl(DS, Declarator::PrototypeContext);
1304 ParseDeclarator(ParmDecl);
1305
1306 // Parse GNU attributes, if present.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001307 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +00001308 ParmDecl.AddAttributes(ParseAttributes());
1309
1310 // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'.
1311 // NOTE: we could trivially allow 'int foo(auto int X)' if we wanted.
1312 if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified &&
1313 DS.getStorageClassSpec() != DeclSpec::SCS_register) {
1314 Diag(DS.getStorageClassSpecLoc(),
1315 diag::err_invalid_storage_class_in_func_decl);
1316 DS.ClearStorageClassSpecs();
1317 }
1318 if (DS.isThreadSpecified()) {
1319 Diag(DS.getThreadSpecLoc(),
1320 diag::err_invalid_storage_class_in_func_decl);
1321 DS.ClearStorageClassSpecs();
1322 }
1323
1324 // Inform the actions module about the parameter declarator, so it gets
1325 // added to the current scope.
1326 Action::TypeResult ParamTy =
Steve Naroff0acc9c92007-09-15 18:49:24 +00001327 Actions.ActOnParamDeclaratorType(CurScope, ParmDecl);
Chris Lattner4b009652007-07-25 00:24:17 +00001328
1329 // Remember this parsed parameter in ParamInfo.
1330 IdentifierInfo *ParmII = ParmDecl.getIdentifier();
1331
1332 // Verify that the argument identifier has not already been mentioned.
1333 if (ParmII && !ParamsSoFar.insert(ParmII)) {
1334 Diag(ParmDecl.getIdentifierLoc(), diag::err_param_redefinition,
1335 ParmII->getName());
1336 ParmII = 0;
1337 }
1338
Steve Naroff91b03f72007-08-28 03:03:08 +00001339 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
1340 ParmDecl.getIdentifierLoc(), ParamTy.Val, ParmDecl.getInvalidType()));
Chris Lattner4b009652007-07-25 00:24:17 +00001341
1342 // If the next token is a comma, consume it and keep reading arguments.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001343 if (Tok.isNot(tok::comma)) break;
Chris Lattner4b009652007-07-25 00:24:17 +00001344
1345 // Consume the comma.
1346 ConsumeToken();
1347 }
1348
1349 HasPrototype = true;
1350
1351 // Leave prototype scope.
1352 ExitScope();
1353 }
1354
1355 // Remember that we parsed a function type, and remember the attributes.
1356 if (!ErrorEmitted)
1357 D.AddTypeInfo(DeclaratorChunk::getFunction(HasPrototype, IsVariadic,
1358 &ParamInfo[0], ParamInfo.size(),
1359 StartLoc));
1360
1361 // If we have the closing ')', eat it and we're done.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001362 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001363 ConsumeParen();
1364 } else {
1365 // If an error happened earlier parsing something else in the proto, don't
1366 // issue another error.
1367 if (!ErrorEmitted)
1368 Diag(Tok, diag::err_expected_rparen);
1369 SkipUntil(tok::r_paren);
1370 }
1371}
1372
1373
1374/// [C90] direct-declarator '[' constant-expression[opt] ']'
1375/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
1376/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
1377/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
1378/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
1379void Parser::ParseBracketDeclarator(Declarator &D) {
1380 SourceLocation StartLoc = ConsumeBracket();
1381
1382 // If valid, this location is the position where we read the 'static' keyword.
1383 SourceLocation StaticLoc;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001384 if (Tok.is(tok::kw_static))
Chris Lattner4b009652007-07-25 00:24:17 +00001385 StaticLoc = ConsumeToken();
1386
1387 // If there is a type-qualifier-list, read it now.
1388 DeclSpec DS;
1389 ParseTypeQualifierListOpt(DS);
1390
1391 // If we haven't already read 'static', check to see if there is one after the
1392 // type-qualifier-list.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001393 if (!StaticLoc.isValid() && Tok.is(tok::kw_static))
Chris Lattner4b009652007-07-25 00:24:17 +00001394 StaticLoc = ConsumeToken();
1395
1396 // Handle "direct-declarator [ type-qual-list[opt] * ]".
1397 bool isStar = false;
1398 ExprResult NumElements(false);
Chris Lattner34a01ad2007-10-09 17:33:22 +00001399 if (Tok.is(tok::star)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001400 // Remember the '*' token, in case we have to un-get it.
1401 Token StarTok = Tok;
1402 ConsumeToken();
1403
1404 // Check that the ']' token is present to avoid incorrectly parsing
1405 // expressions starting with '*' as [*].
Chris Lattner34a01ad2007-10-09 17:33:22 +00001406 if (Tok.is(tok::r_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001407 if (StaticLoc.isValid())
1408 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
1409 StaticLoc = SourceLocation(); // Drop the static.
1410 isStar = true;
1411 } else {
1412 // Otherwise, the * must have been some expression (such as '*ptr') that
1413 // started an assignment-expr. We already consumed the token, but now we
1414 // need to reparse it. This handles cases like 'X[*p + 4]'
1415 NumElements = ParseAssignmentExpressionWithLeadingStar(StarTok);
1416 }
Chris Lattner34a01ad2007-10-09 17:33:22 +00001417 } else if (Tok.isNot(tok::r_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001418 // Parse the assignment-expression now.
1419 NumElements = ParseAssignmentExpression();
1420 }
1421
1422 // If there was an error parsing the assignment-expression, recover.
1423 if (NumElements.isInvalid) {
1424 // If the expression was invalid, skip it.
1425 SkipUntil(tok::r_square);
1426 return;
1427 }
1428
1429 MatchRHSPunctuation(tok::r_square, StartLoc);
1430
1431 // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
1432 // it was not a constant expression.
1433 if (!getLang().C99) {
1434 // TODO: check C90 array constant exprness.
1435 if (isStar || StaticLoc.isValid() ||
1436 0/*TODO: NumElts is not a C90 constantexpr */)
1437 Diag(StartLoc, diag::ext_c99_array_usage);
1438 }
1439
1440 // Remember that we parsed a pointer type, and remember the type-quals.
1441 D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
1442 StaticLoc.isValid(), isStar,
1443 NumElements.Val, StartLoc));
1444}
1445
Steve Naroff7cbb1462007-07-31 12:34:36 +00001446/// [GNU] typeof-specifier:
1447/// typeof ( expressions )
1448/// typeof ( type-name )
1449///
1450void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001451 assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier");
Steve Naroff14bbce82007-08-02 02:53:48 +00001452 const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
Steve Naroff7cbb1462007-07-31 12:34:36 +00001453 SourceLocation StartLoc = ConsumeToken();
1454
Chris Lattner34a01ad2007-10-09 17:33:22 +00001455 if (Tok.isNot(tok::l_paren)) {
Steve Naroff14bbce82007-08-02 02:53:48 +00001456 Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName());
1457 return;
Steve Naroff7cbb1462007-07-31 12:34:36 +00001458 }
1459 SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
1460
1461 if (isTypeSpecifierQualifier()) {
1462 TypeTy *Ty = ParseTypeName();
1463
Steve Naroff4c255ab2007-07-31 23:56:32 +00001464 assert(Ty && "Parser::ParseTypeofSpecifier(): missing type");
1465
Chris Lattner34a01ad2007-10-09 17:33:22 +00001466 if (Tok.isNot(tok::r_paren)) {
Steve Naroff4c255ab2007-07-31 23:56:32 +00001467 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff14bbce82007-08-02 02:53:48 +00001468 return;
1469 }
1470 RParenLoc = ConsumeParen();
1471 const char *PrevSpec = 0;
1472 // Check for duplicate type specifiers (e.g. "int typeof(int)").
1473 if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, Ty))
1474 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
Steve Naroff7cbb1462007-07-31 12:34:36 +00001475 } else { // we have an expression.
1476 ExprResult Result = ParseExpression();
Steve Naroff4c255ab2007-07-31 23:56:32 +00001477
Chris Lattner34a01ad2007-10-09 17:33:22 +00001478 if (Result.isInvalid || Tok.isNot(tok::r_paren)) {
Steve Naroff4c255ab2007-07-31 23:56:32 +00001479 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff14bbce82007-08-02 02:53:48 +00001480 return;
1481 }
1482 RParenLoc = ConsumeParen();
1483 const char *PrevSpec = 0;
1484 // Check for duplicate type specifiers (e.g. "int typeof(int)").
1485 if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
1486 Result.Val))
1487 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
Steve Naroff7cbb1462007-07-31 12:34:36 +00001488 }
Steve Naroff7cbb1462007-07-31 12:34:36 +00001489}
1490