Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 1 | //===--- 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 Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "RAIIObjectsForParser.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/Parse/ParseDiagnostic.h" |
John McCall | 8b0666c | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 18 | #include "clang/Sema/DeclSpec.h" |
| 19 | #include "clang/Sema/Scope.h" |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 22 | /// ParseCXXInlineMethodDef - We parsed and verified that the specified |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 23 | /// 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 Espindola | c2453dd | 2013-01-08 21:00:12 +0000 | [diff] [blame] | 25 | NamedDecl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, |
Erik Verbruggen | ca98f2a | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 26 | AttributeList *AccessAttrs, |
| 27 | ParsingDeclarator &D, |
Douglas Gregor | 5d1b4e3 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 28 | const ParsedTemplateInfo &TemplateInfo, |
Eli Bendersky | 4184222 | 2015-03-23 23:49:41 +0000 | [diff] [blame] | 29 | const VirtSpecifiers& VS, |
Richard Smith | 9ba0fec | 2015-06-30 01:28:56 +0000 | [diff] [blame] | 30 | SourceLocation PureSpecLoc) { |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 31 | assert(D.isFunctionDeclarator() && "This isn't a function declarator!"); |
Daniel Marjamaki | e59f8d7 | 2015-06-18 10:59:26 +0000 | [diff] [blame] | 32 | assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try, tok::equal) && |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 33 | "Current token not a '{', ':', '=', or 'try'!"); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 34 | |
Benjamin Kramer | cc4c49d | 2012-08-23 23:38:35 +0000 | [diff] [blame] | 35 | MultiTemplateParamsArg TemplateParams( |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 36 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() |
| 37 | : nullptr, |
Nico Weber | 77c76c5 | 2014-05-10 17:43:15 +0000 | [diff] [blame] | 38 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); |
Alexis Hunt | 1deb972 | 2010-04-14 23:07:37 +0000 | [diff] [blame] | 39 | |
Rafael Espindola | c2453dd | 2013-01-08 21:00:12 +0000 | [diff] [blame] | 40 | NamedDecl *FnD; |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 41 | if (D.getDeclSpec().isFriendSpecified()) |
Kaelyn Uhrain | 4dc695d | 2011-10-11 00:28:45 +0000 | [diff] [blame] | 42 | FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, |
Benjamin Kramer | 62b95d8 | 2012-08-23 21:35:17 +0000 | [diff] [blame] | 43 | TemplateParams); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 44 | else { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 45 | FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 46 | TemplateParams, nullptr, |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 47 | VS, ICIS_NoInit); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 48 | if (FnD) { |
Richard Smith | f8a75c3 | 2013-08-29 00:47:48 +0000 | [diff] [blame] | 49 | Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs); |
Richard Smith | 9ba0fec | 2015-06-30 01:28:56 +0000 | [diff] [blame] | 50 | if (PureSpecLoc.isValid()) |
| 51 | Actions.ActOnPureSpecifier(FnD, PureSpecLoc); |
Douglas Gregor | 728d00b | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 52 | } |
Nico Weber | 24b2a82 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 53 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 54 | |
Reid Kleckner | bde5ede | 2016-02-19 01:15:08 +0000 | [diff] [blame] | 55 | if (FnD) |
| 56 | HandleMemberFunctionDeclDelays(D, FnD); |
Eli Friedman | 3af2a77 | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 57 | |
John McCall | c146582 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 58 | D.complete(FnD); |
| 59 | |
Alp Toker | a3ebe6e | 2013-12-17 14:12:37 +0000 | [diff] [blame] | 60 | if (TryConsumeToken(tok::equal)) { |
Richard Smith | 1c70473 | 2011-11-10 09:08:44 +0000 | [diff] [blame] | 61 | if (!FnD) { |
| 62 | SkipUntil(tok::semi); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 63 | return nullptr; |
Richard Smith | 1c70473 | 2011-11-10 09:08:44 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 66 | bool Delete = false; |
| 67 | SourceLocation KWLoc; |
Eli Bendersky | 5f4d76e | 2015-03-23 21:43:28 +0000 | [diff] [blame] | 68 | SourceLocation KWEndLoc = Tok.getEndLoc().getLocWithOffset(-1); |
Alp Toker | a3ebe6e | 2013-12-17 14:12:37 +0000 | [diff] [blame] | 69 | if (TryConsumeToken(tok::kw_delete, KWLoc)) { |
| 70 | Diag(KWLoc, getLangOpts().CPlusPlus11 |
Craig Topper | 54a6a68 | 2015-11-14 18:16:08 +0000 | [diff] [blame] | 71 | ? diag::warn_cxx98_compat_defaulted_deleted_function |
| 72 | : diag::ext_defaulted_deleted_function) |
| 73 | << 1 /* deleted */; |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 74 | Actions.SetDeclDeleted(FnD, KWLoc); |
| 75 | Delete = true; |
Eli Bendersky | 5f4d76e | 2015-03-23 21:43:28 +0000 | [diff] [blame] | 76 | if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { |
| 77 | DeclAsFunction->setRangeEnd(KWEndLoc); |
| 78 | } |
Alp Toker | a3ebe6e | 2013-12-17 14:12:37 +0000 | [diff] [blame] | 79 | } else if (TryConsumeToken(tok::kw_default, KWLoc)) { |
| 80 | Diag(KWLoc, getLangOpts().CPlusPlus11 |
Craig Topper | 54a6a68 | 2015-11-14 18:16:08 +0000 | [diff] [blame] | 81 | ? diag::warn_cxx98_compat_defaulted_deleted_function |
| 82 | : diag::ext_defaulted_deleted_function) |
| 83 | << 0 /* defaulted */; |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 84 | Actions.SetDeclDefaulted(FnD, KWLoc); |
Eli Bendersky | 5f4d76e | 2015-03-23 21:43:28 +0000 | [diff] [blame] | 85 | if (auto *DeclAsFunction = dyn_cast<FunctionDecl>(FnD)) { |
| 86 | DeclAsFunction->setRangeEnd(KWEndLoc); |
| 87 | } |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 88 | } 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 Toker | 383d2c4 | 2014-01-01 03:08:43 +0000 | [diff] [blame] | 96 | } else if (ExpectAndConsume(tok::semi, diag::err_expected_after, |
| 97 | Delete ? "delete" : "default")) { |
| 98 | SkipUntil(tok::semi); |
Alexis Hunt | 5a7fa25 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | return FnD; |
| 102 | } |
Eli Bendersky | 4184222 | 2015-03-23 23:49:41 +0000 | [diff] [blame] | 103 | |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 104 | // In delayed template parsing mode, if we are within a class template |
| 105 | // or if we are about to parse function member template then consume |
| 106 | // the tokens and store them for parsing at the end of the translation unit. |
David Majnemer | 90b1729 | 2013-09-14 05:46:42 +0000 | [diff] [blame] | 107 | if (getLangOpts().DelayedTemplateParsing && |
Eli Bendersky | 4184222 | 2015-03-23 23:49:41 +0000 | [diff] [blame] | 108 | D.getFunctionDefinitionKind() == FDK_Definition && |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 109 | !D.getDeclSpec().isConstexprSpecified() && |
| 110 | !(FnD && FnD->getAsFunction() && |
Alp Toker | 314cc81 | 2014-01-25 16:55:45 +0000 | [diff] [blame] | 111 | FnD->getAsFunction()->getReturnType()->getContainedAutoType()) && |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 112 | ((Actions.CurContext->isDependentContext() || |
David Majnemer | 90b1729 | 2013-09-14 05:46:42 +0000 | [diff] [blame] | 113 | (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && |
| 114 | TemplateInfo.Kind != ParsedTemplateInfo::ExplicitSpecialization)) && |
| 115 | !Actions.IsInsideALocalClassWithinATemplateFunction())) { |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 116 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 117 | CachedTokens Toks; |
| 118 | LexTemplateFunctionForLateParsing(Toks); |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 119 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 120 | if (FnD) { |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 121 | FunctionDecl *FD = FnD->getAsFunction(); |
Chandler Carruth | bc0f9ae | 2011-04-25 07:09:43 +0000 | [diff] [blame] | 122 | Actions.CheckForFunctionRedefinition(FD); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 123 | Actions.MarkAsLateParsedTemplate(FD, FnD, Toks); |
Francois Pichet | 1c229c0 | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | return FnD; |
| 127 | } |
| 128 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 129 | // Consume the tokens and store them for later parsing. |
| 130 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 131 | LexedMethod* LM = new LexedMethod(this, FnD); |
| 132 | getCurrentClass().LateParsedDeclarations.push_back(LM); |
| 133 | LM->TemplateScope = getCurScope()->isTemplateParamScope(); |
| 134 | CachedTokens &Toks = LM->Toks; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 135 | |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 136 | tok::TokenKind kind = Tok.getKind(); |
Sebastian Redl | 0d16401 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 137 | // Consume everything up to (and including) the left brace of the |
| 138 | // function body. |
| 139 | if (ConsumeAndStoreFunctionPrologue(Toks)) { |
| 140 | // We didn't find the left-brace we expected after the |
Eli Friedman | 7cd4a9b | 2012-02-22 04:49:04 +0000 | [diff] [blame] | 141 | // constructor initializer; we already printed an error, and it's likely |
| 142 | // impossible to recover, so don't try to parse this method later. |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 143 | // Skip over the rest of the decl and back to somewhere that looks |
| 144 | // reasonable. |
| 145 | SkipMalformedDecl(); |
Eli Friedman | 7cd4a9b | 2012-02-22 04:49:04 +0000 | [diff] [blame] | 146 | delete getCurrentClass().LateParsedDeclarations.back(); |
| 147 | getCurrentClass().LateParsedDeclarations.pop_back(); |
| 148 | return FnD; |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 149 | } else { |
Sebastian Redl | 0d16401 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 150 | // Consume everything up to (and including) the matching right brace. |
| 151 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Douglas Gregor | e8381c0 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 152 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 153 | |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 154 | // If we're in a function-try-block, we need to store all the catch blocks. |
| 155 | if (kind == tok::kw_try) { |
| 156 | while (Tok.is(tok::kw_catch)) { |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 157 | ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false); |
| 158 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Sebastian Redl | a7b98a7 | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | |
Stephen Lin | 9354fc5 | 2013-06-23 07:37:13 +0000 | [diff] [blame] | 162 | if (FnD) { |
| 163 | // If this is a friend function, mark that it's late-parsed so that |
| 164 | // it's still known to be a definition even before we attach the |
| 165 | // parsed body. Sema needs to treat friend function definitions |
| 166 | // differently during template instantiation, and it's possible for |
| 167 | // the containing class to be instantiated before all its member |
| 168 | // function definitions are parsed. |
| 169 | // |
| 170 | // If you remove this, you can remove the code that clears the flag |
| 171 | // after parsing the member. |
| 172 | if (D.getDeclSpec().isFriendSpecified()) { |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 173 | FunctionDecl *FD = FnD->getAsFunction(); |
Alp Toker | 19bff32 | 2013-10-18 05:54:24 +0000 | [diff] [blame] | 174 | Actions.CheckForFunctionRedefinition(FD); |
| 175 | FD->setLateTemplateParsed(true); |
Stephen Lin | 9354fc5 | 2013-06-23 07:37:13 +0000 | [diff] [blame] | 176 | } |
| 177 | } else { |
Douglas Gregor | 6ca6410 | 2011-04-14 23:19:27 +0000 | [diff] [blame] | 178 | // If semantic analysis could not build a function declaration, |
| 179 | // just throw away the late-parsed declaration. |
| 180 | delete getCurrentClass().LateParsedDeclarations.back(); |
| 181 | getCurrentClass().LateParsedDeclarations.pop_back(); |
| 182 | } |
| 183 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 184 | return FnD; |
| 185 | } |
| 186 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 187 | /// ParseCXXNonStaticMemberInitializer - We parsed and verified that the |
| 188 | /// specified Declarator is a well formed C++ non-static data member |
| 189 | /// declaration. Now lex its initializer and store its tokens for parsing |
| 190 | /// after the class is complete. |
| 191 | void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) { |
Daniel Marjamaki | e59f8d7 | 2015-06-18 10:59:26 +0000 | [diff] [blame] | 192 | assert(Tok.isOneOf(tok::l_brace, tok::equal) && |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 193 | "Current token not a '{' or '='!"); |
| 194 | |
| 195 | LateParsedMemberInitializer *MI = |
| 196 | new LateParsedMemberInitializer(this, VarD); |
| 197 | getCurrentClass().LateParsedDeclarations.push_back(MI); |
| 198 | CachedTokens &Toks = MI->Toks; |
| 199 | |
| 200 | tok::TokenKind kind = Tok.getKind(); |
| 201 | if (kind == tok::equal) { |
| 202 | Toks.push_back(Tok); |
Douglas Gregor | 0cf55e9 | 2012-03-08 01:00:17 +0000 | [diff] [blame] | 203 | ConsumeToken(); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | if (kind == tok::l_brace) { |
| 207 | // Begin by storing the '{' token. |
| 208 | Toks.push_back(Tok); |
| 209 | ConsumeBrace(); |
| 210 | |
| 211 | // Consume everything up to (and including) the matching right brace. |
| 212 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true); |
| 213 | } else { |
| 214 | // Consume everything up to (but excluding) the comma or semicolon. |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 215 | ConsumeAndStoreInitializer(Toks, CIK_DefaultInitializer); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | // Store an artificial EOF token to ensure that we don't run off the end of |
| 219 | // the initializer when we come to parse it. |
| 220 | Token Eof; |
| 221 | Eof.startToken(); |
| 222 | Eof.setKind(tok::eof); |
| 223 | Eof.setLocation(Tok.getLocation()); |
David Majnemer | ce1d301 | 2014-12-19 02:13:56 +0000 | [diff] [blame] | 224 | Eof.setEofData(VarD); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 225 | Toks.push_back(Eof); |
| 226 | } |
| 227 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 228 | Parser::LateParsedDeclaration::~LateParsedDeclaration() {} |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 229 | void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {} |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 230 | void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {} |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 231 | void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {} |
| 232 | |
| 233 | Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C) |
| 234 | : Self(P), Class(C) {} |
| 235 | |
| 236 | Parser::LateParsedClass::~LateParsedClass() { |
| 237 | Self->DeallocateParsedClasses(Class); |
| 238 | } |
| 239 | |
| 240 | void Parser::LateParsedClass::ParseLexedMethodDeclarations() { |
| 241 | Self->ParseLexedMethodDeclarations(*Class); |
| 242 | } |
| 243 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 244 | void Parser::LateParsedClass::ParseLexedMemberInitializers() { |
| 245 | Self->ParseLexedMemberInitializers(*Class); |
| 246 | } |
| 247 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 248 | void Parser::LateParsedClass::ParseLexedMethodDefs() { |
| 249 | Self->ParseLexedMethodDefs(*Class); |
| 250 | } |
| 251 | |
| 252 | void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() { |
| 253 | Self->ParseLexedMethodDeclaration(*this); |
| 254 | } |
| 255 | |
| 256 | void Parser::LexedMethod::ParseLexedMethodDefs() { |
| 257 | Self->ParseLexedMethodDef(*this); |
| 258 | } |
| 259 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 260 | void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { |
| 261 | Self->ParseLexedMemberInitializer(*this); |
| 262 | } |
| 263 | |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 264 | /// ParseLexedMethodDeclarations - We finished parsing the member |
| 265 | /// specification of a top (non-nested) C++ class. Now go over the |
| 266 | /// stack of method declarations with some parts for which parsing was |
| 267 | /// delayed (such as default arguments) and parse them. |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 268 | void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { |
| 269 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
Nico Weber | 77c76c5 | 2014-05-10 17:43:15 +0000 | [diff] [blame] | 270 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, |
| 271 | HasTemplateScope); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 272 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 273 | if (HasTemplateScope) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 274 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 275 | ++CurTemplateDepthTracker; |
| 276 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 277 | |
John McCall | 6df5fef | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 278 | // The current scope is still active if we're the top-level class. |
| 279 | // Otherwise we'll need to push and enter a new scope. |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 280 | bool HasClassScope = !Class.TopLevelClass; |
Alexis Hunt | 1deb972 | 2010-04-14 23:07:37 +0000 | [diff] [blame] | 281 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
| 282 | HasClassScope); |
John McCall | 6df5fef | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 283 | if (HasClassScope) |
Nico Weber | 77c76c5 | 2014-05-10 17:43:15 +0000 | [diff] [blame] | 284 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), |
| 285 | Class.TagOrTemplate); |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 286 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 287 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 288 | Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations(); |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 289 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 290 | |
John McCall | 6df5fef | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 291 | if (HasClassScope) |
Nico Weber | 77c76c5 | 2014-05-10 17:43:15 +0000 | [diff] [blame] | 292 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), |
| 293 | Class.TagOrTemplate); |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 296 | void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { |
| 297 | // If this is a member template, introduce the template parameter scope. |
| 298 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 299 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 300 | if (LM.TemplateScope) { |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 301 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 302 | ++CurTemplateDepthTracker; |
| 303 | } |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 304 | // Start the delayed C++ method declaration |
| 305 | Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
| 306 | |
| 307 | // Introduce the parameters into scope and parse their default |
| 308 | // arguments. |
Richard Smith | e233fbf | 2013-01-28 22:42:45 +0000 | [diff] [blame] | 309 | ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | |
| 310 | Scope::FunctionDeclarationScope | Scope::DeclScope); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 311 | for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) { |
Nathan Sidwell | 5bb231c | 2015-02-19 14:03:22 +0000 | [diff] [blame] | 312 | auto Param = cast<ParmVarDecl>(LM.DefaultArgs[I].Param); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 313 | // Introduce the parameter into scope. |
Nathan Sidwell | 5bb231c | 2015-02-19 14:03:22 +0000 | [diff] [blame] | 314 | bool HasUnparsed = Param->hasUnparsedDefaultArg(); |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 315 | Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 316 | if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) { |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 317 | // Mark the end of the default argument so that we know when to stop when |
| 318 | // we parse it later on. |
| 319 | Token LastDefaultArgToken = Toks->back(); |
| 320 | Token DefArgEnd; |
| 321 | DefArgEnd.startToken(); |
| 322 | DefArgEnd.setKind(tok::eof); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 323 | DefArgEnd.setLocation(LastDefaultArgToken.getEndLoc()); |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 324 | DefArgEnd.setEofData(Param); |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 325 | Toks->push_back(DefArgEnd); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 326 | |
| 327 | // Parse the default argument from its saved token stream. |
| 328 | Toks->push_back(Tok); // So that the current token doesn't get lost |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 329 | PP.EnterTokenStream(*Toks, true); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 330 | |
| 331 | // Consume the previously-pushed token. |
| 332 | ConsumeAnyToken(); |
| 333 | |
| 334 | // Consume the '='. |
| 335 | assert(Tok.is(tok::equal) && "Default argument not starting with '='"); |
| 336 | SourceLocation EqualLoc = ConsumeToken(); |
| 337 | |
| 338 | // The argument isn't actually potentially evaluated unless it is |
| 339 | // used. |
| 340 | EnterExpressionEvaluationContext Eval(Actions, |
Douglas Gregor | 7fcbd90 | 2012-02-21 00:37:24 +0000 | [diff] [blame] | 341 | Sema::PotentiallyEvaluatedIfUsed, |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 342 | Param); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 343 | |
Sebastian Redl | db63af2 | 2012-03-14 15:54:00 +0000 | [diff] [blame] | 344 | ExprResult DefArgResult; |
Richard Smith | 2bf7fdb | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 345 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
Sebastian Redl | 6db0b1b | 2012-03-20 21:24:03 +0000 | [diff] [blame] | 346 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
Sebastian Redl | db63af2 | 2012-03-14 15:54:00 +0000 | [diff] [blame] | 347 | DefArgResult = ParseBraceInitializer(); |
Sebastian Redl | 6db0b1b | 2012-03-20 21:24:03 +0000 | [diff] [blame] | 348 | } else |
Sebastian Redl | db63af2 | 2012-03-14 15:54:00 +0000 | [diff] [blame] | 349 | DefArgResult = ParseAssignmentExpression(); |
Kaelyn Takata | b16e632 | 2014-11-20 22:06:40 +0000 | [diff] [blame] | 350 | DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult); |
David Majnemer | bba1234 | 2015-01-12 06:51:15 +0000 | [diff] [blame] | 351 | if (DefArgResult.isInvalid()) { |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 352 | Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); |
David Majnemer | bba1234 | 2015-01-12 06:51:15 +0000 | [diff] [blame] | 353 | } else { |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 354 | if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) { |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 355 | // The last two tokens are the terminator and the saved value of |
| 356 | // Tok; the last token in the default argument is the one before |
| 357 | // those. |
| 358 | assert(Toks->size() >= 3 && "expected a token in default arg"); |
| 359 | Diag(Tok.getLocation(), diag::err_default_arg_unparsed) |
| 360 | << SourceRange(Tok.getLocation(), |
| 361 | (*Toks)[Toks->size() - 3].getLocation()); |
| 362 | } |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 363 | Actions.ActOnParamDefaultArgument(Param, EqualLoc, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 364 | DefArgResult.get()); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 367 | // There could be leftover tokens (e.g. because of an error). |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 368 | // Skip through until we reach the 'end of default argument' token. |
| 369 | while (Tok.isNot(tok::eof)) |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 370 | ConsumeAnyToken(); |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 371 | |
Nathan Sidwell | 55d53fe | 2015-01-30 14:21:35 +0000 | [diff] [blame] | 372 | if (Tok.is(tok::eof) && Tok.getEofData() == Param) |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 373 | ConsumeAnyToken(); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 374 | |
| 375 | delete Toks; |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 376 | LM.DefaultArgs[I].Toks = nullptr; |
Nathan Sidwell | 5bb231c | 2015-02-19 14:03:22 +0000 | [diff] [blame] | 377 | } else if (HasUnparsed) { |
| 378 | assert(Param->hasInheritedDefaultArg()); |
| 379 | FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl(); |
| 380 | ParmVarDecl *OldParam = Old->getParamDecl(I); |
| 381 | assert (!OldParam->hasUnparsedDefaultArg()); |
| 382 | if (OldParam->hasUninstantiatedDefaultArg()) |
| 383 | Param->setUninstantiatedDefaultArg( |
| 384 | Param->getUninstantiatedDefaultArg()); |
| 385 | else |
| 386 | Param->setDefaultArg(OldParam->getInit()); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
Douglas Gregor | 433e053 | 2012-04-16 18:27:27 +0000 | [diff] [blame] | 389 | |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 390 | // Parse a delayed exception-specification, if there is one. |
| 391 | if (CachedTokens *Toks = LM.ExceptionSpecTokens) { |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 392 | // Add the 'stop' token. |
| 393 | Token LastExceptionSpecToken = Toks->back(); |
| 394 | Token ExceptionSpecEnd; |
| 395 | ExceptionSpecEnd.startToken(); |
| 396 | ExceptionSpecEnd.setKind(tok::eof); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 397 | ExceptionSpecEnd.setLocation(LastExceptionSpecToken.getEndLoc()); |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 398 | ExceptionSpecEnd.setEofData(LM.Method); |
| 399 | Toks->push_back(ExceptionSpecEnd); |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 400 | |
| 401 | // Parse the default argument from its saved token stream. |
| 402 | Toks->push_back(Tok); // So that the current token doesn't get lost |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 403 | PP.EnterTokenStream(*Toks, true); |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 404 | |
| 405 | // Consume the previously-pushed token. |
| 406 | ConsumeAnyToken(); |
| 407 | |
| 408 | // C++11 [expr.prim.general]p3: |
| 409 | // If a declaration declares a member function or member function |
| 410 | // template of a class X, the expression this is a prvalue of type |
| 411 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| 412 | // and the end of the function-definition, member-declarator, or |
| 413 | // declarator. |
| 414 | CXXMethodDecl *Method; |
| 415 | if (FunctionTemplateDecl *FunTmpl |
| 416 | = dyn_cast<FunctionTemplateDecl>(LM.Method)) |
| 417 | Method = cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl()); |
| 418 | else |
| 419 | Method = cast<CXXMethodDecl>(LM.Method); |
| 420 | |
| 421 | Sema::CXXThisScopeRAII ThisScope(Actions, Method->getParent(), |
| 422 | Method->getTypeQualifiers(), |
| 423 | getLangOpts().CPlusPlus11); |
| 424 | |
| 425 | // Parse the exception-specification. |
| 426 | SourceRange SpecificationRange; |
| 427 | SmallVector<ParsedType, 4> DynamicExceptions; |
| 428 | SmallVector<SourceRange, 4> DynamicExceptionRanges; |
| 429 | ExprResult NoexceptExpr; |
| 430 | CachedTokens *ExceptionSpecTokens; |
| 431 | |
| 432 | ExceptionSpecificationType EST |
| 433 | = tryParseExceptionSpecification(/*Delayed=*/false, SpecificationRange, |
| 434 | DynamicExceptions, |
| 435 | DynamicExceptionRanges, NoexceptExpr, |
| 436 | ExceptionSpecTokens); |
| 437 | |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 438 | if (Tok.isNot(tok::eof) || Tok.getEofData() != LM.Method) |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 439 | Diag(Tok.getLocation(), diag::err_except_spec_unparsed); |
| 440 | |
| 441 | // Attach the exception-specification to the method. |
Richard Smith | 3ef3e89 | 2014-11-20 22:32:11 +0000 | [diff] [blame] | 442 | Actions.actOnDelayedExceptionSpecification(LM.Method, EST, |
| 443 | SpecificationRange, |
| 444 | DynamicExceptions, |
| 445 | DynamicExceptionRanges, |
| 446 | NoexceptExpr.isUsable()? |
| 447 | NoexceptExpr.get() : nullptr); |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 448 | |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 449 | // There could be leftover tokens (e.g. because of an error). |
| 450 | // Skip through until we reach the original token position. |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 451 | while (Tok.isNot(tok::eof)) |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 452 | ConsumeAnyToken(); |
David Majnemer | 7cceba5 | 2015-01-13 04:20:57 +0000 | [diff] [blame] | 453 | |
| 454 | // Clean up the remaining EOF token. |
| 455 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.Method) |
| 456 | ConsumeAnyToken(); |
Richard Smith | 0b3a462 | 2014-11-13 20:01:57 +0000 | [diff] [blame] | 457 | |
| 458 | delete Toks; |
| 459 | LM.ExceptionSpecTokens = nullptr; |
| 460 | } |
| 461 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 462 | PrototypeScope.Exit(); |
| 463 | |
| 464 | // Finish the delayed C++ method declaration. |
| 465 | Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
| 466 | } |
| 467 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 468 | /// ParseLexedMethodDefs - We finished parsing the member specification of a top |
| 469 | /// (non-nested) C++ class. Now go over the stack of lexed methods that were |
| 470 | /// collected during its parsing and parse them all. |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 471 | void Parser::ParseLexedMethodDefs(ParsingClass &Class) { |
| 472 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 473 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 474 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 475 | if (HasTemplateScope) { |
Douglas Gregor | 0be31a2 | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 476 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 477 | ++CurTemplateDepthTracker; |
| 478 | } |
Douglas Gregor | e44a2ad | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 479 | bool HasClassScope = !Class.TopLevelClass; |
| 480 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
| 481 | HasClassScope); |
| 482 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 483 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 484 | Class.LateParsedDeclarations[i]->ParseLexedMethodDefs(); |
| 485 | } |
| 486 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 487 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 488 | void Parser::ParseLexedMethodDef(LexedMethod &LM) { |
| 489 | // If this is a member template, introduce the template parameter scope. |
| 490 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 491 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 492 | if (LM.TemplateScope) { |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 493 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.D); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 494 | ++CurTemplateDepthTracker; |
| 495 | } |
Argyrios Kyrtzidis | 0204197 | 2010-03-31 00:38:09 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 497 | assert(!LM.Toks.empty() && "Empty body!"); |
David Majnemer | a7ea1b1 | 2015-01-13 05:06:20 +0000 | [diff] [blame] | 498 | Token LastBodyToken = LM.Toks.back(); |
| 499 | Token BodyEnd; |
| 500 | BodyEnd.startToken(); |
| 501 | BodyEnd.setKind(tok::eof); |
David Majnemer | a8f2f1d | 2015-03-19 00:10:23 +0000 | [diff] [blame] | 502 | BodyEnd.setLocation(LastBodyToken.getEndLoc()); |
David Majnemer | a7ea1b1 | 2015-01-13 05:06:20 +0000 | [diff] [blame] | 503 | BodyEnd.setEofData(LM.D); |
| 504 | LM.Toks.push_back(BodyEnd); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 505 | // Append the current token at the end of the new token stream so that it |
| 506 | // doesn't get lost. |
| 507 | LM.Toks.push_back(Tok); |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 508 | PP.EnterTokenStream(LM.Toks, true); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 509 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 510 | // Consume the previously pushed token. |
Argyrios Kyrtzidis | c36633c | 2013-03-27 23:58:17 +0000 | [diff] [blame] | 511 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Daniel Marjamaki | e59f8d7 | 2015-06-18 10:59:26 +0000 | [diff] [blame] | 512 | assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 513 | && "Inline method not starting with '{', ':' or 'try'"); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 514 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 515 | // Parse the method body. Function body parsing code is similar enough |
| 516 | // to be re-used for method bodies as well. |
| 517 | ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope); |
| 518 | Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 520 | if (Tok.is(tok::kw_try)) { |
Douglas Gregor | a0ff0c3 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 521 | ParseFunctionTryBlock(LM.D, FnScope); |
David Majnemer | a7ea1b1 | 2015-01-13 05:06:20 +0000 | [diff] [blame] | 522 | |
| 523 | while (Tok.isNot(tok::eof)) |
| 524 | ConsumeAnyToken(); |
| 525 | |
| 526 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 527 | ConsumeAnyToken(); |
| 528 | return; |
| 529 | } |
| 530 | if (Tok.is(tok::colon)) { |
| 531 | ParseConstructorInitializer(LM.D); |
| 532 | |
| 533 | // Error recovery. |
| 534 | if (!Tok.is(tok::l_brace)) { |
Douglas Gregor | a0ff0c3 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 535 | FnScope.Exit(); |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 536 | Actions.ActOnFinishFunctionBody(LM.D, nullptr); |
David Majnemer | a7ea1b1 | 2015-01-13 05:06:20 +0000 | [diff] [blame] | 537 | |
| 538 | while (Tok.isNot(tok::eof)) |
| 539 | ConsumeAnyToken(); |
| 540 | |
| 541 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
Matt Beaumont-Gay | d045792 | 2011-09-23 22:39:23 +0000 | [diff] [blame] | 542 | ConsumeAnyToken(); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 543 | return; |
| 544 | } |
| 545 | } else |
| 546 | Actions.ActOnDefaultCtorInitializers(LM.D); |
| 547 | |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 548 | assert((Actions.getDiagnostics().hasErrorOccurred() || |
| 549 | !isa<FunctionTemplateDecl>(LM.D) || |
| 550 | cast<FunctionTemplateDecl>(LM.D)->getTemplateParameters()->getDepth() |
| 551 | < TemplateParameterDepth) && |
| 552 | "TemplateParameterDepth should be greater than the depth of " |
| 553 | "current template being instantiated!"); |
| 554 | |
Douglas Gregor | a0ff0c3 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 555 | ParseFunctionStatementBody(LM.D, FnScope); |
Douglas Gregor | efc4695 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 556 | |
John McCall | e68672f | 2013-03-14 05:13:41 +0000 | [diff] [blame] | 557 | // Clear the late-template-parsed bit if we set it before. |
Alp Toker | a2794f9 | 2014-01-22 07:29:52 +0000 | [diff] [blame] | 558 | if (LM.D) |
| 559 | LM.D->getAsFunction()->setLateTemplateParsed(false); |
John McCall | e68672f | 2013-03-14 05:13:41 +0000 | [diff] [blame] | 560 | |
David Majnemer | a7ea1b1 | 2015-01-13 05:06:20 +0000 | [diff] [blame] | 561 | while (Tok.isNot(tok::eof)) |
| 562 | ConsumeAnyToken(); |
| 563 | |
| 564 | if (Tok.is(tok::eof) && Tok.getEofData() == LM.D) |
| 565 | ConsumeAnyToken(); |
Hans Wennborg | a926d84 | 2014-05-23 20:37:38 +0000 | [diff] [blame] | 566 | |
Stephan Bergmann | 17d7d14 | 2016-03-30 06:27:31 +0000 | [diff] [blame] | 567 | if (auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D)) |
| 568 | if (isa<CXXMethodDecl>(FD) || |
| 569 | FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend)) |
| 570 | Actions.ActOnFinishInlineFunctionDef(FD); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 573 | /// ParseLexedMemberInitializers - We finished parsing the member specification |
| 574 | /// of a top (non-nested) C++ class. Now go over the stack of lexed data member |
| 575 | /// initializers that were collected during its parsing and parse them all. |
| 576 | void Parser::ParseLexedMemberInitializers(ParsingClass &Class) { |
| 577 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
| 578 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, |
| 579 | HasTemplateScope); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 580 | TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth); |
| 581 | if (HasTemplateScope) { |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 582 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
Richard Smith | c837895 | 2013-04-29 11:55:38 +0000 | [diff] [blame] | 583 | ++CurTemplateDepthTracker; |
| 584 | } |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 585 | // Set or update the scope flags. |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 586 | bool AlreadyHasClassScope = Class.TopLevelClass; |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 587 | unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope; |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 588 | ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); |
| 589 | ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); |
| 590 | |
| 591 | if (!AlreadyHasClassScope) |
| 592 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), |
| 593 | Class.TagOrTemplate); |
| 594 | |
Benjamin Kramer | 1d373c6 | 2012-05-17 12:01:52 +0000 | [diff] [blame] | 595 | if (!Class.LateParsedDeclarations.empty()) { |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 596 | // C++11 [expr.prim.general]p4: |
| 597 | // Otherwise, if a member-declarator declares a non-static data member |
| 598 | // (9.2) of a class X, the expression this is a prvalue of type "pointer |
| 599 | // to X" within the optional brace-or-equal-initializer. It shall not |
| 600 | // appear elsewhere in the member-declarator. |
| 601 | Sema::CXXThisScopeRAII ThisScope(Actions, Class.TagOrTemplate, |
| 602 | /*TypeQuals=*/(unsigned)0); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 603 | |
Douglas Gregor | 3024f07 | 2012-04-16 07:05:22 +0000 | [diff] [blame] | 604 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 605 | Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers(); |
| 606 | } |
| 607 | } |
| 608 | |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 609 | if (!AlreadyHasClassScope) |
| 610 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), |
| 611 | Class.TagOrTemplate); |
| 612 | |
| 613 | Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate); |
| 614 | } |
| 615 | |
| 616 | void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { |
Richard Smith | 1a526fd | 2011-09-29 19:42:27 +0000 | [diff] [blame] | 617 | if (!MI.Field || MI.Field->isInvalidDecl()) |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 618 | return; |
| 619 | |
| 620 | // Append the current token at the end of the new token stream so that it |
| 621 | // doesn't get lost. |
| 622 | MI.Toks.push_back(Tok); |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 623 | PP.EnterTokenStream(MI.Toks, true); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 624 | |
| 625 | // Consume the previously pushed token. |
Argyrios Kyrtzidis | c36633c | 2013-03-27 23:58:17 +0000 | [diff] [blame] | 626 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 627 | |
| 628 | SourceLocation EqualLoc; |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 629 | |
Richard Smith | 7410817 | 2014-01-17 03:11:34 +0000 | [diff] [blame] | 630 | Actions.ActOnStartCXXInClassMemberInitializer(); |
| 631 | |
Douglas Gregor | 926410d | 2012-02-21 02:22:07 +0000 | [diff] [blame] | 632 | ExprResult Init = ParseCXXMemberInitializer(MI.Field, /*IsFunction=*/false, |
| 633 | EqualLoc); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 634 | |
Richard Smith | 7410817 | 2014-01-17 03:11:34 +0000 | [diff] [blame] | 635 | Actions.ActOnFinishCXXInClassMemberInitializer(MI.Field, EqualLoc, |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 636 | Init.get()); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 637 | |
| 638 | // The next token should be our artificial terminating EOF token. |
| 639 | if (Tok.isNot(tok::eof)) { |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 640 | if (!Init.isInvalid()) { |
| 641 | SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation); |
| 642 | if (!EndLoc.isValid()) |
| 643 | EndLoc = Tok.getLocation(); |
| 644 | // No fixit; we can't recover as if there were a semicolon here. |
| 645 | Diag(EndLoc, diag::err_expected_semi_decl_list); |
| 646 | } |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 647 | |
| 648 | // Consume tokens until we hit the artificial EOF. |
| 649 | while (Tok.isNot(tok::eof)) |
| 650 | ConsumeAnyToken(); |
| 651 | } |
David Majnemer | 2d3663e | 2014-12-18 09:57:31 +0000 | [diff] [blame] | 652 | // Make sure this is *our* artificial EOF token. |
David Majnemer | ce1d301 | 2014-12-19 02:13:56 +0000 | [diff] [blame] | 653 | if (Tok.getEofData() == MI.Field) |
David Majnemer | 2d3663e | 2014-12-18 09:57:31 +0000 | [diff] [blame] | 654 | ConsumeAnyToken(); |
Richard Smith | 938f40b | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 657 | /// ConsumeAndStoreUntil - Consume and store the token at the passed token |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 658 | /// container until the token 'T' is reached (which gets |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 659 | /// consumed/stored too, if ConsumeFinalToken). |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 660 | /// If StopAtSemi is true, then we will stop early at a ';' character. |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 661 | /// Returns true if token 'T1' or 'T2' was found. |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 662 | /// NOTE: This is a specialized version of Parser::SkipUntil. |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 663 | bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
| 664 | CachedTokens &Toks, |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 665 | bool StopAtSemi, bool ConsumeFinalToken) { |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 666 | // We always want this function to consume at least one token if the first |
| 667 | // token isn't T and if not at EOF. |
| 668 | bool isFirstTokenConsumed = true; |
| 669 | while (1) { |
| 670 | // If we found one of the tokens, stop and return true. |
Douglas Gregor | 4d87df5 | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 671 | if (Tok.is(T1) || Tok.is(T2)) { |
| 672 | if (ConsumeFinalToken) { |
| 673 | Toks.push_back(Tok); |
| 674 | ConsumeAnyToken(); |
| 675 | } |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 676 | return true; |
| 677 | } |
| 678 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 679 | switch (Tok.getKind()) { |
| 680 | case tok::eof: |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 681 | case tok::annot_module_begin: |
| 682 | case tok::annot_module_end: |
| 683 | case tok::annot_module_include: |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 684 | // Ran out of tokens. |
| 685 | return false; |
| 686 | |
| 687 | case tok::l_paren: |
| 688 | // Recursively consume properly-nested parens. |
| 689 | Toks.push_back(Tok); |
| 690 | ConsumeParen(); |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 691 | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 692 | break; |
| 693 | case tok::l_square: |
| 694 | // Recursively consume properly-nested square brackets. |
| 695 | Toks.push_back(Tok); |
| 696 | ConsumeBracket(); |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 697 | ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 698 | break; |
| 699 | case tok::l_brace: |
| 700 | // Recursively consume properly-nested braces. |
| 701 | Toks.push_back(Tok); |
| 702 | ConsumeBrace(); |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 703 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
| 707 | // Since the user wasn't looking for this token (if they were, it would |
| 708 | // already be handled), this isn't balanced. If there is a LHS token at a |
| 709 | // higher level, we will assume that this matches the unbalanced token |
| 710 | // and return it. Otherwise, this is a spurious RHS token, which we skip. |
| 711 | case tok::r_paren: |
| 712 | if (ParenCount && !isFirstTokenConsumed) |
| 713 | return false; // Matches something. |
| 714 | Toks.push_back(Tok); |
| 715 | ConsumeParen(); |
| 716 | break; |
| 717 | case tok::r_square: |
| 718 | if (BracketCount && !isFirstTokenConsumed) |
| 719 | return false; // Matches something. |
| 720 | Toks.push_back(Tok); |
| 721 | ConsumeBracket(); |
| 722 | break; |
| 723 | case tok::r_brace: |
| 724 | if (BraceCount && !isFirstTokenConsumed) |
| 725 | return false; // Matches something. |
| 726 | Toks.push_back(Tok); |
| 727 | ConsumeBrace(); |
| 728 | break; |
| 729 | |
Argyrios Kyrtzidis | 5cec2ae | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 730 | case tok::code_completion: |
| 731 | Toks.push_back(Tok); |
| 732 | ConsumeCodeCompletionToken(); |
| 733 | break; |
| 734 | |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 735 | case tok::string_literal: |
| 736 | case tok::wide_string_literal: |
Douglas Gregor | fb65e59 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 737 | case tok::utf8_string_literal: |
| 738 | case tok::utf16_string_literal: |
| 739 | case tok::utf32_string_literal: |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 740 | Toks.push_back(Tok); |
| 741 | ConsumeStringToken(); |
| 742 | break; |
Argyrios Kyrtzidis | 8d7bdba | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 743 | case tok::semi: |
| 744 | if (StopAtSemi) |
| 745 | return false; |
| 746 | // FALL THROUGH. |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 747 | default: |
| 748 | // consume this token. |
| 749 | Toks.push_back(Tok); |
| 750 | ConsumeToken(); |
| 751 | break; |
| 752 | } |
| 753 | isFirstTokenConsumed = false; |
| 754 | } |
| 755 | } |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 756 | |
| 757 | /// \brief Consume tokens and store them in the passed token container until |
| 758 | /// we've passed the try keyword and constructor initializers and have consumed |
Sebastian Redl | 0d16401 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 759 | /// the opening brace of the function body. The opening brace will be consumed |
| 760 | /// if and only if there was no error. |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 761 | /// |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 762 | /// \return True on error. |
Sebastian Redl | 0d16401 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 763 | bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 764 | if (Tok.is(tok::kw_try)) { |
| 765 | Toks.push_back(Tok); |
| 766 | ConsumeToken(); |
| 767 | } |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 768 | |
| 769 | if (Tok.isNot(tok::colon)) { |
| 770 | // Easy case, just a function body. |
| 771 | |
| 772 | // Grab any remaining garbage to be diagnosed later. We stop when we reach a |
| 773 | // brace: an opening one is the function body, while a closing one probably |
| 774 | // means we've reached the end of the class. |
| 775 | ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks, |
| 776 | /*StopAtSemi=*/true, |
| 777 | /*ConsumeFinalToken=*/false); |
| 778 | if (Tok.isNot(tok::l_brace)) |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 779 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 780 | |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 781 | Toks.push_back(Tok); |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 782 | ConsumeBrace(); |
| 783 | return false; |
Eli Friedman | 7cd4a9b | 2012-02-22 04:49:04 +0000 | [diff] [blame] | 784 | } |
Sebastian Redl | 0d16401 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 785 | |
| 786 | Toks.push_back(Tok); |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 787 | ConsumeToken(); |
| 788 | |
| 789 | // We can't reliably skip over a mem-initializer-id, because it could be |
| 790 | // a template-id involving not-yet-declared names. Given: |
| 791 | // |
| 792 | // S ( ) : a < b < c > ( e ) |
| 793 | // |
| 794 | // 'e' might be an initializer or part of a template argument, depending |
| 795 | // on whether 'b' is a template. |
| 796 | |
| 797 | // Track whether we might be inside a template argument. We can give |
| 798 | // significantly better diagnostics if we know that we're not. |
| 799 | bool MightBeTemplateArgument = false; |
| 800 | |
| 801 | while (true) { |
| 802 | // Skip over the mem-initializer-id, if possible. |
| 803 | if (Tok.is(tok::kw_decltype)) { |
| 804 | Toks.push_back(Tok); |
| 805 | SourceLocation OpenLoc = ConsumeToken(); |
| 806 | if (Tok.isNot(tok::l_paren)) |
| 807 | return Diag(Tok.getLocation(), diag::err_expected_lparen_after) |
| 808 | << "decltype"; |
| 809 | Toks.push_back(Tok); |
| 810 | ConsumeParen(); |
| 811 | if (!ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/true)) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 812 | Diag(Tok.getLocation(), diag::err_expected) << tok::r_paren; |
| 813 | Diag(OpenLoc, diag::note_matching) << tok::l_paren; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 814 | return true; |
| 815 | } |
| 816 | } |
| 817 | do { |
| 818 | // Walk over a component of a nested-name-specifier. |
| 819 | if (Tok.is(tok::coloncolon)) { |
| 820 | Toks.push_back(Tok); |
| 821 | ConsumeToken(); |
| 822 | |
| 823 | if (Tok.is(tok::kw_template)) { |
| 824 | Toks.push_back(Tok); |
| 825 | ConsumeToken(); |
| 826 | } |
| 827 | } |
| 828 | |
Daniel Marjamaki | e59f8d7 | 2015-06-18 10:59:26 +0000 | [diff] [blame] | 829 | if (Tok.isOneOf(tok::identifier, tok::kw_template)) { |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 830 | Toks.push_back(Tok); |
| 831 | ConsumeToken(); |
| 832 | } else if (Tok.is(tok::code_completion)) { |
| 833 | Toks.push_back(Tok); |
| 834 | ConsumeCodeCompletionToken(); |
| 835 | // Consume the rest of the initializers permissively. |
| 836 | // FIXME: We should be able to perform code-completion here even if |
| 837 | // there isn't a subsequent '{' token. |
| 838 | MightBeTemplateArgument = true; |
| 839 | break; |
| 840 | } else { |
| 841 | break; |
| 842 | } |
| 843 | } while (Tok.is(tok::coloncolon)); |
| 844 | |
| 845 | if (Tok.is(tok::less)) |
| 846 | MightBeTemplateArgument = true; |
| 847 | |
| 848 | if (MightBeTemplateArgument) { |
| 849 | // We may be inside a template argument list. Grab up to the start of the |
| 850 | // next parenthesized initializer or braced-init-list. This *might* be the |
| 851 | // initializer, or it might be a subexpression in the template argument |
| 852 | // list. |
| 853 | // FIXME: Count angle brackets, and clear MightBeTemplateArgument |
| 854 | // if all angles are closed. |
| 855 | if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks, |
| 856 | /*StopAtSemi=*/true, |
| 857 | /*ConsumeFinalToken=*/false)) { |
| 858 | // We're not just missing the initializer, we're also missing the |
| 859 | // function body! |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 860 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_brace; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 861 | } |
| 862 | } else if (Tok.isNot(tok::l_paren) && Tok.isNot(tok::l_brace)) { |
| 863 | // We found something weird in a mem-initializer-id. |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 864 | if (getLangOpts().CPlusPlus11) |
| 865 | return Diag(Tok.getLocation(), diag::err_expected_either) |
| 866 | << tok::l_paren << tok::l_brace; |
| 867 | else |
| 868 | return Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | tok::TokenKind kind = Tok.getKind(); |
| 872 | Toks.push_back(Tok); |
| 873 | bool IsLParen = (kind == tok::l_paren); |
| 874 | SourceLocation OpenLoc = Tok.getLocation(); |
| 875 | |
| 876 | if (IsLParen) { |
| 877 | ConsumeParen(); |
| 878 | } else { |
| 879 | assert(kind == tok::l_brace && "Must be left paren or brace here."); |
| 880 | ConsumeBrace(); |
| 881 | // In C++03, this has to be the start of the function body, which |
| 882 | // means the initializer is malformed; we'll diagnose it later. |
| 883 | if (!getLangOpts().CPlusPlus11) |
| 884 | return false; |
| 885 | } |
| 886 | |
| 887 | // Grab the initializer (or the subexpression of the template argument). |
| 888 | // FIXME: If we support lambdas here, we'll need to set StopAtSemi to false |
| 889 | // if we might be inside the braces of a lambda-expression. |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 890 | tok::TokenKind CloseKind = IsLParen ? tok::r_paren : tok::r_brace; |
| 891 | if (!ConsumeAndStoreUntil(CloseKind, Toks, /*StopAtSemi=*/true)) { |
| 892 | Diag(Tok, diag::err_expected) << CloseKind; |
| 893 | Diag(OpenLoc, diag::note_matching) << kind; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 894 | return true; |
| 895 | } |
| 896 | |
| 897 | // Grab pack ellipsis, if present. |
| 898 | if (Tok.is(tok::ellipsis)) { |
| 899 | Toks.push_back(Tok); |
| 900 | ConsumeToken(); |
| 901 | } |
| 902 | |
| 903 | // If we know we just consumed a mem-initializer, we must have ',' or '{' |
| 904 | // next. |
| 905 | if (Tok.is(tok::comma)) { |
| 906 | Toks.push_back(Tok); |
| 907 | ConsumeToken(); |
| 908 | } else if (Tok.is(tok::l_brace)) { |
| 909 | // This is the function body if the ')' or '}' is immediately followed by |
| 910 | // a '{'. That cannot happen within a template argument, apart from the |
| 911 | // case where a template argument contains a compound literal: |
| 912 | // |
| 913 | // S ( ) : a < b < c > ( d ) { } |
| 914 | // // End of declaration, or still inside the template argument? |
| 915 | // |
| 916 | // ... and the case where the template argument contains a lambda: |
| 917 | // |
| 918 | // S ( ) : a < 0 && b < c > ( d ) + [ ] ( ) { return 0; } |
| 919 | // ( ) > ( ) { } |
| 920 | // |
| 921 | // FIXME: Disambiguate these cases. Note that the latter case is probably |
| 922 | // going to be made ill-formed by core issue 1607. |
| 923 | Toks.push_back(Tok); |
| 924 | ConsumeBrace(); |
| 925 | return false; |
| 926 | } else if (!MightBeTemplateArgument) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 927 | return Diag(Tok.getLocation(), diag::err_expected_either) << tok::l_brace |
| 928 | << tok::comma; |
Richard Smith | cde3fd8 | 2013-07-04 00:13:48 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
Sebastian Redl | a74948d | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 931 | } |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 932 | |
| 933 | /// \brief Consume and store tokens from the '?' to the ':' in a conditional |
| 934 | /// expression. |
| 935 | bool Parser::ConsumeAndStoreConditional(CachedTokens &Toks) { |
| 936 | // Consume '?'. |
| 937 | assert(Tok.is(tok::question)); |
| 938 | Toks.push_back(Tok); |
| 939 | ConsumeToken(); |
| 940 | |
| 941 | while (Tok.isNot(tok::colon)) { |
Nico Weber | 77c76c5 | 2014-05-10 17:43:15 +0000 | [diff] [blame] | 942 | if (!ConsumeAndStoreUntil(tok::question, tok::colon, Toks, |
| 943 | /*StopAtSemi=*/true, |
| 944 | /*ConsumeFinalToken=*/false)) |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 945 | return false; |
| 946 | |
| 947 | // If we found a nested conditional, consume it. |
| 948 | if (Tok.is(tok::question) && !ConsumeAndStoreConditional(Toks)) |
| 949 | return false; |
| 950 | } |
| 951 | |
| 952 | // Consume ':'. |
| 953 | Toks.push_back(Tok); |
| 954 | ConsumeToken(); |
| 955 | return true; |
| 956 | } |
| 957 | |
| 958 | /// \brief A tentative parsing action that can also revert token annotations. |
| 959 | class Parser::UnannotatedTentativeParsingAction : public TentativeParsingAction { |
| 960 | public: |
| 961 | explicit UnannotatedTentativeParsingAction(Parser &Self, |
| 962 | tok::TokenKind EndKind) |
| 963 | : TentativeParsingAction(Self), Self(Self), EndKind(EndKind) { |
| 964 | // Stash away the old token stream, so we can restore it once the |
| 965 | // tentative parse is complete. |
| 966 | TentativeParsingAction Inner(Self); |
| 967 | Self.ConsumeAndStoreUntil(EndKind, Toks, true, /*ConsumeFinalToken*/false); |
| 968 | Inner.Revert(); |
| 969 | } |
| 970 | |
| 971 | void RevertAnnotations() { |
| 972 | Revert(); |
| 973 | |
| 974 | // Put back the original tokens. |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 975 | Self.SkipUntil(EndKind, StopAtSemi | StopBeforeMatch); |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 976 | if (Toks.size()) { |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 977 | auto Buffer = llvm::make_unique<Token[]>(Toks.size()); |
| 978 | std::copy(Toks.begin() + 1, Toks.end(), Buffer.get()); |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 979 | Buffer[Toks.size() - 1] = Self.Tok; |
David Blaikie | 2eabcc9 | 2016-02-09 18:52:09 +0000 | [diff] [blame] | 980 | Self.PP.EnterTokenStream(std::move(Buffer), Toks.size(), true); |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 981 | |
| 982 | Self.Tok = Toks.front(); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | private: |
| 987 | Parser &Self; |
| 988 | CachedTokens Toks; |
| 989 | tok::TokenKind EndKind; |
| 990 | }; |
| 991 | |
| 992 | /// ConsumeAndStoreInitializer - Consume and store the token at the passed token |
| 993 | /// container until the end of the current initializer expression (either a |
| 994 | /// default argument or an in-class initializer for a non-static data member). |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 995 | /// |
| 996 | /// Returns \c true if we reached the end of something initializer-shaped, |
| 997 | /// \c false if we bailed out. |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 998 | bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks, |
| 999 | CachedInitKind CIK) { |
| 1000 | // We always want this function to consume at least one token if not at EOF. |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1001 | bool IsFirstToken = true; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1002 | |
| 1003 | // Number of possible unclosed <s we've seen so far. These might be templates, |
| 1004 | // and might not, but if there were none of them (or we know for sure that |
| 1005 | // we're within a template), we can avoid a tentative parse. |
| 1006 | unsigned AngleCount = 0; |
| 1007 | unsigned KnownTemplateCount = 0; |
| 1008 | |
| 1009 | while (1) { |
| 1010 | switch (Tok.getKind()) { |
| 1011 | case tok::comma: |
| 1012 | // If we might be in a template, perform a tentative parse to check. |
| 1013 | if (!AngleCount) |
| 1014 | // Not a template argument: this is the end of the initializer. |
| 1015 | return true; |
| 1016 | if (KnownTemplateCount) |
| 1017 | goto consume_token; |
| 1018 | |
| 1019 | // We hit a comma inside angle brackets. This is the hard case. The |
| 1020 | // rule we follow is: |
| 1021 | // * For a default argument, if the tokens after the comma form a |
| 1022 | // syntactically-valid parameter-declaration-clause, in which each |
| 1023 | // parameter has an initializer, then this comma ends the default |
| 1024 | // argument. |
| 1025 | // * For a default initializer, if the tokens after the comma form a |
| 1026 | // syntactically-valid init-declarator-list, then this comma ends |
| 1027 | // the default initializer. |
| 1028 | { |
| 1029 | UnannotatedTentativeParsingAction PA(*this, |
| 1030 | CIK == CIK_DefaultInitializer |
| 1031 | ? tok::semi : tok::r_paren); |
| 1032 | Sema::TentativeAnalysisScope Scope(Actions); |
| 1033 | |
Richard Smith | ee39043 | 2014-05-16 01:56:53 +0000 | [diff] [blame] | 1034 | TPResult Result = TPResult::Error; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1035 | ConsumeToken(); |
| 1036 | switch (CIK) { |
| 1037 | case CIK_DefaultInitializer: |
| 1038 | Result = TryParseInitDeclaratorList(); |
| 1039 | // If we parsed a complete, ambiguous init-declarator-list, this |
| 1040 | // is only syntactically-valid if it's followed by a semicolon. |
Richard Smith | ee39043 | 2014-05-16 01:56:53 +0000 | [diff] [blame] | 1041 | if (Result == TPResult::Ambiguous && Tok.isNot(tok::semi)) |
| 1042 | Result = TPResult::False; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1043 | break; |
| 1044 | |
| 1045 | case CIK_DefaultArgument: |
| 1046 | bool InvalidAsDeclaration = false; |
| 1047 | Result = TryParseParameterDeclarationClause( |
Nico Weber | c29c483 | 2014-12-28 23:24:02 +0000 | [diff] [blame] | 1048 | &InvalidAsDeclaration, /*VersusTemplateArgument=*/true); |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1049 | // If this is an expression or a declaration with a missing |
| 1050 | // 'typename', assume it's not a declaration. |
Richard Smith | ee39043 | 2014-05-16 01:56:53 +0000 | [diff] [blame] | 1051 | if (Result == TPResult::Ambiguous && InvalidAsDeclaration) |
| 1052 | Result = TPResult::False; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | // If what follows could be a declaration, it is a declaration. |
Richard Smith | ee39043 | 2014-05-16 01:56:53 +0000 | [diff] [blame] | 1057 | if (Result != TPResult::False && Result != TPResult::Error) { |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1058 | PA.Revert(); |
| 1059 | return true; |
| 1060 | } |
| 1061 | |
| 1062 | // In the uncommon case that we decide the following tokens are part |
| 1063 | // of a template argument, revert any annotations we've performed in |
| 1064 | // those tokens. We're not going to look them up until we've parsed |
| 1065 | // the rest of the class, and that might add more declarations. |
| 1066 | PA.RevertAnnotations(); |
| 1067 | } |
| 1068 | |
| 1069 | // Keep going. We know we're inside a template argument list now. |
| 1070 | ++KnownTemplateCount; |
| 1071 | goto consume_token; |
| 1072 | |
| 1073 | case tok::eof: |
Richard Smith | 34f3051 | 2013-11-23 04:06:09 +0000 | [diff] [blame] | 1074 | case tok::annot_module_begin: |
| 1075 | case tok::annot_module_end: |
| 1076 | case tok::annot_module_include: |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1077 | // Ran out of tokens. |
| 1078 | return false; |
| 1079 | |
| 1080 | case tok::less: |
| 1081 | // FIXME: A '<' can only start a template-id if it's preceded by an |
| 1082 | // identifier, an operator-function-id, or a literal-operator-id. |
| 1083 | ++AngleCount; |
| 1084 | goto consume_token; |
| 1085 | |
| 1086 | case tok::question: |
| 1087 | // In 'a ? b : c', 'b' can contain an unparenthesized comma. If it does, |
| 1088 | // that is *never* the end of the initializer. Skip to the ':'. |
| 1089 | if (!ConsumeAndStoreConditional(Toks)) |
| 1090 | return false; |
| 1091 | break; |
| 1092 | |
| 1093 | case tok::greatergreatergreater: |
| 1094 | if (!getLangOpts().CPlusPlus11) |
| 1095 | goto consume_token; |
| 1096 | if (AngleCount) --AngleCount; |
| 1097 | if (KnownTemplateCount) --KnownTemplateCount; |
| 1098 | // Fall through. |
| 1099 | case tok::greatergreater: |
| 1100 | if (!getLangOpts().CPlusPlus11) |
| 1101 | goto consume_token; |
| 1102 | if (AngleCount) --AngleCount; |
| 1103 | if (KnownTemplateCount) --KnownTemplateCount; |
| 1104 | // Fall through. |
| 1105 | case tok::greater: |
| 1106 | if (AngleCount) --AngleCount; |
| 1107 | if (KnownTemplateCount) --KnownTemplateCount; |
| 1108 | goto consume_token; |
| 1109 | |
| 1110 | case tok::kw_template: |
| 1111 | // 'template' identifier '<' is known to start a template argument list, |
| 1112 | // and can be used to disambiguate the parse. |
| 1113 | // FIXME: Support all forms of 'template' unqualified-id '<'. |
| 1114 | Toks.push_back(Tok); |
| 1115 | ConsumeToken(); |
| 1116 | if (Tok.is(tok::identifier)) { |
| 1117 | Toks.push_back(Tok); |
| 1118 | ConsumeToken(); |
| 1119 | if (Tok.is(tok::less)) { |
Richard Smith | 9303357 | 2014-07-27 05:38:12 +0000 | [diff] [blame] | 1120 | ++AngleCount; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1121 | ++KnownTemplateCount; |
| 1122 | Toks.push_back(Tok); |
| 1123 | ConsumeToken(); |
| 1124 | } |
| 1125 | } |
| 1126 | break; |
| 1127 | |
| 1128 | case tok::kw_operator: |
| 1129 | // If 'operator' precedes other punctuation, that punctuation loses |
| 1130 | // its special behavior. |
| 1131 | Toks.push_back(Tok); |
| 1132 | ConsumeToken(); |
| 1133 | switch (Tok.getKind()) { |
| 1134 | case tok::comma: |
| 1135 | case tok::greatergreatergreater: |
| 1136 | case tok::greatergreater: |
| 1137 | case tok::greater: |
| 1138 | case tok::less: |
| 1139 | Toks.push_back(Tok); |
| 1140 | ConsumeToken(); |
| 1141 | break; |
| 1142 | default: |
| 1143 | break; |
| 1144 | } |
| 1145 | break; |
| 1146 | |
| 1147 | case tok::l_paren: |
| 1148 | // Recursively consume properly-nested parens. |
| 1149 | Toks.push_back(Tok); |
| 1150 | ConsumeParen(); |
| 1151 | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
| 1152 | break; |
| 1153 | case tok::l_square: |
| 1154 | // Recursively consume properly-nested square brackets. |
| 1155 | Toks.push_back(Tok); |
| 1156 | ConsumeBracket(); |
| 1157 | ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); |
| 1158 | break; |
| 1159 | case tok::l_brace: |
| 1160 | // Recursively consume properly-nested braces. |
| 1161 | Toks.push_back(Tok); |
| 1162 | ConsumeBrace(); |
| 1163 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
| 1164 | break; |
| 1165 | |
| 1166 | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
| 1167 | // Since the user wasn't looking for this token (if they were, it would |
| 1168 | // already be handled), this isn't balanced. If there is a LHS token at a |
| 1169 | // higher level, we will assume that this matches the unbalanced token |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1170 | // and return it. Otherwise, this is a spurious RHS token, which we |
| 1171 | // consume and pass on to downstream code to diagnose. |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1172 | case tok::r_paren: |
| 1173 | if (CIK == CIK_DefaultArgument) |
| 1174 | return true; // End of the default argument. |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1175 | if (ParenCount && !IsFirstToken) |
| 1176 | return false; |
| 1177 | Toks.push_back(Tok); |
| 1178 | ConsumeParen(); |
| 1179 | continue; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1180 | case tok::r_square: |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1181 | if (BracketCount && !IsFirstToken) |
| 1182 | return false; |
| 1183 | Toks.push_back(Tok); |
| 1184 | ConsumeBracket(); |
| 1185 | continue; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1186 | case tok::r_brace: |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1187 | if (BraceCount && !IsFirstToken) |
| 1188 | return false; |
| 1189 | Toks.push_back(Tok); |
| 1190 | ConsumeBrace(); |
| 1191 | continue; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1192 | |
| 1193 | case tok::code_completion: |
| 1194 | Toks.push_back(Tok); |
| 1195 | ConsumeCodeCompletionToken(); |
| 1196 | break; |
| 1197 | |
| 1198 | case tok::string_literal: |
| 1199 | case tok::wide_string_literal: |
| 1200 | case tok::utf8_string_literal: |
| 1201 | case tok::utf16_string_literal: |
| 1202 | case tok::utf32_string_literal: |
| 1203 | Toks.push_back(Tok); |
| 1204 | ConsumeStringToken(); |
| 1205 | break; |
| 1206 | case tok::semi: |
| 1207 | if (CIK == CIK_DefaultInitializer) |
| 1208 | return true; // End of the default initializer. |
| 1209 | // FALL THROUGH. |
| 1210 | default: |
| 1211 | consume_token: |
| 1212 | Toks.push_back(Tok); |
| 1213 | ConsumeToken(); |
| 1214 | break; |
| 1215 | } |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 1216 | IsFirstToken = false; |
Richard Smith | 1fff95c | 2013-09-12 23:28:08 +0000 | [diff] [blame] | 1217 | } |
| 1218 | } |