blob: 1fbe32a4591c9befcf9f25b06e033b8b86fe9cc7 [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"
Chris Lattner500d3292009-01-29 05:15:15 +000015#include "clang/Parse/ParseDiagnostic.h"
Douglas Gregore37ac4f2008-04-13 21:30:24 +000016#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.
Douglas Gregorb696ea32009-02-04 17:00:24 +0000235 TypeTy *Type = Actions.getTypeName(*Tok.getIdentifierInfo(),
236 Tok.getLocation(), CurScope, SS);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000237 if (!Type) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000238 Diag(Tok, diag::err_expected_class_name);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000239 return 0;
240 }
241
242 // Consume the identifier.
243 ConsumeToken();
244
245 return Type;
246}
247
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000248/// ParseClassSpecifier - Parse a C++ class-specifier [C++ class] or
249/// elaborated-type-specifier [C++ dcl.type.elab]; we can't tell which
250/// until we reach the start of a definition or see a token that
251/// cannot start a definition.
252///
253/// class-specifier: [C++ class]
254/// class-head '{' member-specification[opt] '}'
255/// class-head '{' member-specification[opt] '}' attributes[opt]
256/// class-head:
257/// class-key identifier[opt] base-clause[opt]
258/// class-key nested-name-specifier identifier base-clause[opt]
259/// class-key nested-name-specifier[opt] simple-template-id
260/// base-clause[opt]
261/// [GNU] class-key attributes[opt] identifier[opt] base-clause[opt]
262/// [GNU] class-key attributes[opt] nested-name-specifier
263/// identifier base-clause[opt]
264/// [GNU] class-key attributes[opt] nested-name-specifier[opt]
265/// simple-template-id base-clause[opt]
266/// class-key:
267/// 'class'
268/// 'struct'
269/// 'union'
270///
271/// elaborated-type-specifier: [C++ dcl.type.elab]
272/// class-key ::[opt] nested-name-specifier[opt] identifier
273/// class-key ::[opt] nested-name-specifier[opt] 'template'[opt]
274/// simple-template-id
275///
276/// Note that the C++ class-specifier and elaborated-type-specifier,
277/// together, subsume the C99 struct-or-union-specifier:
278///
279/// struct-or-union-specifier: [C99 6.7.2.1]
280/// struct-or-union identifier[opt] '{' struct-contents '}'
281/// struct-or-union identifier
282/// [GNU] struct-or-union attributes[opt] identifier[opt] '{' struct-contents
283/// '}' attributes[opt]
284/// [GNU] struct-or-union attributes[opt] identifier
285/// struct-or-union:
286/// 'struct'
287/// 'union'
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000288void Parser::ParseClassSpecifier(DeclSpec &DS,
289 TemplateParameterLists *TemplateParams) {
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000290 assert((Tok.is(tok::kw_class) ||
291 Tok.is(tok::kw_struct) ||
292 Tok.is(tok::kw_union)) &&
293 "Not a class specifier");
294 DeclSpec::TST TagType =
295 Tok.is(tok::kw_class) ? DeclSpec::TST_class :
296 Tok.is(tok::kw_struct) ? DeclSpec::TST_struct :
297 DeclSpec::TST_union;
298
299 SourceLocation StartLoc = ConsumeToken();
300
301 AttributeList *Attr = 0;
302 // If attributes exist after tag, parse them.
303 if (Tok.is(tok::kw___attribute))
304 Attr = ParseAttributes();
305
Steve Narofff59e17e2008-12-24 20:59:21 +0000306 // If declspecs exist after tag, parse them.
307 if (Tok.is(tok::kw___declspec) && PP.getLangOptions().Microsoft)
308 FuzzyParseMicrosoftDeclSpec();
309
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000310 // Parse the (optional) nested-name-specifier.
311 CXXScopeSpec SS;
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000312 if (getLang().CPlusPlus && ParseOptionalCXXScopeSpecifier(SS)) {
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000313 if (Tok.isNot(tok::identifier))
314 Diag(Tok, diag::err_expected_ident);
315 }
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000316
317 // Parse the (optional) class name.
318 // FIXME: Alternatively, parse a simple-template-id.
319 IdentifierInfo *Name = 0;
320 SourceLocation NameLoc;
321 if (Tok.is(tok::identifier)) {
322 Name = Tok.getIdentifierInfo();
323 NameLoc = ConsumeToken();
324 }
325
326 // There are three options here. If we have 'struct foo;', then
327 // this is a forward declaration. If we have 'struct foo {...' or
328 // 'struct fo :...' then this is a definition. Otherwise we have
329 // something like 'struct foo xyz', a reference.
330 Action::TagKind TK;
331 if (Tok.is(tok::l_brace) || (getLang().CPlusPlus && Tok.is(tok::colon)))
332 TK = Action::TK_Definition;
333 else if (Tok.is(tok::semi))
334 TK = Action::TK_Declaration;
335 else
336 TK = Action::TK_Reference;
337
338 if (!Name && TK != Action::TK_Definition) {
339 // We have a declaration or reference to an anonymous class.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000340 Diag(StartLoc, diag::err_anon_type_definition)
341 << DeclSpec::getSpecifierName(TagType);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000342
343 // Skip the rest of this declarator, up until the comma or semicolon.
344 SkipUntil(tok::comma, true);
345 return;
346 }
347
348 // Parse the tag portion of this.
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +0000349 DeclTy *TagDecl
350 = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, Name,
351 NameLoc, Attr,
352 Action::MultiTemplateParamsArg(
353 Actions,
354 TemplateParams? &(*TemplateParams)[0] : 0,
355 TemplateParams? TemplateParams->size() : 0));
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000356
357 // Parse the optional base clause (C++ only).
358 if (getLang().CPlusPlus && Tok.is(tok::colon)) {
359 ParseBaseClause(TagDecl);
360 }
361
362 // If there is a body, parse it and inform the actions module.
363 if (Tok.is(tok::l_brace))
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000364 if (getLang().CPlusPlus)
365 ParseCXXMemberSpecification(StartLoc, TagType, TagDecl);
366 else
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000367 ParseStructUnionBody(StartLoc, TagType, TagDecl);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000368 else if (TK == Action::TK_Definition) {
369 // FIXME: Complain that we have a base-specifier list but no
370 // definition.
Chris Lattner1ab3b962008-11-18 07:48:38 +0000371 Diag(Tok, diag::err_expected_lbrace);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000372 }
373
374 const char *PrevSpec = 0;
375 if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, TagDecl))
Chris Lattner1ab3b962008-11-18 07:48:38 +0000376 Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec;
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000377}
378
379/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived].
380///
381/// base-clause : [C++ class.derived]
382/// ':' base-specifier-list
383/// base-specifier-list:
384/// base-specifier '...'[opt]
385/// base-specifier-list ',' base-specifier '...'[opt]
386void Parser::ParseBaseClause(DeclTy *ClassDecl)
387{
388 assert(Tok.is(tok::colon) && "Not a base clause");
389 ConsumeToken();
390
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000391 // Build up an array of parsed base specifiers.
392 llvm::SmallVector<BaseTy *, 8> BaseInfo;
393
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000394 while (true) {
395 // Parse a base-specifier.
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000396 BaseResult Result = ParseBaseSpecifier(ClassDecl);
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000397 if (Result.isInvalid()) {
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000398 // Skip the rest of this base specifier, up until the comma or
399 // opening brace.
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000400 SkipUntil(tok::comma, tok::l_brace, true, true);
401 } else {
402 // Add this to our array of base specifiers.
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000403 BaseInfo.push_back(Result.get());
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000404 }
405
406 // If the next token is a comma, consume it and keep reading
407 // base-specifiers.
408 if (Tok.isNot(tok::comma)) break;
409
410 // Consume the comma.
411 ConsumeToken();
412 }
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000413
414 // Attach the base specifiers
415 Actions.ActOnBaseSpecifiers(ClassDecl, &BaseInfo[0], BaseInfo.size());
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000416}
417
418/// ParseBaseSpecifier - Parse a C++ base-specifier. A base-specifier is
419/// one entry in the base class list of a class specifier, for example:
420/// class foo : public bar, virtual private baz {
421/// 'public bar' and 'virtual private baz' are each base-specifiers.
422///
423/// base-specifier: [C++ class.derived]
424/// ::[opt] nested-name-specifier[opt] class-name
425/// 'virtual' access-specifier[opt] ::[opt] nested-name-specifier[opt]
426/// class-name
427/// access-specifier 'virtual'[opt] ::[opt] nested-name-specifier[opt]
428/// class-name
Douglas Gregorf8268ae2008-10-22 17:49:05 +0000429Parser::BaseResult Parser::ParseBaseSpecifier(DeclTy *ClassDecl)
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000430{
431 bool IsVirtual = false;
432 SourceLocation StartLoc = Tok.getLocation();
433
434 // Parse the 'virtual' keyword.
435 if (Tok.is(tok::kw_virtual)) {
436 ConsumeToken();
437 IsVirtual = true;
438 }
439
440 // Parse an (optional) access specifier.
441 AccessSpecifier Access = getAccessSpecifierIfPresent();
442 if (Access)
443 ConsumeToken();
444
445 // Parse the 'virtual' keyword (again!), in case it came after the
446 // access specifier.
447 if (Tok.is(tok::kw_virtual)) {
448 SourceLocation VirtualLoc = ConsumeToken();
449 if (IsVirtual) {
450 // Complain about duplicate 'virtual'
Chris Lattner1ab3b962008-11-18 07:48:38 +0000451 Diag(VirtualLoc, diag::err_dup_virtual)
452 << SourceRange(VirtualLoc, VirtualLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000453 }
454
455 IsVirtual = true;
456 }
457
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000458 // Parse optional '::' and optional nested-name-specifier.
459 CXXScopeSpec SS;
Chris Lattner7a0ab5f2009-01-06 06:59:53 +0000460 ParseOptionalCXXScopeSpecifier(SS);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000461
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000462 // The location of the base class itself.
463 SourceLocation BaseLoc = Tok.getLocation();
Douglas Gregor42a552f2008-11-05 20:51:48 +0000464
465 // Parse the class-name.
Argyrios Kyrtzidiseb83ecd2008-11-08 16:45:02 +0000466 TypeTy *BaseType = ParseClassName(&SS);
Douglas Gregor42a552f2008-11-05 20:51:48 +0000467 if (!BaseType)
468 return true;
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000469
470 // Find the complete source range for the base-specifier.
471 SourceRange Range(StartLoc, BaseLoc);
472
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000473 // Notify semantic analysis that we have parsed a complete
474 // base-specifier.
Sebastian Redla55e52c2008-11-25 22:21:31 +0000475 return Actions.ActOnBaseSpecifier(ClassDecl, Range, IsVirtual, Access,
476 BaseType, BaseLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000477}
478
479/// getAccessSpecifierIfPresent - Determine whether the next token is
480/// a C++ access-specifier.
481///
482/// access-specifier: [C++ class.derived]
483/// 'private'
484/// 'protected'
485/// 'public'
Douglas Gregor1b7f8982008-04-14 00:13:42 +0000486AccessSpecifier Parser::getAccessSpecifierIfPresent() const
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000487{
488 switch (Tok.getKind()) {
489 default: return AS_none;
490 case tok::kw_private: return AS_private;
491 case tok::kw_protected: return AS_protected;
492 case tok::kw_public: return AS_public;
493 }
494}
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000495
496/// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration.
497///
498/// member-declaration:
499/// decl-specifier-seq[opt] member-declarator-list[opt] ';'
500/// function-definition ';'[opt]
501/// ::[opt] nested-name-specifier template[opt] unqualified-id ';'[TODO]
502/// using-declaration [TODO]
503/// [C++0x] static_assert-declaration [TODO]
504/// template-declaration [TODO]
Chris Lattnerbc8d5642008-12-18 01:12:00 +0000505/// [GNU] '__extension__' member-declaration
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000506///
507/// member-declarator-list:
508/// member-declarator
509/// member-declarator-list ',' member-declarator
510///
511/// member-declarator:
512/// declarator pure-specifier[opt]
513/// declarator constant-initializer[opt]
514/// identifier[opt] ':' constant-expression
515///
516/// pure-specifier: [TODO]
517/// '= 0'
518///
519/// constant-initializer:
520/// '=' constant-expression
521///
522Parser::DeclTy *Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) {
Chris Lattnerbc8d5642008-12-18 01:12:00 +0000523 // Handle: member-declaration ::= '__extension__' member-declaration
524 if (Tok.is(tok::kw___extension__)) {
525 // __extension__ silences extension warnings in the subexpression.
526 ExtensionRAIIObject O(Diags); // Use RAII to do this.
527 ConsumeToken();
528 return ParseCXXClassMemberDeclaration(AS);
529 }
530
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000531 SourceLocation DSStart = Tok.getLocation();
532 // decl-specifier-seq:
533 // Parse the common declaration-specifiers piece.
534 DeclSpec DS;
535 ParseDeclarationSpecifiers(DS);
536
537 if (Tok.is(tok::semi)) {
538 ConsumeToken();
539 // C++ 9.2p7: The member-declarator-list can be omitted only after a
540 // class-specifier or an enum-specifier or in a friend declaration.
541 // FIXME: Friend declarations.
542 switch (DS.getTypeSpecType()) {
543 case DeclSpec::TST_struct:
544 case DeclSpec::TST_union:
545 case DeclSpec::TST_class:
546 case DeclSpec::TST_enum:
547 return Actions.ParsedFreeStandingDeclSpec(CurScope, DS);
548 default:
549 Diag(DSStart, diag::err_no_declarators);
550 return 0;
551 }
552 }
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000553
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000554 Declarator DeclaratorInfo(DS, Declarator::MemberContext);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000555
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000556 if (Tok.isNot(tok::colon)) {
557 // Parse the first declarator.
558 ParseDeclarator(DeclaratorInfo);
559 // Error parsing the declarator?
Douglas Gregor10bd3682008-11-17 22:58:34 +0000560 if (!DeclaratorInfo.hasName()) {
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000561 // If so, skip until the semi-colon or a }.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000562 SkipUntil(tok::r_brace, true);
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000563 if (Tok.is(tok::semi))
564 ConsumeToken();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000565 return 0;
566 }
567
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000568 // function-definition:
Douglas Gregor7ad83902008-11-05 04:29:56 +0000569 if (Tok.is(tok::l_brace)
570 || (DeclaratorInfo.isFunctionDeclarator() && Tok.is(tok::colon))) {
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000571 if (!DeclaratorInfo.isFunctionDeclarator()) {
572 Diag(Tok, diag::err_func_def_no_params);
573 ConsumeBrace();
574 SkipUntil(tok::r_brace, true);
575 return 0;
576 }
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000577
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000578 if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
579 Diag(Tok, diag::err_function_declared_typedef);
580 // This recovery skips the entire function body. It would be nice
581 // to simply call ParseCXXInlineMethodDef() below, however Sema
582 // assumes the declarator represents a function, not a typedef.
583 ConsumeBrace();
584 SkipUntil(tok::r_brace, true);
585 return 0;
586 }
587
588 return ParseCXXInlineMethodDef(AS, DeclaratorInfo);
589 }
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000590 }
591
592 // member-declarator-list:
593 // member-declarator
594 // member-declarator-list ',' member-declarator
595
596 DeclTy *LastDeclInGroup = 0;
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000597 OwningExprResult BitfieldSize(Actions);
598 OwningExprResult Init(Actions);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000599
600 while (1) {
601
602 // member-declarator:
603 // declarator pure-specifier[opt]
604 // declarator constant-initializer[opt]
605 // identifier[opt] ':' constant-expression
606
607 if (Tok.is(tok::colon)) {
608 ConsumeToken();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000609 BitfieldSize = ParseConstantExpression();
610 if (BitfieldSize.isInvalid())
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000611 SkipUntil(tok::comma, true, true);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000612 }
613
614 // pure-specifier:
615 // '= 0'
616 //
617 // constant-initializer:
618 // '=' constant-expression
619
620 if (Tok.is(tok::equal)) {
621 ConsumeToken();
Sebastian Redl0e9eabc2008-12-09 13:15:23 +0000622 Init = ParseInitializer();
623 if (Init.isInvalid())
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000624 SkipUntil(tok::comma, true, true);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000625 }
626
627 // If attributes exist after the declarator, parse them.
628 if (Tok.is(tok::kw___attribute))
629 DeclaratorInfo.AddAttributes(ParseAttributes());
630
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000631 // NOTE: If Sema is the Action module and declarator is an instance field,
632 // this call will *not* return the created decl; LastDeclInGroup will be
633 // returned instead.
634 // See Sema::ActOnCXXMemberDeclarator for details.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000635 LastDeclInGroup = Actions.ActOnCXXMemberDeclarator(CurScope, AS,
636 DeclaratorInfo,
Sebastian Redleffa8d12008-12-10 00:02:53 +0000637 BitfieldSize.release(),
638 Init.release(),
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000639 LastDeclInGroup);
640
Douglas Gregor72b505b2008-12-16 21:30:33 +0000641 if (DeclaratorInfo.isFunctionDeclarator() &&
642 DeclaratorInfo.getDeclSpec().getStorageClassSpec()
643 != DeclSpec::SCS_typedef) {
644 // We just declared a member function. If this member function
645 // has any default arguments, we'll need to parse them later.
646 LateParsedMethodDeclaration *LateMethod = 0;
647 DeclaratorChunk::FunctionTypeInfo &FTI
648 = DeclaratorInfo.getTypeObject(0).Fun;
649 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) {
650 if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) {
651 if (!LateMethod) {
652 // Push this method onto the stack of late-parsed method
653 // declarations.
654 getCurTopClassStack().MethodDecls.push_back(
655 LateParsedMethodDeclaration(LastDeclInGroup));
656 LateMethod = &getCurTopClassStack().MethodDecls.back();
657
658 // Add all of the parameters prior to this one (they don't
659 // have default arguments).
660 LateMethod->DefaultArgs.reserve(FTI.NumArgs);
661 for (unsigned I = 0; I < ParamIdx; ++I)
662 LateMethod->DefaultArgs.push_back(
663 LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param));
664 }
665
666 // Add this parameter to the list of parameters (it or may
667 // not have a default argument).
668 LateMethod->DefaultArgs.push_back(
669 LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param,
670 FTI.ArgInfo[ParamIdx].DefaultArgTokens));
671 }
672 }
673 }
674
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000675 // If we don't have a comma, it is either the end of the list (a ';')
676 // or an error, bail out.
677 if (Tok.isNot(tok::comma))
678 break;
679
680 // Consume the comma.
681 ConsumeToken();
682
683 // Parse the next declarator.
684 DeclaratorInfo.clear();
Sebastian Redl15faa7f2008-12-09 20:22:58 +0000685 BitfieldSize = 0;
686 Init = 0;
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000687
688 // Attributes are only allowed on the second declarator.
689 if (Tok.is(tok::kw___attribute))
690 DeclaratorInfo.AddAttributes(ParseAttributes());
691
Argyrios Kyrtzidis3a9fdb42008-06-28 08:10:48 +0000692 if (Tok.isNot(tok::colon))
693 ParseDeclarator(DeclaratorInfo);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000694 }
695
696 if (Tok.is(tok::semi)) {
697 ConsumeToken();
698 // Reverse the chain list.
699 return Actions.FinalizeDeclaratorGroup(CurScope, LastDeclInGroup);
700 }
701
702 Diag(Tok, diag::err_expected_semi_decl_list);
703 // Skip to end of block or statement
704 SkipUntil(tok::r_brace, true, true);
705 if (Tok.is(tok::semi))
706 ConsumeToken();
707 return 0;
708}
709
710/// ParseCXXMemberSpecification - Parse the class definition.
711///
712/// member-specification:
713/// member-declaration member-specification[opt]
714/// access-specifier ':' member-specification[opt]
715///
716void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc,
717 unsigned TagType, DeclTy *TagDecl) {
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000718 assert((TagType == DeclSpec::TST_struct ||
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000719 TagType == DeclSpec::TST_union ||
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000720 TagType == DeclSpec::TST_class) && "Invalid TagType!");
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000721
722 SourceLocation LBraceLoc = ConsumeBrace();
723
Douglas Gregor3218c4b2009-01-09 22:42:13 +0000724 if (!CurScope->isClassScope() && // Not about to define a nested class.
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000725 CurScope->isInCXXInlineMethodScope()) {
726 // We will define a local class of an inline method.
727 // Push a new LexedMethodsForTopClass for its inline methods.
728 PushTopClassStack();
729 }
730
731 // Enter a scope for the class.
Douglas Gregor3218c4b2009-01-09 22:42:13 +0000732 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000733
Douglas Gregor72de6672009-01-08 20:45:30 +0000734 Actions.ActOnTagStartDefinition(CurScope, TagDecl);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000735
736 // C++ 11p3: Members of a class defined with the keyword class are private
737 // by default. Members of a class defined with the keywords struct or union
738 // are public by default.
739 AccessSpecifier CurAS;
740 if (TagType == DeclSpec::TST_class)
741 CurAS = AS_private;
742 else
743 CurAS = AS_public;
744
745 // While we still have something to read, read the member-declarations.
746 while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
747 // Each iteration of this loop reads one member-declaration.
748
749 // Check for extraneous top-level semicolon.
750 if (Tok.is(tok::semi)) {
751 Diag(Tok, diag::ext_extra_struct_semi);
752 ConsumeToken();
753 continue;
754 }
755
756 AccessSpecifier AS = getAccessSpecifierIfPresent();
757 if (AS != AS_none) {
758 // Current token is a C++ access specifier.
759 CurAS = AS;
760 ConsumeToken();
761 ExpectAndConsume(tok::colon, diag::err_expected_colon);
762 continue;
763 }
764
765 // Parse all the comma separated declarators.
766 ParseCXXClassMemberDeclaration(CurAS);
767 }
768
769 SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc);
770
771 AttributeList *AttrList = 0;
772 // If attributes exist after class contents, parse them.
773 if (Tok.is(tok::kw___attribute))
774 AttrList = ParseAttributes(); // FIXME: where should I put them?
775
776 Actions.ActOnFinishCXXMemberSpecification(CurScope, RecordLoc, TagDecl,
777 LBraceLoc, RBraceLoc);
778
779 // C++ 9.2p2: Within the class member-specification, the class is regarded as
780 // complete within function bodies, default arguments,
781 // exception-specifications, and constructor ctor-initializers (including
782 // such things in nested classes).
783 //
Douglas Gregor72b505b2008-12-16 21:30:33 +0000784 // FIXME: Only function bodies and constructor ctor-initializers are
785 // parsed correctly, fix the rest.
Douglas Gregor3218c4b2009-01-09 22:42:13 +0000786 if (!CurScope->getParent()->isClassScope()) {
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000787 // We are not inside a nested class. This class and its nested classes
Douglas Gregor72b505b2008-12-16 21:30:33 +0000788 // are complete and we can parse the delayed portions of method
789 // declarations and the lexed inline method definitions.
790 ParseLexedMethodDeclarations();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000791 ParseLexedMethodDefs();
792
793 // For a local class of inline method, pop the LexedMethodsForTopClass that
794 // was previously pushed.
795
Sanjiv Gupta31fc07d2008-10-31 09:52:39 +0000796 assert((CurScope->isInCXXInlineMethodScope() ||
797 TopClassStacks.size() == 1) &&
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000798 "MethodLexers not getting popped properly!");
799 if (CurScope->isInCXXInlineMethodScope())
800 PopTopClassStack();
801 }
802
803 // Leave the class scope.
Douglas Gregor8935b8b2008-12-10 06:34:36 +0000804 ClassScope.Exit();
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000805
Douglas Gregor72de6672009-01-08 20:45:30 +0000806 Actions.ActOnTagFinishDefinition(CurScope, TagDecl);
Argyrios Kyrtzidis4cc18a42008-06-24 22:12:16 +0000807}
Douglas Gregor7ad83902008-11-05 04:29:56 +0000808
809/// ParseConstructorInitializer - Parse a C++ constructor initializer,
810/// which explicitly initializes the members or base classes of a
811/// class (C++ [class.base.init]). For example, the three initializers
812/// after the ':' in the Derived constructor below:
813///
814/// @code
815/// class Base { };
816/// class Derived : Base {
817/// int x;
818/// float f;
819/// public:
820/// Derived(float f) : Base(), x(17), f(f) { }
821/// };
822/// @endcode
823///
824/// [C++] ctor-initializer:
825/// ':' mem-initializer-list
826///
827/// [C++] mem-initializer-list:
828/// mem-initializer
829/// mem-initializer , mem-initializer-list
830void Parser::ParseConstructorInitializer(DeclTy *ConstructorDecl) {
831 assert(Tok.is(tok::colon) && "Constructor initializer always starts with ':'");
832
833 SourceLocation ColonLoc = ConsumeToken();
834
835 llvm::SmallVector<MemInitTy*, 4> MemInitializers;
836
837 do {
838 MemInitResult MemInit = ParseMemInitializer(ConstructorDecl);
Douglas Gregor5ac8aff2009-01-26 22:44:13 +0000839 if (!MemInit.isInvalid())
840 MemInitializers.push_back(MemInit.get());
Douglas Gregor7ad83902008-11-05 04:29:56 +0000841
842 if (Tok.is(tok::comma))
843 ConsumeToken();
844 else if (Tok.is(tok::l_brace))
845 break;
846 else {
847 // Skip over garbage, until we get to '{'. Don't eat the '{'.
848 SkipUntil(tok::l_brace, true, true);
849 break;
850 }
851 } while (true);
852
853 Actions.ActOnMemInitializers(ConstructorDecl, ColonLoc,
854 &MemInitializers[0], MemInitializers.size());
855}
856
857/// ParseMemInitializer - Parse a C++ member initializer, which is
858/// part of a constructor initializer that explicitly initializes one
859/// member or base class (C++ [class.base.init]). See
860/// ParseConstructorInitializer for an example.
861///
862/// [C++] mem-initializer:
863/// mem-initializer-id '(' expression-list[opt] ')'
864///
865/// [C++] mem-initializer-id:
866/// '::'[opt] nested-name-specifier[opt] class-name
867/// identifier
868Parser::MemInitResult Parser::ParseMemInitializer(DeclTy *ConstructorDecl) {
869 // FIXME: parse '::'[opt] nested-name-specifier[opt]
870
871 if (Tok.isNot(tok::identifier)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000872 Diag(Tok, diag::err_expected_member_or_base_name);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000873 return true;
874 }
875
876 // Get the identifier. This may be a member name or a class name,
877 // but we'll let the semantic analysis determine which it is.
878 IdentifierInfo *II = Tok.getIdentifierInfo();
879 SourceLocation IdLoc = ConsumeToken();
880
881 // Parse the '('.
882 if (Tok.isNot(tok::l_paren)) {
Chris Lattner1ab3b962008-11-18 07:48:38 +0000883 Diag(Tok, diag::err_expected_lparen);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000884 return true;
885 }
886 SourceLocation LParenLoc = ConsumeParen();
887
888 // Parse the optional expression-list.
Sebastian Redla55e52c2008-11-25 22:21:31 +0000889 ExprVector ArgExprs(Actions);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000890 CommaLocsTy CommaLocs;
891 if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
892 SkipUntil(tok::r_paren);
893 return true;
894 }
895
896 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
897
Sebastian Redla55e52c2008-11-25 22:21:31 +0000898 return Actions.ActOnMemInitializer(ConstructorDecl, CurScope, II, IdLoc,
899 LParenLoc, ArgExprs.take(),
900 ArgExprs.size(), &CommaLocs[0], RParenLoc);
Douglas Gregor7ad83902008-11-05 04:29:56 +0000901}
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000902
903/// ParseExceptionSpecification - Parse a C++ exception-specification
904/// (C++ [except.spec]).
905///
Douglas Gregora4745612008-12-01 18:00:20 +0000906/// exception-specification:
907/// 'throw' '(' type-id-list [opt] ')'
908/// [MS] 'throw' '(' '...' ')'
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000909///
Douglas Gregora4745612008-12-01 18:00:20 +0000910/// type-id-list:
911/// type-id
912/// type-id-list ',' type-id
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000913///
914bool Parser::ParseExceptionSpecification() {
915 assert(Tok.is(tok::kw_throw) && "expected throw");
916
917 SourceLocation ThrowLoc = ConsumeToken();
918
919 if (!Tok.is(tok::l_paren)) {
920 return Diag(Tok, diag::err_expected_lparen_after) << "throw";
921 }
922 SourceLocation LParenLoc = ConsumeParen();
923
Douglas Gregora4745612008-12-01 18:00:20 +0000924 // Parse throw(...), a Microsoft extension that means "this function
925 // can throw anything".
926 if (Tok.is(tok::ellipsis)) {
927 SourceLocation EllipsisLoc = ConsumeToken();
928 if (!getLang().Microsoft)
929 Diag(EllipsisLoc, diag::ext_ellipsis_exception_spec);
930 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
931 return false;
932 }
933
Douglas Gregor0fe7bea2008-11-25 03:22:00 +0000934 // Parse the sequence of type-ids.
935 while (Tok.isNot(tok::r_paren)) {
936 ParseTypeName();
937 if (Tok.is(tok::comma))
938 ConsumeToken();
939 else
940 break;
941 }
942
943 SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, LParenLoc);
944 return false;
945}