blob: 47d21be60d253c60c22a21e2e78235a05426f54e [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- ParseDecl.cpp - Declaration Parsing ------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Declaration portions of the Parser interfaces.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Chris Lattner500d3292009-01-29 05:15:15 +000015#include "clang/Parse/ParseDiagnostic.h"
Chris Lattner31e05722007-08-26 06:24:45 +000016#include "clang/Parse/Scope.h"
Chris Lattnerc46d1a12008-10-20 06:45:43 +000017#include "ExtensionRAIIObject.h"
Sebastian Redla55e52c2008-11-25 22:21:31 +000018#include "AstGuard.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019#include "llvm/ADT/SmallSet.h"
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// C99 6.7: Declarations.
24//===----------------------------------------------------------------------===//
25
26/// ParseTypeName
27/// type-name: [C99 6.7.6]
28/// specifier-qualifier-list abstract-declarator[opt]
Sebastian Redl4c5d3202008-11-21 19:14:01 +000029///
30/// Called type-id in C++.
Douglas Gregor809070a2009-02-18 17:45:20 +000031Action::TypeResult Parser::ParseTypeName() {
Reid Spencer5f016e22007-07-11 17:01:13 +000032 // Parse the common declaration-specifiers piece.
33 DeclSpec DS;
34 ParseSpecifierQualifierList(DS);
35
36 // Parse the abstract-declarator, if present.
37 Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
38 ParseDeclarator(DeclaratorInfo);
39
Douglas Gregor809070a2009-02-18 17:45:20 +000040 if (DeclaratorInfo.getInvalidType())
41 return true;
42
43 return Actions.ActOnTypeName(CurScope, DeclaratorInfo);
Reid Spencer5f016e22007-07-11 17:01:13 +000044}
45
46/// ParseAttributes - Parse a non-empty attributes list.
47///
48/// [GNU] attributes:
49/// attribute
50/// attributes attribute
51///
52/// [GNU] attribute:
53/// '__attribute__' '(' '(' attribute-list ')' ')'
54///
55/// [GNU] attribute-list:
56/// attrib
57/// attribute_list ',' attrib
58///
59/// [GNU] attrib:
60/// empty
61/// attrib-name
62/// attrib-name '(' identifier ')'
63/// attrib-name '(' identifier ',' nonempty-expr-list ')'
64/// attrib-name '(' argument-expression-list [C99 6.5.2] ')'
65///
66/// [GNU] attrib-name:
67/// identifier
68/// typespec
69/// typequal
70/// storageclass
71///
72/// FIXME: The GCC grammar/code for this construct implies we need two
73/// token lookahead. Comment from gcc: "If they start with an identifier
74/// which is followed by a comma or close parenthesis, then the arguments
75/// start with that identifier; otherwise they are an expression list."
76///
77/// At the moment, I am not doing 2 token lookahead. I am also unaware of
78/// any attributes that don't work (based on my limited testing). Most
79/// attributes are very simple in practice. Until we find a bug, I don't see
80/// a pressing need to implement the 2 token lookahead.
81
Sebastian Redlab197ba2009-02-09 18:23:29 +000082AttributeList *Parser::ParseAttributes(SourceLocation *EndLoc) {
Chris Lattner04d66662007-10-09 17:33:22 +000083 assert(Tok.is(tok::kw___attribute) && "Not an attribute list!");
Reid Spencer5f016e22007-07-11 17:01:13 +000084
85 AttributeList *CurrAttr = 0;
86
Chris Lattner04d66662007-10-09 17:33:22 +000087 while (Tok.is(tok::kw___attribute)) {
Reid Spencer5f016e22007-07-11 17:01:13 +000088 ConsumeToken();
89 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
90 "attribute")) {
91 SkipUntil(tok::r_paren, true); // skip until ) or ;
92 return CurrAttr;
93 }
94 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "(")) {
95 SkipUntil(tok::r_paren, true); // skip until ) or ;
96 return CurrAttr;
97 }
98 // Parse the attribute-list. e.g. __attribute__(( weak, alias("__f") ))
Chris Lattner04d66662007-10-09 17:33:22 +000099 while (Tok.is(tok::identifier) || isDeclarationSpecifier() ||
100 Tok.is(tok::comma)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000101
Chris Lattner04d66662007-10-09 17:33:22 +0000102 if (Tok.is(tok::comma)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000103 // allows for empty/non-empty attributes. ((__vector_size__(16),,,,))
104 ConsumeToken();
105 continue;
106 }
107 // we have an identifier or declaration specifier (const, int, etc.)
108 IdentifierInfo *AttrName = Tok.getIdentifierInfo();
109 SourceLocation AttrNameLoc = ConsumeToken();
110
111 // check if we have a "paramterized" attribute
Chris Lattner04d66662007-10-09 17:33:22 +0000112 if (Tok.is(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000113 ConsumeParen(); // ignore the left paren loc for now
114
Chris Lattner04d66662007-10-09 17:33:22 +0000115 if (Tok.is(tok::identifier)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000116 IdentifierInfo *ParmName = Tok.getIdentifierInfo();
117 SourceLocation ParmLoc = ConsumeToken();
118
Chris Lattner04d66662007-10-09 17:33:22 +0000119 if (Tok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000120 // __attribute__(( mode(byte) ))
121 ConsumeParen(); // ignore the right paren loc for now
122 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
123 ParmName, ParmLoc, 0, 0, CurrAttr);
Chris Lattner04d66662007-10-09 17:33:22 +0000124 } else if (Tok.is(tok::comma)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000125 ConsumeToken();
126 // __attribute__(( format(printf, 1, 2) ))
Sebastian Redla55e52c2008-11-25 22:21:31 +0000127 ExprVector ArgExprs(Actions);
Reid Spencer5f016e22007-07-11 17:01:13 +0000128 bool ArgExprsOk = true;
129
130 // now parse the non-empty comma separated list of expressions
131 while (1) {
Sebastian Redl2f7ece72008-12-11 21:36:32 +0000132 OwningExprResult ArgExpr(ParseAssignmentExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000133 if (ArgExpr.isInvalid()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000134 ArgExprsOk = false;
135 SkipUntil(tok::r_paren);
136 break;
137 } else {
Sebastian Redleffa8d12008-12-10 00:02:53 +0000138 ArgExprs.push_back(ArgExpr.release());
Reid Spencer5f016e22007-07-11 17:01:13 +0000139 }
Chris Lattner04d66662007-10-09 17:33:22 +0000140 if (Tok.isNot(tok::comma))
Reid Spencer5f016e22007-07-11 17:01:13 +0000141 break;
142 ConsumeToken(); // Eat the comma, move to the next argument
143 }
Chris Lattner04d66662007-10-09 17:33:22 +0000144 if (ArgExprsOk && Tok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000145 ConsumeParen(); // ignore the right paren loc for now
146 CurrAttr = new AttributeList(AttrName, AttrNameLoc, ParmName,
Sebastian Redla55e52c2008-11-25 22:21:31 +0000147 ParmLoc, ArgExprs.take(), ArgExprs.size(), CurrAttr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000148 }
149 }
150 } else { // not an identifier
151 // parse a possibly empty comma separated list of expressions
Chris Lattner04d66662007-10-09 17:33:22 +0000152 if (Tok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000153 // __attribute__(( nonnull() ))
154 ConsumeParen(); // ignore the right paren loc for now
155 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
156 0, SourceLocation(), 0, 0, CurrAttr);
157 } else {
158 // __attribute__(( aligned(16) ))
Sebastian Redla55e52c2008-11-25 22:21:31 +0000159 ExprVector ArgExprs(Actions);
Reid Spencer5f016e22007-07-11 17:01:13 +0000160 bool ArgExprsOk = true;
161
162 // now parse the list of expressions
163 while (1) {
Sebastian Redl2f7ece72008-12-11 21:36:32 +0000164 OwningExprResult ArgExpr(ParseAssignmentExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000165 if (ArgExpr.isInvalid()) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000166 ArgExprsOk = false;
167 SkipUntil(tok::r_paren);
168 break;
169 } else {
Sebastian Redleffa8d12008-12-10 00:02:53 +0000170 ArgExprs.push_back(ArgExpr.release());
Reid Spencer5f016e22007-07-11 17:01:13 +0000171 }
Chris Lattner04d66662007-10-09 17:33:22 +0000172 if (Tok.isNot(tok::comma))
Reid Spencer5f016e22007-07-11 17:01:13 +0000173 break;
174 ConsumeToken(); // Eat the comma, move to the next argument
175 }
176 // Match the ')'.
Chris Lattner04d66662007-10-09 17:33:22 +0000177 if (ArgExprsOk && Tok.is(tok::r_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000178 ConsumeParen(); // ignore the right paren loc for now
Sebastian Redla55e52c2008-11-25 22:21:31 +0000179 CurrAttr = new AttributeList(AttrName, AttrNameLoc, 0,
180 SourceLocation(), ArgExprs.take(), ArgExprs.size(),
Reid Spencer5f016e22007-07-11 17:01:13 +0000181 CurrAttr);
182 }
183 }
184 }
185 } else {
186 CurrAttr = new AttributeList(AttrName, AttrNameLoc,
187 0, SourceLocation(), 0, 0, CurrAttr);
188 }
189 }
190 if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
Reid Spencer5f016e22007-07-11 17:01:13 +0000191 SkipUntil(tok::r_paren, false);
Sebastian Redlab197ba2009-02-09 18:23:29 +0000192 SourceLocation Loc = Tok.getLocation();;
193 if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen)) {
194 SkipUntil(tok::r_paren, false);
195 }
196 if (EndLoc)
197 *EndLoc = Loc;
Reid Spencer5f016e22007-07-11 17:01:13 +0000198 }
199 return CurrAttr;
200}
201
Steve Narofff59e17e2008-12-24 20:59:21 +0000202/// FuzzyParseMicrosoftDeclSpec. When -fms-extensions is enabled, this
203/// routine is called to skip/ignore tokens that comprise the MS declspec.
204void Parser::FuzzyParseMicrosoftDeclSpec() {
205 assert(Tok.is(tok::kw___declspec) && "Not a declspec!");
206 ConsumeToken();
207 if (Tok.is(tok::l_paren)) {
208 unsigned short savedParenCount = ParenCount;
209 do {
210 ConsumeAnyToken();
211 } while (ParenCount > savedParenCount && Tok.isNot(tok::eof));
212 }
213 return;
214}
215
Reid Spencer5f016e22007-07-11 17:01:13 +0000216/// ParseDeclaration - Parse a full 'declaration', which consists of
217/// declaration-specifiers, some number of declarators, and a semicolon.
Chris Lattner97144fc2009-04-02 04:16:50 +0000218/// 'Context' should be a Declarator::TheContext value. This returns the
219/// location of the semicolon in DeclEnd.
Chris Lattner8f08cb72007-08-25 06:57:03 +0000220///
221/// declaration: [C99 6.7]
222/// block-declaration ->
223/// simple-declaration
224/// others [FIXME]
Douglas Gregoradcac882008-12-01 23:54:00 +0000225/// [C++] template-declaration
Chris Lattner8f08cb72007-08-25 06:57:03 +0000226/// [C++] namespace-definition
Douglas Gregorf780abc2008-12-30 03:27:21 +0000227/// [C++] using-directive
228/// [C++] using-declaration [TODO]
Sebastian Redl50de12f2009-03-24 22:27:57 +0000229/// [C++0x] static_assert-declaration
Chris Lattner8f08cb72007-08-25 06:57:03 +0000230/// others... [FIXME]
231///
Chris Lattner97144fc2009-04-02 04:16:50 +0000232Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context,
233 SourceLocation &DeclEnd) {
Chris Lattner682bf922009-03-29 16:50:03 +0000234 DeclPtrTy SingleDecl;
Chris Lattner8f08cb72007-08-25 06:57:03 +0000235 switch (Tok.getKind()) {
Douglas Gregoradcac882008-12-01 23:54:00 +0000236 case tok::kw_export:
237 case tok::kw_template:
Chris Lattner97144fc2009-04-02 04:16:50 +0000238 SingleDecl = ParseTemplateDeclarationOrSpecialization(Context, DeclEnd);
Chris Lattner682bf922009-03-29 16:50:03 +0000239 break;
Chris Lattner8f08cb72007-08-25 06:57:03 +0000240 case tok::kw_namespace:
Chris Lattner97144fc2009-04-02 04:16:50 +0000241 SingleDecl = ParseNamespace(Context, DeclEnd);
Chris Lattner682bf922009-03-29 16:50:03 +0000242 break;
Douglas Gregorf780abc2008-12-30 03:27:21 +0000243 case tok::kw_using:
Chris Lattner97144fc2009-04-02 04:16:50 +0000244 SingleDecl = ParseUsingDirectiveOrDeclaration(Context, DeclEnd);
Chris Lattner682bf922009-03-29 16:50:03 +0000245 break;
Anders Carlsson511d7ab2009-03-11 16:27:10 +0000246 case tok::kw_static_assert:
Chris Lattner97144fc2009-04-02 04:16:50 +0000247 SingleDecl = ParseStaticAssertDeclaration(DeclEnd);
Chris Lattner682bf922009-03-29 16:50:03 +0000248 break;
Chris Lattner8f08cb72007-08-25 06:57:03 +0000249 default:
Chris Lattner97144fc2009-04-02 04:16:50 +0000250 return ParseSimpleDeclaration(Context, DeclEnd);
Chris Lattner8f08cb72007-08-25 06:57:03 +0000251 }
Chris Lattner682bf922009-03-29 16:50:03 +0000252
253 // This routine returns a DeclGroup, if the thing we parsed only contains a
254 // single decl, convert it now.
255 return Actions.ConvertDeclToDeclGroup(SingleDecl);
Chris Lattner8f08cb72007-08-25 06:57:03 +0000256}
257
258/// simple-declaration: [C99 6.7: declaration] [C++ 7p1: dcl.dcl]
259/// declaration-specifiers init-declarator-list[opt] ';'
260///[C90/C++]init-declarator-list ';' [TODO]
261/// [OMP] threadprivate-directive [TODO]
Chris Lattnercd147752009-03-29 17:27:48 +0000262///
263/// If RequireSemi is false, this does not check for a ';' at the end of the
264/// declaration.
265Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration(unsigned Context,
Chris Lattner97144fc2009-04-02 04:16:50 +0000266 SourceLocation &DeclEnd,
Chris Lattnercd147752009-03-29 17:27:48 +0000267 bool RequireSemi) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000268 // Parse the common declaration-specifiers piece.
269 DeclSpec DS;
270 ParseDeclarationSpecifiers(DS);
271
272 // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
273 // declaration-specifiers init-declarator-list[opt] ';'
Chris Lattner04d66662007-10-09 17:33:22 +0000274 if (Tok.is(tok::semi)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000275 ConsumeToken();
Chris Lattner682bf922009-03-29 16:50:03 +0000276 DeclPtrTy TheDecl = Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
277 return Actions.ConvertDeclToDeclGroup(TheDecl);
Reid Spencer5f016e22007-07-11 17:01:13 +0000278 }
279
280 Declarator DeclaratorInfo(DS, (Declarator::TheContext)Context);
281 ParseDeclarator(DeclaratorInfo);
282
Chris Lattner23c4b182009-03-29 17:18:04 +0000283 DeclGroupPtrTy DG =
284 ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo);
Chris Lattnercd147752009-03-29 17:27:48 +0000285
Chris Lattner97144fc2009-04-02 04:16:50 +0000286 DeclEnd = Tok.getLocation();
287
Chris Lattnercd147752009-03-29 17:27:48 +0000288 // If the client wants to check what comes after the declaration, just return
289 // immediately without checking anything!
290 if (!RequireSemi) return DG;
Chris Lattner23c4b182009-03-29 17:18:04 +0000291
292 if (Tok.is(tok::semi)) {
293 ConsumeToken();
Chris Lattner23c4b182009-03-29 17:18:04 +0000294 return DG;
295 }
296
Chris Lattner23c4b182009-03-29 17:18:04 +0000297 Diag(Tok, diag::err_expected_semi_declation);
298 // Skip to end of block or statement
299 SkipUntil(tok::r_brace, true, true);
300 if (Tok.is(tok::semi))
301 ConsumeToken();
302 return DG;
Reid Spencer5f016e22007-07-11 17:01:13 +0000303}
304
Chris Lattner8f08cb72007-08-25 06:57:03 +0000305
Reid Spencer5f016e22007-07-11 17:01:13 +0000306/// ParseInitDeclaratorListAfterFirstDeclarator - Parse 'declaration' after
307/// parsing 'declaration-specifiers declarator'. This method is split out this
308/// way to handle the ambiguity between top-level function-definitions and
309/// declarations.
310///
Reid Spencer5f016e22007-07-11 17:01:13 +0000311/// init-declarator-list: [C99 6.7]
312/// init-declarator
313/// init-declarator-list ',' init-declarator
314/// init-declarator: [C99 6.7]
315/// declarator
316/// declarator '=' initializer
317/// [GNU] declarator simple-asm-expr[opt] attributes[opt]
318/// [GNU] declarator simple-asm-expr[opt] attributes[opt] '=' initializer
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000319/// [C++] declarator initializer[opt]
320///
321/// [C++] initializer:
322/// [C++] '=' initializer-clause
323/// [C++] '(' expression-list ')'
Sebastian Redl50de12f2009-03-24 22:27:57 +0000324/// [C++0x] '=' 'default' [TODO]
325/// [C++0x] '=' 'delete'
326///
327/// According to the standard grammar, =default and =delete are function
328/// definitions, but that definitely doesn't fit with the parser here.
Reid Spencer5f016e22007-07-11 17:01:13 +0000329///
Chris Lattner682bf922009-03-29 16:50:03 +0000330Parser::DeclGroupPtrTy Parser::
Reid Spencer5f016e22007-07-11 17:01:13 +0000331ParseInitDeclaratorListAfterFirstDeclarator(Declarator &D) {
Chris Lattner682bf922009-03-29 16:50:03 +0000332 // Declarators may be grouped together ("int X, *Y, Z();"). Remember the decls
333 // that we parse together here.
334 llvm::SmallVector<DeclPtrTy, 8> DeclsInGroup;
Reid Spencer5f016e22007-07-11 17:01:13 +0000335
336 // At this point, we know that it is not a function definition. Parse the
337 // rest of the init-declarator-list.
338 while (1) {
339 // If a simple-asm-expr is present, parse it.
Daniel Dunbara80f8742008-08-05 01:35:17 +0000340 if (Tok.is(tok::kw_asm)) {
Sebastian Redlab197ba2009-02-09 18:23:29 +0000341 SourceLocation Loc;
342 OwningExprResult AsmLabel(ParseSimpleAsm(&Loc));
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000343 if (AsmLabel.isInvalid()) {
Chris Lattner23c4b182009-03-29 17:18:04 +0000344 SkipUntil(tok::semi, true, true);
Chris Lattner682bf922009-03-29 16:50:03 +0000345 return DeclGroupPtrTy();
Daniel Dunbara80f8742008-08-05 01:35:17 +0000346 }
Sebastian Redlab197ba2009-02-09 18:23:29 +0000347
Sebastian Redleffa8d12008-12-10 00:02:53 +0000348 D.setAsmLabel(AsmLabel.release());
Sebastian Redlab197ba2009-02-09 18:23:29 +0000349 D.SetRangeEnd(Loc);
Daniel Dunbara80f8742008-08-05 01:35:17 +0000350 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000351
352 // If attributes are present, parse them.
Sebastian Redlab197ba2009-02-09 18:23:29 +0000353 if (Tok.is(tok::kw___attribute)) {
354 SourceLocation Loc;
355 AttributeList *AttrList = ParseAttributes(&Loc);
356 D.AddAttributes(AttrList, Loc);
357 }
Steve Naroffbb204692007-09-12 14:07:44 +0000358
359 // Inform the current actions module that we just parsed this declarator.
Chris Lattner682bf922009-03-29 16:50:03 +0000360 DeclPtrTy ThisDecl = Actions.ActOnDeclarator(CurScope, D);
361 DeclsInGroup.push_back(ThisDecl);
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000362
Reid Spencer5f016e22007-07-11 17:01:13 +0000363 // Parse declarator '=' initializer.
Chris Lattner04d66662007-10-09 17:33:22 +0000364 if (Tok.is(tok::equal)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000365 ConsumeToken();
Sebastian Redl50de12f2009-03-24 22:27:57 +0000366 if (getLang().CPlusPlus0x && Tok.is(tok::kw_delete)) {
367 SourceLocation DelLoc = ConsumeToken();
Chris Lattner682bf922009-03-29 16:50:03 +0000368 Actions.SetDeclDeleted(ThisDecl, DelLoc);
Sebastian Redl50de12f2009-03-24 22:27:57 +0000369 } else {
370 OwningExprResult Init(ParseInitializer());
371 if (Init.isInvalid()) {
Chris Lattner23c4b182009-03-29 17:18:04 +0000372 SkipUntil(tok::semi, true, true);
Chris Lattner682bf922009-03-29 16:50:03 +0000373 return DeclGroupPtrTy();
Sebastian Redl50de12f2009-03-24 22:27:57 +0000374 }
Chris Lattner682bf922009-03-29 16:50:03 +0000375 Actions.AddInitializerToDecl(ThisDecl, move(Init));
Reid Spencer5f016e22007-07-11 17:01:13 +0000376 }
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000377 } else if (Tok.is(tok::l_paren)) {
378 // Parse C++ direct initializer: '(' expression-list ')'
379 SourceLocation LParenLoc = ConsumeParen();
Sebastian Redla55e52c2008-11-25 22:21:31 +0000380 ExprVector Exprs(Actions);
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000381 CommaLocsTy CommaLocs;
382
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000383 if (ParseExpressionList(Exprs, CommaLocs)) {
384 SkipUntil(tok::r_paren);
Chris Lattner8129edb2009-04-12 22:23:27 +0000385 } else {
386 // Match the ')'.
387 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000388
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000389 assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() &&
390 "Unexpected number of commas!");
Chris Lattner682bf922009-03-29 16:50:03 +0000391 Actions.AddCXXDirectInitializerToDecl(ThisDecl, LParenLoc,
Sebastian Redlf53597f2009-03-15 17:47:39 +0000392 move_arg(Exprs),
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000393 &CommaLocs[0], RParenLoc);
394 }
Douglas Gregor27c8dc02008-10-29 00:13:59 +0000395 } else {
Chris Lattner682bf922009-03-29 16:50:03 +0000396 Actions.ActOnUninitializedDecl(ThisDecl);
Reid Spencer5f016e22007-07-11 17:01:13 +0000397 }
398
Reid Spencer5f016e22007-07-11 17:01:13 +0000399 // If we don't have a comma, it is either the end of the list (a ';') or an
400 // error, bail out.
Chris Lattner04d66662007-10-09 17:33:22 +0000401 if (Tok.isNot(tok::comma))
Reid Spencer5f016e22007-07-11 17:01:13 +0000402 break;
403
404 // Consume the comma.
405 ConsumeToken();
406
407 // Parse the next declarator.
408 D.clear();
Chris Lattneraab740a2008-10-20 04:57:38 +0000409
410 // Accept attributes in an init-declarator. In the first declarator in a
411 // declaration, these would be part of the declspec. In subsequent
412 // declarators, they become part of the declarator itself, so that they
413 // don't apply to declarators after *this* one. Examples:
414 // short __attribute__((common)) var; -> declspec
415 // short var __attribute__((common)); -> declarator
416 // short x, __attribute__((common)) var; -> declarator
Sebastian Redlab197ba2009-02-09 18:23:29 +0000417 if (Tok.is(tok::kw___attribute)) {
418 SourceLocation Loc;
419 AttributeList *AttrList = ParseAttributes(&Loc);
420 D.AddAttributes(AttrList, Loc);
421 }
Chris Lattneraab740a2008-10-20 04:57:38 +0000422
Reid Spencer5f016e22007-07-11 17:01:13 +0000423 ParseDeclarator(D);
424 }
425
Chris Lattner23c4b182009-03-29 17:18:04 +0000426 return Actions.FinalizeDeclaratorGroup(CurScope, &DeclsInGroup[0],
427 DeclsInGroup.size());
Reid Spencer5f016e22007-07-11 17:01:13 +0000428}
429
430/// ParseSpecifierQualifierList
431/// specifier-qualifier-list:
432/// type-specifier specifier-qualifier-list[opt]
433/// type-qualifier specifier-qualifier-list[opt]
434/// [GNU] attributes specifier-qualifier-list[opt]
435///
436void Parser::ParseSpecifierQualifierList(DeclSpec &DS) {
437 /// specifier-qualifier-list is a subset of declaration-specifiers. Just
438 /// parse declaration-specifiers and complain about extra stuff.
Reid Spencer5f016e22007-07-11 17:01:13 +0000439 ParseDeclarationSpecifiers(DS);
440
441 // Validate declspec for type-name.
442 unsigned Specs = DS.getParsedSpecifiers();
Chris Lattnerb6645dd2009-04-14 21:16:09 +0000443 if (Specs == DeclSpec::PQ_None && !DS.getNumProtocolQualifiers() &&
444 !DS.getAttributes())
Reid Spencer5f016e22007-07-11 17:01:13 +0000445 Diag(Tok, diag::err_typename_requires_specqual);
446
447 // Issue diagnostic and remove storage class if present.
448 if (Specs & DeclSpec::PQ_StorageClassSpecifier) {
449 if (DS.getStorageClassSpecLoc().isValid())
450 Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass);
451 else
452 Diag(DS.getThreadSpecLoc(), diag::err_typename_invalid_storageclass);
453 DS.ClearStorageClassSpecs();
454 }
455
456 // Issue diagnostic and remove function specfier if present.
457 if (Specs & DeclSpec::PQ_FunctionSpecifier) {
Douglas Gregorb48fe382008-10-31 09:07:45 +0000458 if (DS.isInlineSpecified())
459 Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec);
460 if (DS.isVirtualSpecified())
461 Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec);
462 if (DS.isExplicitSpecified())
463 Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec);
Reid Spencer5f016e22007-07-11 17:01:13 +0000464 DS.ClearFunctionSpecs();
465 }
466}
467
Chris Lattnerc199ab32009-04-12 20:42:31 +0000468/// isValidAfterIdentifierInDeclaratorAfterDeclSpec - Return true if the
469/// specified token is valid after the identifier in a declarator which
470/// immediately follows the declspec. For example, these things are valid:
471///
472/// int x [ 4]; // direct-declarator
473/// int x ( int y); // direct-declarator
474/// int(int x ) // direct-declarator
475/// int x ; // simple-declaration
476/// int x = 17; // init-declarator-list
477/// int x , y; // init-declarator-list
478/// int x __asm__ ("foo"); // init-declarator-list
Chris Lattnerb6645dd2009-04-14 21:16:09 +0000479/// int x : 4; // struct-declarator
Chris Lattnerc83c27a2009-04-12 22:29:43 +0000480/// int x { 5}; // C++'0x unified initializers
Chris Lattnerc199ab32009-04-12 20:42:31 +0000481///
482/// This is not, because 'x' does not immediately follow the declspec (though
483/// ')' happens to be valid anyway).
484/// int (x)
485///
486static bool isValidAfterIdentifierInDeclarator(const Token &T) {
487 return T.is(tok::l_square) || T.is(tok::l_paren) || T.is(tok::r_paren) ||
488 T.is(tok::semi) || T.is(tok::comma) || T.is(tok::equal) ||
Chris Lattnerb6645dd2009-04-14 21:16:09 +0000489 T.is(tok::kw_asm) || T.is(tok::l_brace) || T.is(tok::colon);
Chris Lattnerc199ab32009-04-12 20:42:31 +0000490}
491
Chris Lattnere40c2952009-04-14 21:34:55 +0000492
493/// ParseImplicitInt - This method is called when we have an non-typename
494/// identifier in a declspec (which normally terminates the decl spec) when
495/// the declspec has no type specifier. In this case, the declspec is either
496/// malformed or is "implicit int" (in K&R and C89).
497///
498/// This method handles diagnosing this prettily and returns false if the
499/// declspec is done being processed. If it recovers and thinks there may be
500/// other pieces of declspec after it, it returns true.
501///
502bool Parser::ParseImplicitInt(DeclSpec &DS,
503 TemplateParameterLists *TemplateParams,
504 AccessSpecifier AS) {
505 SourceLocation Loc = Tok.getLocation();
506 // If we see an identifier that is not a type name, we normally would
507 // parse it as the identifer being declared. However, when a typename
508 // is typo'd or the definition is not included, this will incorrectly
509 // parse the typename as the identifier name and fall over misparsing
510 // later parts of the diagnostic.
511 //
512 // As such, we try to do some look-ahead in cases where this would
513 // otherwise be an "implicit-int" case to see if this is invalid. For
514 // example: "static foo_t x = 4;" In this case, if we parsed foo_t as
515 // an identifier with implicit int, we'd get a parse error because the
516 // next token is obviously invalid for a type. Parse these as a case
517 // with an invalid type specifier.
518 assert(!DS.hasTypeSpecifier() && "Type specifier checked above");
519
520 // Since we know that this either implicit int (which is rare) or an
521 // error, we'd do lookahead to try to do better recovery.
522 if (isValidAfterIdentifierInDeclarator(NextToken())) {
523 // If this token is valid for implicit int, e.g. "static x = 4", then
524 // we just avoid eating the identifier, so it will be parsed as the
525 // identifier in the declarator.
526 return false;
527 }
528
529 // Otherwise, if we don't consume this token, we are going to emit an
530 // error anyway. Try to recover from various common problems. Check
531 // to see if this was a reference to a tag name without a tag specified.
532 // This is a common problem in C (saying 'foo' instead of 'struct foo').
533 const char *TagName = 0;
534 tok::TokenKind TagKind = tok::unknown;
535
536 if (Tok.is(tok::identifier)) {
537 switch (Actions.isTagName(*Tok.getIdentifierInfo(), CurScope)) {
538 default: break;
539 case DeclSpec::TST_enum: TagName="enum" ;TagKind=tok::kw_enum ;break;
540 case DeclSpec::TST_union: TagName="union" ;TagKind=tok::kw_union ;break;
541 case DeclSpec::TST_struct:TagName="struct";TagKind=tok::kw_struct;break;
542 case DeclSpec::TST_class: TagName="class" ;TagKind=tok::kw_class ;break;
543 }
544 }
545
546 if (TagName) {
547 Diag(Loc, diag::err_use_of_tag_name_without_tag)
548 << Tok.getIdentifierInfo() << TagName
549 << CodeModificationHint::CreateInsertion(Tok.getLocation(),TagName);
550
551 // Parse this as a tag as if the missing tag were present.
552 if (TagKind == tok::kw_enum)
553 ParseEnumSpecifier(Loc, DS, AS);
554 else
555 ParseClassSpecifier(TagKind, Loc, DS, TemplateParams, AS);
556 return true;
557 }
558
559 // Since this is almost certainly an invalid type name, emit a
560 // diagnostic that says it, eat the token, and mark the declspec as
561 // invalid.
562 Diag(Loc, diag::err_unknown_typename) << Tok.getIdentifierInfo();
563 const char *PrevSpec;
564 DS.SetTypeSpecType(DeclSpec::TST_error, Loc, PrevSpec);
565 DS.SetRangeEnd(Tok.getLocation());
566 ConsumeToken();
567
568 // TODO: Could inject an invalid typedef decl in an enclosing scope to
569 // avoid rippling error messages on subsequent uses of the same type,
570 // could be useful if #include was forgotten.
571 return false;
572}
573
Reid Spencer5f016e22007-07-11 17:01:13 +0000574/// ParseDeclarationSpecifiers
575/// declaration-specifiers: [C99 6.7]
576/// storage-class-specifier declaration-specifiers[opt]
577/// type-specifier declaration-specifiers[opt]
Reid Spencer5f016e22007-07-11 17:01:13 +0000578/// [C99] function-specifier declaration-specifiers[opt]
579/// [GNU] attributes declaration-specifiers[opt]
580///
581/// storage-class-specifier: [C99 6.7.1]
582/// 'typedef'
583/// 'extern'
584/// 'static'
585/// 'auto'
586/// 'register'
Sebastian Redl669d5d72008-11-14 23:42:31 +0000587/// [C++] 'mutable'
Reid Spencer5f016e22007-07-11 17:01:13 +0000588/// [GNU] '__thread'
Reid Spencer5f016e22007-07-11 17:01:13 +0000589/// function-specifier: [C99 6.7.4]
590/// [C99] 'inline'
Douglas Gregorb48fe382008-10-31 09:07:45 +0000591/// [C++] 'virtual'
592/// [C++] 'explicit'
Reid Spencer5f016e22007-07-11 17:01:13 +0000593///
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000594void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
Douglas Gregor06c0fec2009-03-25 22:00:53 +0000595 TemplateParameterLists *TemplateParams,
Chris Lattnerc199ab32009-04-12 20:42:31 +0000596 AccessSpecifier AS) {
Chris Lattner81c018d2008-03-13 06:29:04 +0000597 DS.SetRangeStart(Tok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000598 while (1) {
599 int isInvalid = false;
600 const char *PrevSpec = 0;
601 SourceLocation Loc = Tok.getLocation();
Douglas Gregor12e083c2008-11-07 15:42:26 +0000602
Reid Spencer5f016e22007-07-11 17:01:13 +0000603 switch (Tok.getKind()) {
Douglas Gregor12e083c2008-11-07 15:42:26 +0000604 default:
Chris Lattnerbce61352008-07-26 00:20:22 +0000605 DoneWithDeclSpec:
Reid Spencer5f016e22007-07-11 17:01:13 +0000606 // If this is not a declaration specifier token, we're done reading decl
607 // specifiers. First verify that DeclSpec's are consistent.
Douglas Gregor9b3064b2009-04-01 22:41:11 +0000608 DS.Finish(Diags, PP);
Reid Spencer5f016e22007-07-11 17:01:13 +0000609 return;
Chris Lattner5e02c472009-01-05 00:07:25 +0000610
611 case tok::coloncolon: // ::foo::bar
612 // Annotate C++ scope specifiers. If we get one, loop.
613 if (TryAnnotateCXXScopeToken())
614 continue;
615 goto DoneWithDeclSpec;
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000616
617 case tok::annot_cxxscope: {
618 if (DS.hasTypeSpecifier())
619 goto DoneWithDeclSpec;
620
621 // We are looking for a qualified typename.
Douglas Gregor9135c722009-03-25 15:40:00 +0000622 Token Next = NextToken();
623 if (Next.is(tok::annot_template_id) &&
624 static_cast<TemplateIdAnnotation *>(Next.getAnnotationValue())
Douglas Gregorc45c2322009-03-31 00:43:58 +0000625 ->Kind == TNK_Type_template) {
Douglas Gregor9135c722009-03-25 15:40:00 +0000626 // We have a qualified template-id, e.g., N::A<int>
627 CXXScopeSpec SS;
628 ParseOptionalCXXScopeSpecifier(SS);
629 assert(Tok.is(tok::annot_template_id) &&
630 "ParseOptionalCXXScopeSpecifier not working");
631 AnnotateTemplateIdTokenAsType(&SS);
632 continue;
633 }
634
635 if (Next.isNot(tok::identifier))
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000636 goto DoneWithDeclSpec;
637
638 CXXScopeSpec SS;
Douglas Gregor35073692009-03-26 23:56:24 +0000639 SS.setScopeRep(Tok.getAnnotationValue());
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000640 SS.setRange(Tok.getAnnotationRange());
641
642 // If the next token is the name of the class type that the C++ scope
643 // denotes, followed by a '(', then this is a constructor declaration.
644 // We're done with the decl-specifiers.
645 if (Actions.isCurrentClassName(*NextToken().getIdentifierInfo(),
646 CurScope, &SS) &&
647 GetLookAheadToken(2).is(tok::l_paren))
648 goto DoneWithDeclSpec;
649
Douglas Gregorb696ea32009-02-04 17:00:24 +0000650 TypeTy *TypeRep = Actions.getTypeName(*Next.getIdentifierInfo(),
651 Next.getLocation(), CurScope, &SS);
Douglas Gregor55f6b142009-02-09 18:46:07 +0000652
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000653 if (TypeRep == 0)
654 goto DoneWithDeclSpec;
Douglas Gregore4e5b052009-03-19 00:18:19 +0000655
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000656 ConsumeToken(); // The C++ scope.
657
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000658 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000659 TypeRep);
660 if (isInvalid)
661 break;
662
663 DS.SetRangeEnd(Tok.getLocation());
664 ConsumeToken(); // The typename.
665
666 continue;
667 }
Chris Lattner80d0c892009-01-21 19:48:37 +0000668
669 case tok::annot_typename: {
Douglas Gregor31a19b62009-04-01 21:51:26 +0000670 if (Tok.getAnnotationValue())
671 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
672 Tok.getAnnotationValue());
673 else
674 DS.SetTypeSpecError();
Chris Lattner80d0c892009-01-21 19:48:37 +0000675 DS.SetRangeEnd(Tok.getAnnotationEndLoc());
676 ConsumeToken(); // The typename
677
678 // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id'
679 // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an
680 // Objective-C interface. If we don't have Objective-C or a '<', this is
681 // just a normal reference to a typedef name.
682 if (!Tok.is(tok::less) || !getLang().ObjC1)
683 continue;
684
685 SourceLocation EndProtoLoc;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000686 llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
Chris Lattner80d0c892009-01-21 19:48:37 +0000687 ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
688 DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
689
690 DS.SetRangeEnd(EndProtoLoc);
691 continue;
692 }
693
Chris Lattner3bd934a2008-07-26 01:18:38 +0000694 // typedef-name
695 case tok::identifier: {
Chris Lattner5e02c472009-01-05 00:07:25 +0000696 // In C++, check to see if this is a scope specifier like foo::bar::, if
697 // so handle it as such. This is important for ctor parsing.
Chris Lattner837acd02009-01-21 19:19:26 +0000698 if (getLang().CPlusPlus && TryAnnotateCXXScopeToken())
699 continue;
Chris Lattner5e02c472009-01-05 00:07:25 +0000700
Chris Lattner3bd934a2008-07-26 01:18:38 +0000701 // This identifier can only be a typedef name if we haven't already seen
702 // a type-specifier. Without this check we misparse:
703 // typedef int X; struct Y { short X; }; as 'short int'.
704 if (DS.hasTypeSpecifier())
705 goto DoneWithDeclSpec;
706
707 // It has to be available as a typedef too!
Douglas Gregorb696ea32009-02-04 17:00:24 +0000708 TypeTy *TypeRep = Actions.getTypeName(*Tok.getIdentifierInfo(),
709 Tok.getLocation(), CurScope);
Douglas Gregor55f6b142009-02-09 18:46:07 +0000710
Chris Lattnerc199ab32009-04-12 20:42:31 +0000711 // If this is not a typedef name, don't parse it as part of the declspec,
712 // it must be an implicit int or an error.
713 if (TypeRep == 0) {
Chris Lattnere40c2952009-04-14 21:34:55 +0000714 if (ParseImplicitInt(DS, TemplateParams, AS)) continue;
Chris Lattner3bd934a2008-07-26 01:18:38 +0000715 goto DoneWithDeclSpec;
Chris Lattnerc199ab32009-04-12 20:42:31 +0000716 }
Douglas Gregor55f6b142009-02-09 18:46:07 +0000717
Douglas Gregorb48fe382008-10-31 09:07:45 +0000718 // C++: If the identifier is actually the name of the class type
719 // being defined and the next token is a '(', then this is a
720 // constructor declaration. We're done with the decl-specifiers
721 // and will treat this token as an identifier.
Chris Lattnerc199ab32009-04-12 20:42:31 +0000722 if (getLang().CPlusPlus && CurScope->isClassScope() &&
Douglas Gregorb48fe382008-10-31 09:07:45 +0000723 Actions.isCurrentClassName(*Tok.getIdentifierInfo(), CurScope) &&
724 NextToken().getKind() == tok::l_paren)
725 goto DoneWithDeclSpec;
726
Douglas Gregor1a51b4a2009-02-09 15:09:02 +0000727 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
Chris Lattner3bd934a2008-07-26 01:18:38 +0000728 TypeRep);
729 if (isInvalid)
730 break;
731
732 DS.SetRangeEnd(Tok.getLocation());
733 ConsumeToken(); // The identifier
734
735 // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id'
736 // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an
737 // Objective-C interface. If we don't have Objective-C or a '<', this is
738 // just a normal reference to a typedef name.
739 if (!Tok.is(tok::less) || !getLang().ObjC1)
740 continue;
741
742 SourceLocation EndProtoLoc;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000743 llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
Chris Lattnere13b9592008-07-26 04:03:38 +0000744 ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
Chris Lattnerae4da612008-07-26 01:53:50 +0000745 DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
Chris Lattner3bd934a2008-07-26 01:18:38 +0000746
747 DS.SetRangeEnd(EndProtoLoc);
748
Steve Naroff4f9b9f12008-09-22 10:28:57 +0000749 // Need to support trailing type qualifiers (e.g. "id<p> const").
750 // If a type specifier follows, it will be diagnosed elsewhere.
751 continue;
Chris Lattner3bd934a2008-07-26 01:18:38 +0000752 }
Douglas Gregor39a8de12009-02-25 19:37:18 +0000753
754 // type-name
755 case tok::annot_template_id: {
756 TemplateIdAnnotation *TemplateId
757 = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
Douglas Gregorc45c2322009-03-31 00:43:58 +0000758 if (TemplateId->Kind != TNK_Type_template) {
Douglas Gregor39a8de12009-02-25 19:37:18 +0000759 // This template-id does not refer to a type name, so we're
760 // done with the type-specifiers.
761 goto DoneWithDeclSpec;
762 }
763
764 // Turn the template-id annotation token into a type annotation
765 // token, then try again to parse it as a type-specifier.
Douglas Gregor31a19b62009-04-01 21:51:26 +0000766 AnnotateTemplateIdTokenAsType();
Douglas Gregor39a8de12009-02-25 19:37:18 +0000767 continue;
768 }
769
Reid Spencer5f016e22007-07-11 17:01:13 +0000770 // GNU attributes support.
771 case tok::kw___attribute:
772 DS.AddAttributes(ParseAttributes());
773 continue;
Steve Narofff59e17e2008-12-24 20:59:21 +0000774
775 // Microsoft declspec support.
776 case tok::kw___declspec:
777 if (!PP.getLangOptions().Microsoft)
778 goto DoneWithDeclSpec;
779 FuzzyParseMicrosoftDeclSpec();
780 continue;
Reid Spencer5f016e22007-07-11 17:01:13 +0000781
Steve Naroff239f0732008-12-25 14:16:32 +0000782 // Microsoft single token adornments.
Steve Naroff86bc6cf2008-12-25 14:41:26 +0000783 case tok::kw___forceinline:
784 case tok::kw___w64:
Steve Naroff239f0732008-12-25 14:16:32 +0000785 case tok::kw___cdecl:
786 case tok::kw___stdcall:
787 case tok::kw___fastcall:
788 if (!PP.getLangOptions().Microsoft)
789 goto DoneWithDeclSpec;
790 // Just ignore it.
791 break;
792
Reid Spencer5f016e22007-07-11 17:01:13 +0000793 // storage-class-specifier
794 case tok::kw_typedef:
795 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, Loc, PrevSpec);
796 break;
797 case tok::kw_extern:
798 if (DS.isThreadSpecified())
Chris Lattner1ab3b962008-11-18 07:48:38 +0000799 Diag(Tok, diag::ext_thread_before) << "extern";
Reid Spencer5f016e22007-07-11 17:01:13 +0000800 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_extern, Loc, PrevSpec);
801 break;
Steve Naroff8d54bf22007-12-18 00:16:02 +0000802 case tok::kw___private_extern__:
Chris Lattnerf97409f2008-04-06 06:57:35 +0000803 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_private_extern, Loc,
804 PrevSpec);
Steve Naroff8d54bf22007-12-18 00:16:02 +0000805 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000806 case tok::kw_static:
807 if (DS.isThreadSpecified())
Chris Lattner1ab3b962008-11-18 07:48:38 +0000808 Diag(Tok, diag::ext_thread_before) << "static";
Reid Spencer5f016e22007-07-11 17:01:13 +0000809 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_static, Loc, PrevSpec);
810 break;
811 case tok::kw_auto:
812 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_auto, Loc, PrevSpec);
813 break;
814 case tok::kw_register:
815 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_register, Loc, PrevSpec);
816 break;
Sebastian Redl669d5d72008-11-14 23:42:31 +0000817 case tok::kw_mutable:
818 isInvalid = DS.SetStorageClassSpec(DeclSpec::SCS_mutable, Loc, PrevSpec);
819 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000820 case tok::kw___thread:
821 isInvalid = DS.SetStorageClassSpecThread(Loc, PrevSpec)*2;
822 break;
Douglas Gregor12e083c2008-11-07 15:42:26 +0000823
Reid Spencer5f016e22007-07-11 17:01:13 +0000824 // function-specifier
825 case tok::kw_inline:
826 isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec);
827 break;
Douglas Gregorb48fe382008-10-31 09:07:45 +0000828 case tok::kw_virtual:
829 isInvalid = DS.SetFunctionSpecVirtual(Loc, PrevSpec);
830 break;
Douglas Gregorb48fe382008-10-31 09:07:45 +0000831 case tok::kw_explicit:
832 isInvalid = DS.SetFunctionSpecExplicit(Loc, PrevSpec);
833 break;
Chris Lattner80d0c892009-01-21 19:48:37 +0000834
835 // type-specifier
836 case tok::kw_short:
837 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec);
838 break;
839 case tok::kw_long:
840 if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
841 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec);
842 else
843 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec);
844 break;
845 case tok::kw_signed:
846 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec);
847 break;
848 case tok::kw_unsigned:
849 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec);
850 break;
851 case tok::kw__Complex:
852 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec);
853 break;
854 case tok::kw__Imaginary:
855 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec);
856 break;
857 case tok::kw_void:
858 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec);
859 break;
860 case tok::kw_char:
861 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec);
862 break;
863 case tok::kw_int:
864 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec);
865 break;
866 case tok::kw_float:
867 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec);
868 break;
869 case tok::kw_double:
870 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
871 break;
872 case tok::kw_wchar_t:
873 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec);
874 break;
875 case tok::kw_bool:
876 case tok::kw__Bool:
877 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
878 break;
879 case tok::kw__Decimal32:
880 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec);
881 break;
882 case tok::kw__Decimal64:
883 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec);
884 break;
885 case tok::kw__Decimal128:
886 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec);
887 break;
888
889 // class-specifier:
890 case tok::kw_class:
891 case tok::kw_struct:
Chris Lattner4c97d762009-04-12 21:49:30 +0000892 case tok::kw_union: {
893 tok::TokenKind Kind = Tok.getKind();
894 ConsumeToken();
895 ParseClassSpecifier(Kind, Loc, DS, TemplateParams, AS);
Chris Lattner80d0c892009-01-21 19:48:37 +0000896 continue;
Chris Lattner4c97d762009-04-12 21:49:30 +0000897 }
Chris Lattner80d0c892009-01-21 19:48:37 +0000898
899 // enum-specifier:
900 case tok::kw_enum:
Chris Lattner4c97d762009-04-12 21:49:30 +0000901 ConsumeToken();
902 ParseEnumSpecifier(Loc, DS, AS);
Chris Lattner80d0c892009-01-21 19:48:37 +0000903 continue;
904
905 // cv-qualifier:
906 case tok::kw_const:
907 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec,getLang())*2;
908 break;
909 case tok::kw_volatile:
910 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
911 getLang())*2;
912 break;
913 case tok::kw_restrict:
914 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
915 getLang())*2;
916 break;
917
Douglas Gregord57959a2009-03-27 23:10:48 +0000918 // C++ typename-specifier:
919 case tok::kw_typename:
920 if (TryAnnotateTypeOrScopeToken())
921 continue;
922 break;
923
Chris Lattner80d0c892009-01-21 19:48:37 +0000924 // GNU typeof support.
925 case tok::kw_typeof:
926 ParseTypeofSpecifier(DS);
927 continue;
928
Steve Naroffd3ded1f2008-06-05 00:02:44 +0000929 case tok::less:
Chris Lattner3bd934a2008-07-26 01:18:38 +0000930 // GCC ObjC supports types like "<SomeProtocol>" as a synonym for
Chris Lattnerbce61352008-07-26 00:20:22 +0000931 // "id<SomeProtocol>". This is hopelessly old fashioned and dangerous,
932 // but we support it.
Chris Lattner3bd934a2008-07-26 01:18:38 +0000933 if (DS.hasTypeSpecifier() || !getLang().ObjC1)
Chris Lattnerbce61352008-07-26 00:20:22 +0000934 goto DoneWithDeclSpec;
935
936 {
937 SourceLocation EndProtoLoc;
Chris Lattnerb28317a2009-03-28 19:18:32 +0000938 llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
Chris Lattnere13b9592008-07-26 04:03:38 +0000939 ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
Chris Lattnerae4da612008-07-26 01:53:50 +0000940 DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
Chris Lattner3bd934a2008-07-26 01:18:38 +0000941 DS.SetRangeEnd(EndProtoLoc);
942
Chris Lattner1ab3b962008-11-18 07:48:38 +0000943 Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id)
Chris Lattner75e36062009-04-03 18:38:42 +0000944 << CodeModificationHint::CreateInsertion(Loc, "id")
Chris Lattner1ab3b962008-11-18 07:48:38 +0000945 << SourceRange(Loc, EndProtoLoc);
Steve Naroff4f9b9f12008-09-22 10:28:57 +0000946 // Need to support trailing type qualifiers (e.g. "id<p> const").
947 // If a type specifier follows, it will be diagnosed elsewhere.
948 continue;
Steve Naroffd3ded1f2008-06-05 00:02:44 +0000949 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000950 }
951 // If the specifier combination wasn't legal, issue a diagnostic.
952 if (isInvalid) {
953 assert(PrevSpec && "Method did not return previous specifier!");
Chris Lattner1ab3b962008-11-18 07:48:38 +0000954 // Pick between error or extwarn.
955 unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
956 : diag::ext_duplicate_declspec;
957 Diag(Tok, DiagID) << PrevSpec;
Reid Spencer5f016e22007-07-11 17:01:13 +0000958 }
Chris Lattner81c018d2008-03-13 06:29:04 +0000959 DS.SetRangeEnd(Tok.getLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +0000960 ConsumeToken();
961 }
962}
Douglas Gregoradcac882008-12-01 23:54:00 +0000963
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000964/// ParseOptionalTypeSpecifier - Try to parse a single type-specifier. We
Douglas Gregor12e083c2008-11-07 15:42:26 +0000965/// primarily follow the C++ grammar with additions for C99 and GNU,
966/// which together subsume the C grammar. Note that the C++
967/// type-specifier also includes the C type-qualifier (for const,
968/// volatile, and C99 restrict). Returns true if a type-specifier was
969/// found (and parsed), false otherwise.
970///
971/// type-specifier: [C++ 7.1.5]
972/// simple-type-specifier
973/// class-specifier
974/// enum-specifier
975/// elaborated-type-specifier [TODO]
976/// cv-qualifier
977///
978/// cv-qualifier: [C++ 7.1.5.1]
979/// 'const'
980/// 'volatile'
981/// [C99] 'restrict'
982///
983/// simple-type-specifier: [ C++ 7.1.5.2]
984/// '::'[opt] nested-name-specifier[opt] type-name [TODO]
985/// '::'[opt] nested-name-specifier 'template' template-id [TODO]
986/// 'char'
987/// 'wchar_t'
988/// 'bool'
989/// 'short'
990/// 'int'
991/// 'long'
992/// 'signed'
993/// 'unsigned'
994/// 'float'
995/// 'double'
996/// 'void'
997/// [C99] '_Bool'
998/// [C99] '_Complex'
999/// [C99] '_Imaginary' // Removed in TC2?
1000/// [GNU] '_Decimal32'
1001/// [GNU] '_Decimal64'
1002/// [GNU] '_Decimal128'
1003/// [GNU] typeof-specifier
1004/// [OBJC] class-name objc-protocol-refs[opt] [TODO]
1005/// [OBJC] typedef-name objc-protocol-refs[opt] [TODO]
Chris Lattner7a0ab5f2009-01-06 06:59:53 +00001006bool Parser::ParseOptionalTypeSpecifier(DeclSpec &DS, int& isInvalid,
1007 const char *&PrevSpec,
1008 TemplateParameterLists *TemplateParams){
Douglas Gregor12e083c2008-11-07 15:42:26 +00001009 SourceLocation Loc = Tok.getLocation();
1010
1011 switch (Tok.getKind()) {
Chris Lattner166a8fc2009-01-04 23:41:41 +00001012 case tok::identifier: // foo::bar
Douglas Gregord57959a2009-03-27 23:10:48 +00001013 case tok::kw_typename: // typename foo::bar
Chris Lattner166a8fc2009-01-04 23:41:41 +00001014 // Annotate typenames and C++ scope specifiers. If we get one, just
1015 // recurse to handle whatever we get.
1016 if (TryAnnotateTypeOrScopeToken())
Chris Lattner7a0ab5f2009-01-06 06:59:53 +00001017 return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec,TemplateParams);
Chris Lattner166a8fc2009-01-04 23:41:41 +00001018 // Otherwise, not a type specifier.
1019 return false;
1020 case tok::coloncolon: // ::foo::bar
1021 if (NextToken().is(tok::kw_new) || // ::new
1022 NextToken().is(tok::kw_delete)) // ::delete
1023 return false;
1024
1025 // Annotate typenames and C++ scope specifiers. If we get one, just
1026 // recurse to handle whatever we get.
1027 if (TryAnnotateTypeOrScopeToken())
Chris Lattner7a0ab5f2009-01-06 06:59:53 +00001028 return ParseOptionalTypeSpecifier(DS, isInvalid, PrevSpec,TemplateParams);
Chris Lattner166a8fc2009-01-04 23:41:41 +00001029 // Otherwise, not a type specifier.
1030 return false;
1031
Douglas Gregor12e083c2008-11-07 15:42:26 +00001032 // simple-type-specifier:
Chris Lattnerb31757b2009-01-06 05:06:21 +00001033 case tok::annot_typename: {
Douglas Gregor31a19b62009-04-01 21:51:26 +00001034 if (Tok.getAnnotationValue())
1035 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec,
1036 Tok.getAnnotationValue());
1037 else
1038 DS.SetTypeSpecError();
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001039 DS.SetRangeEnd(Tok.getAnnotationEndLoc());
1040 ConsumeToken(); // The typename
Douglas Gregor12e083c2008-11-07 15:42:26 +00001041
1042 // Objective-C supports syntax of the form 'id<proto1,proto2>' where 'id'
1043 // is a specific typedef and 'itf<proto1,proto2>' where 'itf' is an
1044 // Objective-C interface. If we don't have Objective-C or a '<', this is
1045 // just a normal reference to a typedef name.
1046 if (!Tok.is(tok::less) || !getLang().ObjC1)
1047 return true;
1048
1049 SourceLocation EndProtoLoc;
Chris Lattnerb28317a2009-03-28 19:18:32 +00001050 llvm::SmallVector<DeclPtrTy, 8> ProtocolDecl;
Douglas Gregor12e083c2008-11-07 15:42:26 +00001051 ParseObjCProtocolReferences(ProtocolDecl, false, EndProtoLoc);
1052 DS.setProtocolQualifiers(&ProtocolDecl[0], ProtocolDecl.size());
1053
1054 DS.SetRangeEnd(EndProtoLoc);
1055 return true;
1056 }
1057
1058 case tok::kw_short:
1059 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec);
1060 break;
1061 case tok::kw_long:
1062 if (DS.getTypeSpecWidth() != DeclSpec::TSW_long)
1063 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec);
1064 else
1065 isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec);
1066 break;
1067 case tok::kw_signed:
1068 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec);
1069 break;
1070 case tok::kw_unsigned:
1071 isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec);
1072 break;
1073 case tok::kw__Complex:
1074 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec);
1075 break;
1076 case tok::kw__Imaginary:
1077 isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec);
1078 break;
1079 case tok::kw_void:
1080 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec);
1081 break;
1082 case tok::kw_char:
1083 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec);
1084 break;
1085 case tok::kw_int:
1086 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec);
1087 break;
1088 case tok::kw_float:
1089 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec);
1090 break;
1091 case tok::kw_double:
1092 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec);
1093 break;
1094 case tok::kw_wchar_t:
1095 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec);
1096 break;
1097 case tok::kw_bool:
1098 case tok::kw__Bool:
1099 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec);
1100 break;
1101 case tok::kw__Decimal32:
1102 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec);
1103 break;
1104 case tok::kw__Decimal64:
1105 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec);
1106 break;
1107 case tok::kw__Decimal128:
1108 isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec);
1109 break;
1110
1111 // class-specifier:
1112 case tok::kw_class:
1113 case tok::kw_struct:
Chris Lattner4c97d762009-04-12 21:49:30 +00001114 case tok::kw_union: {
1115 tok::TokenKind Kind = Tok.getKind();
1116 ConsumeToken();
1117 ParseClassSpecifier(Kind, Loc, DS, TemplateParams);
Douglas Gregor12e083c2008-11-07 15:42:26 +00001118 return true;
Chris Lattner4c97d762009-04-12 21:49:30 +00001119 }
Douglas Gregor12e083c2008-11-07 15:42:26 +00001120
1121 // enum-specifier:
1122 case tok::kw_enum:
Chris Lattner4c97d762009-04-12 21:49:30 +00001123 ConsumeToken();
1124 ParseEnumSpecifier(Loc, DS);
Douglas Gregor12e083c2008-11-07 15:42:26 +00001125 return true;
1126
1127 // cv-qualifier:
1128 case tok::kw_const:
1129 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
1130 getLang())*2;
1131 break;
1132 case tok::kw_volatile:
1133 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
1134 getLang())*2;
1135 break;
1136 case tok::kw_restrict:
1137 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
1138 getLang())*2;
1139 break;
1140
1141 // GNU typeof support.
1142 case tok::kw_typeof:
1143 ParseTypeofSpecifier(DS);
1144 return true;
1145
Steve Naroff239f0732008-12-25 14:16:32 +00001146 case tok::kw___cdecl:
1147 case tok::kw___stdcall:
1148 case tok::kw___fastcall:
Chris Lattner837acd02009-01-21 19:19:26 +00001149 if (!PP.getLangOptions().Microsoft) return false;
1150 ConsumeToken();
1151 return true;
Steve Naroff239f0732008-12-25 14:16:32 +00001152
Douglas Gregor12e083c2008-11-07 15:42:26 +00001153 default:
1154 // Not a type-specifier; do nothing.
1155 return false;
1156 }
1157
1158 // If the specifier combination wasn't legal, issue a diagnostic.
1159 if (isInvalid) {
1160 assert(PrevSpec && "Method did not return previous specifier!");
Chris Lattner1ab3b962008-11-18 07:48:38 +00001161 // Pick between error or extwarn.
1162 unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
1163 : diag::ext_duplicate_declspec;
1164 Diag(Tok, DiagID) << PrevSpec;
Douglas Gregor12e083c2008-11-07 15:42:26 +00001165 }
1166 DS.SetRangeEnd(Tok.getLocation());
1167 ConsumeToken(); // whatever we parsed above.
1168 return true;
1169}
Reid Spencer5f016e22007-07-11 17:01:13 +00001170
Chris Lattnercd4b83c2007-10-29 04:42:53 +00001171/// ParseStructDeclaration - Parse a struct declaration without the terminating
1172/// semicolon.
1173///
Reid Spencer5f016e22007-07-11 17:01:13 +00001174/// struct-declaration:
Chris Lattnercd4b83c2007-10-29 04:42:53 +00001175/// specifier-qualifier-list struct-declarator-list
Reid Spencer5f016e22007-07-11 17:01:13 +00001176/// [GNU] __extension__ struct-declaration
Chris Lattnercd4b83c2007-10-29 04:42:53 +00001177/// [GNU] specifier-qualifier-list
Reid Spencer5f016e22007-07-11 17:01:13 +00001178/// struct-declarator-list:
1179/// struct-declarator
1180/// struct-declarator-list ',' struct-declarator
1181/// [GNU] struct-declarator-list ',' attributes[opt] struct-declarator
1182/// struct-declarator:
1183/// declarator
1184/// [GNU] declarator attributes[opt]
1185/// declarator[opt] ':' constant-expression
1186/// [GNU] declarator[opt] ':' constant-expression attributes[opt]
1187///
Chris Lattnere1359422008-04-10 06:46:29 +00001188void Parser::
1189ParseStructDeclaration(DeclSpec &DS,
1190 llvm::SmallVectorImpl<FieldDeclarator> &Fields) {
Chris Lattnerc46d1a12008-10-20 06:45:43 +00001191 if (Tok.is(tok::kw___extension__)) {
1192 // __extension__ silences extension warnings in the subexpression.
1193 ExtensionRAIIObject O(Diags); // Use RAII to do this.
Steve Naroff28a7ca82007-08-20 22:28:22 +00001194 ConsumeToken();
Chris Lattnerc46d1a12008-10-20 06:45:43 +00001195 return ParseStructDeclaration(DS, Fields);
1196 }
Steve Naroff28a7ca82007-08-20 22:28:22 +00001197
1198 // Parse the common specifier-qualifiers-list piece.
Chris Lattner60b1e3e2008-04-10 06:15:14 +00001199 SourceLocation DSStart = Tok.getLocation();
Steve Naroff28a7ca82007-08-20 22:28:22 +00001200 ParseSpecifierQualifierList(DS);
Steve Naroff28a7ca82007-08-20 22:28:22 +00001201
Douglas Gregor4920f1f2009-01-12 22:49:06 +00001202 // If there are no declarators, this is a free-standing declaration
1203 // specifier. Let the actions module cope with it.
Chris Lattner04d66662007-10-09 17:33:22 +00001204 if (Tok.is(tok::semi)) {
Douglas Gregor4920f1f2009-01-12 22:49:06 +00001205 Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
Steve Naroff28a7ca82007-08-20 22:28:22 +00001206 return;
1207 }
1208
1209 // Read struct-declarators until we find the semicolon.
Chris Lattnerebe457c2008-04-10 16:37:40 +00001210 Fields.push_back(FieldDeclarator(DS));
Steve Naroff28a7ca82007-08-20 22:28:22 +00001211 while (1) {
Chris Lattnere1359422008-04-10 06:46:29 +00001212 FieldDeclarator &DeclaratorInfo = Fields.back();
1213
Steve Naroff28a7ca82007-08-20 22:28:22 +00001214 /// struct-declarator: declarator
1215 /// struct-declarator: declarator[opt] ':' constant-expression
Chris Lattner04d66662007-10-09 17:33:22 +00001216 if (Tok.isNot(tok::colon))
Chris Lattnere1359422008-04-10 06:46:29 +00001217 ParseDeclarator(DeclaratorInfo.D);
Steve Naroff28a7ca82007-08-20 22:28:22 +00001218
Chris Lattner04d66662007-10-09 17:33:22 +00001219 if (Tok.is(tok::colon)) {
Steve Naroff28a7ca82007-08-20 22:28:22 +00001220 ConsumeToken();
Sebastian Redl2f7ece72008-12-11 21:36:32 +00001221 OwningExprResult Res(ParseConstantExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001222 if (Res.isInvalid())
Steve Naroff28a7ca82007-08-20 22:28:22 +00001223 SkipUntil(tok::semi, true, true);
Chris Lattner60b1e3e2008-04-10 06:15:14 +00001224 else
Sebastian Redleffa8d12008-12-10 00:02:53 +00001225 DeclaratorInfo.BitfieldSize = Res.release();
Steve Naroff28a7ca82007-08-20 22:28:22 +00001226 }
Sebastian Redlab197ba2009-02-09 18:23:29 +00001227
Steve Naroff28a7ca82007-08-20 22:28:22 +00001228 // If attributes exist after the declarator, parse them.
Sebastian Redlab197ba2009-02-09 18:23:29 +00001229 if (Tok.is(tok::kw___attribute)) {
1230 SourceLocation Loc;
1231 AttributeList *AttrList = ParseAttributes(&Loc);
1232 DeclaratorInfo.D.AddAttributes(AttrList, Loc);
1233 }
1234
Steve Naroff28a7ca82007-08-20 22:28:22 +00001235 // If we don't have a comma, it is either the end of the list (a ';')
1236 // or an error, bail out.
Chris Lattner04d66662007-10-09 17:33:22 +00001237 if (Tok.isNot(tok::comma))
Chris Lattnercd4b83c2007-10-29 04:42:53 +00001238 return;
Sebastian Redlab197ba2009-02-09 18:23:29 +00001239
Steve Naroff28a7ca82007-08-20 22:28:22 +00001240 // Consume the comma.
1241 ConsumeToken();
Sebastian Redlab197ba2009-02-09 18:23:29 +00001242
Steve Naroff28a7ca82007-08-20 22:28:22 +00001243 // Parse the next declarator.
Chris Lattnerebe457c2008-04-10 16:37:40 +00001244 Fields.push_back(FieldDeclarator(DS));
Sebastian Redlab197ba2009-02-09 18:23:29 +00001245
Steve Naroff28a7ca82007-08-20 22:28:22 +00001246 // Attributes are only allowed on the second declarator.
Sebastian Redlab197ba2009-02-09 18:23:29 +00001247 if (Tok.is(tok::kw___attribute)) {
1248 SourceLocation Loc;
1249 AttributeList *AttrList = ParseAttributes(&Loc);
1250 Fields.back().D.AddAttributes(AttrList, Loc);
1251 }
Steve Naroff28a7ca82007-08-20 22:28:22 +00001252 }
Steve Naroff28a7ca82007-08-20 22:28:22 +00001253}
1254
1255/// ParseStructUnionBody
1256/// struct-contents:
1257/// struct-declaration-list
1258/// [EXT] empty
1259/// [GNU] "struct-declaration-list" without terminatoring ';'
1260/// struct-declaration-list:
1261/// struct-declaration
1262/// struct-declaration-list struct-declaration
Chris Lattner5a6ddbf2008-06-21 19:39:06 +00001263/// [OBC] '@' 'defs' '(' class-name ')'
Steve Naroff28a7ca82007-08-20 22:28:22 +00001264///
Reid Spencer5f016e22007-07-11 17:01:13 +00001265void Parser::ParseStructUnionBody(SourceLocation RecordLoc,
Chris Lattnerb28317a2009-03-28 19:18:32 +00001266 unsigned TagType, DeclPtrTy TagDecl) {
Chris Lattner49f28ca2009-03-05 08:00:35 +00001267 PrettyStackTraceActionsDecl CrashInfo(TagDecl, RecordLoc, Actions,
1268 PP.getSourceManager(),
1269 "parsing struct/union body");
Chris Lattner27b7f102009-03-05 02:25:03 +00001270
Reid Spencer5f016e22007-07-11 17:01:13 +00001271 SourceLocation LBraceLoc = ConsumeBrace();
1272
Douglas Gregor3218c4b2009-01-09 22:42:13 +00001273 ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope);
Douglas Gregor72de6672009-01-08 20:45:30 +00001274 Actions.ActOnTagStartDefinition(CurScope, TagDecl);
1275
Reid Spencer5f016e22007-07-11 17:01:13 +00001276 // Empty structs are an extension in C (C99 6.7.2.1p7), but are allowed in
1277 // C++.
Douglas Gregore37ac4f2008-04-13 21:30:24 +00001278 if (Tok.is(tok::r_brace) && !getLang().CPlusPlus)
Chris Lattner1ab3b962008-11-18 07:48:38 +00001279 Diag(Tok, diag::ext_empty_struct_union_enum)
1280 << DeclSpec::getSpecifierName((DeclSpec::TST)TagType);
Reid Spencer5f016e22007-07-11 17:01:13 +00001281
Chris Lattnerb28317a2009-03-28 19:18:32 +00001282 llvm::SmallVector<DeclPtrTy, 32> FieldDecls;
Chris Lattnere1359422008-04-10 06:46:29 +00001283 llvm::SmallVector<FieldDeclarator, 8> FieldDeclarators;
1284
Reid Spencer5f016e22007-07-11 17:01:13 +00001285 // While we still have something to read, read the declarations in the struct.
Chris Lattner04d66662007-10-09 17:33:22 +00001286 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001287 // Each iteration of this loop reads one struct-declaration.
1288
1289 // Check for extraneous top-level semicolon.
Chris Lattner04d66662007-10-09 17:33:22 +00001290 if (Tok.is(tok::semi)) {
Douglas Gregor9b3064b2009-04-01 22:41:11 +00001291 Diag(Tok, diag::ext_extra_struct_semi)
1292 << CodeModificationHint::CreateRemoval(SourceRange(Tok.getLocation()));
Reid Spencer5f016e22007-07-11 17:01:13 +00001293 ConsumeToken();
1294 continue;
1295 }
Chris Lattnere1359422008-04-10 06:46:29 +00001296
1297 // Parse all the comma separated declarators.
1298 DeclSpec DS;
1299 FieldDeclarators.clear();
Chris Lattner5a6ddbf2008-06-21 19:39:06 +00001300 if (!Tok.is(tok::at)) {
1301 ParseStructDeclaration(DS, FieldDeclarators);
1302
1303 // Convert them all to fields.
1304 for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) {
1305 FieldDeclarator &FD = FieldDeclarators[i];
1306 // Install the declarator into the current TagDecl.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001307 DeclPtrTy Field = Actions.ActOnField(CurScope, TagDecl,
1308 DS.getSourceRange().getBegin(),
1309 FD.D, FD.BitfieldSize);
Chris Lattner5a6ddbf2008-06-21 19:39:06 +00001310 FieldDecls.push_back(Field);
1311 }
1312 } else { // Handle @defs
1313 ConsumeToken();
1314 if (!Tok.isObjCAtKeyword(tok::objc_defs)) {
1315 Diag(Tok, diag::err_unexpected_at);
1316 SkipUntil(tok::semi, true, true);
1317 continue;
1318 }
1319 ConsumeToken();
1320 ExpectAndConsume(tok::l_paren, diag::err_expected_lparen);
1321 if (!Tok.is(tok::identifier)) {
1322 Diag(Tok, diag::err_expected_ident);
1323 SkipUntil(tok::semi, true, true);
1324 continue;
1325 }
Chris Lattnerb28317a2009-03-28 19:18:32 +00001326 llvm::SmallVector<DeclPtrTy, 16> Fields;
Douglas Gregor44b43212008-12-11 16:49:14 +00001327 Actions.ActOnDefs(CurScope, TagDecl, Tok.getLocation(),
1328 Tok.getIdentifierInfo(), Fields);
Chris Lattner5a6ddbf2008-06-21 19:39:06 +00001329 FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end());
1330 ConsumeToken();
1331 ExpectAndConsume(tok::r_paren, diag::err_expected_rparen);
1332 }
Reid Spencer5f016e22007-07-11 17:01:13 +00001333
Chris Lattner04d66662007-10-09 17:33:22 +00001334 if (Tok.is(tok::semi)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001335 ConsumeToken();
Chris Lattner04d66662007-10-09 17:33:22 +00001336 } else if (Tok.is(tok::r_brace)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00001337 Diag(Tok, diag::ext_expected_semi_decl_list);
Reid Spencer5f016e22007-07-11 17:01:13 +00001338 break;
1339 } else {
1340 Diag(Tok, diag::err_expected_semi_decl_list);
1341 // Skip to end of block or statement
1342 SkipUntil(tok::r_brace, true, true);
1343 }
1344 }
1345
Steve Naroff60fccee2007-10-29 21:38:07 +00001346 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001347
Reid Spencer5f016e22007-07-11 17:01:13 +00001348 AttributeList *AttrList = 0;
1349 // If attributes exist after struct contents, parse them.
Chris Lattner04d66662007-10-09 17:33:22 +00001350 if (Tok.is(tok::kw___attribute))
Daniel Dunbar5e592d82008-10-03 16:42:10 +00001351 AttrList = ParseAttributes();
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +00001352
1353 Actions.ActOnFields(CurScope,
1354 RecordLoc,TagDecl,&FieldDecls[0],FieldDecls.size(),
1355 LBraceLoc, RBraceLoc,
Douglas Gregor72de6672009-01-08 20:45:30 +00001356 AttrList);
1357 StructScope.Exit();
1358 Actions.ActOnTagFinishDefinition(CurScope, TagDecl);
Reid Spencer5f016e22007-07-11 17:01:13 +00001359}
1360
1361
1362/// ParseEnumSpecifier
1363/// enum-specifier: [C99 6.7.2.2]
1364/// 'enum' identifier[opt] '{' enumerator-list '}'
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001365///[C99/C++]'enum' identifier[opt] '{' enumerator-list ',' '}'
Reid Spencer5f016e22007-07-11 17:01:13 +00001366/// [GNU] 'enum' attributes[opt] identifier[opt] '{' enumerator-list ',' [opt]
1367/// '}' attributes[opt]
1368/// 'enum' identifier
1369/// [GNU] 'enum' attributes[opt] identifier
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001370///
1371/// [C++] elaborated-type-specifier:
1372/// [C++] 'enum' '::'[opt] nested-name-specifier[opt] identifier
1373///
Chris Lattner4c97d762009-04-12 21:49:30 +00001374void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
1375 AccessSpecifier AS) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001376 // Parse the tag portion of this.
Argyrios Kyrtzidise281b4c2008-09-11 00:21:41 +00001377
1378 AttributeList *Attr = 0;
1379 // If attributes exist after tag, parse them.
1380 if (Tok.is(tok::kw___attribute))
1381 Attr = ParseAttributes();
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001382
1383 CXXScopeSpec SS;
Chris Lattner7a0ab5f2009-01-06 06:59:53 +00001384 if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS)) {
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001385 if (Tok.isNot(tok::identifier)) {
1386 Diag(Tok, diag::err_expected_ident);
1387 if (Tok.isNot(tok::l_brace)) {
1388 // Has no name and is not a definition.
1389 // Skip the rest of this declarator, up until the comma or semicolon.
1390 SkipUntil(tok::comma, true);
1391 return;
1392 }
1393 }
1394 }
Argyrios Kyrtzidise281b4c2008-09-11 00:21:41 +00001395
1396 // Must have either 'enum name' or 'enum {...}'.
1397 if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
1398 Diag(Tok, diag::err_expected_ident_lbrace);
1399
1400 // Skip the rest of this declarator, up until the comma or semicolon.
1401 SkipUntil(tok::comma, true);
Reid Spencer5f016e22007-07-11 17:01:13 +00001402 return;
Argyrios Kyrtzidise281b4c2008-09-11 00:21:41 +00001403 }
1404
1405 // If an identifier is present, consume and remember it.
1406 IdentifierInfo *Name = 0;
1407 SourceLocation NameLoc;
1408 if (Tok.is(tok::identifier)) {
1409 Name = Tok.getIdentifierInfo();
1410 NameLoc = ConsumeToken();
1411 }
1412
1413 // There are three options here. If we have 'enum foo;', then this is a
1414 // forward declaration. If we have 'enum foo {...' then this is a
1415 // definition. Otherwise we have something like 'enum foo xyz', a reference.
1416 //
1417 // This is needed to handle stuff like this right (C99 6.7.2.3p11):
1418 // enum foo {..}; void bar() { enum foo; } <- new foo in bar.
1419 // enum foo {..}; void bar() { enum foo x; } <- use of old foo.
1420 //
1421 Action::TagKind TK;
1422 if (Tok.is(tok::l_brace))
1423 TK = Action::TK_Definition;
1424 else if (Tok.is(tok::semi))
1425 TK = Action::TK_Declaration;
1426 else
1427 TK = Action::TK_Reference;
Chris Lattnerb28317a2009-03-28 19:18:32 +00001428 DeclPtrTy TagDecl = Actions.ActOnTag(CurScope, DeclSpec::TST_enum, TK,
1429 StartLoc, SS, Name, NameLoc, Attr, AS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001430
Chris Lattner04d66662007-10-09 17:33:22 +00001431 if (Tok.is(tok::l_brace))
Reid Spencer5f016e22007-07-11 17:01:13 +00001432 ParseEnumBody(StartLoc, TagDecl);
1433
1434 // TODO: semantic analysis on the declspec for enums.
1435 const char *PrevSpec = 0;
Chris Lattnerb28317a2009-03-28 19:18:32 +00001436 if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, PrevSpec,
1437 TagDecl.getAs<void>()))
Chris Lattner1ab3b962008-11-18 07:48:38 +00001438 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
Reid Spencer5f016e22007-07-11 17:01:13 +00001439}
1440
1441/// ParseEnumBody - Parse a {} enclosed enumerator-list.
1442/// enumerator-list:
1443/// enumerator
1444/// enumerator-list ',' enumerator
1445/// enumerator:
1446/// enumeration-constant
1447/// enumeration-constant '=' constant-expression
1448/// enumeration-constant:
1449/// identifier
1450///
Chris Lattnerb28317a2009-03-28 19:18:32 +00001451void Parser::ParseEnumBody(SourceLocation StartLoc, DeclPtrTy EnumDecl) {
Douglas Gregor074149e2009-01-05 19:45:36 +00001452 // Enter the scope of the enum body and start the definition.
1453 ParseScope EnumScope(this, Scope::DeclScope);
Douglas Gregor72de6672009-01-08 20:45:30 +00001454 Actions.ActOnTagStartDefinition(CurScope, EnumDecl);
Douglas Gregor074149e2009-01-05 19:45:36 +00001455
Reid Spencer5f016e22007-07-11 17:01:13 +00001456 SourceLocation LBraceLoc = ConsumeBrace();
1457
Chris Lattner7946dd32007-08-27 17:24:30 +00001458 // C does not allow an empty enumerator-list, C++ does [dcl.enum].
Chris Lattner04d66662007-10-09 17:33:22 +00001459 if (Tok.is(tok::r_brace) && !getLang().CPlusPlus)
Chris Lattner1ab3b962008-11-18 07:48:38 +00001460 Diag(Tok, diag::ext_empty_struct_union_enum) << "enum";
Reid Spencer5f016e22007-07-11 17:01:13 +00001461
Chris Lattnerb28317a2009-03-28 19:18:32 +00001462 llvm::SmallVector<DeclPtrTy, 32> EnumConstantDecls;
Reid Spencer5f016e22007-07-11 17:01:13 +00001463
Chris Lattnerb28317a2009-03-28 19:18:32 +00001464 DeclPtrTy LastEnumConstDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +00001465
1466 // Parse the enumerator-list.
Chris Lattner04d66662007-10-09 17:33:22 +00001467 while (Tok.is(tok::identifier)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001468 IdentifierInfo *Ident = Tok.getIdentifierInfo();
1469 SourceLocation IdentLoc = ConsumeToken();
1470
1471 SourceLocation EqualLoc;
Sebastian Redl15faa7f2008-12-09 20:22:58 +00001472 OwningExprResult AssignedVal(Actions);
Chris Lattner04d66662007-10-09 17:33:22 +00001473 if (Tok.is(tok::equal)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001474 EqualLoc = ConsumeToken();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00001475 AssignedVal = ParseConstantExpression();
1476 if (AssignedVal.isInvalid())
Reid Spencer5f016e22007-07-11 17:01:13 +00001477 SkipUntil(tok::comma, tok::r_brace, true, true);
Reid Spencer5f016e22007-07-11 17:01:13 +00001478 }
1479
1480 // Install the enumerator constant into EnumDecl.
Chris Lattnerb28317a2009-03-28 19:18:32 +00001481 DeclPtrTy EnumConstDecl = Actions.ActOnEnumConstant(CurScope, EnumDecl,
1482 LastEnumConstDecl,
1483 IdentLoc, Ident,
1484 EqualLoc,
1485 AssignedVal.release());
Reid Spencer5f016e22007-07-11 17:01:13 +00001486 EnumConstantDecls.push_back(EnumConstDecl);
1487 LastEnumConstDecl = EnumConstDecl;
1488
Chris Lattner04d66662007-10-09 17:33:22 +00001489 if (Tok.isNot(tok::comma))
Reid Spencer5f016e22007-07-11 17:01:13 +00001490 break;
1491 SourceLocation CommaLoc = ConsumeToken();
1492
Douglas Gregor9b3064b2009-04-01 22:41:11 +00001493 if (Tok.isNot(tok::identifier) &&
1494 !(getLang().C99 || getLang().CPlusPlus0x))
1495 Diag(CommaLoc, diag::ext_enumerator_list_comma)
1496 << getLang().CPlusPlus
1497 << CodeModificationHint::CreateRemoval((SourceRange(CommaLoc)));
Reid Spencer5f016e22007-07-11 17:01:13 +00001498 }
1499
1500 // Eat the }.
1501 MatchRHSPunctuation(tok::r_brace, LBraceLoc);
1502
Steve Naroff08d92e42007-09-15 18:49:24 +00001503 Actions.ActOnEnumBody(StartLoc, EnumDecl, &EnumConstantDecls[0],
Reid Spencer5f016e22007-07-11 17:01:13 +00001504 EnumConstantDecls.size());
1505
Chris Lattnerb28317a2009-03-28 19:18:32 +00001506 Action::AttrTy *AttrList = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +00001507 // If attributes exist after the identifier list, parse them.
Chris Lattner04d66662007-10-09 17:33:22 +00001508 if (Tok.is(tok::kw___attribute))
Reid Spencer5f016e22007-07-11 17:01:13 +00001509 AttrList = ParseAttributes(); // FIXME: where do they do?
Douglas Gregor72de6672009-01-08 20:45:30 +00001510
1511 EnumScope.Exit();
1512 Actions.ActOnTagFinishDefinition(CurScope, EnumDecl);
Reid Spencer5f016e22007-07-11 17:01:13 +00001513}
1514
1515/// isTypeSpecifierQualifier - Return true if the current token could be the
Steve Naroff5f8aa692008-02-11 23:15:56 +00001516/// start of a type-qualifier-list.
1517bool Parser::isTypeQualifier() const {
1518 switch (Tok.getKind()) {
1519 default: return false;
1520 // type-qualifier
1521 case tok::kw_const:
1522 case tok::kw_volatile:
1523 case tok::kw_restrict:
1524 return true;
1525 }
1526}
1527
1528/// isTypeSpecifierQualifier - Return true if the current token could be the
Reid Spencer5f016e22007-07-11 17:01:13 +00001529/// start of a specifier-qualifier-list.
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001530bool Parser::isTypeSpecifierQualifier() {
Reid Spencer5f016e22007-07-11 17:01:13 +00001531 switch (Tok.getKind()) {
1532 default: return false;
Chris Lattner166a8fc2009-01-04 23:41:41 +00001533
1534 case tok::identifier: // foo::bar
Douglas Gregord57959a2009-03-27 23:10:48 +00001535 case tok::kw_typename: // typename T::type
Chris Lattner166a8fc2009-01-04 23:41:41 +00001536 // Annotate typenames and C++ scope specifiers. If we get one, just
1537 // recurse to handle whatever we get.
1538 if (TryAnnotateTypeOrScopeToken())
1539 return isTypeSpecifierQualifier();
1540 // Otherwise, not a type specifier.
1541 return false;
Douglas Gregord57959a2009-03-27 23:10:48 +00001542
Chris Lattner166a8fc2009-01-04 23:41:41 +00001543 case tok::coloncolon: // ::foo::bar
1544 if (NextToken().is(tok::kw_new) || // ::new
1545 NextToken().is(tok::kw_delete)) // ::delete
1546 return false;
1547
1548 // Annotate typenames and C++ scope specifiers. If we get one, just
1549 // recurse to handle whatever we get.
1550 if (TryAnnotateTypeOrScopeToken())
1551 return isTypeSpecifierQualifier();
1552 // Otherwise, not a type specifier.
1553 return false;
1554
Reid Spencer5f016e22007-07-11 17:01:13 +00001555 // GNU attributes support.
1556 case tok::kw___attribute:
Steve Naroffd1861fd2007-07-31 12:34:36 +00001557 // GNU typeof support.
1558 case tok::kw_typeof:
1559
Reid Spencer5f016e22007-07-11 17:01:13 +00001560 // type-specifiers
1561 case tok::kw_short:
1562 case tok::kw_long:
1563 case tok::kw_signed:
1564 case tok::kw_unsigned:
1565 case tok::kw__Complex:
1566 case tok::kw__Imaginary:
1567 case tok::kw_void:
1568 case tok::kw_char:
Argyrios Kyrtzidis64c438a2008-08-09 16:51:54 +00001569 case tok::kw_wchar_t:
Reid Spencer5f016e22007-07-11 17:01:13 +00001570 case tok::kw_int:
1571 case tok::kw_float:
1572 case tok::kw_double:
Chris Lattner9298d962007-11-15 05:25:19 +00001573 case tok::kw_bool:
Reid Spencer5f016e22007-07-11 17:01:13 +00001574 case tok::kw__Bool:
1575 case tok::kw__Decimal32:
1576 case tok::kw__Decimal64:
1577 case tok::kw__Decimal128:
1578
Chris Lattner99dc9142008-04-13 18:59:07 +00001579 // struct-or-union-specifier (C99) or class-specifier (C++)
1580 case tok::kw_class:
Reid Spencer5f016e22007-07-11 17:01:13 +00001581 case tok::kw_struct:
1582 case tok::kw_union:
1583 // enum-specifier
1584 case tok::kw_enum:
1585
1586 // type-qualifier
1587 case tok::kw_const:
1588 case tok::kw_volatile:
1589 case tok::kw_restrict:
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001590
1591 // typedef-name
Chris Lattnerb31757b2009-01-06 05:06:21 +00001592 case tok::annot_typename:
Reid Spencer5f016e22007-07-11 17:01:13 +00001593 return true;
Chris Lattner7c186be2008-10-20 00:25:30 +00001594
1595 // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'.
1596 case tok::less:
1597 return getLang().ObjC1;
Steve Naroff239f0732008-12-25 14:16:32 +00001598
1599 case tok::kw___cdecl:
1600 case tok::kw___stdcall:
1601 case tok::kw___fastcall:
1602 return PP.getLangOptions().Microsoft;
Reid Spencer5f016e22007-07-11 17:01:13 +00001603 }
1604}
1605
1606/// isDeclarationSpecifier() - Return true if the current token is part of a
1607/// declaration specifier.
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001608bool Parser::isDeclarationSpecifier() {
Reid Spencer5f016e22007-07-11 17:01:13 +00001609 switch (Tok.getKind()) {
1610 default: return false;
Chris Lattner166a8fc2009-01-04 23:41:41 +00001611
1612 case tok::identifier: // foo::bar
Steve Naroff61f72cb2009-03-09 21:12:44 +00001613 // Unfortunate hack to support "Class.factoryMethod" notation.
1614 if (getLang().ObjC1 && NextToken().is(tok::period))
1615 return false;
Douglas Gregord57959a2009-03-27 23:10:48 +00001616 // Fall through
Steve Naroff61f72cb2009-03-09 21:12:44 +00001617
Douglas Gregord57959a2009-03-27 23:10:48 +00001618 case tok::kw_typename: // typename T::type
Chris Lattner166a8fc2009-01-04 23:41:41 +00001619 // Annotate typenames and C++ scope specifiers. If we get one, just
1620 // recurse to handle whatever we get.
1621 if (TryAnnotateTypeOrScopeToken())
1622 return isDeclarationSpecifier();
1623 // Otherwise, not a declaration specifier.
1624 return false;
1625 case tok::coloncolon: // ::foo::bar
1626 if (NextToken().is(tok::kw_new) || // ::new
1627 NextToken().is(tok::kw_delete)) // ::delete
1628 return false;
1629
1630 // Annotate typenames and C++ scope specifiers. If we get one, just
1631 // recurse to handle whatever we get.
1632 if (TryAnnotateTypeOrScopeToken())
1633 return isDeclarationSpecifier();
1634 // Otherwise, not a declaration specifier.
1635 return false;
1636
Reid Spencer5f016e22007-07-11 17:01:13 +00001637 // storage-class-specifier
1638 case tok::kw_typedef:
1639 case tok::kw_extern:
Steve Naroff8d54bf22007-12-18 00:16:02 +00001640 case tok::kw___private_extern__:
Reid Spencer5f016e22007-07-11 17:01:13 +00001641 case tok::kw_static:
1642 case tok::kw_auto:
1643 case tok::kw_register:
1644 case tok::kw___thread:
1645
1646 // type-specifiers
1647 case tok::kw_short:
1648 case tok::kw_long:
1649 case tok::kw_signed:
1650 case tok::kw_unsigned:
1651 case tok::kw__Complex:
1652 case tok::kw__Imaginary:
1653 case tok::kw_void:
1654 case tok::kw_char:
Argyrios Kyrtzidis64c438a2008-08-09 16:51:54 +00001655 case tok::kw_wchar_t:
Reid Spencer5f016e22007-07-11 17:01:13 +00001656 case tok::kw_int:
1657 case tok::kw_float:
1658 case tok::kw_double:
Chris Lattner9298d962007-11-15 05:25:19 +00001659 case tok::kw_bool:
Reid Spencer5f016e22007-07-11 17:01:13 +00001660 case tok::kw__Bool:
1661 case tok::kw__Decimal32:
1662 case tok::kw__Decimal64:
1663 case tok::kw__Decimal128:
1664
Chris Lattner99dc9142008-04-13 18:59:07 +00001665 // struct-or-union-specifier (C99) or class-specifier (C++)
1666 case tok::kw_class:
Reid Spencer5f016e22007-07-11 17:01:13 +00001667 case tok::kw_struct:
1668 case tok::kw_union:
1669 // enum-specifier
1670 case tok::kw_enum:
1671
1672 // type-qualifier
1673 case tok::kw_const:
1674 case tok::kw_volatile:
1675 case tok::kw_restrict:
Steve Naroffd1861fd2007-07-31 12:34:36 +00001676
Reid Spencer5f016e22007-07-11 17:01:13 +00001677 // function-specifier
1678 case tok::kw_inline:
Douglas Gregorb48fe382008-10-31 09:07:45 +00001679 case tok::kw_virtual:
1680 case tok::kw_explicit:
Chris Lattnerd6c7c182007-08-09 16:40:21 +00001681
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001682 // typedef-name
Chris Lattnerb31757b2009-01-06 05:06:21 +00001683 case tok::annot_typename:
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001684
Chris Lattner1ef08762007-08-09 17:01:07 +00001685 // GNU typeof support.
1686 case tok::kw_typeof:
1687
1688 // GNU attributes.
Chris Lattnerd6c7c182007-08-09 16:40:21 +00001689 case tok::kw___attribute:
Reid Spencer5f016e22007-07-11 17:01:13 +00001690 return true;
Chris Lattnerf3948c42008-07-26 03:38:44 +00001691
1692 // GNU ObjC bizarre protocol extension: <proto1,proto2> with implicit 'id'.
1693 case tok::less:
1694 return getLang().ObjC1;
Steve Naroff239f0732008-12-25 14:16:32 +00001695
Steve Naroff47f52092009-01-06 19:34:12 +00001696 case tok::kw___declspec:
Steve Naroff239f0732008-12-25 14:16:32 +00001697 case tok::kw___cdecl:
1698 case tok::kw___stdcall:
1699 case tok::kw___fastcall:
1700 return PP.getLangOptions().Microsoft;
Reid Spencer5f016e22007-07-11 17:01:13 +00001701 }
1702}
1703
1704
1705/// ParseTypeQualifierListOpt
1706/// type-qualifier-list: [C99 6.7.5]
1707/// type-qualifier
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001708/// [GNU] attributes [ only if AttributesAllowed=true ]
Reid Spencer5f016e22007-07-11 17:01:13 +00001709/// type-qualifier-list type-qualifier
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001710/// [GNU] type-qualifier-list attributes [ only if AttributesAllowed=true ]
Reid Spencer5f016e22007-07-11 17:01:13 +00001711///
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001712void Parser::ParseTypeQualifierListOpt(DeclSpec &DS, bool AttributesAllowed) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001713 while (1) {
1714 int isInvalid = false;
1715 const char *PrevSpec = 0;
1716 SourceLocation Loc = Tok.getLocation();
1717
1718 switch (Tok.getKind()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001719 case tok::kw_const:
1720 isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec,
1721 getLang())*2;
1722 break;
1723 case tok::kw_volatile:
1724 isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec,
1725 getLang())*2;
1726 break;
1727 case tok::kw_restrict:
1728 isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec,
1729 getLang())*2;
1730 break;
Steve Naroff86bc6cf2008-12-25 14:41:26 +00001731 case tok::kw___ptr64:
Steve Naroff239f0732008-12-25 14:16:32 +00001732 case tok::kw___cdecl:
1733 case tok::kw___stdcall:
1734 case tok::kw___fastcall:
1735 if (!PP.getLangOptions().Microsoft)
1736 goto DoneWithTypeQuals;
1737 // Just ignore it.
1738 break;
Reid Spencer5f016e22007-07-11 17:01:13 +00001739 case tok::kw___attribute:
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001740 if (AttributesAllowed) {
1741 DS.AddAttributes(ParseAttributes());
1742 continue; // do *not* consume the next token!
1743 }
1744 // otherwise, FALL THROUGH!
1745 default:
Steve Naroff239f0732008-12-25 14:16:32 +00001746 DoneWithTypeQuals:
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001747 // If this is not a type-qualifier token, we're done reading type
1748 // qualifiers. First verify that DeclSpec's are consistent.
Douglas Gregor9b3064b2009-04-01 22:41:11 +00001749 DS.Finish(Diags, PP);
Chris Lattner5a69d1c2008-12-18 07:02:59 +00001750 return;
Reid Spencer5f016e22007-07-11 17:01:13 +00001751 }
Chris Lattnera1fcbad2008-12-18 06:50:14 +00001752
Reid Spencer5f016e22007-07-11 17:01:13 +00001753 // If the specifier combination wasn't legal, issue a diagnostic.
1754 if (isInvalid) {
1755 assert(PrevSpec && "Method did not return previous specifier!");
Chris Lattner1ab3b962008-11-18 07:48:38 +00001756 // Pick between error or extwarn.
1757 unsigned DiagID = isInvalid == 1 ? diag::err_invalid_decl_spec_combination
1758 : diag::ext_duplicate_declspec;
1759 Diag(Tok, DiagID) << PrevSpec;
Reid Spencer5f016e22007-07-11 17:01:13 +00001760 }
1761 ConsumeToken();
1762 }
1763}
1764
1765
1766/// ParseDeclarator - Parse and verify a newly-initialized declarator.
1767///
1768void Parser::ParseDeclarator(Declarator &D) {
1769 /// This implements the 'declarator' production in the C grammar, then checks
1770 /// for well-formedness and issues diagnostics.
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001771 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
Reid Spencer5f016e22007-07-11 17:01:13 +00001772}
1773
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001774/// ParseDeclaratorInternal - Parse a C or C++ declarator. The direct-declarator
1775/// is parsed by the function passed to it. Pass null, and the direct-declarator
1776/// isn't parsed at all, making this function effectively parse the C++
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001777/// ptr-operator production.
1778///
Sebastian Redlf30208a2009-01-24 21:16:55 +00001779/// declarator: [C99 6.7.5] [C++ 8p4, dcl.decl]
1780/// [C] pointer[opt] direct-declarator
1781/// [C++] direct-declarator
1782/// [C++] ptr-operator declarator
Reid Spencer5f016e22007-07-11 17:01:13 +00001783///
1784/// pointer: [C99 6.7.5]
1785/// '*' type-qualifier-list[opt]
1786/// '*' type-qualifier-list[opt] pointer
1787///
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001788/// ptr-operator:
1789/// '*' cv-qualifier-seq[opt]
1790/// '&'
Sebastian Redl05532f22009-03-15 22:02:01 +00001791/// [C++0x] '&&'
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001792/// [GNU] '&' restrict[opt] attributes[opt]
Sebastian Redl05532f22009-03-15 22:02:01 +00001793/// [GNU?] '&&' restrict[opt] attributes[opt]
Sebastian Redlf30208a2009-01-24 21:16:55 +00001794/// '::'[opt] nested-name-specifier '*' cv-qualifier-seq[opt]
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001795void Parser::ParseDeclaratorInternal(Declarator &D,
1796 DirectDeclParseFunction DirectDeclParser) {
Reid Spencer5f016e22007-07-11 17:01:13 +00001797
Sebastian Redlf30208a2009-01-24 21:16:55 +00001798 // C++ member pointers start with a '::' or a nested-name.
1799 // Member pointers get special handling, since there's no place for the
1800 // scope spec in the generic path below.
Chris Lattnerf919bfe2009-03-24 17:04:48 +00001801 if (getLang().CPlusPlus &&
1802 (Tok.is(tok::coloncolon) || Tok.is(tok::identifier) ||
1803 Tok.is(tok::annot_cxxscope))) {
Sebastian Redlf30208a2009-01-24 21:16:55 +00001804 CXXScopeSpec SS;
1805 if (ParseOptionalCXXScopeSpecifier(SS)) {
1806 if(Tok.isNot(tok::star)) {
1807 // The scope spec really belongs to the direct-declarator.
1808 D.getCXXScopeSpec() = SS;
1809 if (DirectDeclParser)
1810 (this->*DirectDeclParser)(D);
1811 return;
1812 }
1813
1814 SourceLocation Loc = ConsumeToken();
Sebastian Redlab197ba2009-02-09 18:23:29 +00001815 D.SetRangeEnd(Loc);
Sebastian Redlf30208a2009-01-24 21:16:55 +00001816 DeclSpec DS;
1817 ParseTypeQualifierListOpt(DS);
Sebastian Redlab197ba2009-02-09 18:23:29 +00001818 D.ExtendWithDeclSpec(DS);
Sebastian Redlf30208a2009-01-24 21:16:55 +00001819
1820 // Recurse to parse whatever is left.
1821 ParseDeclaratorInternal(D, DirectDeclParser);
1822
1823 // Sema will have to catch (syntactically invalid) pointers into global
1824 // scope. It has to catch pointers into namespace scope anyway.
1825 D.AddTypeInfo(DeclaratorChunk::getMemberPointer(SS,DS.getTypeQualifiers(),
Sebastian Redlab197ba2009-02-09 18:23:29 +00001826 Loc, DS.TakeAttributes()),
1827 /* Don't replace range end. */SourceLocation());
Sebastian Redlf30208a2009-01-24 21:16:55 +00001828 return;
1829 }
1830 }
1831
1832 tok::TokenKind Kind = Tok.getKind();
Steve Naroff5618bd42008-08-27 16:04:49 +00001833 // Not a pointer, C++ reference, or block.
Chris Lattner9af55002009-03-27 04:18:06 +00001834 if (Kind != tok::star && Kind != tok::caret &&
Chris Lattnerf919bfe2009-03-24 17:04:48 +00001835 (Kind != tok::amp || !getLang().CPlusPlus) &&
Sebastian Redl743de1f2009-03-23 00:00:23 +00001836 // We parse rvalue refs in C++03, because otherwise the errors are scary.
Chris Lattner9af55002009-03-27 04:18:06 +00001837 (Kind != tok::ampamp || !getLang().CPlusPlus)) {
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001838 if (DirectDeclParser)
1839 (this->*DirectDeclParser)(D);
Douglas Gregor2f1bc522008-11-07 20:08:42 +00001840 return;
1841 }
Sebastian Redlf30208a2009-01-24 21:16:55 +00001842
Sebastian Redl05532f22009-03-15 22:02:01 +00001843 // Otherwise, '*' -> pointer, '^' -> block, '&' -> lvalue reference,
1844 // '&&' -> rvalue reference
Sebastian Redl743de1f2009-03-23 00:00:23 +00001845 SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&.
Sebastian Redlab197ba2009-02-09 18:23:29 +00001846 D.SetRangeEnd(Loc);
Reid Spencer5f016e22007-07-11 17:01:13 +00001847
Chris Lattner9af55002009-03-27 04:18:06 +00001848 if (Kind == tok::star || Kind == tok::caret) {
Chris Lattner76549142008-02-21 01:32:26 +00001849 // Is a pointer.
Reid Spencer5f016e22007-07-11 17:01:13 +00001850 DeclSpec DS;
Sebastian Redlf30208a2009-01-24 21:16:55 +00001851
Reid Spencer5f016e22007-07-11 17:01:13 +00001852 ParseTypeQualifierListOpt(DS);
Sebastian Redlab197ba2009-02-09 18:23:29 +00001853 D.ExtendWithDeclSpec(DS);
Sebastian Redlf30208a2009-01-24 21:16:55 +00001854
Reid Spencer5f016e22007-07-11 17:01:13 +00001855 // Recursively parse the declarator.
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001856 ParseDeclaratorInternal(D, DirectDeclParser);
Steve Naroff5618bd42008-08-27 16:04:49 +00001857 if (Kind == tok::star)
1858 // Remember that we parsed a pointer type, and remember the type-quals.
1859 D.AddTypeInfo(DeclaratorChunk::getPointer(DS.getTypeQualifiers(), Loc,
Sebastian Redlab197ba2009-02-09 18:23:29 +00001860 DS.TakeAttributes()),
1861 SourceLocation());
Steve Naroff5618bd42008-08-27 16:04:49 +00001862 else
1863 // Remember that we parsed a Block type, and remember the type-quals.
1864 D.AddTypeInfo(DeclaratorChunk::getBlockPointer(DS.getTypeQualifiers(),
Sebastian Redlab197ba2009-02-09 18:23:29 +00001865 Loc),
1866 SourceLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +00001867 } else {
1868 // Is a reference
1869 DeclSpec DS;
1870
Sebastian Redl743de1f2009-03-23 00:00:23 +00001871 // Complain about rvalue references in C++03, but then go on and build
1872 // the declarator.
1873 if (Kind == tok::ampamp && !getLang().CPlusPlus0x)
1874 Diag(Loc, diag::err_rvalue_reference);
1875
Reid Spencer5f016e22007-07-11 17:01:13 +00001876 // C++ 8.3.2p1: cv-qualified references are ill-formed except when the
1877 // cv-qualifiers are introduced through the use of a typedef or of a
1878 // template type argument, in which case the cv-qualifiers are ignored.
1879 //
1880 // [GNU] Retricted references are allowed.
1881 // [GNU] Attributes on references are allowed.
1882 ParseTypeQualifierListOpt(DS);
Sebastian Redlab197ba2009-02-09 18:23:29 +00001883 D.ExtendWithDeclSpec(DS);
Reid Spencer5f016e22007-07-11 17:01:13 +00001884
1885 if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) {
1886 if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
1887 Diag(DS.getConstSpecLoc(),
Chris Lattner1ab3b962008-11-18 07:48:38 +00001888 diag::err_invalid_reference_qualifier_application) << "const";
Reid Spencer5f016e22007-07-11 17:01:13 +00001889 if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile)
1890 Diag(DS.getVolatileSpecLoc(),
Chris Lattner1ab3b962008-11-18 07:48:38 +00001891 diag::err_invalid_reference_qualifier_application) << "volatile";
Reid Spencer5f016e22007-07-11 17:01:13 +00001892 }
1893
1894 // Recursively parse the declarator.
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001895 ParseDeclaratorInternal(D, DirectDeclParser);
Reid Spencer5f016e22007-07-11 17:01:13 +00001896
Douglas Gregorf1f9b4e2008-11-03 15:51:28 +00001897 if (D.getNumTypeObjects() > 0) {
1898 // C++ [dcl.ref]p4: There shall be no references to references.
1899 DeclaratorChunk& InnerChunk = D.getTypeObject(D.getNumTypeObjects() - 1);
1900 if (InnerChunk.Kind == DeclaratorChunk::Reference) {
Chris Lattnerda83bac2008-11-19 07:37:42 +00001901 if (const IdentifierInfo *II = D.getIdentifier())
1902 Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference)
1903 << II;
1904 else
1905 Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference)
1906 << "type name";
Douglas Gregorf1f9b4e2008-11-03 15:51:28 +00001907
Sebastian Redl4c5d3202008-11-21 19:14:01 +00001908 // Once we've complained about the reference-to-reference, we
Douglas Gregorf1f9b4e2008-11-03 15:51:28 +00001909 // can go ahead and build the (technically ill-formed)
1910 // declarator: reference collapsing will take care of it.
1911 }
1912 }
1913
Reid Spencer5f016e22007-07-11 17:01:13 +00001914 // Remember that we parsed a reference type. It doesn't have type-quals.
Chris Lattner76549142008-02-21 01:32:26 +00001915 D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc,
Sebastian Redl05532f22009-03-15 22:02:01 +00001916 DS.TakeAttributes(),
1917 Kind == tok::amp),
Sebastian Redlab197ba2009-02-09 18:23:29 +00001918 SourceLocation());
Reid Spencer5f016e22007-07-11 17:01:13 +00001919 }
1920}
1921
1922/// ParseDirectDeclarator
1923/// direct-declarator: [C99 6.7.5]
Douglas Gregor42a552f2008-11-05 20:51:48 +00001924/// [C99] identifier
Reid Spencer5f016e22007-07-11 17:01:13 +00001925/// '(' declarator ')'
1926/// [GNU] '(' attributes declarator ')'
1927/// [C90] direct-declarator '[' constant-expression[opt] ']'
1928/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
1929/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
1930/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
1931/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
1932/// direct-declarator '(' parameter-type-list ')'
1933/// direct-declarator '(' identifier-list[opt] ')'
1934/// [GNU] direct-declarator '(' parameter-forward-declarations
1935/// parameter-type-list[opt] ')'
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00001936/// [C++] direct-declarator '(' parameter-declaration-clause ')'
1937/// cv-qualifier-seq[opt] exception-specification[opt]
Douglas Gregorb48fe382008-10-31 09:07:45 +00001938/// [C++] declarator-id
Douglas Gregor42a552f2008-11-05 20:51:48 +00001939///
1940/// declarator-id: [C++ 8]
1941/// id-expression
1942/// '::'[opt] nested-name-specifier[opt] type-name
1943///
1944/// id-expression: [C++ 5.1]
1945/// unqualified-id
1946/// qualified-id [TODO]
1947///
1948/// unqualified-id: [C++ 5.1]
1949/// identifier
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001950/// operator-function-id
Douglas Gregor42a552f2008-11-05 20:51:48 +00001951/// conversion-function-id [TODO]
1952/// '~' class-name
Douglas Gregor39a8de12009-02-25 19:37:18 +00001953/// template-id
Argyrios Kyrtzidisc7ed9c62008-11-07 22:02:30 +00001954///
Reid Spencer5f016e22007-07-11 17:01:13 +00001955void Parser::ParseDirectDeclarator(Declarator &D) {
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001956 DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec());
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001957
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001958 if (getLang().CPlusPlus) {
1959 if (D.mayHaveIdentifier()) {
Sebastian Redlf30208a2009-01-24 21:16:55 +00001960 // ParseDeclaratorInternal might already have parsed the scope.
1961 bool afterCXXScope = D.getCXXScopeSpec().isSet() ||
1962 ParseOptionalCXXScopeSpecifier(D.getCXXScopeSpec());
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001963 if (afterCXXScope) {
1964 // Change the declaration context for name lookup, until this function
1965 // is exited (and the declarator has been parsed).
1966 DeclScopeObj.EnterDeclaratorScope();
1967 }
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00001968
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001969 if (Tok.is(tok::identifier)) {
1970 assert(Tok.getIdentifierInfo() && "Not an identifier?");
Douglas Gregord6fb7ef2008-12-18 19:37:40 +00001971
Douglas Gregord6fb7ef2008-12-18 19:37:40 +00001972 // If this identifier is the name of the current class, it's a
1973 // constructor name.
Douglas Gregor39a8de12009-02-25 19:37:18 +00001974 if (Actions.isCurrentClassName(*Tok.getIdentifierInfo(),CurScope)){
Steve Naroffb43a50f2009-01-28 19:39:02 +00001975 D.setConstructor(Actions.getTypeName(*Tok.getIdentifierInfo(),
Douglas Gregorb696ea32009-02-04 17:00:24 +00001976 Tok.getLocation(), CurScope),
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001977 Tok.getLocation());
Douglas Gregord6fb7ef2008-12-18 19:37:40 +00001978 // This is a normal identifier.
Sebastian Redlab197ba2009-02-09 18:23:29 +00001979 } else
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00001980 D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1981 ConsumeToken();
1982 goto PastIdentifier;
Douglas Gregor39a8de12009-02-25 19:37:18 +00001983 } else if (Tok.is(tok::annot_template_id)) {
1984 TemplateIdAnnotation *TemplateId
1985 = static_cast<TemplateIdAnnotation *>(Tok.getAnnotationValue());
1986
1987 // FIXME: Could this template-id name a constructor?
1988
1989 // FIXME: This is an egregious hack, where we silently ignore
1990 // the specialization (which should be a function template
1991 // specialization name) and use the name instead. This hack
1992 // will go away when we have support for function
1993 // specializations.
1994 D.SetIdentifier(TemplateId->Name, Tok.getLocation());
1995 TemplateId->Destroy();
1996 ConsumeToken();
1997 goto PastIdentifier;
Douglas Gregor70316a02008-12-26 15:00:45 +00001998 } else if (Tok.is(tok::kw_operator)) {
1999 SourceLocation OperatorLoc = Tok.getLocation();
Sebastian Redlab197ba2009-02-09 18:23:29 +00002000 SourceLocation EndLoc;
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002001
Douglas Gregor70316a02008-12-26 15:00:45 +00002002 // First try the name of an overloaded operator
Sebastian Redlab197ba2009-02-09 18:23:29 +00002003 if (OverloadedOperatorKind Op = TryParseOperatorFunctionId(&EndLoc)) {
2004 D.setOverloadedOperator(Op, OperatorLoc, EndLoc);
Douglas Gregor70316a02008-12-26 15:00:45 +00002005 } else {
2006 // This must be a conversion function (C++ [class.conv.fct]).
Sebastian Redlab197ba2009-02-09 18:23:29 +00002007 if (TypeTy *ConvType = ParseConversionFunctionId(&EndLoc))
2008 D.setConversionFunction(ConvType, OperatorLoc, EndLoc);
2009 else {
Douglas Gregor70316a02008-12-26 15:00:45 +00002010 D.SetIdentifier(0, Tok.getLocation());
Sebastian Redlab197ba2009-02-09 18:23:29 +00002011 }
Douglas Gregor70316a02008-12-26 15:00:45 +00002012 }
2013 goto PastIdentifier;
2014 } else if (Tok.is(tok::tilde)) {
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002015 // This should be a C++ destructor.
2016 SourceLocation TildeLoc = ConsumeToken();
2017 if (Tok.is(tok::identifier)) {
Sebastian Redlab197ba2009-02-09 18:23:29 +00002018 // FIXME: Inaccurate.
2019 SourceLocation NameLoc = Tok.getLocation();
Douglas Gregor7f43d672009-02-25 23:52:28 +00002020 SourceLocation EndLoc;
Douglas Gregor31a19b62009-04-01 21:51:26 +00002021 TypeResult Type = ParseClassName(EndLoc);
2022 if (Type.isInvalid())
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002023 D.SetIdentifier(0, TildeLoc);
Douglas Gregor31a19b62009-04-01 21:51:26 +00002024 else
2025 D.setDestructor(Type.get(), TildeLoc, NameLoc);
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002026 } else {
2027 Diag(Tok, diag::err_expected_class_name);
2028 D.SetIdentifier(0, TildeLoc);
2029 }
2030 goto PastIdentifier;
2031 }
2032
2033 // If we reached this point, token is not identifier and not '~'.
2034
2035 if (afterCXXScope) {
2036 Diag(Tok, diag::err_expected_unqualified_id);
2037 D.SetIdentifier(0, Tok.getLocation());
2038 D.setInvalidType(true);
2039 goto PastIdentifier;
Douglas Gregor2f1bc522008-11-07 20:08:42 +00002040 }
Douglas Gregor1cd1b1e2008-11-06 22:13:31 +00002041 }
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002042 }
2043
2044 // If we reached this point, we are either in C/ObjC or the token didn't
2045 // satisfy any of the C++-specific checks.
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002046 if (Tok.is(tok::identifier) && D.mayHaveIdentifier()) {
2047 assert(!getLang().CPlusPlus &&
2048 "There's a C++-specific check for tok::identifier above");
2049 assert(Tok.getIdentifierInfo() && "Not an identifier?");
2050 D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
2051 ConsumeToken();
2052 } else if (Tok.is(tok::l_paren)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00002053 // direct-declarator: '(' declarator ')'
2054 // direct-declarator: '(' attributes declarator ')'
2055 // Example: 'char (*X)' or 'int (*XX)(void)'
2056 ParseParenDeclarator(D);
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002057 } else if (D.mayOmitIdentifier()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00002058 // This could be something simple like "int" (in which case the declarator
2059 // portion is empty), if an abstract-declarator is allowed.
2060 D.SetIdentifier(0, Tok.getLocation());
2061 } else {
Douglas Gregore950d4b2009-03-06 23:28:18 +00002062 if (D.getContext() == Declarator::MemberContext)
2063 Diag(Tok, diag::err_expected_member_name_or_semi)
2064 << D.getDeclSpec().getSourceRange();
2065 else if (getLang().CPlusPlus)
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +00002066 Diag(Tok, diag::err_expected_unqualified_id);
2067 else
Chris Lattner1ab3b962008-11-18 07:48:38 +00002068 Diag(Tok, diag::err_expected_ident_lparen);
Reid Spencer5f016e22007-07-11 17:01:13 +00002069 D.SetIdentifier(0, Tok.getLocation());
Chris Lattner1f6f54b2008-11-11 06:13:16 +00002070 D.setInvalidType(true);
Reid Spencer5f016e22007-07-11 17:01:13 +00002071 }
2072
Argyrios Kyrtzidis314fe782008-11-26 22:40:03 +00002073 PastIdentifier:
Reid Spencer5f016e22007-07-11 17:01:13 +00002074 assert(D.isPastIdentifier() &&
2075 "Haven't past the location of the identifier yet?");
2076
2077 while (1) {
Chris Lattner04d66662007-10-09 17:33:22 +00002078 if (Tok.is(tok::l_paren)) {
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002079 // The paren may be part of a C++ direct initializer, eg. "int x(1);".
2080 // In such a case, check if we actually have a function declarator; if it
2081 // is not, the declarator has been fully parsed.
Chris Lattner7399ee02008-10-20 02:05:46 +00002082 if (getLang().CPlusPlus && D.mayBeFollowedByCXXDirectInit()) {
2083 // When not in file scope, warn for ambiguous function declarators, just
2084 // in case the author intended it as a variable definition.
2085 bool warnIfAmbiguous = D.getContext() != Declarator::FileContext;
2086 if (!isCXXFunctionDeclarator(warnIfAmbiguous))
2087 break;
2088 }
Chris Lattneref4715c2008-04-06 05:45:57 +00002089 ParseFunctionDeclarator(ConsumeParen(), D);
Chris Lattner04d66662007-10-09 17:33:22 +00002090 } else if (Tok.is(tok::l_square)) {
Reid Spencer5f016e22007-07-11 17:01:13 +00002091 ParseBracketDeclarator(D);
2092 } else {
2093 break;
2094 }
2095 }
2096}
2097
Chris Lattneref4715c2008-04-06 05:45:57 +00002098/// ParseParenDeclarator - We parsed the declarator D up to a paren. This is
2099/// only called before the identifier, so these are most likely just grouping
2100/// parens for precedence. If we find that these are actually function
2101/// parameter parens in an abstract-declarator, we call ParseFunctionDeclarator.
2102///
2103/// direct-declarator:
2104/// '(' declarator ')'
2105/// [GNU] '(' attributes declarator ')'
Chris Lattner7399ee02008-10-20 02:05:46 +00002106/// direct-declarator '(' parameter-type-list ')'
2107/// direct-declarator '(' identifier-list[opt] ')'
2108/// [GNU] direct-declarator '(' parameter-forward-declarations
2109/// parameter-type-list[opt] ')'
Chris Lattneref4715c2008-04-06 05:45:57 +00002110///
2111void Parser::ParseParenDeclarator(Declarator &D) {
2112 SourceLocation StartLoc = ConsumeParen();
2113 assert(!D.isPastIdentifier() && "Should be called before passing identifier");
2114
Chris Lattner7399ee02008-10-20 02:05:46 +00002115 // Eat any attributes before we look at whether this is a grouping or function
2116 // declarator paren. If this is a grouping paren, the attribute applies to
2117 // the type being built up, for example:
2118 // int (__attribute__(()) *x)(long y)
2119 // If this ends up not being a grouping paren, the attribute applies to the
2120 // first argument, for example:
2121 // int (__attribute__(()) int x)
2122 // In either case, we need to eat any attributes to be able to determine what
2123 // sort of paren this is.
2124 //
2125 AttributeList *AttrList = 0;
2126 bool RequiresArg = false;
2127 if (Tok.is(tok::kw___attribute)) {
2128 AttrList = ParseAttributes();
2129
2130 // We require that the argument list (if this is a non-grouping paren) be
2131 // present even if the attribute list was empty.
2132 RequiresArg = true;
2133 }
Steve Naroff239f0732008-12-25 14:16:32 +00002134 // Eat any Microsoft extensions.
Douglas Gregor5a2f5d32009-01-10 00:48:18 +00002135 while ((Tok.is(tok::kw___cdecl) || Tok.is(tok::kw___stdcall) ||
2136 (Tok.is(tok::kw___fastcall))) && PP.getLangOptions().Microsoft)
Steve Naroff239f0732008-12-25 14:16:32 +00002137 ConsumeToken();
Chris Lattner7399ee02008-10-20 02:05:46 +00002138
Chris Lattneref4715c2008-04-06 05:45:57 +00002139 // If we haven't past the identifier yet (or where the identifier would be
2140 // stored, if this is an abstract declarator), then this is probably just
2141 // grouping parens. However, if this could be an abstract-declarator, then
2142 // this could also be the start of function arguments (consider 'void()').
2143 bool isGrouping;
2144
2145 if (!D.mayOmitIdentifier()) {
2146 // If this can't be an abstract-declarator, this *must* be a grouping
2147 // paren, because we haven't seen the identifier yet.
2148 isGrouping = true;
2149 } else if (Tok.is(tok::r_paren) || // 'int()' is a function.
Argyrios Kyrtzidise25d2702008-10-06 00:07:55 +00002150 (getLang().CPlusPlus && Tok.is(tok::ellipsis)) || // C++ int(...)
Chris Lattneref4715c2008-04-06 05:45:57 +00002151 isDeclarationSpecifier()) { // 'int(int)' is a function.
2152 // This handles C99 6.7.5.3p11: in "typedef int X; void foo(X)", X is
2153 // considered to be a type, not a K&R identifier-list.
2154 isGrouping = false;
2155 } else {
2156 // Otherwise, this is a grouping paren, e.g. 'int (*X)' or 'int(X)'.
2157 isGrouping = true;
2158 }
2159
2160 // If this is a grouping paren, handle:
2161 // direct-declarator: '(' declarator ')'
2162 // direct-declarator: '(' attributes declarator ')'
2163 if (isGrouping) {
Argyrios Kyrtzidis3f2a8a02008-10-07 10:21:57 +00002164 bool hadGroupingParens = D.hasGroupingParens();
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002165 D.setGroupingParens(true);
Chris Lattner7399ee02008-10-20 02:05:46 +00002166 if (AttrList)
Sebastian Redlab197ba2009-02-09 18:23:29 +00002167 D.AddAttributes(AttrList, SourceLocation());
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +00002168
Sebastian Redl4c5d3202008-11-21 19:14:01 +00002169 ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator);
Chris Lattneref4715c2008-04-06 05:45:57 +00002170 // Match the ')'.
Sebastian Redlab197ba2009-02-09 18:23:29 +00002171 SourceLocation Loc = MatchRHSPunctuation(tok::r_paren, StartLoc);
Argyrios Kyrtzidis3f2a8a02008-10-07 10:21:57 +00002172
2173 D.setGroupingParens(hadGroupingParens);
Sebastian Redlab197ba2009-02-09 18:23:29 +00002174 D.SetRangeEnd(Loc);
Chris Lattneref4715c2008-04-06 05:45:57 +00002175 return;
2176 }
2177
2178 // Okay, if this wasn't a grouping paren, it must be the start of a function
2179 // argument list. Recognize that this declarator will never have an
Chris Lattner7399ee02008-10-20 02:05:46 +00002180 // identifier (and remember where it would have been), then call into
2181 // ParseFunctionDeclarator to handle of argument list.
Chris Lattneref4715c2008-04-06 05:45:57 +00002182 D.SetIdentifier(0, Tok.getLocation());
2183
Chris Lattner7399ee02008-10-20 02:05:46 +00002184 ParseFunctionDeclarator(StartLoc, D, AttrList, RequiresArg);
Chris Lattneref4715c2008-04-06 05:45:57 +00002185}
2186
2187/// ParseFunctionDeclarator - We are after the identifier and have parsed the
2188/// declarator D up to a paren, which indicates that we are parsing function
2189/// arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +00002190///
Chris Lattner7399ee02008-10-20 02:05:46 +00002191/// If AttrList is non-null, then the caller parsed those arguments immediately
2192/// after the open paren - they should be considered to be the first argument of
2193/// a parameter. If RequiresArg is true, then the first argument of the
2194/// function is required to be present and required to not be an identifier
2195/// list.
2196///
Reid Spencer5f016e22007-07-11 17:01:13 +00002197/// This method also handles this portion of the grammar:
2198/// parameter-type-list: [C99 6.7.5]
2199/// parameter-list
2200/// parameter-list ',' '...'
2201///
2202/// parameter-list: [C99 6.7.5]
2203/// parameter-declaration
2204/// parameter-list ',' parameter-declaration
2205///
2206/// parameter-declaration: [C99 6.7.5]
2207/// declaration-specifiers declarator
Chris Lattner04421082008-04-08 04:40:51 +00002208/// [C++] declaration-specifiers declarator '=' assignment-expression
Reid Spencer5f016e22007-07-11 17:01:13 +00002209/// [GNU] declaration-specifiers declarator attributes
Sebastian Redl50de12f2009-03-24 22:27:57 +00002210/// declaration-specifiers abstract-declarator[opt]
2211/// [C++] declaration-specifiers abstract-declarator[opt]
Chris Lattner8123a952008-04-10 02:22:51 +00002212/// '=' assignment-expression
Reid Spencer5f016e22007-07-11 17:01:13 +00002213/// [GNU] declaration-specifiers abstract-declarator[opt] attributes
2214///
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002215/// For C++, after the parameter-list, it also parses "cv-qualifier-seq[opt]"
Sebastian Redl50de12f2009-03-24 22:27:57 +00002216/// and "exception-specification[opt]".
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002217///
Chris Lattner7399ee02008-10-20 02:05:46 +00002218void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,
2219 AttributeList *AttrList,
2220 bool RequiresArg) {
Chris Lattneref4715c2008-04-06 05:45:57 +00002221 // lparen is already consumed!
2222 assert(D.isPastIdentifier() && "Should not call before identifier!");
Reid Spencer5f016e22007-07-11 17:01:13 +00002223
Chris Lattner7399ee02008-10-20 02:05:46 +00002224 // This parameter list may be empty.
Chris Lattner04d66662007-10-09 17:33:22 +00002225 if (Tok.is(tok::r_paren)) {
Chris Lattner7399ee02008-10-20 02:05:46 +00002226 if (RequiresArg) {
Chris Lattner1ab3b962008-11-18 07:48:38 +00002227 Diag(Tok, diag::err_argument_required_after_attribute);
Chris Lattner7399ee02008-10-20 02:05:46 +00002228 delete AttrList;
2229 }
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002230
Sebastian Redlab197ba2009-02-09 18:23:29 +00002231 SourceLocation Loc = ConsumeParen(); // Eat the closing ')'.
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002232
2233 // cv-qualifier-seq[opt].
2234 DeclSpec DS;
2235 if (getLang().CPlusPlus) {
Chris Lattner5a69d1c2008-12-18 07:02:59 +00002236 ParseTypeQualifierListOpt(DS, false /*no attributes*/);
Sebastian Redlab197ba2009-02-09 18:23:29 +00002237 if (!DS.getSourceRange().getEnd().isInvalid())
2238 Loc = DS.getSourceRange().getEnd();
Douglas Gregor0fe7bea2008-11-25 03:22:00 +00002239
2240 // Parse exception-specification[opt].
2241 if (Tok.is(tok::kw_throw))
Sebastian Redlab197ba2009-02-09 18:23:29 +00002242 ParseExceptionSpecification(Loc);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002243 }
2244
Chris Lattnerf97409f2008-04-06 06:57:35 +00002245 // Remember that we parsed a function type, and remember the attributes.
Reid Spencer5f016e22007-07-11 17:01:13 +00002246 // int() -> no prototype, no '...'.
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002247 D.AddTypeInfo(DeclaratorChunk::getFunction(/*prototype*/getLang().CPlusPlus,
Chris Lattnerf97409f2008-04-06 06:57:35 +00002248 /*variadic*/ false,
Douglas Gregor965acbb2009-02-18 07:07:28 +00002249 SourceLocation(),
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002250 /*arglist*/ 0, 0,
2251 DS.getTypeQualifiers(),
Sebastian Redlab197ba2009-02-09 18:23:29 +00002252 LParenLoc, D),
2253 Loc);
Chris Lattnerf97409f2008-04-06 06:57:35 +00002254 return;
Chris Lattner7399ee02008-10-20 02:05:46 +00002255 }
2256
2257 // Alternatively, this parameter list may be an identifier list form for a
2258 // K&R-style function: void foo(a,b,c)
Steve Naroff2d081c42009-01-28 19:16:40 +00002259 if (!getLang().CPlusPlus && Tok.is(tok::identifier)) {
Steve Narofff64ef622009-01-30 14:23:32 +00002260 if (!TryAnnotateTypeOrScopeToken()) {
Chris Lattner7399ee02008-10-20 02:05:46 +00002261 // K&R identifier lists can't have typedefs as identifiers, per
2262 // C99 6.7.5.3p11.
Steve Naroff2d081c42009-01-28 19:16:40 +00002263 if (RequiresArg) {
2264 Diag(Tok, diag::err_argument_required_after_attribute);
2265 delete AttrList;
2266 }
Steve Naroff2d081c42009-01-28 19:16:40 +00002267 // Identifier list. Note that '(' identifier-list ')' is only allowed for
2268 // normal declarators, not for abstract-declarators.
2269 return ParseFunctionDeclaratorIdentifierList(LParenLoc, D);
Chris Lattner7399ee02008-10-20 02:05:46 +00002270 }
Chris Lattnerf97409f2008-04-06 06:57:35 +00002271 }
2272
2273 // Finally, a normal, non-empty parameter type list.
2274
2275 // Build up an array of information about the parsed arguments.
2276 llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
Chris Lattner04421082008-04-08 04:40:51 +00002277
2278 // Enter function-declaration scope, limiting any declarators to the
2279 // function prototype scope, including parameter declarators.
Chris Lattnerae50fa02009-03-05 00:00:31 +00002280 ParseScope PrototypeScope(this,
2281 Scope::FunctionPrototypeScope|Scope::DeclScope);
Chris Lattnerf97409f2008-04-06 06:57:35 +00002282
2283 bool IsVariadic = false;
Douglas Gregor965acbb2009-02-18 07:07:28 +00002284 SourceLocation EllipsisLoc;
Chris Lattnerf97409f2008-04-06 06:57:35 +00002285 while (1) {
2286 if (Tok.is(tok::ellipsis)) {
2287 IsVariadic = true;
Douglas Gregor965acbb2009-02-18 07:07:28 +00002288 EllipsisLoc = ConsumeToken(); // Consume the ellipsis.
Chris Lattnerf97409f2008-04-06 06:57:35 +00002289 break;
Reid Spencer5f016e22007-07-11 17:01:13 +00002290 }
2291
Chris Lattnerf97409f2008-04-06 06:57:35 +00002292 SourceLocation DSStart = Tok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +00002293
Chris Lattnerf97409f2008-04-06 06:57:35 +00002294 // Parse the declaration-specifiers.
2295 DeclSpec DS;
Chris Lattner7399ee02008-10-20 02:05:46 +00002296
2297 // If the caller parsed attributes for the first argument, add them now.
2298 if (AttrList) {
2299 DS.AddAttributes(AttrList);
2300 AttrList = 0; // Only apply the attributes to the first parameter.
2301 }
Chris Lattnere64c5492009-02-27 18:38:20 +00002302 ParseDeclarationSpecifiers(DS);
2303
Chris Lattnerf97409f2008-04-06 06:57:35 +00002304 // Parse the declarator. This is "PrototypeContext", because we must
2305 // accept either 'declarator' or 'abstract-declarator' here.
2306 Declarator ParmDecl(DS, Declarator::PrototypeContext);
2307 ParseDeclarator(ParmDecl);
2308
2309 // Parse GNU attributes, if present.
Sebastian Redlab197ba2009-02-09 18:23:29 +00002310 if (Tok.is(tok::kw___attribute)) {
2311 SourceLocation Loc;
2312 AttributeList *AttrList = ParseAttributes(&Loc);
2313 ParmDecl.AddAttributes(AttrList, Loc);
2314 }
Chris Lattnerf97409f2008-04-06 06:57:35 +00002315
Chris Lattnerf97409f2008-04-06 06:57:35 +00002316 // Remember this parsed parameter in ParamInfo.
2317 IdentifierInfo *ParmII = ParmDecl.getIdentifier();
2318
Douglas Gregor72b505b2008-12-16 21:30:33 +00002319 // DefArgToks is used when the parsing of default arguments needs
2320 // to be delayed.
2321 CachedTokens *DefArgToks = 0;
2322
Chris Lattnerf97409f2008-04-06 06:57:35 +00002323 // If no parameter was specified, verify that *something* was specified,
2324 // otherwise we have a missing type and identifier.
Chris Lattnere64c5492009-02-27 18:38:20 +00002325 if (DS.isEmpty() && ParmDecl.getIdentifier() == 0 &&
2326 ParmDecl.getNumTypeObjects() == 0) {
Chris Lattnerf97409f2008-04-06 06:57:35 +00002327 // Completely missing, emit error.
2328 Diag(DSStart, diag::err_missing_param);
2329 } else {
2330 // Otherwise, we have something. Add it and let semantic analysis try
2331 // to grok it and add the result to the ParamInfo we are building.
2332
2333 // Inform the actions module about the parameter declarator, so it gets
2334 // added to the current scope.
Chris Lattnerb28317a2009-03-28 19:18:32 +00002335 DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
Chris Lattner04421082008-04-08 04:40:51 +00002336
2337 // Parse the default argument, if any. We parse the default
2338 // arguments in all dialects; the semantic analysis in
2339 // ActOnParamDefaultArgument will reject the default argument in
2340 // C.
2341 if (Tok.is(tok::equal)) {
Douglas Gregor61366e92008-12-24 00:01:03 +00002342 SourceLocation EqualLoc = Tok.getLocation();
2343
Chris Lattner04421082008-04-08 04:40:51 +00002344 // Parse the default argument
Douglas Gregor72b505b2008-12-16 21:30:33 +00002345 if (D.getContext() == Declarator::MemberContext) {
2346 // If we're inside a class definition, cache the tokens
2347 // corresponding to the default argument. We'll actually parse
2348 // them when we see the end of the class definition.
2349 // FIXME: Templates will require something similar.
2350 // FIXME: Can we use a smart pointer for Toks?
2351 DefArgToks = new CachedTokens;
2352
2353 if (!ConsumeAndStoreUntil(tok::comma, tok::r_paren, *DefArgToks,
2354 tok::semi, false)) {
2355 delete DefArgToks;
2356 DefArgToks = 0;
Douglas Gregor61366e92008-12-24 00:01:03 +00002357 Actions.ActOnParamDefaultArgumentError(Param);
2358 } else
2359 Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc);
Chris Lattner04421082008-04-08 04:40:51 +00002360 } else {
Douglas Gregor72b505b2008-12-16 21:30:33 +00002361 // Consume the '='.
Douglas Gregor61366e92008-12-24 00:01:03 +00002362 ConsumeToken();
Douglas Gregor72b505b2008-12-16 21:30:33 +00002363
2364 OwningExprResult DefArgResult(ParseAssignmentExpression());
2365 if (DefArgResult.isInvalid()) {
2366 Actions.ActOnParamDefaultArgumentError(Param);
2367 SkipUntil(tok::comma, tok::r_paren, true, true);
2368 } else {
2369 // Inform the actions module about the default argument
2370 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
Sebastian Redlf53597f2009-03-15 17:47:39 +00002371 move(DefArgResult));
Douglas Gregor72b505b2008-12-16 21:30:33 +00002372 }
Chris Lattner04421082008-04-08 04:40:51 +00002373 }
2374 }
Chris Lattnerf97409f2008-04-06 06:57:35 +00002375
2376 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
Douglas Gregor72b505b2008-12-16 21:30:33 +00002377 ParmDecl.getIdentifierLoc(), Param,
2378 DefArgToks));
Chris Lattnerf97409f2008-04-06 06:57:35 +00002379 }
2380
2381 // If the next token is a comma, consume it and keep reading arguments.
2382 if (Tok.isNot(tok::comma)) break;
2383
2384 // Consume the comma.
2385 ConsumeToken();
Reid Spencer5f016e22007-07-11 17:01:13 +00002386 }
2387
Chris Lattnerf97409f2008-04-06 06:57:35 +00002388 // Leave prototype scope.
Douglas Gregor8935b8b2008-12-10 06:34:36 +00002389 PrototypeScope.Exit();
Chris Lattnerf97409f2008-04-06 06:57:35 +00002390
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002391 // If we have the closing ')', eat it.
Sebastian Redlab197ba2009-02-09 18:23:29 +00002392 SourceLocation Loc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002393
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002394 DeclSpec DS;
2395 if (getLang().CPlusPlus) {
Douglas Gregor0fe7bea2008-11-25 03:22:00 +00002396 // Parse cv-qualifier-seq[opt].
Chris Lattner5a69d1c2008-12-18 07:02:59 +00002397 ParseTypeQualifierListOpt(DS, false /*no attributes*/);
Sebastian Redlab197ba2009-02-09 18:23:29 +00002398 if (!DS.getSourceRange().getEnd().isInvalid())
2399 Loc = DS.getSourceRange().getEnd();
Douglas Gregor0fe7bea2008-11-25 03:22:00 +00002400
2401 // Parse exception-specification[opt].
2402 if (Tok.is(tok::kw_throw))
Sebastian Redlab197ba2009-02-09 18:23:29 +00002403 ParseExceptionSpecification(Loc);
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002404 }
2405
Reid Spencer5f016e22007-07-11 17:01:13 +00002406 // Remember that we parsed a function type, and remember the attributes.
Chris Lattnerf97409f2008-04-06 06:57:35 +00002407 D.AddTypeInfo(DeclaratorChunk::getFunction(/*proto*/true, IsVariadic,
Douglas Gregor965acbb2009-02-18 07:07:28 +00002408 EllipsisLoc,
Chris Lattnerf97409f2008-04-06 06:57:35 +00002409 &ParamInfo[0], ParamInfo.size(),
Argyrios Kyrtzidis971c4fa2008-10-24 21:46:40 +00002410 DS.getTypeQualifiers(),
Sebastian Redlab197ba2009-02-09 18:23:29 +00002411 LParenLoc, D),
2412 Loc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002413}
2414
Chris Lattner66d28652008-04-06 06:34:08 +00002415/// ParseFunctionDeclaratorIdentifierList - While parsing a function declarator
2416/// we found a K&R-style identifier list instead of a type argument list. The
2417/// current token is known to be the first identifier in the list.
2418///
2419/// identifier-list: [C99 6.7.5]
2420/// identifier
2421/// identifier-list ',' identifier
2422///
2423void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,
2424 Declarator &D) {
2425 // Build up an array of information about the parsed arguments.
2426 llvm::SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo;
2427 llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar;
2428
2429 // If there was no identifier specified for the declarator, either we are in
2430 // an abstract-declarator, or we are in a parameter declarator which was found
2431 // to be abstract. In abstract-declarators, identifier lists are not valid:
2432 // diagnose this.
2433 if (!D.getIdentifier())
2434 Diag(Tok, diag::ext_ident_list_in_param);
2435
2436 // Tok is known to be the first identifier in the list. Remember this
2437 // identifier in ParamInfo.
Chris Lattner3825c2e2008-04-06 06:50:56 +00002438 ParamsSoFar.insert(Tok.getIdentifierInfo());
Chris Lattner66d28652008-04-06 06:34:08 +00002439 ParamInfo.push_back(DeclaratorChunk::ParamInfo(Tok.getIdentifierInfo(),
Chris Lattnerb28317a2009-03-28 19:18:32 +00002440 Tok.getLocation(),
2441 DeclPtrTy()));
Chris Lattner66d28652008-04-06 06:34:08 +00002442
Chris Lattner50c64772008-04-06 06:39:19 +00002443 ConsumeToken(); // eat the first identifier.
Chris Lattner66d28652008-04-06 06:34:08 +00002444
2445 while (Tok.is(tok::comma)) {
2446 // Eat the comma.
2447 ConsumeToken();
2448
Chris Lattner50c64772008-04-06 06:39:19 +00002449 // If this isn't an identifier, report the error and skip until ')'.
Chris Lattner66d28652008-04-06 06:34:08 +00002450 if (Tok.isNot(tok::identifier)) {
2451 Diag(Tok, diag::err_expected_ident);
Chris Lattner50c64772008-04-06 06:39:19 +00002452 SkipUntil(tok::r_paren);
2453 return;
Chris Lattner66d28652008-04-06 06:34:08 +00002454 }
Chris Lattneraaf9ddb2008-04-06 06:47:48 +00002455
Chris Lattner66d28652008-04-06 06:34:08 +00002456 IdentifierInfo *ParmII = Tok.getIdentifierInfo();
Chris Lattneraaf9ddb2008-04-06 06:47:48 +00002457
2458 // Reject 'typedef int y; int test(x, y)', but continue parsing.
Douglas Gregorb696ea32009-02-04 17:00:24 +00002459 if (Actions.getTypeName(*ParmII, Tok.getLocation(), CurScope))
Chris Lattnerda83bac2008-11-19 07:37:42 +00002460 Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII;
Chris Lattner66d28652008-04-06 06:34:08 +00002461
2462 // Verify that the argument identifier has not already been mentioned.
2463 if (!ParamsSoFar.insert(ParmII)) {
Chris Lattnerda83bac2008-11-19 07:37:42 +00002464 Diag(Tok, diag::err_param_redefinition) << ParmII;
Chris Lattner50c64772008-04-06 06:39:19 +00002465 } else {
2466 // Remember this identifier in ParamInfo.
Chris Lattner66d28652008-04-06 06:34:08 +00002467 ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
Chris Lattnerb28317a2009-03-28 19:18:32 +00002468 Tok.getLocation(),
2469 DeclPtrTy()));
Chris Lattner50c64772008-04-06 06:39:19 +00002470 }
Chris Lattner66d28652008-04-06 06:34:08 +00002471
2472 // Eat the identifier.
2473 ConsumeToken();
2474 }
Sebastian Redlab197ba2009-02-09 18:23:29 +00002475
2476 // If we have the closing ')', eat it and we're done.
2477 SourceLocation RLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
2478
Chris Lattner50c64772008-04-06 06:39:19 +00002479 // Remember that we parsed a function type, and remember the attributes. This
2480 // function type is always a K&R style function type, which is not varargs and
2481 // has no prototype.
2482 D.AddTypeInfo(DeclaratorChunk::getFunction(/*proto*/false, /*varargs*/false,
Douglas Gregor965acbb2009-02-18 07:07:28 +00002483 SourceLocation(),
Chris Lattner50c64772008-04-06 06:39:19 +00002484 &ParamInfo[0], ParamInfo.size(),
Sebastian Redlab197ba2009-02-09 18:23:29 +00002485 /*TypeQuals*/0, LParenLoc, D),
2486 RLoc);
Chris Lattner66d28652008-04-06 06:34:08 +00002487}
Chris Lattneref4715c2008-04-06 05:45:57 +00002488
Reid Spencer5f016e22007-07-11 17:01:13 +00002489/// [C90] direct-declarator '[' constant-expression[opt] ']'
2490/// [C99] direct-declarator '[' type-qual-list[opt] assignment-expr[opt] ']'
2491/// [C99] direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']'
2492/// [C99] direct-declarator '[' type-qual-list 'static' assignment-expr ']'
2493/// [C99] direct-declarator '[' type-qual-list[opt] '*' ']'
2494void Parser::ParseBracketDeclarator(Declarator &D) {
2495 SourceLocation StartLoc = ConsumeBracket();
2496
Chris Lattner378c7e42008-12-18 07:27:21 +00002497 // C array syntax has many features, but by-far the most common is [] and [4].
2498 // This code does a fast path to handle some of the most obvious cases.
2499 if (Tok.getKind() == tok::r_square) {
Sebastian Redlab197ba2009-02-09 18:23:29 +00002500 SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc);
Chris Lattner378c7e42008-12-18 07:27:21 +00002501 // Remember that we parsed the empty array type.
2502 OwningExprResult NumElements(Actions);
Sebastian Redlab197ba2009-02-09 18:23:29 +00002503 D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, 0, StartLoc),
2504 EndLoc);
Chris Lattner378c7e42008-12-18 07:27:21 +00002505 return;
2506 } else if (Tok.getKind() == tok::numeric_constant &&
2507 GetLookAheadToken(1).is(tok::r_square)) {
2508 // [4] is very common. Parse the numeric constant expression.
Sebastian Redlcd965b92009-01-18 18:53:16 +00002509 OwningExprResult ExprRes(Actions.ActOnNumericConstant(Tok));
Chris Lattner378c7e42008-12-18 07:27:21 +00002510 ConsumeToken();
2511
Sebastian Redlab197ba2009-02-09 18:23:29 +00002512 SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc);
Chris Lattner378c7e42008-12-18 07:27:21 +00002513
2514 // If there was an error parsing the assignment-expression, recover.
2515 if (ExprRes.isInvalid())
2516 ExprRes.release(); // Deallocate expr, just use [].
2517
2518 // Remember that we parsed a array type, and remember its features.
2519 D.AddTypeInfo(DeclaratorChunk::getArray(0, false, 0,
Sebastian Redlab197ba2009-02-09 18:23:29 +00002520 ExprRes.release(), StartLoc),
2521 EndLoc);
Chris Lattner378c7e42008-12-18 07:27:21 +00002522 return;
2523 }
2524
Reid Spencer5f016e22007-07-11 17:01:13 +00002525 // If valid, this location is the position where we read the 'static' keyword.
2526 SourceLocation StaticLoc;
Chris Lattner04d66662007-10-09 17:33:22 +00002527 if (Tok.is(tok::kw_static))
Reid Spencer5f016e22007-07-11 17:01:13 +00002528 StaticLoc = ConsumeToken();
2529
2530 // If there is a type-qualifier-list, read it now.
Chris Lattnera1fcbad2008-12-18 06:50:14 +00002531 // Type qualifiers in an array subscript are a C99 feature.
Reid Spencer5f016e22007-07-11 17:01:13 +00002532 DeclSpec DS;
Chris Lattner5a69d1c2008-12-18 07:02:59 +00002533 ParseTypeQualifierListOpt(DS, false /*no attributes*/);
Reid Spencer5f016e22007-07-11 17:01:13 +00002534
2535 // If we haven't already read 'static', check to see if there is one after the
2536 // type-qualifier-list.
Chris Lattner04d66662007-10-09 17:33:22 +00002537 if (!StaticLoc.isValid() && Tok.is(tok::kw_static))
Reid Spencer5f016e22007-07-11 17:01:13 +00002538 StaticLoc = ConsumeToken();
2539
2540 // Handle "direct-declarator [ type-qual-list[opt] * ]".
2541 bool isStar = false;
Sebastian Redl15faa7f2008-12-09 20:22:58 +00002542 OwningExprResult NumElements(Actions);
Chris Lattner5dcc6ce2008-04-06 05:26:30 +00002543
2544 // Handle the case where we have '[*]' as the array size. However, a leading
2545 // star could be the start of an expression, for example 'X[*p + 4]'. Verify
2546 // the the token after the star is a ']'. Since stars in arrays are
2547 // infrequent, use of lookahead is not costly here.
2548 if (Tok.is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) {
Chris Lattnera711dd02008-04-06 05:27:21 +00002549 ConsumeToken(); // Eat the '*'.
Reid Spencer5f016e22007-07-11 17:01:13 +00002550
Chris Lattnera1fcbad2008-12-18 06:50:14 +00002551 if (StaticLoc.isValid()) {
Chris Lattner5dcc6ce2008-04-06 05:26:30 +00002552 Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
Chris Lattnera1fcbad2008-12-18 06:50:14 +00002553 StaticLoc = SourceLocation(); // Drop the static.
2554 }
Chris Lattner5dcc6ce2008-04-06 05:26:30 +00002555 isStar = true;
Chris Lattner04d66662007-10-09 17:33:22 +00002556 } else if (Tok.isNot(tok::r_square)) {
Chris Lattner378c7e42008-12-18 07:27:21 +00002557 // Note, in C89, this production uses the constant-expr production instead
2558 // of assignment-expr. The only difference is that assignment-expr allows
2559 // things like '=' and '*='. Sema rejects these in C89 mode because they
2560 // are not i-c-e's, so we don't need to distinguish between the two here.
2561
Reid Spencer5f016e22007-07-11 17:01:13 +00002562 // Parse the assignment-expression now.
2563 NumElements = ParseAssignmentExpression();
2564 }
2565
2566 // If there was an error parsing the assignment-expression, recover.
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00002567 if (NumElements.isInvalid()) {
Reid Spencer5f016e22007-07-11 17:01:13 +00002568 // If the expression was invalid, skip it.
2569 SkipUntil(tok::r_square);
2570 return;
2571 }
Sebastian Redlab197ba2009-02-09 18:23:29 +00002572
2573 SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc);
2574
Chris Lattner378c7e42008-12-18 07:27:21 +00002575 // Remember that we parsed a array type, and remember its features.
Reid Spencer5f016e22007-07-11 17:01:13 +00002576 D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
2577 StaticLoc.isValid(), isStar,
Sebastian Redlab197ba2009-02-09 18:23:29 +00002578 NumElements.release(), StartLoc),
2579 EndLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +00002580}
2581
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002582/// [GNU] typeof-specifier:
2583/// typeof ( expressions )
2584/// typeof ( type-name )
2585/// [GNU/C++] typeof unary-expression
Steve Naroffd1861fd2007-07-31 12:34:36 +00002586///
2587void Parser::ParseTypeofSpecifier(DeclSpec &DS) {
Chris Lattner04d66662007-10-09 17:33:22 +00002588 assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier");
Steve Naroff9dfa7b42007-08-02 02:53:48 +00002589 const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo();
Steve Naroffd1861fd2007-07-31 12:34:36 +00002590 SourceLocation StartLoc = ConsumeToken();
2591
Chris Lattner04d66662007-10-09 17:33:22 +00002592 if (Tok.isNot(tok::l_paren)) {
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002593 if (!getLang().CPlusPlus) {
Chris Lattner08631c52008-11-23 21:45:46 +00002594 Diag(Tok, diag::err_expected_lparen_after_id) << BuiltinII;
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002595 return;
2596 }
2597
Sebastian Redl2f7ece72008-12-11 21:36:32 +00002598 OwningExprResult Result(ParseCastExpression(true/*isUnaryExpression*/));
Douglas Gregor809070a2009-02-18 17:45:20 +00002599 if (Result.isInvalid()) {
2600 DS.SetTypeSpecError();
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002601 return;
Douglas Gregor809070a2009-02-18 17:45:20 +00002602 }
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002603
2604 const char *PrevSpec = 0;
2605 // Check for duplicate type specifiers.
2606 if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
Sebastian Redleffa8d12008-12-10 00:02:53 +00002607 Result.release()))
Chris Lattner1ab3b962008-11-18 07:48:38 +00002608 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002609
2610 // FIXME: Not accurate, the range gets one token more than it should.
2611 DS.SetRangeEnd(Tok.getLocation());
Steve Naroff9dfa7b42007-08-02 02:53:48 +00002612 return;
Steve Naroffd1861fd2007-07-31 12:34:36 +00002613 }
Argyrios Kyrtzidis0f072032008-09-05 11:26:19 +00002614
Steve Naroffd1861fd2007-07-31 12:34:36 +00002615 SourceLocation LParenLoc = ConsumeParen(), RParenLoc;
2616
Argyrios Kyrtzidis78c8d802008-10-05 19:56:22 +00002617 if (isTypeIdInParens()) {
Douglas Gregor809070a2009-02-18 17:45:20 +00002618 Action::TypeResult Ty = ParseTypeName();
Steve Naroffd1861fd2007-07-31 12:34:36 +00002619
Douglas Gregor809070a2009-02-18 17:45:20 +00002620 assert((Ty.isInvalid() || Ty.get()) &&
2621 "Parser::ParseTypeofSpecifier(): missing type");
Steve Naroff2cb64ec2007-07-31 23:56:32 +00002622
Chris Lattner04d66662007-10-09 17:33:22 +00002623 if (Tok.isNot(tok::r_paren)) {
Steve Naroff2cb64ec2007-07-31 23:56:32 +00002624 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Steve Naroff9dfa7b42007-08-02 02:53:48 +00002625 return;
2626 }
2627 RParenLoc = ConsumeParen();
Douglas Gregor809070a2009-02-18 17:45:20 +00002628
2629 if (Ty.isInvalid())
2630 DS.SetTypeSpecError();
2631 else {
2632 const char *PrevSpec = 0;
2633 // Check for duplicate type specifiers (e.g. "int typeof(int)").
2634 if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec,
2635 Ty.get()))
2636 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
2637 }
Steve Naroffd1861fd2007-07-31 12:34:36 +00002638 } else { // we have an expression.
Sebastian Redl2f7ece72008-12-11 21:36:32 +00002639 OwningExprResult Result(ParseExpression());
Sebastian Redl0e9eabc2008-12-09 13:15:23 +00002640
2641 if (Result.isInvalid() || Tok.isNot(tok::r_paren)) {
Steve Naroff2cb64ec2007-07-31 23:56:32 +00002642 MatchRHSPunctuation(tok::r_paren, LParenLoc);
Douglas Gregor809070a2009-02-18 17:45:20 +00002643 DS.SetTypeSpecError();
Steve Naroff9dfa7b42007-08-02 02:53:48 +00002644 return;
2645 }
2646 RParenLoc = ConsumeParen();
2647 const char *PrevSpec = 0;
2648 // Check for duplicate type specifiers (e.g. "int typeof(int)").
2649 if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec,
Sebastian Redleffa8d12008-12-10 00:02:53 +00002650 Result.release()))
Chris Lattner1ab3b962008-11-18 07:48:38 +00002651 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
Steve Naroffd1861fd2007-07-31 12:34:36 +00002652 }
Argyrios Kyrtzidis0919f9e2008-08-16 10:21:33 +00002653 DS.SetRangeEnd(RParenLoc);
Steve Naroffd1861fd2007-07-31 12:34:36 +00002654}
2655
Argyrios Kyrtzidis00bc6452008-05-09 23:39:43 +00002656