blob: 2b3d4ba85bd8d091d46d11a6d77cf90f0e6b939b [file] [log] [blame]
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +00001//===--- ParseCXXInlineMethods.cpp - C++ class inline methods parsing------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements parsing for C++ class inline methods.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/Parse/Parser.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/AST/DeclTemplate.h"
16#include "clang/Parse/ParseDiagnostic.h"
Vassil Vassilev11ad3392017-03-23 15:11:07 +000017#include "clang/Parse/RAIIObjectsForParser.h"
John McCall8b0666c2010-08-20 18:27:03 +000018#include "clang/Sema/DeclSpec.h"
19#include "clang/Sema/Scope.h"
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000020using namespace clang;
21
Sebastian Redla7b98a72009-04-26 20:35:05 +000022/// ParseCXXInlineMethodDef - We parsed and verified that the specified
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000023/// Declarator is a well formed C++ inline method definition. Now lex its body
24/// and store its tokens for parsing after the C++ class is complete.
Rafael Espindolac2453dd2013-01-08 21:00:12 +000025NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS,
Erik Verbruggenca98f2a2011-10-13 09:41:32 +000026 AttributeList *AccessAttrs,
27 ParsingDeclarator &D,
Douglas Gregor5d1b4e32011-11-07 20:56:01 +000028 const ParsedTemplateInfo &TemplateInfo,
Eli Bendersky41842222015-03-23 23:49:41 +000029 const VirtSpecifiers& VS,
Richard Smith9ba0fec2015-06-30 01:28:56 +000030 SourceLocation PureSpecLoc) {
Abramo Bagnara924a8f32010-12-10 16:29:40 +000031 assert(D.isFunctionDeclarator() && "This isn't a function declarator!");
Daniel Marjamakie59f8d72015-06-18 10:59:26 +000032 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) &&
Alexis Hunt5a7fa252011-05-12 06:15:49 +000033 "Current token not a '{', ':', '=', or 'try'!");
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000034
Benjamin Kramercc4c49d2012-08-23 23:38:35 +000035 MultiTemplateParamsArg TemplateParams(
Craig Topper161e4db2014-05-21 06:02:52 +000036 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data()
37 : nullptr,
Nico Weber77c76c52014-05-10 17:43:15 +000038 TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0);
Alexis Hunt1deb9722010-04-14 23:07:37 +000039
Rafael Espindolac2453dd2013-01-08 21:00:12 +000040 NamedDecl *FnD;
John McCall07e91c02009-08-06 02:15:43 +000041 if (D.getDeclSpec().isFriendSpecified())
Kaelyn Uhrain4dc695d2011-10-11 00:28:45 +000042 FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D,
Benjamin Kramer62b95d82012-08-23 21:35:17 +000043 TemplateParams);
Douglas Gregor728d00b2011-10-10 14:49:18 +000044 else {
Douglas Gregor0be31a22010-07-02 17:43:08 +000045 FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D,
Craig Topper161e4db2014-05-21 06:02:52 +000046 TemplateParams, nullptr,
Richard Smith2b013182012-06-10 03:12:00 +000047 VS, ICIS_NoInit);
Douglas Gregor728d00b2011-10-10 14:49:18 +000048 if (FnD) {
Richard Smithf8a75c32013-08-29 00:47:48 +000049 Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs);
Richard Smith9ba0fec2015-06-30 01:28:56 +000050 if (PureSpecLoc.isValid())
51 Actions.ActOnPureSpecifier(FnD, PureSpecLoc);
Douglas Gregor728d00b2011-10-10 14:49:18 +000052 }
Nico Weber24b2a822011-01-28 06:07:34 +000053 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000054
Reid Klecknerbde5ede2016-02-19 01:15:08 +000055 if (FnD)
56 HandleMemberFunctionDeclDelays(D, FnD);
Eli Friedman3af2a772009-07-22 21:45:50 +000057
John McCallc1465822011-02-14 07:13:47 +000058 D.complete(FnD);
59
Alp Tokera3ebe6e2013-12-17 14:12:37 +000060 if (TryConsumeToken(tok::equal)) {
Richard Smith1c704732011-11-10 09:08:44 +000061 if (!FnD) {
62 SkipUntil(tok::semi);
Craig Topper161e4db2014-05-21 06:02:52 +000063 return nullptr;
Richard Smith1c704732011-11-10 09:08:44 +000064 }
65
Alexis Hunt5a7fa252011-05-12 06:15:49 +000066 bool Delete = false;
67 SourceLocation KWLoc;
Eli Bendersky5f4d76e2015-03-23 21:43:28 +000068 SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1);
Alp Tokera3ebe6e2013-12-17 14:12:37 +000069 if (TryConsumeToken(tok::kw_delete, KWLoc)) {
70 Diag(KWLoc, getLangOpts().CPlusPlus11
Craig Topper54a6a682015-11-14 18:16:08 +000071 ? diag::warn_cxx98_compat_defaulted_deleted_function
72 : diag::ext_defaulted_deleted_function)
73 << 1 /* deleted */;
Alexis Hunt5a7fa252011-05-12 06:15:49 +000074 Actions.SetDeclDeleted(FnD, KWLoc);
75 Delete = true;
Eli Bendersky5f4d76e2015-03-23 21:43:28 +000076 if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
77 DeclAsFunction->setRangeEnd(KWEndLoc);
78 }
Alp Tokera3ebe6e2013-12-17 14:12:37 +000079 } else if (TryConsumeToken(tok::kw_default, KWLoc)) {
80 Diag(KWLoc, getLangOpts().CPlusPlus11
Craig Topper54a6a682015-11-14 18:16:08 +000081 ? diag::warn_cxx98_compat_defaulted_deleted_function
82 : diag::ext_defaulted_deleted_function)
83 << 0 /* defaulted */;
Alexis Hunt5a7fa252011-05-12 06:15:49 +000084 Actions.SetDeclDefaulted(FnD, KWLoc);
Eli Bendersky5f4d76e2015-03-23 21:43:28 +000085 if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) {
86 DeclAsFunction->setRangeEnd(KWEndLoc);
87 }
Alexis Hunt5a7fa252011-05-12 06:15:49 +000088 } else {
89 llvm_unreachable("function definition after = not 'delete' or 'default'");
90 }
91
92 if (Tok.is(tok::comma)) {
93 Diag(KWLoc, diag::err_default_delete_in_multiple_declaration)
94 << Delete;
95 SkipUntil(tok::semi);
Alp Toker383d2c42014-01-01 03:08:43 +000096 } else if (ExpectAndConsume(tok::semi, diag::err_expected_after,
97 Delete ? "delete" : "default")) {
98 SkipUntil(tok::semi);
Alexis Hunt5a7fa252011-05-12 06:15:49 +000099 }
100
101 return FnD;
102 }
Eli Bendersky41842222015-03-23 23:49:41 +0000103
Olivier Goffartf9e890c2016-06-16 21:40:06 +0000104 if (SkipFunctionBodies && (!FnD || Actions.canSkipFunctionBody(FnD)) &&
105 trySkippingFunctionBody()) {
106 Actions.ActOnSkippedFunctionBody(FnD);
107 return FnD;
108 }
109
Francois Pichet1c229c02011-04-22 22:18:13 +0000110 // In delayed template parsing mode, if we are within a class template
111 // or if we are about to parse function member template then consume
112 // the tokens and store them for parsing at the end of the translation unit.
David Majnemer90b17292013-09-14 05:46:42 +0000113 if (getLangOpts().DelayedTemplateParsing &&
Eli Bendersky41842222015-03-23 23:49:41 +0000114 D.getFunctionDefinitionKind() == FDK_Definition &&
Alp Tokera2794f92014-01-22 07:29:52 +0000115 !D.getDeclSpec().isConstexprSpecified() &&
116 !(FnD && FnD->getAsFunction() &&
Alp Toker314cc812014-01-25 16:55:45 +0000117 FnD->getAsFunction()->getReturnType()->getContainedAutoType()) &&
Francois Pichet1c229c02011-04-22 22:18:13 +0000118 ((Actions.CurContext->isDependentContext() ||
David Majnemer90b17292013-09-14 05:46:42 +0000119 (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
120 TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) &&
121 !Actions.IsInsideALocalClassWithinATemplateFunction())) {
Francois Pichet1c229c02011-04-22 22:18:13 +0000122
Richard Smithe40f2ba2013-08-07 21:41:30 +0000123 CachedTokens Toks;
124 LexTemplateFunctionForLateParsing(Toks);
Francois Pichet1c229c02011-04-22 22:18:13 +0000125
Richard Smithe40f2ba2013-08-07 21:41:30 +0000126 if (FnD) {
Alp Tokera2794f92014-01-22 07:29:52 +0000127 FunctionDecl *FD = FnD->getAsFunction();
Chandler Carruthbc0f9ae2011-04-25 07:09:43 +0000128 Actions.CheckForFunctionRedefinition(FD);
Richard Smithe40f2ba2013-08-07 21:41:30 +0000129 Actions.MarkAsLateParsedTemplate(FD, FnD, Toks);
Francois Pichet1c229c02011-04-22 22:18:13 +0000130 }
131
132 return FnD;
133 }
134
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000135 // Consume the tokens and store them for later parsing.
136
Douglas Gregorefc46952010-10-12 16:25:54 +0000137 LexedMethod* LM = new LexedMethod(this, FnD);
138 getCurrentClass().LateParsedDeclarations.push_back(LM);
139 LM->TemplateScope = getCurScope()->isTemplateParamScope();
140 CachedTokens &Toks = LM->Toks;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000141
Sebastian Redla7b98a72009-04-26 20:35:05 +0000142 tok::TokenKind kind = Tok.getKind();
Sebastian Redl0d164012011-09-30 08:32:17 +0000143 // Consume everything up to (and including) the left brace of the
144 // function body.
145 if (ConsumeAndStoreFunctionPrologue(Toks)) {
146 // We didn't find the left-brace we expected after the
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000147 // constructor initializer; we already printed an error, and it's likely
148 // impossible to recover, so don't try to parse this method later.
Richard Smithcde3fd82013-07-04 00:13:48 +0000149 // Skip over the rest of the decl and back to somewhere that looks
150 // reasonable.
151 SkipMalformedDecl();
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000152 delete getCurrentClass().LateParsedDeclarations.back();
153 getCurrentClass().LateParsedDeclarations.pop_back();
154 return FnD;
Douglas Gregore8381c02008-11-05 04:29:56 +0000155 } else {
Sebastian Redl0d164012011-09-30 08:32:17 +0000156 // Consume everything up to (and including) the matching right brace.
157 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Douglas Gregore8381c02008-11-05 04:29:56 +0000158 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000159
Sebastian Redla7b98a72009-04-26 20:35:05 +0000160 // If we're in a function-try-block, we need to store all the catch blocks.
161 if (kind == tok::kw_try) {
162 while (Tok.is(tok::kw_catch)) {
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000163 ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false);
164 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Sebastian Redla7b98a72009-04-26 20:35:05 +0000165 }
166 }
167
Stephen Lin9354fc52013-06-23 07:37:13 +0000168 if (FnD) {
Richard Smith6c7161162017-08-12 01:46:03 +0000169 FunctionDecl *FD = FnD->getAsFunction();
170 // Track that this function will eventually have a body; Sema needs
171 // to know this.
172 Actions.CheckForFunctionRedefinition(FD);
173 FD->setWillHaveBody(true);
Stephen Lin9354fc52013-06-23 07:37:13 +0000174 } else {
Douglas Gregor6ca64102011-04-14 23:19:27 +0000175 // If semantic analysis could not build a function declaration,
176 // just throw away the late-parsed declaration.
177 delete getCurrentClass().LateParsedDeclarations.back();
178 getCurrentClass().LateParsedDeclarations.pop_back();
179 }
180
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000181 return FnD;
182}
183
Richard Smith938f40b2011-06-11 17:19:42 +0000184/// ParseCXXNonStaticMemberInitializer - We parsed and verified that the
185/// specified Declarator is a well formed C++ non-static data member
186/// declaration. Now lex its initializer and store its tokens for parsing
187/// after the class is complete.
188void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) {
Daniel Marjamakie59f8d72015-06-18 10:59:26 +0000189 assert(Tok.isOneOf(tok::l_brace, tok::equal) &&
Richard Smith938f40b2011-06-11 17:19:42 +0000190 "Current token not a '{' or '='!");
191
192 LateParsedMemberInitializer *MI =
193 new LateParsedMemberInitializer(this, VarD);
194 getCurrentClass().LateParsedDeclarations.push_back(MI);
195 CachedTokens &Toks = MI->Toks;
196
197 tok::TokenKind kind = Tok.getKind();
198 if (kind == tok::equal) {
199 Toks.push_back(Tok);
Douglas Gregor0cf55e92012-03-08 01:00:17 +0000200 ConsumeToken();
Richard Smith938f40b2011-06-11 17:19:42 +0000201 }
202
203 if (kind == tok::l_brace) {
204 // Begin by storing the '{' token.
205 Toks.push_back(Tok);
206 ConsumeBrace();
207
208 // Consume everything up to (and including) the matching right brace.
209 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true);
210 } else {
211 // Consume everything up to (but excluding) the comma or semicolon.
Richard Smith1fff95c2013-09-12 23:28:08 +0000212 ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer);
Richard Smith938f40b2011-06-11 17:19:42 +0000213 }
214
215 // Store an artificial EOF token to ensure that we don't run off the end of
216 // the initializer when we come to parse it.
217 Token Eof;
218 Eof.startToken();
219 Eof.setKind(tok::eof);
220 Eof.setLocation(Tok.getLocation());
David Majnemerce1d3012014-12-19 02:13:56 +0000221 Eof.setEofData(VarD);
Richard Smith938f40b2011-06-11 17:19:42 +0000222 Toks.push_back(Eof);
223}
224
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +0000225Parser::LateParsedDeclaration::~LateParsedDeclaration() {}
Douglas Gregorefc46952010-10-12 16:25:54 +0000226void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {}
Richard Smith938f40b2011-06-11 17:19:42 +0000227void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {}
Douglas Gregorefc46952010-10-12 16:25:54 +0000228void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {}
229
230Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C)
231 : Self(P), Class(C) {}
232
233Parser::LateParsedClass::~LateParsedClass() {
234 Self->DeallocateParsedClasses(Class);
235}
236
237void Parser::LateParsedClass::ParseLexedMethodDeclarations() {
238 Self->ParseLexedMethodDeclarations(*Class);
239}
240
Richard Smith938f40b2011-06-11 17:19:42 +0000241void Parser::LateParsedClass::ParseLexedMemberInitializers() {
242 Self->ParseLexedMemberInitializers(*Class);
243}
244
Douglas Gregorefc46952010-10-12 16:25:54 +0000245void Parser::LateParsedClass::ParseLexedMethodDefs() {
246 Self->ParseLexedMethodDefs(*Class);
247}
248
249void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() {
250 Self->ParseLexedMethodDeclaration(*this);
251}
252
253void Parser::LexedMethod::ParseLexedMethodDefs() {
254 Self->ParseLexedMethodDef(*this);
255}
256
Richard Smith938f40b2011-06-11 17:19:42 +0000257void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() {
258 Self->ParseLexedMemberInitializer(*this);
259}
260
Douglas Gregor4d87df52008-12-16 21:30:33 +0000261/// ParseLexedMethodDeclarations - We finished parsing the member
262/// specification of a top (non-nested) C++ class. Now go over the
263/// stack of method declarations with some parts for which parsing was
264/// delayed (such as default arguments) and parse them.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000265void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) {
266 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
Nico Weber77c76c52014-05-10 17:43:15 +0000267 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope,
268 HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000269 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
270 if (HasTemplateScope) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000271 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000272 ++CurTemplateDepthTracker;
273 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000274
John McCall6df5fef2009-12-19 10:49:29 +0000275 // The current scope is still active if we're the top-level class.
276 // Otherwise we'll need to push and enter a new scope.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000277 bool HasClassScope = !Class.TopLevelClass;
Alexis Hunt1deb9722010-04-14 23:07:37 +0000278 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
279 HasClassScope);
John McCall6df5fef2009-12-19 10:49:29 +0000280 if (HasClassScope)
Nico Weber77c76c52014-05-10 17:43:15 +0000281 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),
282 Class.TagOrTemplate);
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000283
Douglas Gregorefc46952010-10-12 16:25:54 +0000284 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
285 Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations();
Douglas Gregor4d87df52008-12-16 21:30:33 +0000286 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000287
John McCall6df5fef2009-12-19 10:49:29 +0000288 if (HasClassScope)
Nico Weber77c76c52014-05-10 17:43:15 +0000289 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(),
290 Class.TagOrTemplate);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000291}
292
Douglas Gregorefc46952010-10-12 16:25:54 +0000293void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
294 // If this is a member template, introduce the template parameter scope.
295 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000296 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
297 if (LM.TemplateScope) {
Douglas Gregorefc46952010-10-12 16:25:54 +0000298 Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method);
Richard Smithc8378952013-04-29 11:55:38 +0000299 ++CurTemplateDepthTracker;
300 }
Douglas Gregorefc46952010-10-12 16:25:54 +0000301 // Start the delayed C++ method declaration
302 Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
303
304 // Introduce the parameters into scope and parse their default
305 // arguments.
Richard Smithe233fbf2013-01-28 22:42:45 +0000306 ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
307 Scope::FunctionDeclarationScope | Scope::DeclScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000308 for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
Nathan Sidwell5bb231c2015-02-19 14:03:22 +0000309 auto Param = cast<ParmVarDecl>(LM.DefaultArgs[I].Param);
Douglas Gregorefc46952010-10-12 16:25:54 +0000310 // Introduce the parameter into scope.
Nathan Sidwell5bb231c2015-02-19 14:03:22 +0000311 bool HasUnparsed = Param->hasUnparsedDefaultArg();
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000312 Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
Malcolm Parsonsff0382c2016-11-17 17:52:58 +0000313 std::unique_ptr<CachedTokens> Toks = std::move(LM.DefaultArgs[I].Toks);
314 if (Toks) {
David Majnemer7cceba52015-01-13 04:20:57 +0000315 // Mark the end of the default argument so that we know when to stop when
316 // we parse it later on.
317 Token LastDefaultArgToken = Toks->back();
318 Token DefArgEnd;
319 DefArgEnd.startToken();
320 DefArgEnd.setKind(tok::eof);
David Majnemera8f2f1d2015-03-19 00:10:23 +0000321 DefArgEnd.setLocation(LastDefaultArgToken.getEndLoc());
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000322 DefArgEnd.setEofData(Param);
David Majnemer7cceba52015-01-13 04:20:57 +0000323 Toks->push_back(DefArgEnd);
Douglas Gregorefc46952010-10-12 16:25:54 +0000324
325 // Parse the default argument from its saved token stream.
326 Toks->push_back(Tok); // So that the current token doesn't get lost
David Blaikie2eabcc92016-02-09 18:52:09 +0000327 PP.EnterTokenStream(*Toks, true);
Douglas Gregorefc46952010-10-12 16:25:54 +0000328
329 // Consume the previously-pushed token.
330 ConsumeAnyToken();
331
332 // Consume the '='.
333 assert(Tok.is(tok::equal) && "Default argument not starting with '='");
334 SourceLocation EqualLoc = ConsumeToken();
335
336 // The argument isn't actually potentially evaluated unless it is
337 // used.
Faisal Valid143a0c2017-04-01 21:30:49 +0000338 EnterExpressionEvaluationContext Eval(
339 Actions,
340 Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, Param);
Douglas Gregorefc46952010-10-12 16:25:54 +0000341
Sebastian Redldb63af22012-03-14 15:54:00 +0000342 ExprResult DefArgResult;
Richard Smith2bf7fdb2013-01-02 11:42:31 +0000343 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
Sebastian Redl6db0b1b2012-03-20 21:24:03 +0000344 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
Sebastian Redldb63af22012-03-14 15:54:00 +0000345 DefArgResult = ParseBraceInitializer();
Sebastian Redl6db0b1b2012-03-20 21:24:03 +0000346 } else
Sebastian Redldb63af22012-03-14 15:54:00 +0000347 DefArgResult = ParseAssignmentExpression();
Kaelyn Takatab16e6322014-11-20 22:06:40 +0000348 DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
David Majnemerbba12342015-01-12 06:51:15 +0000349 if (DefArgResult.isInvalid()) {
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000350 Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
David Majnemerbba12342015-01-12 06:51:15 +0000351 } else {
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000352 if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) {
Richard Smith1fff95c2013-09-12 23:28:08 +0000353 // The last two tokens are the terminator and the saved value of
354 // Tok; the last token in the default argument is the one before
355 // those.
356 assert(Toks->size() >= 3 && "expected a token in default arg");
357 Diag(Tok.getLocation(), diag::err_default_arg_unparsed)
358 << SourceRange(Tok.getLocation(),
359 (*Toks)[Toks->size() - 3].getLocation());
360 }
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000361 Actions.ActOnParamDefaultArgument(Param, EqualLoc,
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000362 DefArgResult.get());
Douglas Gregorefc46952010-10-12 16:25:54 +0000363 }
364
Douglas Gregorefc46952010-10-12 16:25:54 +0000365 // There could be leftover tokens (e.g. because of an error).
David Majnemer7cceba52015-01-13 04:20:57 +0000366 // Skip through until we reach the 'end of default argument' token.
367 while (Tok.isNot(tok::eof))
Douglas Gregorefc46952010-10-12 16:25:54 +0000368 ConsumeAnyToken();
David Majnemer7cceba52015-01-13 04:20:57 +0000369
Nathan Sidwell55d53fe2015-01-30 14:21:35 +0000370 if (Tok.is(tok::eof) && Tok.getEofData() == Param)
David Majnemer7cceba52015-01-13 04:20:57 +0000371 ConsumeAnyToken();
Nathan Sidwell5bb231c2015-02-19 14:03:22 +0000372 } else if (HasUnparsed) {
373 assert(Param->hasInheritedDefaultArg());
374 FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl();
375 ParmVarDecl *OldParam = Old->getParamDecl(I);
376 assert (!OldParam->hasUnparsedDefaultArg());
377 if (OldParam->hasUninstantiatedDefaultArg())
378 Param->setUninstantiatedDefaultArg(
David Majnemercef7d372016-06-10 20:21:15 +0000379 OldParam->getUninstantiatedDefaultArg());
Nathan Sidwell5bb231c2015-02-19 14:03:22 +0000380 else
381 Param->setDefaultArg(OldParam->getInit());
Douglas Gregorefc46952010-10-12 16:25:54 +0000382 }
383 }
Douglas Gregor433e0532012-04-16 18:27:27 +0000384
Richard Smith0b3a4622014-11-13 20:01:57 +0000385 // Parse a delayed exception-specification, if there is one.
386 if (CachedTokens *Toks = LM.ExceptionSpecTokens) {
David Majnemer7cceba52015-01-13 04:20:57 +0000387 // Add the 'stop' token.
388 Token LastExceptionSpecToken = Toks->back();
389 Token ExceptionSpecEnd;
390 ExceptionSpecEnd.startToken();
391 ExceptionSpecEnd.setKind(tok::eof);
David Majnemera8f2f1d2015-03-19 00:10:23 +0000392 ExceptionSpecEnd.setLocation(LastExceptionSpecToken.getEndLoc());
David Majnemer7cceba52015-01-13 04:20:57 +0000393 ExceptionSpecEnd.setEofData(LM.Method);
394 Toks->push_back(ExceptionSpecEnd);
Richard Smith0b3a4622014-11-13 20:01:57 +0000395
396 // Parse the default argument from its saved token stream.
397 Toks->push_back(Tok); // So that the current token doesn't get lost
David Blaikie2eabcc92016-02-09 18:52:09 +0000398 PP.EnterTokenStream(*Toks, true);
Richard Smith0b3a4622014-11-13 20:01:57 +0000399
400 // Consume the previously-pushed token.
401 ConsumeAnyToken();
402
403 // C++11 [expr.prim.general]p3:
404 // If a declaration declares a member function or member function
405 // template of a class X, the expression this is a prvalue of type
406 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
407 // and the end of the function-definition, member-declarator, or
408 // declarator.
409 CXXMethodDecl *Method;
410 if (FunctionTemplateDecl *FunTmpl
411 = dyn_cast<FunctionTemplateDecl>(LM.Method))
412 Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
413 else
414 Method = cast<CXXMethodDecl>(LM.Method);
415
416 Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(),
417 Method->getTypeQualifiers(),
418 getLangOpts().CPlusPlus11);
419
420 // Parse the exception-specification.
421 SourceRange SpecificationRange;
422 SmallVector<ParsedType, 4> DynamicExceptions;
423 SmallVector<SourceRange, 4> DynamicExceptionRanges;
424 ExprResult NoexceptExpr;
425 CachedTokens *ExceptionSpecTokens;
426
427 ExceptionSpecificationType EST
428 = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange,
429 DynamicExceptions,
430 DynamicExceptionRanges, NoexceptExpr,
431 ExceptionSpecTokens);
432
David Majnemer7cceba52015-01-13 04:20:57 +0000433 if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method)
Richard Smith0b3a4622014-11-13 20:01:57 +0000434 Diag(Tok.getLocation(), diag::err_except_spec_unparsed);
435
436 // Attach the exception-specification to the method.
Richard Smith3ef3e892014-11-20 22:32:11 +0000437 Actions.actOnDelayedExceptionSpecification(LM.Method, EST,
438 SpecificationRange,
439 DynamicExceptions,
440 DynamicExceptionRanges,
441 NoexceptExpr.isUsable()?
442 NoexceptExpr.get() : nullptr);
Richard Smith0b3a4622014-11-13 20:01:57 +0000443
Richard Smith0b3a4622014-11-13 20:01:57 +0000444 // There could be leftover tokens (e.g. because of an error).
445 // Skip through until we reach the original token position.
David Majnemer7cceba52015-01-13 04:20:57 +0000446 while (Tok.isNot(tok::eof))
Richard Smith0b3a4622014-11-13 20:01:57 +0000447 ConsumeAnyToken();
David Majnemer7cceba52015-01-13 04:20:57 +0000448
449 // Clean up the remaining EOF token.
450 if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method)
451 ConsumeAnyToken();
Richard Smith0b3a4622014-11-13 20:01:57 +0000452
453 delete Toks;
454 LM.ExceptionSpecTokens = nullptr;
455 }
456
Douglas Gregorefc46952010-10-12 16:25:54 +0000457 PrototypeScope.Exit();
458
459 // Finish the delayed C++ method declaration.
460 Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method);
461}
462
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000463/// ParseLexedMethodDefs - We finished parsing the member specification of a top
464/// (non-nested) C++ class. Now go over the stack of lexed methods that were
465/// collected during its parsing and parse them all.
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000466void Parser::ParseLexedMethodDefs(ParsingClass &Class) {
467 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
Douglas Gregorefc46952010-10-12 16:25:54 +0000468 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000469 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
470 if (HasTemplateScope) {
Douglas Gregor0be31a22010-07-02 17:43:08 +0000471 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000472 ++CurTemplateDepthTracker;
473 }
Douglas Gregore44a2ad2009-05-27 23:11:45 +0000474 bool HasClassScope = !Class.TopLevelClass;
475 ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope,
476 HasClassScope);
477
Douglas Gregorefc46952010-10-12 16:25:54 +0000478 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
479 Class.LateParsedDeclarations[i]->ParseLexedMethodDefs();
480 }
481}
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000482
Douglas Gregorefc46952010-10-12 16:25:54 +0000483void Parser::ParseLexedMethodDef(LexedMethod &LM) {
484 // If this is a member template, introduce the template parameter scope.
485 ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000486 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
487 if (LM.TemplateScope) {
Douglas Gregorefc46952010-10-12 16:25:54 +0000488 Actions.ActOnReenterTemplateScope(getCurScope(), LM.D);
Richard Smithc8378952013-04-29 11:55:38 +0000489 ++CurTemplateDepthTracker;
490 }
Argyrios Kyrtzidis02041972010-03-31 00:38:09 +0000491
Douglas Gregorefc46952010-10-12 16:25:54 +0000492 assert(!LM.Toks.empty() && "Empty body!");
David Majnemera7ea1b12015-01-13 05:06:20 +0000493 Token LastBodyToken = LM.Toks.back();
494 Token BodyEnd;
495 BodyEnd.startToken();
496 BodyEnd.setKind(tok::eof);
David Majnemera8f2f1d2015-03-19 00:10:23 +0000497 BodyEnd.setLocation(LastBodyToken.getEndLoc());
David Majnemera7ea1b12015-01-13 05:06:20 +0000498 BodyEnd.setEofData(LM.D);
499 LM.Toks.push_back(BodyEnd);
Douglas Gregorefc46952010-10-12 16:25:54 +0000500 // Append the current token at the end of the new token stream so that it
501 // doesn't get lost.
502 LM.Toks.push_back(Tok);
David Blaikie2eabcc92016-02-09 18:52:09 +0000503 PP.EnterTokenStream(LM.Toks, true);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000504
Douglas Gregorefc46952010-10-12 16:25:54 +0000505 // Consume the previously pushed token.
Argyrios Kyrtzidisc36633c2013-03-27 23:58:17 +0000506 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Daniel Marjamakie59f8d72015-06-18 10:59:26 +0000507 assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try)
Douglas Gregorefc46952010-10-12 16:25:54 +0000508 && "Inline method not starting with '{', ':' or 'try'");
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000509
Douglas Gregorefc46952010-10-12 16:25:54 +0000510 // Parse the method body. Function body parsing code is similar enough
511 // to be re-used for method bodies as well.
Momchil Velikov57c681f2017-08-10 15:43:06 +0000512 ParseScope FnScope(this, Scope::FnScope | Scope::DeclScope |
513 Scope::CompoundStmtScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000514 Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000515
Douglas Gregorefc46952010-10-12 16:25:54 +0000516 if (Tok.is(tok::kw_try)) {
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000517 ParseFunctionTryBlock(LM.D, FnScope);
David Majnemera7ea1b12015-01-13 05:06:20 +0000518
519 while (Tok.isNot(tok::eof))
520 ConsumeAnyToken();
521
522 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
Douglas Gregorefc46952010-10-12 16:25:54 +0000523 ConsumeAnyToken();
524 return;
525 }
526 if (Tok.is(tok::colon)) {
527 ParseConstructorInitializer(LM.D);
528
529 // Error recovery.
530 if (!Tok.is(tok::l_brace)) {
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000531 FnScope.Exit();
Craig Topper161e4db2014-05-21 06:02:52 +0000532 Actions.ActOnFinishFunctionBody(LM.D, nullptr);
David Majnemera7ea1b12015-01-13 05:06:20 +0000533
534 while (Tok.isNot(tok::eof))
535 ConsumeAnyToken();
536
537 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
Matt Beaumont-Gayd0457922011-09-23 22:39:23 +0000538 ConsumeAnyToken();
Douglas Gregorefc46952010-10-12 16:25:54 +0000539 return;
540 }
541 } else
542 Actions.ActOnDefaultCtorInitializers(LM.D);
543
Richard Smithc8378952013-04-29 11:55:38 +0000544 assert((Actions.getDiagnostics().hasErrorOccurred() ||
545 !isa<FunctionTemplateDecl>(LM.D) ||
546 cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth()
547 < TemplateParameterDepth) &&
548 "TemplateParameterDepth should be greater than the depth of "
549 "current template being instantiated!");
550
Douglas Gregora0ff0c32011-03-16 17:05:57 +0000551 ParseFunctionStatementBody(LM.D, FnScope);
Douglas Gregorefc46952010-10-12 16:25:54 +0000552
David Majnemera7ea1b12015-01-13 05:06:20 +0000553 while (Tok.isNot(tok::eof))
554 ConsumeAnyToken();
555
556 if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
557 ConsumeAnyToken();
Hans Wennborga926d842014-05-23 20:37:38 +0000558
Stephan Bergmann17d7d142016-03-30 06:27:31 +0000559 if (auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D))
560 if (isa<CXXMethodDecl>(FD) ||
561 FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
562 Actions.ActOnFinishInlineFunctionDef(FD);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000563}
564
Richard Smith938f40b2011-06-11 17:19:42 +0000565/// ParseLexedMemberInitializers - We finished parsing the member specification
566/// of a top (non-nested) C++ class. Now go over the stack of lexed data member
567/// initializers that were collected during its parsing and parse them all.
568void Parser::ParseLexedMemberInitializers(ParsingClass &Class) {
569 bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope;
570 ParseScope ClassTemplateScope(this, Scope::TemplateParamScope,
571 HasTemplateScope);
Richard Smithc8378952013-04-29 11:55:38 +0000572 TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
573 if (HasTemplateScope) {
Richard Smith938f40b2011-06-11 17:19:42 +0000574 Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate);
Richard Smithc8378952013-04-29 11:55:38 +0000575 ++CurTemplateDepthTracker;
576 }
Douglas Gregor3024f072012-04-16 07:05:22 +0000577 // Set or update the scope flags.
Richard Smith938f40b2011-06-11 17:19:42 +0000578 bool AlreadyHasClassScope = Class.TopLevelClass;
Douglas Gregor3024f072012-04-16 07:05:22 +0000579 unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope;
Richard Smith938f40b2011-06-11 17:19:42 +0000580 ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope);
581 ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope);
582
583 if (!AlreadyHasClassScope)
584 Actions.ActOnStartDelayedMemberDeclarations(getCurScope(),
585 Class.TagOrTemplate);
586
Benjamin Kramer1d373c62012-05-17 12:01:52 +0000587 if (!Class.LateParsedDeclarations.empty()) {
Douglas Gregor3024f072012-04-16 07:05:22 +0000588 // C++11 [expr.prim.general]p4:
589 // Otherwise, if a member-declarator declares a non-static data member
590 // (9.2) of a class X, the expression this is a prvalue of type "pointer
591 // to X" within the optional brace-or-equal-initializer. It shall not
592 // appear elsewhere in the member-declarator.
593 Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate,
594 /*TypeQuals=*/(unsigned)0);
Richard Smith938f40b2011-06-11 17:19:42 +0000595
Douglas Gregor3024f072012-04-16 07:05:22 +0000596 for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) {
597 Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers();
598 }
599 }
600
Richard Smith938f40b2011-06-11 17:19:42 +0000601 if (!AlreadyHasClassScope)
602 Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(),
603 Class.TagOrTemplate);
604
605 Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate);
606}
607
608void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) {
Richard Smith1a526fd2011-09-29 19:42:27 +0000609 if (!MI.Field || MI.Field->isInvalidDecl())
Richard Smith938f40b2011-06-11 17:19:42 +0000610 return;
611
612 // Append the current token at the end of the new token stream so that it
613 // doesn't get lost.
614 MI.Toks.push_back(Tok);
David Blaikie2eabcc92016-02-09 18:52:09 +0000615 PP.EnterTokenStream(MI.Toks, true);
Richard Smith938f40b2011-06-11 17:19:42 +0000616
617 // Consume the previously pushed token.
Argyrios Kyrtzidisc36633c2013-03-27 23:58:17 +0000618 ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
Richard Smith938f40b2011-06-11 17:19:42 +0000619
620 SourceLocation EqualLoc;
Richard Smith2b013182012-06-10 03:12:00 +0000621
Richard Smith74108172014-01-17 03:11:34 +0000622 Actions.ActOnStartCXXInClassMemberInitializer();
623
Douglas Gregor926410d2012-02-21 02:22:07 +0000624 ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false,
625 EqualLoc);
Richard Smith938f40b2011-06-11 17:19:42 +0000626
Richard Smith74108172014-01-17 03:11:34 +0000627 Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc,
Nikola Smiljanic01a75982014-05-29 10:55:11 +0000628 Init.get());
Richard Smith938f40b2011-06-11 17:19:42 +0000629
630 // The next token should be our artificial terminating EOF token.
631 if (Tok.isNot(tok::eof)) {
Richard Smith95e1fb02014-08-27 03:23:12 +0000632 if (!Init.isInvalid()) {
633 SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation);
634 if (!EndLoc.isValid())
635 EndLoc = Tok.getLocation();
636 // No fixit; we can't recover as if there were a semicolon here.
637 Diag(EndLoc, diag::err_expected_semi_decl_list);
638 }
Richard Smith938f40b2011-06-11 17:19:42 +0000639
640 // Consume tokens until we hit the artificial EOF.
641 while (Tok.isNot(tok::eof))
642 ConsumeAnyToken();
643 }
David Majnemer2d3663e2014-12-18 09:57:31 +0000644 // Make sure this is *our* artificial EOF token.
David Majnemerce1d3012014-12-19 02:13:56 +0000645 if (Tok.getEofData() == MI.Field)
David Majnemer2d3663e2014-12-18 09:57:31 +0000646 ConsumeAnyToken();
Richard Smith938f40b2011-06-11 17:19:42 +0000647}
648
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000649/// ConsumeAndStoreUntil - Consume and store the token at the passed token
Douglas Gregor4d87df52008-12-16 21:30:33 +0000650/// container until the token 'T' is reached (which gets
Mike Stump11289f42009-09-09 15:08:12 +0000651/// consumed/stored too, if ConsumeFinalToken).
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000652/// If StopAtSemi is true, then we will stop early at a ';' character.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000653/// Returns true if token 'T1' or 'T2' was found.
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000654/// NOTE: This is a specialized version of Parser::SkipUntil.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000655bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2,
656 CachedTokens &Toks,
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000657 bool StopAtSemi, bool ConsumeFinalToken) {
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000658 // We always want this function to consume at least one token if the first
659 // token isn't T and if not at EOF.
660 bool isFirstTokenConsumed = true;
661 while (1) {
662 // If we found one of the tokens, stop and return true.
Douglas Gregor4d87df52008-12-16 21:30:33 +0000663 if (Tok.is(T1) || Tok.is(T2)) {
664 if (ConsumeFinalToken) {
665 Toks.push_back(Tok);
666 ConsumeAnyToken();
667 }
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000668 return true;
669 }
670
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000671 switch (Tok.getKind()) {
672 case tok::eof:
Richard Smith34f30512013-11-23 04:06:09 +0000673 case tok::annot_module_begin:
674 case tok::annot_module_end:
675 case tok::annot_module_include:
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000676 // Ran out of tokens.
677 return false;
678
679 case tok::l_paren:
680 // Recursively consume properly-nested parens.
681 Toks.push_back(Tok);
682 ConsumeParen();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000683 ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000684 break;
685 case tok::l_square:
686 // Recursively consume properly-nested square brackets.
687 Toks.push_back(Tok);
688 ConsumeBracket();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000689 ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000690 break;
691 case tok::l_brace:
692 // Recursively consume properly-nested braces.
693 Toks.push_back(Tok);
694 ConsumeBrace();
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000695 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000696 break;
697
698 // Okay, we found a ']' or '}' or ')', which we think should be balanced.
699 // Since the user wasn't looking for this token (if they were, it would
700 // already be handled), this isn't balanced. If there is a LHS token at a
701 // higher level, we will assume that this matches the unbalanced token
702 // and return it. Otherwise, this is a spurious RHS token, which we skip.
703 case tok::r_paren:
704 if (ParenCount && !isFirstTokenConsumed)
705 return false; // Matches something.
706 Toks.push_back(Tok);
707 ConsumeParen();
708 break;
709 case tok::r_square:
710 if (BracketCount && !isFirstTokenConsumed)
711 return false; // Matches something.
712 Toks.push_back(Tok);
713 ConsumeBracket();
714 break;
715 case tok::r_brace:
716 if (BraceCount && !isFirstTokenConsumed)
717 return false; // Matches something.
718 Toks.push_back(Tok);
719 ConsumeBrace();
720 break;
721
Argyrios Kyrtzidis8d7bdba2010-04-23 21:20:12 +0000722 case tok::semi:
723 if (StopAtSemi)
724 return false;
725 // FALL THROUGH.
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000726 default:
727 // consume this token.
728 Toks.push_back(Tok);
Richard Smithaf3b3252017-05-18 19:21:48 +0000729 ConsumeAnyToken(/*ConsumeCodeCompletionTok*/true);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000730 break;
731 }
732 isFirstTokenConsumed = false;
733 }
734}
Sebastian Redla74948d2011-09-24 17:48:25 +0000735
736/// \brief Consume tokens and store them in the passed token container until
737/// we've passed the try keyword and constructor initializers and have consumed
Sebastian Redl0d164012011-09-30 08:32:17 +0000738/// the opening brace of the function body. The opening brace will be consumed
739/// if and only if there was no error.
Sebastian Redla74948d2011-09-24 17:48:25 +0000740///
Richard Smithcde3fd82013-07-04 00:13:48 +0000741/// \return True on error.
Sebastian Redl0d164012011-09-30 08:32:17 +0000742bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) {
Sebastian Redla74948d2011-09-24 17:48:25 +0000743 if (Tok.is(tok::kw_try)) {
744 Toks.push_back(Tok);
745 ConsumeToken();
746 }
Richard Smithcde3fd82013-07-04 00:13:48 +0000747
748 if (Tok.isNot(tok::colon)) {
749 // Easy case, just a function body.
750
751 // Grab any remaining garbage to be diagnosed later. We stop when we reach a
752 // brace: an opening one is the function body, while a closing one probably
753 // means we've reached the end of the class.
754 ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks,
755 /*StopAtSemi=*/true,
756 /*ConsumeFinalToken=*/false);
757 if (Tok.isNot(tok::l_brace))
Alp Tokerec543272013-12-24 09:48:30 +0000758 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
Richard Smithcde3fd82013-07-04 00:13:48 +0000759
Sebastian Redla74948d2011-09-24 17:48:25 +0000760 Toks.push_back(Tok);
Richard Smithcde3fd82013-07-04 00:13:48 +0000761 ConsumeBrace();
762 return false;
Eli Friedman7cd4a9b2012-02-22 04:49:04 +0000763 }
Sebastian Redl0d164012011-09-30 08:32:17 +0000764
765 Toks.push_back(Tok);
Richard Smithcde3fd82013-07-04 00:13:48 +0000766 ConsumeToken();
767
768 // We can't reliably skip over a mem-initializer-id, because it could be
769 // a template-id involving not-yet-declared names. Given:
770 //
771 // S ( ) : a < b < c > ( e )
772 //
773 // 'e' might be an initializer or part of a template argument, depending
774 // on whether 'b' is a template.
775
776 // Track whether we might be inside a template argument. We can give
777 // significantly better diagnostics if we know that we're not.
778 bool MightBeTemplateArgument = false;
779
780 while (true) {
781 // Skip over the mem-initializer-id, if possible.
782 if (Tok.is(tok::kw_decltype)) {
783 Toks.push_back(Tok);
784 SourceLocation OpenLoc = ConsumeToken();
785 if (Tok.isNot(tok::l_paren))
786 return Diag(Tok.getLocation(), diag::err_expected_lparen_after)
787 << "decltype";
788 Toks.push_back(Tok);
789 ConsumeParen();
790 if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) {
Alp Tokerec543272013-12-24 09:48:30 +0000791 Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren;
792 Diag(OpenLoc, diag::note_matching) << tok::l_paren;
Richard Smithcde3fd82013-07-04 00:13:48 +0000793 return true;
794 }
795 }
796 do {
797 // Walk over a component of a nested-name-specifier.
798 if (Tok.is(tok::coloncolon)) {
799 Toks.push_back(Tok);
800 ConsumeToken();
801
802 if (Tok.is(tok::kw_template)) {
803 Toks.push_back(Tok);
804 ConsumeToken();
805 }
806 }
807
Olivier Goffart3cd10132016-11-03 07:36:17 +0000808 if (Tok.is(tok::identifier)) {
Richard Smithcde3fd82013-07-04 00:13:48 +0000809 Toks.push_back(Tok);
810 ConsumeToken();
Richard Smithcde3fd82013-07-04 00:13:48 +0000811 } else {
812 break;
813 }
814 } while (Tok.is(tok::coloncolon));
815
Olivier Goffart3cd10132016-11-03 07:36:17 +0000816 if (Tok.is(tok::code_completion)) {
817 Toks.push_back(Tok);
818 ConsumeCodeCompletionToken();
819 if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype)) {
820 // Could be the start of another member initializer (the ',' has not
821 // been written yet)
822 continue;
823 }
824 }
825
826 if (Tok.is(tok::comma)) {
827 // The initialization is missing, we'll diagnose it later.
828 Toks.push_back(Tok);
829 ConsumeToken();
830 continue;
831 }
Richard Smithcde3fd82013-07-04 00:13:48 +0000832 if (Tok.is(tok::less))
833 MightBeTemplateArgument = true;
834
835 if (MightBeTemplateArgument) {
836 // We may be inside a template argument list. Grab up to the start of the
837 // next parenthesized initializer or braced-init-list. This *might* be the
838 // initializer, or it might be a subexpression in the template argument
839 // list.
840 // FIXME: Count angle brackets, and clear MightBeTemplateArgument
841 // if all angles are closed.
842 if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks,
843 /*StopAtSemi=*/true,
844 /*ConsumeFinalToken=*/false)) {
845 // We're not just missing the initializer, we're also missing the
846 // function body!
Alp Tokerec543272013-12-24 09:48:30 +0000847 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace;
Richard Smithcde3fd82013-07-04 00:13:48 +0000848 }
849 } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) {
850 // We found something weird in a mem-initializer-id.
Alp Tokerec543272013-12-24 09:48:30 +0000851 if (getLangOpts().CPlusPlus11)
852 return Diag(Tok.getLocation(), diag::err_expected_either)
853 << tok::l_paren << tok::l_brace;
854 else
855 return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren;
Richard Smithcde3fd82013-07-04 00:13:48 +0000856 }
857
858 tok::TokenKind kind = Tok.getKind();
859 Toks.push_back(Tok);
860 bool IsLParen = (kind == tok::l_paren);
861 SourceLocation OpenLoc = Tok.getLocation();
862
863 if (IsLParen) {
864 ConsumeParen();
865 } else {
866 assert(kind == tok::l_brace && "Must be left paren or brace here.");
867 ConsumeBrace();
868 // In C++03, this has to be the start of the function body, which
869 // means the initializer is malformed; we'll diagnose it later.
870 if (!getLangOpts().CPlusPlus11)
871 return false;
Olivier Goffart3cd10132016-11-03 07:36:17 +0000872
873 const Token &PreviousToken = Toks[Toks.size() - 2];
874 if (!MightBeTemplateArgument &&
875 !PreviousToken.isOneOf(tok::identifier, tok::greater,
876 tok::greatergreater)) {
877 // If the opening brace is not preceded by one of these tokens, we are
878 // missing the mem-initializer-id. In order to recover better, we need
879 // to use heuristics to determine if this '{' is most likely the
Hiroshi Inouea5141c82017-07-13 06:51:20 +0000880 // beginning of a brace-init-list or the function body.
Olivier Goffart3cd10132016-11-03 07:36:17 +0000881 // Check the token after the corresponding '}'.
882 TentativeParsingAction PA(*this);
883 if (SkipUntil(tok::r_brace) &&
884 !Tok.isOneOf(tok::comma, tok::ellipsis, tok::l_brace)) {
885 // Consider there was a malformed initializer and this is the start
886 // of the function body. We'll diagnose it later.
887 PA.Revert();
888 return false;
889 }
890 PA.Revert();
891 }
Richard Smithcde3fd82013-07-04 00:13:48 +0000892 }
893
894 // Grab the initializer (or the subexpression of the template argument).
895 // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false
896 // if we might be inside the braces of a lambda-expression.
Alp Tokerec543272013-12-24 09:48:30 +0000897 tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace;
898 if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) {
899 Diag(Tok, diag::err_expected) << CloseKind;
900 Diag(OpenLoc, diag::note_matching) << kind;
Richard Smithcde3fd82013-07-04 00:13:48 +0000901 return true;
902 }
903
904 // Grab pack ellipsis, if present.
905 if (Tok.is(tok::ellipsis)) {
906 Toks.push_back(Tok);
907 ConsumeToken();
908 }
909
910 // If we know we just consumed a mem-initializer, we must have ',' or '{'
911 // next.
912 if (Tok.is(tok::comma)) {
913 Toks.push_back(Tok);
914 ConsumeToken();
915 } else if (Tok.is(tok::l_brace)) {
916 // This is the function body if the ')' or '}' is immediately followed by
917 // a '{'. That cannot happen within a template argument, apart from the
918 // case where a template argument contains a compound literal:
919 //
920 // S ( ) : a < b < c > ( d ) { }
921 // // End of declaration, or still inside the template argument?
922 //
923 // ... and the case where the template argument contains a lambda:
924 //
925 // S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; }
926 // ( ) > ( ) { }
927 //
928 // FIXME: Disambiguate these cases. Note that the latter case is probably
929 // going to be made ill-formed by core issue 1607.
930 Toks.push_back(Tok);
931 ConsumeBrace();
932 return false;
933 } else if (!MightBeTemplateArgument) {
Alp Tokerec543272013-12-24 09:48:30 +0000934 return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace
935 << tok::comma;
Richard Smithcde3fd82013-07-04 00:13:48 +0000936 }
937 }
Sebastian Redla74948d2011-09-24 17:48:25 +0000938}
Richard Smith1fff95c2013-09-12 23:28:08 +0000939
940/// \brief Consume and store tokens from the '?' to the ':' in a conditional
941/// expression.
942bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) {
943 // Consume '?'.
944 assert(Tok.is(tok::question));
945 Toks.push_back(Tok);
946 ConsumeToken();
947
948 while (Tok.isNot(tok::colon)) {
Nico Weber77c76c52014-05-10 17:43:15 +0000949 if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks,
950 /*StopAtSemi=*/true,
951 /*ConsumeFinalToken=*/false))
Richard Smith1fff95c2013-09-12 23:28:08 +0000952 return false;
953
954 // If we found a nested conditional, consume it.
955 if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks))
956 return false;
957 }
958
959 // Consume ':'.
960 Toks.push_back(Tok);
961 ConsumeToken();
962 return true;
963}
964
965/// \brief A tentative parsing action that can also revert token annotations.
966class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction {
967public:
968 explicit UnannotatedTentativeParsingAction(Parser &Self,
969 tok::TokenKind EndKind)
970 : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) {
971 // Stash away the old token stream, so we can restore it once the
972 // tentative parse is complete.
973 TentativeParsingAction Inner(Self);
974 Self.ConsumeAndStoreUntil(EndKind, Toks, true, /*ConsumeFinalToken*/false);
975 Inner.Revert();
976 }
977
978 void RevertAnnotations() {
979 Revert();
980
981 // Put back the original tokens.
Alexey Bataevee6507d2013-11-18 08:17:37 +0000982 Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch);
Richard Smith1fff95c2013-09-12 23:28:08 +0000983 if (Toks.size()) {
David Blaikie2eabcc92016-02-09 18:52:09 +0000984 auto Buffer = llvm::make_unique<Token[]>(Toks.size());
985 std::copy(Toks.begin() + 1, Toks.end(), Buffer.get());
Richard Smith1fff95c2013-09-12 23:28:08 +0000986 Buffer[Toks.size() - 1] = Self.Tok;
David Blaikie2eabcc92016-02-09 18:52:09 +0000987 Self.PP.EnterTokenStream(std::move(Buffer), Toks.size(), true);
Richard Smith1fff95c2013-09-12 23:28:08 +0000988
989 Self.Tok = Toks.front();
990 }
991 }
992
993private:
994 Parser &Self;
995 CachedTokens Toks;
996 tok::TokenKind EndKind;
997};
998
999/// ConsumeAndStoreInitializer - Consume and store the token at the passed token
1000/// container until the end of the current initializer expression (either a
1001/// default argument or an in-class initializer for a non-static data member).
Richard Smith95e1fb02014-08-27 03:23:12 +00001002///
1003/// Returns \c true if we reached the end of something initializer-shaped,
1004/// \c false if we bailed out.
Richard Smith1fff95c2013-09-12 23:28:08 +00001005bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
1006 CachedInitKind CIK) {
1007 // We always want this function to consume at least one token if not at EOF.
Richard Smith95e1fb02014-08-27 03:23:12 +00001008 bool IsFirstToken = true;
Richard Smith1fff95c2013-09-12 23:28:08 +00001009
1010 // Number of possible unclosed <s we've seen so far. These might be templates,
1011 // and might not, but if there were none of them (or we know for sure that
1012 // we're within a template), we can avoid a tentative parse.
1013 unsigned AngleCount = 0;
1014 unsigned KnownTemplateCount = 0;
1015
1016 while (1) {
1017 switch (Tok.getKind()) {
1018 case tok::comma:
1019 // If we might be in a template, perform a tentative parse to check.
1020 if (!AngleCount)
1021 // Not a template argument: this is the end of the initializer.
1022 return true;
1023 if (KnownTemplateCount)
1024 goto consume_token;
1025
1026 // We hit a comma inside angle brackets. This is the hard case. The
1027 // rule we follow is:
1028 // * For a default argument, if the tokens after the comma form a
1029 // syntactically-valid parameter-declaration-clause, in which each
1030 // parameter has an initializer, then this comma ends the default
1031 // argument.
1032 // * For a default initializer, if the tokens after the comma form a
1033 // syntactically-valid init-declarator-list, then this comma ends
1034 // the default initializer.
1035 {
1036 UnannotatedTentativeParsingAction PA(*this,
1037 CIK == CIK_DefaultInitializer
1038 ? tok::semi : tok::r_paren);
1039 Sema::TentativeAnalysisScope Scope(Actions);
1040
Richard Smithee390432014-05-16 01:56:53 +00001041 TPResult Result = TPResult::Error;
Richard Smith1fff95c2013-09-12 23:28:08 +00001042 ConsumeToken();
1043 switch (CIK) {
1044 case CIK_DefaultInitializer:
1045 Result = TryParseInitDeclaratorList();
1046 // If we parsed a complete, ambiguous init-declarator-list, this
1047 // is only syntactically-valid if it's followed by a semicolon.
Richard Smithee390432014-05-16 01:56:53 +00001048 if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi))
1049 Result = TPResult::False;
Richard Smith1fff95c2013-09-12 23:28:08 +00001050 break;
1051
1052 case CIK_DefaultArgument:
1053 bool InvalidAsDeclaration = false;
1054 Result = TryParseParameterDeclarationClause(
Nico Weberc29c4832014-12-28 23:24:02 +00001055 &InvalidAsDeclaration, /*VersusTemplateArgument=*/true);
Richard Smith1fff95c2013-09-12 23:28:08 +00001056 // If this is an expression or a declaration with a missing
1057 // 'typename', assume it's not a declaration.
Richard Smithee390432014-05-16 01:56:53 +00001058 if (Result == TPResult::Ambiguous && InvalidAsDeclaration)
1059 Result = TPResult::False;
Richard Smith1fff95c2013-09-12 23:28:08 +00001060 break;
1061 }
1062
1063 // If what follows could be a declaration, it is a declaration.
Richard Smithee390432014-05-16 01:56:53 +00001064 if (Result != TPResult::False && Result != TPResult::Error) {
Richard Smith1fff95c2013-09-12 23:28:08 +00001065 PA.Revert();
1066 return true;
1067 }
1068
1069 // In the uncommon case that we decide the following tokens are part
1070 // of a template argument, revert any annotations we've performed in
1071 // those tokens. We're not going to look them up until we've parsed
1072 // the rest of the class, and that might add more declarations.
1073 PA.RevertAnnotations();
1074 }
1075
1076 // Keep going. We know we're inside a template argument list now.
1077 ++KnownTemplateCount;
1078 goto consume_token;
1079
1080 case tok::eof:
Richard Smith34f30512013-11-23 04:06:09 +00001081 case tok::annot_module_begin:
1082 case tok::annot_module_end:
1083 case tok::annot_module_include:
Richard Smith1fff95c2013-09-12 23:28:08 +00001084 // Ran out of tokens.
1085 return false;
1086
1087 case tok::less:
1088 // FIXME: A '<' can only start a template-id if it's preceded by an
1089 // identifier, an operator-function-id, or a literal-operator-id.
1090 ++AngleCount;
1091 goto consume_token;
1092
1093 case tok::question:
1094 // In 'a ? b : c', 'b' can contain an unparenthesized comma. If it does,
1095 // that is *never* the end of the initializer. Skip to the ':'.
1096 if (!ConsumeAndStoreConditional(Toks))
1097 return false;
1098 break;
1099
1100 case tok::greatergreatergreater:
1101 if (!getLangOpts().CPlusPlus11)
1102 goto consume_token;
1103 if (AngleCount) --AngleCount;
1104 if (KnownTemplateCount) --KnownTemplateCount;
1105 // Fall through.
1106 case tok::greatergreater:
1107 if (!getLangOpts().CPlusPlus11)
1108 goto consume_token;
1109 if (AngleCount) --AngleCount;
1110 if (KnownTemplateCount) --KnownTemplateCount;
1111 // Fall through.
1112 case tok::greater:
1113 if (AngleCount) --AngleCount;
1114 if (KnownTemplateCount) --KnownTemplateCount;
1115 goto consume_token;
1116
1117 case tok::kw_template:
1118 // 'template' identifier '<' is known to start a template argument list,
1119 // and can be used to disambiguate the parse.
1120 // FIXME: Support all forms of 'template' unqualified-id '<'.
1121 Toks.push_back(Tok);
1122 ConsumeToken();
1123 if (Tok.is(tok::identifier)) {
1124 Toks.push_back(Tok);
1125 ConsumeToken();
1126 if (Tok.is(tok::less)) {
Richard Smith93033572014-07-27 05:38:12 +00001127 ++AngleCount;
Richard Smith1fff95c2013-09-12 23:28:08 +00001128 ++KnownTemplateCount;
1129 Toks.push_back(Tok);
1130 ConsumeToken();
1131 }
1132 }
1133 break;
1134
1135 case tok::kw_operator:
1136 // If 'operator' precedes other punctuation, that punctuation loses
1137 // its special behavior.
1138 Toks.push_back(Tok);
1139 ConsumeToken();
1140 switch (Tok.getKind()) {
1141 case tok::comma:
1142 case tok::greatergreatergreater:
1143 case tok::greatergreater:
1144 case tok::greater:
1145 case tok::less:
1146 Toks.push_back(Tok);
1147 ConsumeToken();
1148 break;
1149 default:
1150 break;
1151 }
1152 break;
1153
1154 case tok::l_paren:
1155 // Recursively consume properly-nested parens.
1156 Toks.push_back(Tok);
1157 ConsumeParen();
1158 ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false);
1159 break;
1160 case tok::l_square:
1161 // Recursively consume properly-nested square brackets.
1162 Toks.push_back(Tok);
1163 ConsumeBracket();
1164 ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false);
1165 break;
1166 case tok::l_brace:
1167 // Recursively consume properly-nested braces.
1168 Toks.push_back(Tok);
1169 ConsumeBrace();
1170 ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
1171 break;
1172
1173 // Okay, we found a ']' or '}' or ')', which we think should be balanced.
1174 // Since the user wasn't looking for this token (if they were, it would
1175 // already be handled), this isn't balanced. If there is a LHS token at a
1176 // higher level, we will assume that this matches the unbalanced token
Richard Smith95e1fb02014-08-27 03:23:12 +00001177 // and return it. Otherwise, this is a spurious RHS token, which we
1178 // consume and pass on to downstream code to diagnose.
Richard Smith1fff95c2013-09-12 23:28:08 +00001179 case tok::r_paren:
1180 if (CIK == CIK_DefaultArgument)
1181 return true; // End of the default argument.
Richard Smith95e1fb02014-08-27 03:23:12 +00001182 if (ParenCount && !IsFirstToken)
1183 return false;
1184 Toks.push_back(Tok);
1185 ConsumeParen();
1186 continue;
Richard Smith1fff95c2013-09-12 23:28:08 +00001187 case tok::r_square:
Richard Smith95e1fb02014-08-27 03:23:12 +00001188 if (BracketCount && !IsFirstToken)
1189 return false;
1190 Toks.push_back(Tok);
1191 ConsumeBracket();
1192 continue;
Richard Smith1fff95c2013-09-12 23:28:08 +00001193 case tok::r_brace:
Richard Smith95e1fb02014-08-27 03:23:12 +00001194 if (BraceCount && !IsFirstToken)
1195 return false;
1196 Toks.push_back(Tok);
1197 ConsumeBrace();
1198 continue;
Richard Smith1fff95c2013-09-12 23:28:08 +00001199
1200 case tok::code_completion:
1201 Toks.push_back(Tok);
1202 ConsumeCodeCompletionToken();
1203 break;
1204
1205 case tok::string_literal:
1206 case tok::wide_string_literal:
1207 case tok::utf8_string_literal:
1208 case tok::utf16_string_literal:
1209 case tok::utf32_string_literal:
1210 Toks.push_back(Tok);
1211 ConsumeStringToken();
1212 break;
1213 case tok::semi:
1214 if (CIK == CIK_DefaultInitializer)
1215 return true; // End of the default initializer.
1216 // FALL THROUGH.
1217 default:
1218 consume_token:
1219 Toks.push_back(Tok);
1220 ConsumeToken();
1221 break;
1222 }
Richard Smith95e1fb02014-08-27 03:23:12 +00001223 IsFirstToken = false;
Richard Smith1fff95c2013-09-12 23:28:08 +00001224 }
1225}