blob: 81ea52ca690ef1d04069e263b45b564ebf2de344 [file] [log] [blame]
Chris Lattner8f08cb72007-08-25 06:57:03 +00001//===--- ParseDeclCXX.cpp - C++ 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.
Chris Lattner8f08cb72007-08-25 06:57:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the C++ Declaration portions of the Parser interfaces.
11//
12//===----------------------------------------------------------------------===//
13
Douglas Gregor1b7f8982008-04-14 00:13:42 +000014#include "clang/Parse/Parser.h"
Douglas Gregore37ac4f2008-04-13 21:30:24 +000015#include "clang/Basic/Diagnostic.h"
16#include "clang/Parse/DeclSpec.h"
Chris Lattner8f08cb72007-08-25 06:57:03 +000017#include "clang/Parse/Scope.h"
Sebastian Redla55e52c2008-11-25 22:21:31 +000018#include "AstGuard.h"
Chris Lattnerbc8d5642008-12-18 01:12:00 +000019#include "ExtensionRAIIObject.h"
Chris Lattner8f08cb72007-08-25 06:57:03 +000020using namespace clang;
21
22/// ParseNamespace - We know that the current token is a namespace keyword. This
23/// may either be a top level namespace or a block-level namespace alias.
24///
25/// namespace-definition: [C++ 7.3: basic.namespace]
26/// named-namespace-definition
27/// unnamed-namespace-definition
28///
29/// unnamed-namespace-definition:
30/// 'namespace' attributes[opt] '{' namespace-body '}'
31///
32/// named-namespace-definition:
33/// original-namespace-definition
34/// extension-namespace-definition
35///
36/// original-namespace-definition:
37/// 'namespace' identifier attributes[opt] '{' namespace-body '}'
38///
39/// extension-namespace-definition:
40/// 'namespace' original-namespace-name '{' namespace-body '}'
41///
42/// namespace-alias-definition: [C++ 7.3.2: namespace.alias]
43/// 'namespace' identifier '=' qualified-namespace-specifier ';'
44///
45Parser::DeclTy *Parser::ParseNamespace(unsigned Context) {
Chris Lattner04d66662007-10-09 17:33:22 +000046 assert(Tok.is(tok::kw_namespace) && "Not a namespace!");
Chris Lattner8f08cb72007-08-25 06:57:03 +000047 SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'.
48
49 SourceLocation IdentLoc;
50 IdentifierInfo *Ident = 0;
51
Chris Lattner04d66662007-10-09 17:33:22 +000052 if (Tok.is(tok::identifier)) {
Chris Lattner8f08cb72007-08-25 06:57:03 +000053 Ident = Tok.getIdentifierInfo();
54 IdentLoc = ConsumeToken(); // eat the identifier.
55 }
56
57 // Read label attributes, if present.
58 DeclTy *AttrList = 0;
Chris Lattner04d66662007-10-09 17:33:22 +000059 if (Tok.is(tok::kw___attribute))
Chris Lattner8f08cb72007-08-25 06:57:03 +000060 // FIXME: save these somewhere.
61 AttrList = ParseAttributes();
62
Chris Lattner04d66662007-10-09 17:33:22 +000063 if (Tok.is(tok::equal)) {
Chris Lattner8f08cb72007-08-25 06:57:03 +000064 // FIXME: Verify no attributes were present.
65 // FIXME: parse this.
Chris Lattner04d66662007-10-09 17:33:22 +000066 } else if (Tok.is(tok::l_brace)) {
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000067
Chris Lattner8f08cb72007-08-25 06:57:03 +000068 SourceLocation LBrace = ConsumeBrace();
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000069
70 // Enter a scope for the namespace.
Douglas Gregor8935b8b2008-12-10 06:34:36 +000071 ParseScope NamespaceScope(this, Scope::DeclScope);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000072
73 DeclTy *NamespcDecl =
74 Actions.ActOnStartNamespaceDef(CurScope, IdentLoc, Ident, LBrace);
75
76 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof))
Chris Lattnerbae35112007-08-25 18:15:16 +000077 ParseExternalDeclaration();
Chris Lattner8f08cb72007-08-25 06:57:03 +000078
Argyrios Kyrtzidis8ba5d792008-05-01 21:44:34 +000079 // Leave the namespace scope.
Douglas Gregor8935b8b2008-12-10 06:34:36 +000080 NamespaceScope.Exit();
Argyrios Kyrtzidis8ba5d792008-05-01 21:44:34 +000081
Chris Lattner8f08cb72007-08-25 06:57:03 +000082 SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000083 Actions.ActOnFinishNamespaceDef(NamespcDecl, RBrace);
84
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +000085 return NamespcDecl;
Chris Lattner8f08cb72007-08-25 06:57:03 +000086
Chris Lattner8f08cb72007-08-25 06:57:03 +000087 } else {
Chris Lattner1ab3b962008-11-18 07:48:38 +000088 Diag(Tok, Ident ? diag::err_expected_lbrace :
89 diag::err_expected_ident_lbrace);
Chris Lattner8f08cb72007-08-25 06:57:03 +000090 }
91
92 return 0;
93}
Chris Lattnerc6fdc342008-01-12 07:05:38 +000094
95/// ParseLinkage - We know that the current token is a string_literal
96/// and just before that, that extern was seen.
97///
98/// linkage-specification: [C++ 7.5p2: dcl.link]
99/// 'extern' string-literal '{' declaration-seq[opt] '}'
100/// 'extern' string-literal declaration
101///
102Parser::DeclTy *Parser::ParseLinkage(unsigned Context) {
Douglas Gregorc19923d2008-11-21 16:10:08 +0000103 assert(Tok.is(tok::string_literal) && "Not a string literal!");
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000104 llvm::SmallVector<char, 8> LangBuffer;
105 // LangBuffer is guaranteed to be big enough.
106 LangBuffer.resize(Tok.getLength());
107 const char *LangBufPtr = &LangBuffer[0];
108 unsigned StrSize = PP.getSpelling(Tok, LangBufPtr);
109
110 SourceLocation Loc = ConsumeStringToken();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000111
Douglas Gregor074149e2009-01-05 19:45:36 +0000112 ParseScope LinkageScope(this, Scope::DeclScope);
113 DeclTy *LinkageSpec
114 = Actions.ActOnStartLinkageSpecification(CurScope,
115 /*FIXME: */SourceLocation(),
116 Loc, LangBufPtr, StrSize,
117 Tok.is(tok::l_brace)? Tok.getLocation()
118 : SourceLocation());
119
120 if (Tok.isNot(tok::l_brace)) {
121 ParseDeclarationOrFunctionDefinition();
122 return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec,
123 SourceLocation());
Douglas Gregorf44515a2008-12-16 22:23:02 +0000124 }
125
126 SourceLocation LBrace = ConsumeBrace();
Douglas Gregorf44515a2008-12-16 22:23:02 +0000127 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
Douglas Gregor074149e2009-01-05 19:45:36 +0000128 ParseExternalDeclaration();
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000129 }
130
Douglas Gregorf44515a2008-12-16 22:23:02 +0000131 SourceLocation RBrace = MatchRHSPunctuation(tok::r_brace, LBrace);
Douglas Gregor074149e2009-01-05 19:45:36 +0000132 return Actions.ActOnFinishLinkageSpecification(CurScope, LinkageSpec, RBrace);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000133}
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000134
Douglas Gregorf780abc2008-12-30 03:27:21 +0000135/// ParseUsingDirectiveOrDeclaration - Parse C++ using using-declaration or
136/// using-directive. Assumes that current token is 'using'.
Chris Lattner2f274772009-01-06 06:55:51 +0000137Parser::DeclTy *Parser::ParseUsingDirectiveOrDeclaration(unsigned Context) {
Douglas Gregorf780abc2008-12-30 03:27:21 +0000138 assert(Tok.is(tok::kw_using) && "Not using token");
139
140 // Eat 'using'.
141 SourceLocation UsingLoc = ConsumeToken();
142
Chris Lattner2f274772009-01-06 06:55:51 +0000143 if (Tok.is(tok::kw_namespace))
Douglas Gregorf780abc2008-12-30 03:27:21 +0000144 // Next token after 'using' is 'namespace' so it must be using-directive
145 return ParseUsingDirective(Context, UsingLoc);
Chris Lattner2f274772009-01-06 06:55:51 +0000146
147 // Otherwise, it must be using-declaration.
148 return ParseUsingDeclaration(Context, UsingLoc);
Douglas Gregorf780abc2008-12-30 03:27:21 +0000149}
150
151/// ParseUsingDirective - Parse C++ using-directive, assumes
152/// that current token is 'namespace' and 'using' was already parsed.
153///
154/// using-directive: [C++ 7.3.p4: namespace.udir]
155/// 'using' 'namespace' ::[opt] nested-name-specifier[opt]
156/// namespace-name ;
157/// [GNU] using-directive:
158/// 'using' 'namespace' ::[opt] nested-name-specifier[opt]
159/// namespace-name attributes[opt] ;
160///
161Parser::DeclTy *Parser::ParseUsingDirective(unsigned Context,
162 SourceLocation UsingLoc) {
163 assert(Tok.is(tok::kw_namespace) && "Not 'namespace' token");
164
165 // Eat 'namespace'.
166 SourceLocation NamespcLoc = ConsumeToken();
167
168 CXXScopeSpec SS;
169 // Parse (optional) nested-name-specifier.
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000170 ParseOptionalCXXScopeSpecifier(SS);
Douglas Gregorf780abc2008-12-30 03:27:21 +0000171
172 AttributeList *AttrList = 0;
173 IdentifierInfo *NamespcName = 0;
174 SourceLocation IdentLoc = SourceLocation();
175
176 // Parse namespace-name.
Chris Lattner823c44e2009-01-06 07:27:21 +0000177 if (SS.isInvalid() || Tok.isNot(tok::identifier)) {
Douglas Gregorf780abc2008-12-30 03:27:21 +0000178 Diag(Tok, diag::err_expected_namespace_name);
179 // If there was invalid namespace name, skip to end of decl, and eat ';'.
180 SkipUntil(tok::semi);
181 // FIXME: Are there cases, when we would like to call ActOnUsingDirective?
182 return 0;
183 }
Chris Lattner823c44e2009-01-06 07:27:21 +0000184
185 // Parse identifier.
186 NamespcName = Tok.getIdentifierInfo();
187 IdentLoc = ConsumeToken();
188
189 // Parse (optional) attributes (most likely GNU strong-using extension).
190 if (Tok.is(tok::kw___attribute))
191 AttrList = ParseAttributes();
192
193 // Eat ';'.
194 ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
195 AttrList ? "attributes list" : "namespace name", tok::semi);
Douglas Gregorf780abc2008-12-30 03:27:21 +0000196
197 return Actions.ActOnUsingDirective(CurScope, UsingLoc, NamespcLoc, SS,
Chris Lattner823c44e2009-01-06 07:27:21 +0000198 IdentLoc, NamespcName, AttrList);
Douglas Gregorf780abc2008-12-30 03:27:21 +0000199}
200
201/// ParseUsingDeclaration - Parse C++ using-declaration. Assumes that
202/// 'using' was already seen.
203///
204/// using-declaration: [C++ 7.3.p3: namespace.udecl]
205/// 'using' 'typename'[opt] ::[opt] nested-name-specifier
206/// unqualified-id [TODO]
207/// 'using' :: unqualified-id [TODO]
208///
209Parser::DeclTy *Parser::ParseUsingDeclaration(unsigned Context,
210 SourceLocation UsingLoc) {
211 assert(false && "Not implemented");
212 // FIXME: Implement parsing.
213 return 0;
214}
215
Douglas Gregor42a552f2008-11-05 20:51:48 +0000216/// ParseClassName - Parse a C++ class-name, which names a class. Note
217/// that we only check that the result names a type; semantic analysis
218/// will need to verify that the type names a class. The result is
219/// either a type or NULL, dependending on whether a type name was
220/// found.
221///
222/// class-name: [C++ 9.1]
223/// identifier
224/// template-id [TODO]
225///
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000226Parser::TypeTy *Parser::ParseClassName(const CXXScopeSpec *SS) {
Douglas Gregor42a552f2008-11-05 20:51:48 +0000227 // Parse the class-name.
228 // FIXME: Alternatively, parse a simple-template-id.
229 if (Tok.isNot(tok::identifier)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000230 Diag(Tok, diag::err_expected_class_name);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000231 return 0;
232 }
233
234 // We have an identifier; check whether it is actually a type.
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000235 TypeTy *Type = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope, SS);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000236 if (!Type) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000237 Diag(Tok, diag::err_expected_class_name);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000238 return 0;
239 }
240
241 // Consume the identifier.
242 ConsumeToken();
243
244 return Type;
245}
246
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000247/// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or
248/// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which
249/// until we reach the start of a definition or see a token that
250/// cannot start a definition.
251///
252/// class-specifier: [C++ class]
253/// class-head '{' member-specification[opt] '}'
254/// class-head '{' member-specification[opt] '}' attributes[opt]
255/// class-head:
256/// class-key identifier[opt] base-clause[opt]
257/// class-key nested-name-specifier identifier base-clause[opt]
258/// class-key nested-name-specifier[opt] simple-template-id
259/// base-clause[opt]
260/// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt]
261/// [GNU] class-key attributes[opt] nested-name-specifier
262/// identifier base-clause[opt]
263/// [GNU] class-key attributes[opt] nested-name-specifier[opt]
264/// simple-template-id base-clause[opt]
265/// class-key:
266/// 'class'
267/// 'struct'
268/// 'union'
269///
270/// elaborated-type-specifier: [C++ dcl.type.elab]
271/// class-key ::[opt] nested-name-specifier[opt] identifier
272/// class-key ::[opt] nested-name-specifier[opt] 'template'[opt]
273/// simple-template-id
274///
275/// Note that the C++ class-specifier and elaborated-type-specifier,
276/// together, subsume the C99 struct-or-union-specifier:
277///
278/// struct-or-union-specifier: [C99 6.7.2.1]
279/// struct-or-union identifier[opt] '{' struct-contents '}'
280/// struct-or-union identifier
281/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents
282/// '}' attributes[opt]
283/// [GNU] struct-or-union attributes[opt] identifier
284/// struct-or-union:
285/// 'struct'
286/// 'union'
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000287void Parser::ParseClassSpecifier(DeclSpec &DS,
288 TemplateParameterLists *TemplateParams) {
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000289 assert((Tok.is(tok::kw_class) ||
290 Tok.is(tok::kw_struct) ||
291 Tok.is(tok::kw_union)) &&
292 "Not a class specifier");
293 DeclSpec::TST TagType =
294 Tok.is(tok::kw_class) ? DeclSpec::TST_class :
295 Tok.is(tok::kw_struct) ? DeclSpec::TST_struct :
296 DeclSpec::TST_union;
297
298 SourceLocation StartLoc = ConsumeToken();
299
300 AttributeList *Attr = 0;
301 // If attributes exist after tag, parse them.
302 if (Tok.is(tok::kw___attribute))
303 Attr = ParseAttributes();
304
Steve Narofff59e17e2008-12-24 20:59:21 +0000305 // If declspecs exist after tag, parse them.
306 if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft)
307 FuzzyParseMicrosoftDeclSpec();
308
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000309 // Parse the (optional) nested-name-specifier.
310 CXXScopeSpec SS;
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000311 if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS)) {
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000312 if (Tok.isNot(tok::identifier))
313 Diag(Tok, diag::err_expected_ident);
314 }
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000315
316 // Parse the (optional) class name.
317 // FIXME: Alternatively, parse a simple-template-id.
318 IdentifierInfo *Name = 0;
319 SourceLocation NameLoc;
320 if (Tok.is(tok::identifier)) {
321 Name = Tok.getIdentifierInfo();
322 NameLoc = ConsumeToken();
323 }
324
325 // There are three options here. If we have 'struct foo;', then
326 // this is a forward declaration. If we have 'struct foo {...' or
327 // 'struct fo :...' then this is a definition. Otherwise we have
328 // something like 'struct foo xyz', a reference.
329 Action::TagKind TK;
330 if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon)))
331 TK = Action::TK_Definition;
332 else if (Tok.is(tok::semi))
333 TK = Action::TK_Declaration;
334 else
335 TK = Action::TK_Reference;
336
337 if (!Name && TK != Action::TK_Definition) {
338 // We have a declaration or reference to an anonymous class.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000339 Diag(StartLoc, diag::err_anon_type_definition)
340 << DeclSpec::getSpecifierName(TagType);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000341
342 // Skip the rest of this declarator, up until the comma or semicolon.
343 SkipUntil(tok::comma, true);
344 return;
345 }
346
347 // Parse the tag portion of this.
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000348 DeclTy *TagDecl
349 = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, Name,
350 NameLoc, Attr,
351 Action::MultiTemplateParamsArg(
352 Actions,
353 TemplateParams? &(*TemplateParams)[0] : 0,
354 TemplateParams? TemplateParams->size() : 0));
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000355
356 // Parse the optional base clause (C++ only).
357 if (getLang().CPlusPlus && Tok.is(tok::colon)) {
358 ParseBaseClause(TagDecl);
359 }
360
361 // If there is a body, parse it and inform the actions module.
362 if (Tok.is(tok::l_brace))
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000363 if (getLang().CPlusPlus)
364 ParseCXXMemberSpecification(StartLoc, TagType, TagDecl);
365 else
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000366 ParseStructUnionBody(StartLoc, TagType, TagDecl);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000367 else if (TK == Action::TK_Definition) {
368 // FIXME: Complain that we have a base-specifier list but no
369 // definition.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000370 Diag(Tok, diag::err_expected_lbrace);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000371 }
372
373 const char *PrevSpec = 0;
374 if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, TagDecl))
Chris Lattner1ab3b962008-11-18 07:48:38 +0000375 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000376}
377
378/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived].
379///
380/// base-clause : [C++ class.derived]
381/// ':' base-specifier-list
382/// base-specifier-list:
383/// base-specifier '...'[opt]
384/// base-specifier-list ',' base-specifier '...'[opt]
385void Parser::ParseBaseClause(DeclTy *ClassDecl)
386{
387 assert(Tok.is(tok::colon) && "Not a base clause");
388 ConsumeToken();
389
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000390 // Build up an array of parsed base specifiers.
391 llvm::SmallVector<BaseTy *, 8> BaseInfo;
392
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000393 while (true) {
394 // Parse a base-specifier.
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000395 BaseResult Result = ParseBaseSpecifier(ClassDecl);
396 if (Result.isInvalid) {
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000397 // Skip the rest of this base specifier, up until the comma or
398 // opening brace.
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000399 SkipUntil(tok::comma, tok::l_brace, true, true);
400 } else {
401 // Add this to our array of base specifiers.
402 BaseInfo.push_back(Result.Val);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000403 }
404
405 // If the next token is a comma, consume it and keep reading
406 // base-specifiers.
407 if (Tok.isNot(tok::comma)) break;
408
409 // Consume the comma.
410 ConsumeToken();
411 }
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000412
413 // Attach the base specifiers
414 Actions.ActOnBaseSpecifiers(ClassDecl, &BaseInfo[0], BaseInfo.size());
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000415}
416
417/// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is
418/// one entry in the base class list of a class specifier, for example:
419/// class foo : public bar, virtual private baz {
420/// 'public bar' and 'virtual private baz' are each base-specifiers.
421///
422/// base-specifier: [C++ class.derived]
423/// ::[opt] nested-name-specifier[opt] class-name
424/// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt]
425/// class-name
426/// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt]
427/// class-name
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000428Parser::BaseResult Parser::ParseBaseSpecifier(DeclTy *ClassDecl)
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000429{
430 bool IsVirtual = false;
431 SourceLocation StartLoc = Tok.getLocation();
432
433 // Parse the 'virtual' keyword.
434 if (Tok.is(tok::kw_virtual)) {
435 ConsumeToken();
436 IsVirtual = true;
437 }
438
439 // Parse an (optional) access specifier.
440 AccessSpecifier Access = getAccessSpecifierIfPresent();
441 if (Access)
442 ConsumeToken();
443
444 // Parse the 'virtual' keyword (again!), in case it came after the
445 // access specifier.
446 if (Tok.is(tok::kw_virtual)) {
447 SourceLocation VirtualLoc = ConsumeToken();
448 if (IsVirtual) {
449 // Complain about duplicate 'virtual'
Chris Lattner1ab3b962008-11-18 07:48:38 +0000450 Diag(VirtualLoc, diag::err_dup_virtual)
451 << SourceRange(VirtualLoc, VirtualLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000452 }
453
454 IsVirtual = true;
455 }
456
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000457 // Parse optional '::' and optional nested-name-specifier.
458 CXXScopeSpec SS;
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000459 ParseOptionalCXXScopeSpecifier(SS);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000460
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000461 // The location of the base class itself.
462 SourceLocation BaseLoc = Tok.getLocation();
Douglas Gregor42a552f2008-11-05 20:51:48 +0000463
464 // Parse the class-name.
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000465 TypeTy *BaseType = ParseClassName(&SS);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000466 if (!BaseType)
467 return true;
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000468
469 // Find the complete source range for the base-specifier.
470 SourceRange Range(StartLoc, BaseLoc);
471
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000472 // Notify semantic analysis that we have parsed a complete
473 // base-specifier.
Sebastian Redla55e52c2008-11-25 22:21:31 +0000474 return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access,
475 BaseType, BaseLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000476}
477
478/// getAccessSpecifierIfPresent - Determine whether the next token is
479/// a C++ access-specifier.
480///
481/// access-specifier: [C++ class.derived]
482/// 'private'
483/// 'protected'
484/// 'public'
Douglas Gregor1b7f8982008-04-14 00:13:42 +0000485AccessSpecifier Parser::getAccessSpecifierIfPresent() const
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000486{
487 switch (Tok.getKind()) {
488 default: return AS_none;
489 case tok::kw_private: return AS_private;
490 case tok::kw_protected: return AS_protected;
491 case tok::kw_public: return AS_public;
492 }
493}
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000494
495/// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration.
496///
497/// member-declaration:
498/// decl-specifier-seq[opt] member-declarator-list[opt] ';'
499/// function-definition ';'[opt]
500/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO]
501/// using-declaration [TODO]
502/// [C++0x] static_assert-declaration [TODO]
503/// template-declaration [TODO]
Chris Lattnerbc8d5642008-12-18 01:12:00 +0000504/// [GNU] '__extension__' member-declaration
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000505///
506/// member-declarator-list:
507/// member-declarator
508/// member-declarator-list ',' member-declarator
509///
510/// member-declarator:
511/// declarator pure-specifier[opt]
512/// declarator constant-initializer[opt]
513/// identifier[opt] ':' constant-expression
514///
515/// pure-specifier: [TODO]
516/// '= 0'
517///
518/// constant-initializer:
519/// '=' constant-expression
520///
521Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
Chris Lattnerbc8d5642008-12-18 01:12:00 +0000522 // Handle: member-declaration ::= '__extension__' member-declaration
523 if (Tok.is(tok::kw___extension__)) {
524 // __extension__ silences extension warnings in the subexpression.
525 ExtensionRAIIObject O(Diags); // Use RAII to do this.
526 ConsumeToken();
527 return ParseCXXClassMemberDeclaration(AS);
528 }
529
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000530 SourceLocation DSStart = Tok.getLocation();
531 // decl-specifier-seq:
532 // Parse the common declaration-specifiers piece.
533 DeclSpec DS;
534 ParseDeclarationSpecifiers(DS);
535
536 if (Tok.is(tok::semi)) {
537 ConsumeToken();
538 // C++ 9.2p7: The member-declarator-list can be omitted only after a
539 // class-specifier or an enum-specifier or in a friend declaration.
540 // FIXME: Friend declarations.
541 switch (DS.getTypeSpecType()) {
542 case DeclSpec::TST_struct:
543 case DeclSpec::TST_union:
544 case DeclSpec::TST_class:
545 case DeclSpec::TST_enum:
546 return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
547 default:
548 Diag(DSStart, diag::err_no_declarators);
549 return 0;
550 }
551 }
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000552
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000553 Declarator DeclaratorInfo(DS, Declarator::MemberContext);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000554
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000555 if (Tok.isNot(tok::colon)) {
556 // Parse the first declarator.
557 ParseDeclarator(DeclaratorInfo);
558 // Error parsing the declarator?
Douglas Gregor10bd3682008-11-17 22:58:34 +0000559 if (!DeclaratorInfo.hasName()) {
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000560 // If so, skip until the semi-colon or a }.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000561 SkipUntil(tok::r_brace, true);
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000562 if (Tok.is(tok::semi))
563 ConsumeToken();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000564 return 0;
565 }
566
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000567 // function-definition:
Douglas Gregor7ad83902008-11-05 04:29:56 +0000568 if (Tok.is(tok::l_brace)
569 || (DeclaratorInfo.isFunctionDeclarator() && Tok.is(tok::colon))) {
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000570 if (!DeclaratorInfo.isFunctionDeclarator()) {
571 Diag(Tok, diag::err_func_def_no_params);
572 ConsumeBrace();
573 SkipUntil(tok::r_brace, true);
574 return 0;
575 }
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000576
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000577 if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
578 Diag(Tok, diag::err_function_declared_typedef);
579 // This recovery skips the entire function body. It would be nice
580 // to simply call ParseCXXInlineMethodDef() below, however Sema
581 // assumes the declarator represents a function, not a typedef.
582 ConsumeBrace();
583 SkipUntil(tok::r_brace, true);
584 return 0;
585 }
586
587 return ParseCXXInlineMethodDef(AS, DeclaratorInfo);
588 }
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000589 }
590
591 // member-declarator-list:
592 // member-declarator
593 // member-declarator-list ',' member-declarator
594
595 DeclTy *LastDeclInGroup = 0;
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000596 OwningExprResult BitfieldSize(Actions);
597 OwningExprResult Init(Actions);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000598
599 while (1) {
600
601 // member-declarator:
602 // declarator pure-specifier[opt]
603 // declarator constant-initializer[opt]
604 // identifier[opt] ':' constant-expression
605
606 if (Tok.is(tok::colon)) {
607 ConsumeToken();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000608 BitfieldSize = ParseConstantExpression();
609 if (BitfieldSize.isInvalid())
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000610 SkipUntil(tok::comma, true, true);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000611 }
612
613 // pure-specifier:
614 // '= 0'
615 //
616 // constant-initializer:
617 // '=' constant-expression
618
619 if (Tok.is(tok::equal)) {
620 ConsumeToken();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000621 Init = ParseInitializer();
622 if (Init.isInvalid())
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000623 SkipUntil(tok::comma, true, true);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000624 }
625
626 // If attributes exist after the declarator, parse them.
627 if (Tok.is(tok::kw___attribute))
628 DeclaratorInfo.AddAttributes(ParseAttributes());
629
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000630 // NOTE: If Sema is the Action module and declarator is an instance field,
631 // this call will *not* return the created decl; LastDeclInGroup will be
632 // returned instead.
633 // See Sema::ActOnCXXMemberDeclarator for details.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000634 LastDeclInGroup = Actions.ActOnCXXMemberDeclarator(CurScope, AS,
635 DeclaratorInfo,
Sebastian Redleffa8d12008-12-10 00:02:53 +0000636 BitfieldSize.release(),
637 Init.release(),
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000638 LastDeclInGroup);
639
Douglas Gregor72b505b2008-12-16 21:30:33 +0000640 if (DeclaratorInfo.isFunctionDeclarator() &&
641 DeclaratorInfo.getDeclSpec().getStorageClassSpec()
642 != DeclSpec::SCS_typedef) {
643 // We just declared a member function. If this member function
644 // has any default arguments, we'll need to parse them later.
645 LateParsedMethodDeclaration *LateMethod = 0;
646 DeclaratorChunk::FunctionTypeInfo &FTI
647 = DeclaratorInfo.getTypeObject(0).Fun;
648 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
649 if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
650 if (!LateMethod) {
651 // Push this method onto the stack of late-parsed method
652 // declarations.
653 getCurTopClassStack().MethodDecls.push_back(
654 LateParsedMethodDeclaration(LastDeclInGroup));
655 LateMethod = &getCurTopClassStack().MethodDecls.back();
656
657 // Add all of the parameters prior to this one (they don't
658 // have default arguments).
659 LateMethod->DefaultArgs.reserve(FTI.NumArgs);
660 for (unsigned I = 0; I < ParamIdx; ++I)
661 LateMethod->DefaultArgs.push_back(
662 LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param));
663 }
664
665 // Add this parameter to the list of parameters (it or may
666 // not have a default argument).
667 LateMethod->DefaultArgs.push_back(
668 LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
669 FTI.ArgInfo[ParamIdx].DefaultArgTokens));
670 }
671 }
672 }
673
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000674 // If we don't have a comma, it is either the end of the list (a ';')
675 // or an error, bail out.
676 if (Tok.isNot(tok::comma))
677 break;
678
679 // Consume the comma.
680 ConsumeToken();
681
682 // Parse the next declarator.
683 DeclaratorInfo.clear();
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000684 BitfieldSize = 0;
685 Init = 0;
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000686
687 // Attributes are only allowed on the second declarator.
688 if (Tok.is(tok::kw___attribute))
689 DeclaratorInfo.AddAttributes(ParseAttributes());
690
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000691 if (Tok.isNot(tok::colon))
692 ParseDeclarator(DeclaratorInfo);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000693 }
694
695 if (Tok.is(tok::semi)) {
696 ConsumeToken();
697 // Reverse the chain list.
698 return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
699 }
700
701 Diag(Tok, diag::err_expected_semi_decl_list);
702 // Skip to end of block or statement
703 SkipUntil(tok::r_brace, true, true);
704 if (Tok.is(tok::semi))
705 ConsumeToken();
706 return 0;
707}
708
709/// ParseCXXMemberSpecification - Parse the class definition.
710///
711/// member-specification:
712/// member-declaration member-specification[opt]
713/// access-specifier ':' member-specification[opt]
714///
715void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
716 unsigned TagType, DeclTy *TagDecl) {
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000717 assert((TagType == DeclSpec::TST_struct ||
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000718 TagType == DeclSpec::TST_union ||
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000719 TagType == DeclSpec::TST_class) && "Invalid TagType!");
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000720
721 SourceLocation LBraceLoc = ConsumeBrace();
722
723 if (!CurScope->isCXXClassScope() && // Not about to define a nested class.
724 CurScope->isInCXXInlineMethodScope()) {
725 // We will define a local class of an inline method.
726 // Push a new LexedMethodsForTopClass for its inline methods.
727 PushTopClassStack();
728 }
729
730 // Enter a scope for the class.
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000731 ParseScope ClassScope(this, Scope::CXXClassScope|Scope::DeclScope);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000732
733 Actions.ActOnStartCXXClassDef(CurScope, TagDecl, LBraceLoc);
734
735 // C++ 11p3: Members of a class defined with the keyword class are private
736 // by default. Members of a class defined with the keywords struct or union
737 // are public by default.
738 AccessSpecifier CurAS;
739 if (TagType == DeclSpec::TST_class)
740 CurAS = AS_private;
741 else
742 CurAS = AS_public;
743
744 // While we still have something to read, read the member-declarations.
745 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
746 // Each iteration of this loop reads one member-declaration.
747
748 // Check for extraneous top-level semicolon.
749 if (Tok.is(tok::semi)) {
750 Diag(Tok, diag::ext_extra_struct_semi);
751 ConsumeToken();
752 continue;
753 }
754
755 AccessSpecifier AS = getAccessSpecifierIfPresent();
756 if (AS != AS_none) {
757 // Current token is a C++ access specifier.
758 CurAS = AS;
759 ConsumeToken();
760 ExpectAndConsume(tok::colon, diag::err_expected_colon);
761 continue;
762 }
763
764 // Parse all the comma separated declarators.
765 ParseCXXClassMemberDeclaration(CurAS);
766 }
767
768 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
769
770 AttributeList *AttrList = 0;
771 // If attributes exist after class contents, parse them.
772 if (Tok.is(tok::kw___attribute))
773 AttrList = ParseAttributes(); // FIXME: where should I put them?
774
775 Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl,
776 LBraceLoc, RBraceLoc);
777
778 // C++ 9.2p2: Within the class member-specification, the class is regarded as
779 // complete within function bodies, default arguments,
780 // exception-specifications, and constructor ctor-initializers (including
781 // such things in nested classes).
782 //
Douglas Gregor72b505b2008-12-16 21:30:33 +0000783 // FIXME: Only function bodies and constructor ctor-initializers are
784 // parsed correctly, fix the rest.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000785 if (!CurScope->getParent()->isCXXClassScope()) {
786 // We are not inside a nested class. This class and its nested classes
Douglas Gregor72b505b2008-12-16 21:30:33 +0000787 // are complete and we can parse the delayed portions of method
788 // declarations and the lexed inline method definitions.
789 ParseLexedMethodDeclarations();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000790 ParseLexedMethodDefs();
791
792 // For a local class of inline method, pop the LexedMethodsForTopClass that
793 // was previously pushed.
794
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000795 assert((CurScope->isInCXXInlineMethodScope() ||
796 TopClassStacks.size() == 1) &&
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000797 "MethodLexers not getting popped properly!");
798 if (CurScope->isInCXXInlineMethodScope())
799 PopTopClassStack();
800 }
801
802 // Leave the class scope.
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000803 ClassScope.Exit();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000804
Argyrios Kyrtzidis5b7f0c82008-08-09 00:39:29 +0000805 Actions.ActOnFinishCXXClassDef(TagDecl);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000806}
Douglas Gregor7ad83902008-11-05 04:29:56 +0000807
808/// ParseConstructorInitializer - Parse a C++ constructor initializer,
809/// which explicitly initializes the members or base classes of a
810/// class (C++ [class.base.init]). For example, the three initializers
811/// after the ':' in the Derived constructor below:
812///
813/// @code
814/// class Base { };
815/// class Derived : Base {
816/// int x;
817/// float f;
818/// public:
819/// Derived(float f) : Base(), x(17), f(f) { }
820/// };
821/// @endcode
822///
823/// [C++] ctor-initializer:
824/// ':' mem-initializer-list
825///
826/// [C++] mem-initializer-list:
827/// mem-initializer
828/// mem-initializer , mem-initializer-list
829void Parser::ParseConstructorInitializer(DeclTy *ConstructorDecl) {
830 assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'");
831
832 SourceLocation ColonLoc = ConsumeToken();
833
834 llvm::SmallVector<MemInitTy*, 4> MemInitializers;
835
836 do {
837 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
838 if (!MemInit.isInvalid)
839 MemInitializers.push_back(MemInit.Val);
840
841 if (Tok.is(tok::comma))
842 ConsumeToken();
843 else if (Tok.is(tok::l_brace))
844 break;
845 else {
846 // Skip over garbage, until we get to '{'. Don't eat the '{'.
847 SkipUntil(tok::l_brace, true, true);
848 break;
849 }
850 } while (true);
851
852 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc,
853 &MemInitializers[0], MemInitializers.size());
854}
855
856/// ParseMemInitializer - Parse a C++ member initializer, which is
857/// part of a constructor initializer that explicitly initializes one
858/// member or base class (C++ [class.base.init]). See
859/// ParseConstructorInitializer for an example.
860///
861/// [C++] mem-initializer:
862/// mem-initializer-id '(' expression-list[opt] ')'
863///
864/// [C++] mem-initializer-id:
865/// '::'[opt] nested-name-specifier[opt] class-name
866/// identifier
867Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) {
868 // FIXME: parse '::'[opt] nested-name-specifier[opt]
869
870 if (Tok.isNot(tok::identifier)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000871 Diag(Tok, diag::err_expected_member_or_base_name);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000872 return true;
873 }
874
875 // Get the identifier. This may be a member name or a class name,
876 // but we'll let the semantic analysis determine which it is.
877 IdentifierInfo *II = Tok.getIdentifierInfo();
878 SourceLocation IdLoc = ConsumeToken();
879
880 // Parse the '('.
881 if (Tok.isNot(tok::l_paren)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000882 Diag(Tok, diag::err_expected_lparen);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000883 return true;
884 }
885 SourceLocation LParenLoc = ConsumeParen();
886
887 // Parse the optional expression-list.
Sebastian Redla55e52c2008-11-25 22:21:31 +0000888 ExprVector ArgExprs(Actions);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000889 CommaLocsTy CommaLocs;
890 if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
891 SkipUntil(tok::r_paren);
892 return true;
893 }
894
895 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
896
Sebastian Redla55e52c2008-11-25 22:21:31 +0000897 return Actions.ActOnMemInitializer(ConstructorDecl, CurScope, II, IdLoc,
898 LParenLoc, ArgExprs.take(),
899 ArgExprs.size(), &CommaLocs[0], RParenLoc);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000900}
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000901
902/// ParseExceptionSpecification - Parse a C++ exception-specification
903/// (C++ [except.spec]).
904///
Douglas Gregora4745612008-12-01 18:00:20 +0000905/// exception-specification:
906/// 'throw' '(' type-id-list [opt] ')'
907/// [MS] 'throw' '(' '...' ')'
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000908///
Douglas Gregora4745612008-12-01 18:00:20 +0000909/// type-id-list:
910/// type-id
911/// type-id-list ',' type-id
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000912///
913bool Parser::ParseExceptionSpecification() {
914 assert(Tok.is(tok::kw_throw) && "expected throw");
915
916 SourceLocation ThrowLoc = ConsumeToken();
917
918 if (!Tok.is(tok::l_paren)) {
919 return Diag(Tok, diag::err_expected_lparen_after) << "throw";
920 }
921 SourceLocation LParenLoc = ConsumeParen();
922
Douglas Gregora4745612008-12-01 18:00:20 +0000923 // Parse throw(...), a Microsoft extension that means "this function
924 // can throw anything".
925 if (Tok.is(tok::ellipsis)) {
926 SourceLocation EllipsisLoc = ConsumeToken();
927 if (!getLang().Microsoft)
928 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
929 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
930 return false;
931 }
932
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000933 // Parse the sequence of type-ids.
934 while (Tok.isNot(tok::r_paren)) {
935 ParseTypeName();
936 if (Tok.is(tok::comma))
937 ConsumeToken();
938 else
939 break;
940 }
941
942 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
943 return false;
944}