blob: dcbbd89e657c449f70da2476a8e8bcc438948a75 [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);
Fariborz Jahaniana096e1d2007-10-05 21:01:53 +0000412 Actions.ActOnFindProtocolDeclaration(CurScope,
413 Loc,
414 &ProtocolRefs[0],
415 ProtocolRefs.size());
Steve Naroff304ed392007-09-05 23:30:30 +0000416 }
Steve Naroffa8ee2262007-08-22 23:18:22 +0000417 continue;
418 }
Chris Lattner4b009652007-07-25 00:24:17 +0000419 }
420 }
421 // FALL THROUGH.
422 default:
423 // If this is not a declaration specifier token, we're done reading decl
424 // specifiers. First verify that DeclSpec's are consistent.
425 DS.Finish(Diags, getLang());
426 return;
427
428 // GNU attributes support.
429 case tok::kw___attribute:
430 DS.AddAttributes(ParseAttributes());
431 continue;
432
433 // storage-class-specifier
434 case tok::kw_typedef:
435 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec);
436 break;
437 case tok::kw_extern:
438 if (DS.isThreadSpecified())
439 Diag(Tok, diag::ext_thread_before, "extern");
440 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec);
441 break;
442 case tok::kw_static:
443 if (DS.isThreadSpecified())
444 Diag(Tok, diag::ext_thread_before, "static");
445 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec);
446 break;
447 case tok::kw_auto:
448 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec);
449 break;
450 case tok::kw_register:
451 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
452 break;
453 case tok::kw___thread:
454 isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec)*2;
455 break;
456
457 // type-specifiers
458 case tok::kw_short:
459 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec);
460 break;
461 case tok::kw_long:
462 if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
463 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec);
464 else
465 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec);
466 break;
467 case tok::kw_signed:
468 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec);
469 break;
470 case tok::kw_unsigned:
471 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec);
472 break;
473 case tok::kw__Complex:
474 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec);
475 break;
476 case tok::kw__Imaginary:
477 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec);
478 break;
479 case tok::kw_void:
480 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec);
481 break;
482 case tok::kw_char:
483 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec);
484 break;
485 case tok::kw_int:
486 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec);
487 break;
488 case tok::kw_float:
489 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec);
490 break;
491 case tok::kw_double:
492 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
493 break;
494 case tok::kw_bool: // [C++ 2.11p1]
495 case tok::kw__Bool:
496 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
497 break;
498 case tok::kw__Decimal32:
499 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec);
500 break;
501 case tok::kw__Decimal64:
502 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec);
503 break;
504 case tok::kw__Decimal128:
505 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec);
506 break;
507
508 case tok::kw_struct:
509 case tok::kw_union:
510 ParseStructUnionSpecifier(DS);
511 continue;
512 case tok::kw_enum:
513 ParseEnumSpecifier(DS);
514 continue;
515
Steve Naroff7cbb1462007-07-31 12:34:36 +0000516 // GNU typeof support.
517 case tok::kw_typeof:
518 ParseTypeofSpecifier(DS);
519 continue;
520
Chris Lattner4b009652007-07-25 00:24:17 +0000521 // type-qualifier
522 case tok::kw_const:
523 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
524 getLang())*2;
525 break;
526 case tok::kw_volatile:
527 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
528 getLang())*2;
529 break;
530 case tok::kw_restrict:
531 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
532 getLang())*2;
533 break;
534
535 // function-specifier
536 case tok::kw_inline:
537 isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec);
538 break;
539 }
540 // If the specifier combination wasn't legal, issue a diagnostic.
541 if (isInvalid) {
542 assert(PrevSpec && "Method did not return previous specifier!");
543 if (isInvalid == 1) // Error.
544 Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec);
545 else // extwarn.
546 Diag(Tok, diag::ext_duplicate_declspec, PrevSpec);
547 }
548 DS.Range.setEnd(Tok.getLocation());
549 ConsumeToken();
550 }
551}
552
553/// ParseTag - Parse "struct-or-union-or-class-or-enum identifier[opt]", where
554/// the first token has already been read and has been turned into an instance
555/// of DeclSpec::TST (TagType). This returns true if there is an error parsing,
556/// otherwise it returns false and fills in Decl.
557bool Parser::ParseTag(DeclTy *&Decl, unsigned TagType, SourceLocation StartLoc){
558 AttributeList *Attr = 0;
559 // If attributes exist after tag, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000560 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000561 Attr = ParseAttributes();
562
563 // Must have either 'struct name' or 'struct {...}'.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000564 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000565 Diag(Tok, diag::err_expected_ident_lbrace);
566
567 // Skip the rest of this declarator, up until the comma or semicolon.
568 SkipUntil(tok::comma, true);
569 return true;
570 }
571
572 // If an identifier is present, consume and remember it.
573 IdentifierInfo *Name = 0;
574 SourceLocation NameLoc;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000575 if (Tok.is(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000576 Name = Tok.getIdentifierInfo();
577 NameLoc = ConsumeToken();
578 }
579
580 // There are three options here. If we have 'struct foo;', then this is a
581 // forward declaration. If we have 'struct foo {...' then this is a
582 // definition. Otherwise we have something like 'struct foo xyz', a reference.
583 //
584 // This is needed to handle stuff like this right (C99 6.7.2.3p11):
585 // struct foo {..}; void bar() { struct foo; } <- new foo in bar.
586 // struct foo {..}; void bar() { struct foo x; } <- use of old foo.
587 //
588 Action::TagKind TK;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000589 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000590 TK = Action::TK_Definition;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000591 else if (Tok.is(tok::semi))
Chris Lattner4b009652007-07-25 00:24:17 +0000592 TK = Action::TK_Declaration;
593 else
594 TK = Action::TK_Reference;
Steve Naroff0acc9c92007-09-15 18:49:24 +0000595 Decl = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, Name, NameLoc, Attr);
Chris Lattner4b009652007-07-25 00:24:17 +0000596 return false;
597}
598
599
600/// ParseStructUnionSpecifier
601/// struct-or-union-specifier: [C99 6.7.2.1]
602/// struct-or-union identifier[opt] '{' struct-contents '}'
603/// struct-or-union identifier
604/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents
605/// '}' attributes[opt]
606/// [GNU] struct-or-union attributes[opt] identifier
607/// struct-or-union:
608/// 'struct'
609/// 'union'
610///
611void Parser::ParseStructUnionSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +0000612 assert((Tok.is(tok::kw_struct) || Tok.is(tok::kw_union)) &&
613 "Not a struct/union specifier");
Chris Lattner4b009652007-07-25 00:24:17 +0000614 DeclSpec::TST TagType =
Chris Lattner34a01ad2007-10-09 17:33:22 +0000615 Tok.is(tok::kw_union) ? DeclSpec::TST_union : DeclSpec::TST_struct;
Chris Lattner4b009652007-07-25 00:24:17 +0000616 SourceLocation StartLoc = ConsumeToken();
617
618 // Parse the tag portion of this.
619 DeclTy *TagDecl;
620 if (ParseTag(TagDecl, TagType, StartLoc))
621 return;
622
623 // If there is a body, parse it and inform the actions module.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000624 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000625 ParseStructUnionBody(StartLoc, TagType, TagDecl);
626
627 const char *PrevSpec = 0;
628 if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, TagDecl))
629 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
630}
631
Steve Naroffa9adf112007-08-20 22:28:22 +0000632/// ParseStructDeclaration
Chris Lattner4b009652007-07-25 00:24:17 +0000633/// struct-declaration:
634/// specifier-qualifier-list struct-declarator-list ';'
635/// [GNU] __extension__ struct-declaration
636/// [GNU] specifier-qualifier-list ';'
637/// struct-declarator-list:
638/// struct-declarator
639/// struct-declarator-list ',' struct-declarator
640/// [GNU] struct-declarator-list ',' attributes[opt] struct-declarator
641/// struct-declarator:
642/// declarator
643/// [GNU] declarator attributes[opt]
644/// declarator[opt] ':' constant-expression
645/// [GNU] declarator[opt] ':' constant-expression attributes[opt]
646///
Steve Naroffa9adf112007-08-20 22:28:22 +0000647void Parser::ParseStructDeclaration(DeclTy *TagDecl,
Steve Naroffc02f4a92007-08-28 16:31:47 +0000648 llvm::SmallVectorImpl<DeclTy*> &FieldDecls) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000649 // FIXME: When __extension__ is specified, disable extension diagnostics.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000650 if (Tok.is(tok::kw___extension__))
Steve Naroffa9adf112007-08-20 22:28:22 +0000651 ConsumeToken();
652
653 // Parse the common specifier-qualifiers-list piece.
654 DeclSpec DS;
655 SourceLocation SpecQualLoc = Tok.getLocation();
656 ParseSpecifierQualifierList(DS);
657 // TODO: Does specifier-qualifier list correctly check that *something* is
658 // specified?
659
660 // If there are no declarators, issue a warning.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000661 if (Tok.is(tok::semi)) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000662 Diag(SpecQualLoc, diag::w_no_declarators);
663 ConsumeToken();
664 return;
665 }
666
667 // Read struct-declarators until we find the semicolon.
668 Declarator DeclaratorInfo(DS, Declarator::MemberContext);
669
670 while (1) {
671 /// struct-declarator: declarator
672 /// struct-declarator: declarator[opt] ':' constant-expression
Chris Lattner34a01ad2007-10-09 17:33:22 +0000673 if (Tok.isNot(tok::colon))
Steve Naroffa9adf112007-08-20 22:28:22 +0000674 ParseDeclarator(DeclaratorInfo);
675
676 ExprTy *BitfieldSize = 0;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000677 if (Tok.is(tok::colon)) {
Steve Naroffa9adf112007-08-20 22:28:22 +0000678 ConsumeToken();
679 ExprResult Res = ParseConstantExpression();
680 if (Res.isInvalid) {
681 SkipUntil(tok::semi, true, true);
682 } else {
683 BitfieldSize = Res.Val;
684 }
685 }
686
687 // If attributes exist after the declarator, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000688 if (Tok.is(tok::kw___attribute))
Steve Naroffa9adf112007-08-20 22:28:22 +0000689 DeclaratorInfo.AddAttributes(ParseAttributes());
690
691 // Install the declarator into the current TagDecl.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000692 DeclTy *Field = Actions.ActOnField(CurScope, TagDecl, SpecQualLoc,
Steve Naroffa9adf112007-08-20 22:28:22 +0000693 DeclaratorInfo, BitfieldSize);
694 FieldDecls.push_back(Field);
695
696 // If we don't have a comma, it is either the end of the list (a ';')
697 // or an error, bail out.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000698 if (Tok.isNot(tok::comma))
Steve Naroffa9adf112007-08-20 22:28:22 +0000699 break;
700
701 // Consume the comma.
702 ConsumeToken();
703
704 // Parse the next declarator.
705 DeclaratorInfo.clear();
706
707 // Attributes are only allowed on the second declarator.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000708 if (Tok.is(tok::kw___attribute))
Steve Naroffa9adf112007-08-20 22:28:22 +0000709 DeclaratorInfo.AddAttributes(ParseAttributes());
710 }
711 return;
712}
713
714/// ParseStructUnionBody
715/// struct-contents:
716/// struct-declaration-list
717/// [EXT] empty
718/// [GNU] "struct-declaration-list" without terminatoring ';'
719/// struct-declaration-list:
720/// struct-declaration
721/// struct-declaration-list struct-declaration
722/// [OBC] '@' 'defs' '(' class-name ')' [TODO]
723///
Chris Lattner4b009652007-07-25 00:24:17 +0000724void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
725 unsigned TagType, DeclTy *TagDecl) {
726 SourceLocation LBraceLoc = ConsumeBrace();
727
728 // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in
729 // C++.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000730 if (Tok.is(tok::r_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000731 Diag(Tok, diag::ext_empty_struct_union_enum,
732 DeclSpec::getSpecifierName((DeclSpec::TST)TagType));
733
734 llvm::SmallVector<DeclTy*, 32> FieldDecls;
735
736 // While we still have something to read, read the declarations in the struct.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000737 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000738 // Each iteration of this loop reads one struct-declaration.
739
740 // Check for extraneous top-level semicolon.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000741 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000742 Diag(Tok, diag::ext_extra_struct_semi);
743 ConsumeToken();
744 continue;
745 }
Steve Naroffa9adf112007-08-20 22:28:22 +0000746 ParseStructDeclaration(TagDecl, FieldDecls);
Chris Lattner4b009652007-07-25 00:24:17 +0000747
Chris Lattner34a01ad2007-10-09 17:33:22 +0000748 if (Tok.is(tok::semi)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000749 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +0000750 } else if (Tok.is(tok::r_brace)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000751 Diag(Tok.getLocation(), diag::ext_expected_semi_decl_list);
752 break;
753 } else {
754 Diag(Tok, diag::err_expected_semi_decl_list);
755 // Skip to end of block or statement
756 SkipUntil(tok::r_brace, true, true);
757 }
758 }
759
760 MatchRHSPunctuation(tok::r_brace, LBraceLoc);
761
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000762 Actions.ActOnFields(CurScope,
763 RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size());
Chris Lattner4b009652007-07-25 00:24:17 +0000764
765 AttributeList *AttrList = 0;
766 // If attributes exist after struct contents, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000767 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000768 AttrList = ParseAttributes(); // FIXME: where should I put them?
769}
770
771
772/// ParseEnumSpecifier
773/// enum-specifier: [C99 6.7.2.2]
774/// 'enum' identifier[opt] '{' enumerator-list '}'
775/// [C99] 'enum' identifier[opt] '{' enumerator-list ',' '}'
776/// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt]
777/// '}' attributes[opt]
778/// 'enum' identifier
779/// [GNU] 'enum' attributes[opt] identifier
780void Parser::ParseEnumSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +0000781 assert(Tok.is(tok::kw_enum) && "Not an enum specifier");
Chris Lattner4b009652007-07-25 00:24:17 +0000782 SourceLocation StartLoc = ConsumeToken();
783
784 // Parse the tag portion of this.
785 DeclTy *TagDecl;
786 if (ParseTag(TagDecl, DeclSpec::TST_enum, StartLoc))
787 return;
788
Chris Lattner34a01ad2007-10-09 17:33:22 +0000789 if (Tok.is(tok::l_brace))
Chris Lattner4b009652007-07-25 00:24:17 +0000790 ParseEnumBody(StartLoc, TagDecl);
791
792 // TODO: semantic analysis on the declspec for enums.
793 const char *PrevSpec = 0;
794 if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec, TagDecl))
795 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
796}
797
798/// ParseEnumBody - Parse a {} enclosed enumerator-list.
799/// enumerator-list:
800/// enumerator
801/// enumerator-list ',' enumerator
802/// enumerator:
803/// enumeration-constant
804/// enumeration-constant '=' constant-expression
805/// enumeration-constant:
806/// identifier
807///
808void Parser::ParseEnumBody(SourceLocation StartLoc, DeclTy *EnumDecl) {
809 SourceLocation LBraceLoc = ConsumeBrace();
810
Chris Lattnerc9a92452007-08-27 17:24:30 +0000811 // C does not allow an empty enumerator-list, C++ does [dcl.enum].
Chris Lattner34a01ad2007-10-09 17:33:22 +0000812 if (Tok.is(tok::r_brace) && !getLang().CPlusPlus)
Chris Lattner4b009652007-07-25 00:24:17 +0000813 Diag(Tok, diag::ext_empty_struct_union_enum, "enum");
814
815 llvm::SmallVector<DeclTy*, 32> EnumConstantDecls;
816
817 DeclTy *LastEnumConstDecl = 0;
818
819 // Parse the enumerator-list.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000820 while (Tok.is(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000821 IdentifierInfo *Ident = Tok.getIdentifierInfo();
822 SourceLocation IdentLoc = ConsumeToken();
823
824 SourceLocation EqualLoc;
825 ExprTy *AssignedVal = 0;
Chris Lattner34a01ad2007-10-09 17:33:22 +0000826 if (Tok.is(tok::equal)) {
Chris Lattner4b009652007-07-25 00:24:17 +0000827 EqualLoc = ConsumeToken();
828 ExprResult Res = ParseConstantExpression();
829 if (Res.isInvalid)
830 SkipUntil(tok::comma, tok::r_brace, true, true);
831 else
832 AssignedVal = Res.Val;
833 }
834
835 // Install the enumerator constant into EnumDecl.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000836 DeclTy *EnumConstDecl = Actions.ActOnEnumConstant(CurScope, EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000837 LastEnumConstDecl,
838 IdentLoc, Ident,
839 EqualLoc, AssignedVal);
840 EnumConstantDecls.push_back(EnumConstDecl);
841 LastEnumConstDecl = EnumConstDecl;
842
Chris Lattner34a01ad2007-10-09 17:33:22 +0000843 if (Tok.isNot(tok::comma))
Chris Lattner4b009652007-07-25 00:24:17 +0000844 break;
845 SourceLocation CommaLoc = ConsumeToken();
846
Chris Lattner34a01ad2007-10-09 17:33:22 +0000847 if (Tok.isNot(tok::identifier) && !getLang().C99)
Chris Lattner4b009652007-07-25 00:24:17 +0000848 Diag(CommaLoc, diag::ext_c99_enumerator_list_comma);
849 }
850
851 // Eat the }.
852 MatchRHSPunctuation(tok::r_brace, LBraceLoc);
853
Steve Naroff0acc9c92007-09-15 18:49:24 +0000854 Actions.ActOnEnumBody(StartLoc, EnumDecl, &EnumConstantDecls[0],
Chris Lattner4b009652007-07-25 00:24:17 +0000855 EnumConstantDecls.size());
856
857 DeclTy *AttrList = 0;
858 // If attributes exist after the identifier list, parse them.
Chris Lattner34a01ad2007-10-09 17:33:22 +0000859 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +0000860 AttrList = ParseAttributes(); // FIXME: where do they do?
861}
862
863/// isTypeSpecifierQualifier - Return true if the current token could be the
864/// start of a specifier-qualifier-list.
865bool Parser::isTypeSpecifierQualifier() const {
866 switch (Tok.getKind()) {
867 default: return false;
868 // GNU attributes support.
869 case tok::kw___attribute:
Steve Naroff7cbb1462007-07-31 12:34:36 +0000870 // GNU typeof support.
871 case tok::kw_typeof:
872
Chris Lattner4b009652007-07-25 00:24:17 +0000873 // type-specifiers
874 case tok::kw_short:
875 case tok::kw_long:
876 case tok::kw_signed:
877 case tok::kw_unsigned:
878 case tok::kw__Complex:
879 case tok::kw__Imaginary:
880 case tok::kw_void:
881 case tok::kw_char:
882 case tok::kw_int:
883 case tok::kw_float:
884 case tok::kw_double:
885 case tok::kw__Bool:
886 case tok::kw__Decimal32:
887 case tok::kw__Decimal64:
888 case tok::kw__Decimal128:
889
890 // struct-or-union-specifier
891 case tok::kw_struct:
892 case tok::kw_union:
893 // enum-specifier
894 case tok::kw_enum:
895
896 // type-qualifier
897 case tok::kw_const:
898 case tok::kw_volatile:
899 case tok::kw_restrict:
900 return true;
901
902 // typedef-name
903 case tok::identifier:
904 return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000905 }
906}
907
908/// isDeclarationSpecifier() - Return true if the current token is part of a
909/// declaration specifier.
910bool Parser::isDeclarationSpecifier() const {
911 switch (Tok.getKind()) {
912 default: return false;
913 // storage-class-specifier
914 case tok::kw_typedef:
915 case tok::kw_extern:
916 case tok::kw_static:
917 case tok::kw_auto:
918 case tok::kw_register:
919 case tok::kw___thread:
920
921 // type-specifiers
922 case tok::kw_short:
923 case tok::kw_long:
924 case tok::kw_signed:
925 case tok::kw_unsigned:
926 case tok::kw__Complex:
927 case tok::kw__Imaginary:
928 case tok::kw_void:
929 case tok::kw_char:
930 case tok::kw_int:
931 case tok::kw_float:
932 case tok::kw_double:
933 case tok::kw__Bool:
934 case tok::kw__Decimal32:
935 case tok::kw__Decimal64:
936 case tok::kw__Decimal128:
937
938 // struct-or-union-specifier
939 case tok::kw_struct:
940 case tok::kw_union:
941 // enum-specifier
942 case tok::kw_enum:
943
944 // type-qualifier
945 case tok::kw_const:
946 case tok::kw_volatile:
947 case tok::kw_restrict:
Steve Naroff7cbb1462007-07-31 12:34:36 +0000948
Chris Lattner4b009652007-07-25 00:24:17 +0000949 // function-specifier
950 case tok::kw_inline:
Chris Lattnere35d2582007-08-09 16:40:21 +0000951
Chris Lattnerb707a7a2007-08-09 17:01:07 +0000952 // GNU typeof support.
953 case tok::kw_typeof:
954
955 // GNU attributes.
Chris Lattnere35d2582007-08-09 16:40:21 +0000956 case tok::kw___attribute:
Chris Lattner4b009652007-07-25 00:24:17 +0000957 return true;
958
959 // typedef-name
960 case tok::identifier:
961 return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000962 }
963}
964
965
966/// ParseTypeQualifierListOpt
967/// type-qualifier-list: [C99 6.7.5]
968/// type-qualifier
969/// [GNU] attributes
970/// type-qualifier-list type-qualifier
971/// [GNU] type-qualifier-list attributes
972///
973void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) {
974 while (1) {
975 int isInvalid = false;
976 const char *PrevSpec = 0;
977 SourceLocation Loc = Tok.getLocation();
978
979 switch (Tok.getKind()) {
980 default:
981 // If this is not a type-qualifier token, we're done reading type
982 // qualifiers. First verify that DeclSpec's are consistent.
983 DS.Finish(Diags, getLang());
984 return;
985 case tok::kw_const:
986 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
987 getLang())*2;
988 break;
989 case tok::kw_volatile:
990 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
991 getLang())*2;
992 break;
993 case tok::kw_restrict:
994 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
995 getLang())*2;
996 break;
997 case tok::kw___attribute:
998 DS.AddAttributes(ParseAttributes());
999 continue; // do *not* consume the next token!
1000 }
1001
1002 // If the specifier combination wasn't legal, issue a diagnostic.
1003 if (isInvalid) {
1004 assert(PrevSpec && "Method did not return previous specifier!");
1005 if (isInvalid == 1) // Error.
1006 Diag(Tok, diag::err_invalid_decl_spec_combination, PrevSpec);
1007 else // extwarn.
1008 Diag(Tok, diag::ext_duplicate_declspec, PrevSpec);
1009 }
1010 ConsumeToken();
1011 }
1012}
1013
1014
1015/// ParseDeclarator - Parse and verify a newly-initialized declarator.
1016///
1017void Parser::ParseDeclarator(Declarator &D) {
1018 /// This implements the 'declarator' production in the C grammar, then checks
1019 /// for well-formedness and issues diagnostics.
1020 ParseDeclaratorInternal(D);
1021
1022 // TODO: validate D.
1023
1024}
1025
1026/// ParseDeclaratorInternal
1027/// declarator: [C99 6.7.5]
1028/// pointer[opt] direct-declarator
1029/// [C++] '&' declarator [C++ 8p4, dcl.decl]
1030/// [GNU] '&' restrict[opt] attributes[opt] declarator
1031///
1032/// pointer: [C99 6.7.5]
1033/// '*' type-qualifier-list[opt]
1034/// '*' type-qualifier-list[opt] pointer
1035///
1036void Parser::ParseDeclaratorInternal(Declarator &D) {
1037 tok::TokenKind Kind = Tok.getKind();
1038
1039 // Not a pointer or C++ reference.
1040 if (Kind != tok::star && !(Kind == tok::amp && getLang().CPlusPlus))
1041 return ParseDirectDeclarator(D);
1042
1043 // Otherwise, '*' -> pointer or '&' -> reference.
1044 SourceLocation Loc = ConsumeToken(); // Eat the * or &.
1045
1046 if (Kind == tok::star) {
1047 // Is a pointer
1048 DeclSpec DS;
1049
1050 ParseTypeQualifierListOpt(DS);
1051
1052 // Recursively parse the declarator.
1053 ParseDeclaratorInternal(D);
1054
1055 // Remember that we parsed a pointer type, and remember the type-quals.
1056 D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc));
1057 } else {
1058 // Is a reference
1059 DeclSpec DS;
1060
1061 // C++ 8.3.2p1: cv-qualified references are ill-formed except when the
1062 // cv-qualifiers are introduced through the use of a typedef or of a
1063 // template type argument, in which case the cv-qualifiers are ignored.
1064 //
1065 // [GNU] Retricted references are allowed.
1066 // [GNU] Attributes on references are allowed.
1067 ParseTypeQualifierListOpt(DS);
1068
1069 if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) {
1070 if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
1071 Diag(DS.getConstSpecLoc(),
1072 diag::err_invalid_reference_qualifier_application,
1073 "const");
1074 if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile)
1075 Diag(DS.getVolatileSpecLoc(),
1076 diag::err_invalid_reference_qualifier_application,
1077 "volatile");
1078 }
1079
1080 // Recursively parse the declarator.
1081 ParseDeclaratorInternal(D);
1082
1083 // Remember that we parsed a reference type. It doesn't have type-quals.
1084 D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc));
1085 }
1086}
1087
1088/// ParseDirectDeclarator
1089/// direct-declarator: [C99 6.7.5]
1090/// identifier
1091/// '(' declarator ')'
1092/// [GNU] '(' attributes declarator ')'
1093/// [C90] direct-declarator '[' constant-expression[opt] ']'
1094/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
1095/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
1096/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
1097/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
1098/// direct-declarator '(' parameter-type-list ')'
1099/// direct-declarator '(' identifier-list[opt] ')'
1100/// [GNU] direct-declarator '(' parameter-forward-declarations
1101/// parameter-type-list[opt] ')'
1102///
1103void Parser::ParseDirectDeclarator(Declarator &D) {
1104 // Parse the first direct-declarator seen.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001105 if (Tok.is(tok::identifier) && D.mayHaveIdentifier()) {
Chris Lattner4b009652007-07-25 00:24:17 +00001106 assert(Tok.getIdentifierInfo() && "Not an identifier?");
1107 D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1108 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +00001109 } else if (Tok.is(tok::l_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001110 // direct-declarator: '(' declarator ')'
1111 // direct-declarator: '(' attributes declarator ')'
1112 // Example: 'char (*X)' or 'int (*XX)(void)'
1113 ParseParenDeclarator(D);
1114 } else if (D.mayOmitIdentifier()) {
1115 // This could be something simple like "int" (in which case the declarator
1116 // portion is empty), if an abstract-declarator is allowed.
1117 D.SetIdentifier(0, Tok.getLocation());
1118 } else {
1119 // Expected identifier or '('.
1120 Diag(Tok, diag::err_expected_ident_lparen);
1121 D.SetIdentifier(0, Tok.getLocation());
1122 }
1123
1124 assert(D.isPastIdentifier() &&
1125 "Haven't past the location of the identifier yet?");
1126
1127 while (1) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001128 if (Tok.is(tok::l_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001129 ParseParenDeclarator(D);
Chris Lattner34a01ad2007-10-09 17:33:22 +00001130 } else if (Tok.is(tok::l_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001131 ParseBracketDeclarator(D);
1132 } else {
1133 break;
1134 }
1135 }
1136}
1137
1138/// ParseParenDeclarator - We parsed the declarator D up to a paren. This may
1139/// either be before the identifier (in which case these are just grouping
1140/// parens for precedence) or it may be after the identifier, in which case
1141/// these are function arguments.
1142///
1143/// This method also handles this portion of the grammar:
1144/// parameter-type-list: [C99 6.7.5]
1145/// parameter-list
1146/// parameter-list ',' '...'
1147///
1148/// parameter-list: [C99 6.7.5]
1149/// parameter-declaration
1150/// parameter-list ',' parameter-declaration
1151///
1152/// parameter-declaration: [C99 6.7.5]
1153/// declaration-specifiers declarator
1154/// [GNU] declaration-specifiers declarator attributes
1155/// declaration-specifiers abstract-declarator[opt]
1156/// [GNU] declaration-specifiers abstract-declarator[opt] attributes
1157///
1158/// identifier-list: [C99 6.7.5]
1159/// identifier
1160/// identifier-list ',' identifier
1161///
1162void Parser::ParseParenDeclarator(Declarator &D) {
1163 SourceLocation StartLoc = ConsumeParen();
1164
1165 // If we haven't past the identifier yet (or where the identifier would be
1166 // stored, if this is an abstract declarator), then this is probably just
1167 // grouping parens.
1168 if (!D.isPastIdentifier()) {
1169 // Okay, this is probably a grouping paren. However, if this could be an
1170 // abstract-declarator, then this could also be the start of function
1171 // arguments (consider 'void()').
1172 bool isGrouping;
1173
1174 if (!D.mayOmitIdentifier()) {
1175 // If this can't be an abstract-declarator, this *must* be a grouping
1176 // paren, because we haven't seen the identifier yet.
1177 isGrouping = true;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001178 } else if (Tok.is(tok::r_paren) || // 'int()' is a function.
Chris Lattner4b009652007-07-25 00:24:17 +00001179 isDeclarationSpecifier()) { // 'int(int)' is a function.
1180 // This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is
1181 // considered to be a type, not a K&R identifier-list.
1182 isGrouping = false;
1183 } else {
1184 // Otherwise, this is a grouping paren, e.g. 'int (*X)' or 'int(X)'.
1185 isGrouping = true;
1186 }
1187
1188 // If this is a grouping paren, handle:
1189 // direct-declarator: '(' declarator ')'
1190 // direct-declarator: '(' attributes declarator ')'
1191 if (isGrouping) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001192 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +00001193 D.AddAttributes(ParseAttributes());
1194
1195 ParseDeclaratorInternal(D);
1196 // Match the ')'.
1197 MatchRHSPunctuation(tok::r_paren, StartLoc);
1198 return;
1199 }
1200
1201 // Okay, if this wasn't a grouping paren, it must be the start of a function
1202 // argument list. Recognize that this declarator will never have an
1203 // identifier (and remember where it would have been), then fall through to
1204 // the handling of argument lists.
1205 D.SetIdentifier(0, Tok.getLocation());
1206 }
1207
1208 // Okay, this is the parameter list of a function definition, or it is an
1209 // identifier list of a K&R-style function.
1210 bool IsVariadic;
1211 bool HasPrototype;
1212 bool ErrorEmitted = false;
1213
1214 // Build up an array of information about the parsed arguments.
1215 llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
1216 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
1217
Chris Lattner34a01ad2007-10-09 17:33:22 +00001218 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001219 // int() -> no prototype, no '...'.
1220 IsVariadic = false;
1221 HasPrototype = false;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001222 } else if (Tok.is(tok::identifier) &&
Chris Lattner4b009652007-07-25 00:24:17 +00001223 // K&R identifier lists can't have typedefs as identifiers, per
1224 // C99 6.7.5.3p11.
1225 !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
1226 // Identifier list. Note that '(' identifier-list ')' is only allowed for
1227 // normal declarators, not for abstract-declarators.
1228 assert(D.isPastIdentifier() && "Identifier (if present) must be passed!");
1229
1230 // If there was no identifier specified, either we are in an
1231 // abstract-declarator, or we are in a parameter declarator which was found
1232 // to be abstract. In abstract-declarators, identifier lists are not valid,
1233 // diagnose this.
1234 if (!D.getIdentifier())
1235 Diag(Tok, diag::ext_ident_list_in_param);
1236
1237 // Remember this identifier in ParamInfo.
1238 ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
1239 Tok.getLocation(), 0));
1240
1241 ConsumeToken();
Chris Lattner34a01ad2007-10-09 17:33:22 +00001242 while (Tok.is(tok::comma)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001243 // Eat the comma.
1244 ConsumeToken();
1245
Chris Lattner34a01ad2007-10-09 17:33:22 +00001246 if (Tok.isNot(tok::identifier)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001247 Diag(Tok, diag::err_expected_ident);
1248 ErrorEmitted = true;
1249 break;
1250 }
1251
1252 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
1253
1254 // Verify that the argument identifier has not already been mentioned.
1255 if (!ParamsSoFar.insert(ParmII)) {
1256 Diag(Tok.getLocation(), diag::err_param_redefinition,ParmII->getName());
1257 ParmII = 0;
1258 }
1259
1260 // Remember this identifier in ParamInfo.
1261 if (ParmII)
1262 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
1263 Tok.getLocation(), 0));
1264
1265 // Eat the identifier.
1266 ConsumeToken();
1267 }
1268
1269 // K&R 'prototype'.
1270 IsVariadic = false;
1271 HasPrototype = false;
1272 } else {
1273 // Finally, a normal, non-empty parameter type list.
1274
1275 // Enter function-declaration scope, limiting any declarators for struct
1276 // tags to the function prototype scope.
1277 // FIXME: is this needed?
Chris Lattnera7549902007-08-26 06:24:45 +00001278 EnterScope(Scope::DeclScope);
Chris Lattner4b009652007-07-25 00:24:17 +00001279
1280 IsVariadic = false;
1281 while (1) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001282 if (Tok.is(tok::ellipsis)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001283 IsVariadic = true;
1284
1285 // Check to see if this is "void(...)" which is not allowed.
1286 if (ParamInfo.empty()) {
1287 // Otherwise, parse parameter type list. If it starts with an
1288 // ellipsis, diagnose the malformed function.
1289 Diag(Tok, diag::err_ellipsis_first_arg);
1290 IsVariadic = false; // Treat this like 'void()'.
1291 }
1292
1293 // Consume the ellipsis.
1294 ConsumeToken();
1295 break;
1296 }
1297
1298 // Parse the declaration-specifiers.
1299 DeclSpec DS;
1300 ParseDeclarationSpecifiers(DS);
1301
1302 // Parse the declarator. This is "PrototypeContext", because we must
1303 // accept either 'declarator' or 'abstract-declarator' here.
1304 Declarator ParmDecl(DS, Declarator::PrototypeContext);
1305 ParseDeclarator(ParmDecl);
1306
1307 // Parse GNU attributes, if present.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001308 if (Tok.is(tok::kw___attribute))
Chris Lattner4b009652007-07-25 00:24:17 +00001309 ParmDecl.AddAttributes(ParseAttributes());
1310
1311 // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'.
1312 // NOTE: we could trivially allow 'int foo(auto int X)' if we wanted.
1313 if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified &&
1314 DS.getStorageClassSpec() != DeclSpec::SCS_register) {
1315 Diag(DS.getStorageClassSpecLoc(),
1316 diag::err_invalid_storage_class_in_func_decl);
1317 DS.ClearStorageClassSpecs();
1318 }
1319 if (DS.isThreadSpecified()) {
1320 Diag(DS.getThreadSpecLoc(),
1321 diag::err_invalid_storage_class_in_func_decl);
1322 DS.ClearStorageClassSpecs();
1323 }
1324
1325 // Inform the actions module about the parameter declarator, so it gets
1326 // added to the current scope.
1327 Action::TypeResult ParamTy =
Steve Naroff0acc9c92007-09-15 18:49:24 +00001328 Actions.ActOnParamDeclaratorType(CurScope, ParmDecl);
Chris Lattner4b009652007-07-25 00:24:17 +00001329
1330 // Remember this parsed parameter in ParamInfo.
1331 IdentifierInfo *ParmII = ParmDecl.getIdentifier();
1332
1333 // Verify that the argument identifier has not already been mentioned.
1334 if (ParmII && !ParamsSoFar.insert(ParmII)) {
1335 Diag(ParmDecl.getIdentifierLoc(), diag::err_param_redefinition,
1336 ParmII->getName());
1337 ParmII = 0;
1338 }
1339
Steve Naroff91b03f72007-08-28 03:03:08 +00001340 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
1341 ParmDecl.getIdentifierLoc(), ParamTy.Val, ParmDecl.getInvalidType()));
Chris Lattner4b009652007-07-25 00:24:17 +00001342
1343 // If the next token is a comma, consume it and keep reading arguments.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001344 if (Tok.isNot(tok::comma)) break;
Chris Lattner4b009652007-07-25 00:24:17 +00001345
1346 // Consume the comma.
1347 ConsumeToken();
1348 }
1349
1350 HasPrototype = true;
1351
1352 // Leave prototype scope.
1353 ExitScope();
1354 }
1355
1356 // Remember that we parsed a function type, and remember the attributes.
1357 if (!ErrorEmitted)
1358 D.AddTypeInfo(DeclaratorChunk::getFunction(HasPrototype, IsVariadic,
1359 &ParamInfo[0], ParamInfo.size(),
1360 StartLoc));
1361
1362 // If we have the closing ')', eat it and we're done.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001363 if (Tok.is(tok::r_paren)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001364 ConsumeParen();
1365 } else {
1366 // If an error happened earlier parsing something else in the proto, don't
1367 // issue another error.
1368 if (!ErrorEmitted)
1369 Diag(Tok, diag::err_expected_rparen);
1370 SkipUntil(tok::r_paren);
1371 }
1372}
1373
1374
1375/// [C90] direct-declarator '[' constant-expression[opt] ']'
1376/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
1377/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
1378/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
1379/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
1380void Parser::ParseBracketDeclarator(Declarator &D) {
1381 SourceLocation StartLoc = ConsumeBracket();
1382
1383 // If valid, this location is the position where we read the 'static' keyword.
1384 SourceLocation StaticLoc;
Chris Lattner34a01ad2007-10-09 17:33:22 +00001385 if (Tok.is(tok::kw_static))
Chris Lattner4b009652007-07-25 00:24:17 +00001386 StaticLoc = ConsumeToken();
1387
1388 // If there is a type-qualifier-list, read it now.
1389 DeclSpec DS;
1390 ParseTypeQualifierListOpt(DS);
1391
1392 // If we haven't already read 'static', check to see if there is one after the
1393 // type-qualifier-list.
Chris Lattner34a01ad2007-10-09 17:33:22 +00001394 if (!StaticLoc.isValid() && Tok.is(tok::kw_static))
Chris Lattner4b009652007-07-25 00:24:17 +00001395 StaticLoc = ConsumeToken();
1396
1397 // Handle "direct-declarator [ type-qual-list[opt] * ]".
1398 bool isStar = false;
1399 ExprResult NumElements(false);
Chris Lattner34a01ad2007-10-09 17:33:22 +00001400 if (Tok.is(tok::star)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001401 // Remember the '*' token, in case we have to un-get it.
1402 Token StarTok = Tok;
1403 ConsumeToken();
1404
1405 // Check that the ']' token is present to avoid incorrectly parsing
1406 // expressions starting with '*' as [*].
Chris Lattner34a01ad2007-10-09 17:33:22 +00001407 if (Tok.is(tok::r_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001408 if (StaticLoc.isValid())
1409 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
1410 StaticLoc = SourceLocation(); // Drop the static.
1411 isStar = true;
1412 } else {
1413 // Otherwise, the * must have been some expression (such as '*ptr') that
1414 // started an assignment-expr. We already consumed the token, but now we
1415 // need to reparse it. This handles cases like 'X[*p + 4]'
1416 NumElements = ParseAssignmentExpressionWithLeadingStar(StarTok);
1417 }
Chris Lattner34a01ad2007-10-09 17:33:22 +00001418 } else if (Tok.isNot(tok::r_square)) {
Chris Lattner4b009652007-07-25 00:24:17 +00001419 // Parse the assignment-expression now.
1420 NumElements = ParseAssignmentExpression();
1421 }
1422
1423 // If there was an error parsing the assignment-expression, recover.
1424 if (NumElements.isInvalid) {
1425 // If the expression was invalid, skip it.
1426 SkipUntil(tok::r_square);
1427 return;
1428 }
1429
1430 MatchRHSPunctuation(tok::r_square, StartLoc);
1431
1432 // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
1433 // it was not a constant expression.
1434 if (!getLang().C99) {
1435 // TODO: check C90 array constant exprness.
1436 if (isStar || StaticLoc.isValid() ||
1437 0/*TODO: NumElts is not a C90 constantexpr */)
1438 Diag(StartLoc, diag::ext_c99_array_usage);
1439 }
1440
1441 // Remember that we parsed a pointer type, and remember the type-quals.
1442 D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
1443 StaticLoc.isValid(), isStar,
1444 NumElements.Val, StartLoc));
1445}
1446
Steve Naroff7cbb1462007-07-31 12:34:36 +00001447/// [GNU] typeof-specifier:
1448/// typeof ( expressions )
1449/// typeof ( type-name )
1450///
1451void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
Chris Lattner34a01ad2007-10-09 17:33:22 +00001452 assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier");
Steve Naroff14bbce82007-08-02 02:53:48 +00001453 const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
Steve Naroff7cbb1462007-07-31 12:34:36 +00001454 SourceLocation StartLoc = ConsumeToken();
1455
Chris Lattner34a01ad2007-10-09 17:33:22 +00001456 if (Tok.isNot(tok::l_paren)) {
Steve Naroff14bbce82007-08-02 02:53:48 +00001457 Diag(Tok, diag::err_expected_lparen_after, BuiltinII->getName());
1458 return;
Steve Naroff7cbb1462007-07-31 12:34:36 +00001459 }
1460 SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
1461
1462 if (isTypeSpecifierQualifier()) {
1463 TypeTy *Ty = ParseTypeName();
1464
Steve Naroff4c255ab2007-07-31 23:56:32 +00001465 assert(Ty && "Parser::ParseTypeofSpecifier(): missing type");
1466
Chris Lattner34a01ad2007-10-09 17:33:22 +00001467 if (Tok.isNot(tok::r_paren)) {
Steve Naroff4c255ab2007-07-31 23:56:32 +00001468 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff14bbce82007-08-02 02:53:48 +00001469 return;
1470 }
1471 RParenLoc = ConsumeParen();
1472 const char *PrevSpec = 0;
1473 // Check for duplicate type specifiers (e.g. "int typeof(int)").
1474 if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, Ty))
1475 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
Steve Naroff7cbb1462007-07-31 12:34:36 +00001476 } else { // we have an expression.
1477 ExprResult Result = ParseExpression();
Steve Naroff4c255ab2007-07-31 23:56:32 +00001478
Chris Lattner34a01ad2007-10-09 17:33:22 +00001479 if (Result.isInvalid || Tok.isNot(tok::r_paren)) {
Steve Naroff4c255ab2007-07-31 23:56:32 +00001480 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff14bbce82007-08-02 02:53:48 +00001481 return;
1482 }
1483 RParenLoc = ConsumeParen();
1484 const char *PrevSpec = 0;
1485 // Check for duplicate type specifiers (e.g. "int typeof(int)").
1486 if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
1487 Result.Val))
1488 Diag(StartLoc, diag::err_invalid_decl_spec_combination, PrevSpec);
Steve Naroff7cbb1462007-07-31 12:34:36 +00001489 }
Steve Naroff7cbb1462007-07-31 12:34:36 +00001490}
1491