Argyrios Kyrtzidis | 4cc18a4 | 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 | |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 15 | #include "clang/Parse/Parser.h" |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 16 | #include "clang/Sema/DeclSpec.h" |
| 17 | #include "clang/Sema/Scope.h" |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 21 | /// ParseCXXInlineMethodDef - We parsed and verified that the specified |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 22 | /// Declarator is a well formed C++ inline method definition. Now lex its body |
| 23 | /// and store its tokens for parsing after the C++ class is complete. |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 24 | Decl *Parser::ParseCXXInlineMethodDef(AccessSpecifier AS, |
| 25 | AttributeList *AccessAttrs, |
| 26 | ParsingDeclarator &D, |
Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 27 | const ParsedTemplateInfo &TemplateInfo, |
| 28 | const VirtSpecifiers& VS, |
| 29 | FunctionDefinitionKind DefinitionKind, |
| 30 | ExprResult& Init) { |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 31 | assert(D.isFunctionDeclarator() && "This isn't a function declarator!"); |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 32 | assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try) || |
| 33 | Tok.is(tok::equal)) && |
| 34 | "Current token not a '{', ':', '=', or 'try'!"); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 35 | |
John McCall | f312b1e | 2010-08-26 23:41:50 +0000 | [diff] [blame] | 36 | MultiTemplateParamsArg TemplateParams(Actions, |
Sean Hunt | 4cd8494 | 2010-04-14 23:07:37 +0000 | [diff] [blame] | 37 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->data() : 0, |
| 38 | TemplateInfo.TemplateParams ? TemplateInfo.TemplateParams->size() : 0); |
| 39 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 40 | Decl *FnD; |
Douglas Gregor | 45fa560 | 2011-11-07 20:56:01 +0000 | [diff] [blame] | 41 | D.setFunctionDefinitionKind(DefinitionKind); |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 42 | if (D.getDeclSpec().isFriendSpecified()) |
Kaelyn Uhrain | 2c712f5 | 2011-10-11 00:28:45 +0000 | [diff] [blame] | 43 | FnD = Actions.ActOnFriendFunctionDecl(getCurScope(), D, |
Sean Hunt | 4cd8494 | 2010-04-14 23:07:37 +0000 | [diff] [blame] | 44 | move(TemplateParams)); |
Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 45 | else { |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 46 | FnD = Actions.ActOnCXXMemberDeclarator(getCurScope(), AS, D, |
Anders Carlsson | 69a8735 | 2011-01-20 03:57:25 +0000 | [diff] [blame] | 47 | move(TemplateParams), 0, |
Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 48 | VS, /*HasDeferredInit=*/false); |
Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 49 | if (FnD) { |
Erik Verbruggen | 5f1c822 | 2011-10-13 09:41:32 +0000 | [diff] [blame] | 50 | Actions.ProcessDeclAttributeList(getCurScope(), FnD, AccessAttrs, |
| 51 | false, true); |
Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 52 | bool TypeSpecContainsAuto |
| 53 | = D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_auto; |
Douglas Gregor | a2b4e5d | 2011-10-17 17:09:53 +0000 | [diff] [blame] | 54 | if (Init.isUsable()) |
Douglas Gregor | 147545d | 2011-10-10 14:49:18 +0000 | [diff] [blame] | 55 | Actions.AddInitializerToDecl(FnD, Init.get(), false, |
| 56 | TypeSpecContainsAuto); |
| 57 | else |
| 58 | Actions.ActOnUninitializedDecl(FnD, TypeSpecContainsAuto); |
| 59 | } |
Nico Weber | 4867347 | 2011-01-28 06:07:34 +0000 | [diff] [blame] | 60 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 61 | |
Eli Friedman | d33133c | 2009-07-22 21:45:50 +0000 | [diff] [blame] | 62 | HandleMemberFunctionDefaultArgs(D, FnD); |
| 63 | |
John McCall | eee1d54 | 2011-02-14 07:13:47 +0000 | [diff] [blame] | 64 | D.complete(FnD); |
| 65 | |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 66 | if (Tok.is(tok::equal)) { |
| 67 | ConsumeToken(); |
| 68 | |
Richard Smith | c430ef4 | 2011-11-10 09:08:44 +0000 | [diff] [blame] | 69 | if (!FnD) { |
| 70 | SkipUntil(tok::semi); |
| 71 | return 0; |
| 72 | } |
| 73 | |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 74 | bool Delete = false; |
| 75 | SourceLocation KWLoc; |
| 76 | if (Tok.is(tok::kw_delete)) { |
Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 77 | Diag(Tok, getLang().CPlusPlus0x ? |
| 78 | diag::warn_cxx98_compat_deleted_function : |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 79 | diag::ext_deleted_function); |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 80 | |
| 81 | KWLoc = ConsumeToken(); |
| 82 | Actions.SetDeclDeleted(FnD, KWLoc); |
| 83 | Delete = true; |
| 84 | } else if (Tok.is(tok::kw_default)) { |
Richard Smith | 7fe6208 | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 85 | Diag(Tok, getLang().CPlusPlus0x ? |
| 86 | diag::warn_cxx98_compat_defaulted_function : |
Richard Smith | d7c56e1 | 2011-12-29 21:57:33 +0000 | [diff] [blame] | 87 | diag::ext_defaulted_function); |
Sean Hunt | e4246a6 | 2011-05-12 06:15:49 +0000 | [diff] [blame] | 88 | |
| 89 | KWLoc = ConsumeToken(); |
| 90 | Actions.SetDeclDefaulted(FnD, KWLoc); |
| 91 | } else { |
| 92 | llvm_unreachable("function definition after = not 'delete' or 'default'"); |
| 93 | } |
| 94 | |
| 95 | if (Tok.is(tok::comma)) { |
| 96 | Diag(KWLoc, diag::err_default_delete_in_multiple_declaration) |
| 97 | << Delete; |
| 98 | SkipUntil(tok::semi); |
| 99 | } else { |
| 100 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 101 | Delete ? "delete" : "default", tok::semi); |
| 102 | } |
| 103 | |
| 104 | return FnD; |
| 105 | } |
| 106 | |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 107 | // In delayed template parsing mode, if we are within a class template |
| 108 | // or if we are about to parse function member template then consume |
| 109 | // the tokens and store them for parsing at the end of the translation unit. |
| 110 | if (getLang().DelayedTemplateParsing && |
| 111 | ((Actions.CurContext->isDependentContext() || |
| 112 | TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) && |
Francois Pichet | 9d38dbc | 2011-11-18 23:47:17 +0000 | [diff] [blame] | 113 | !Actions.IsInsideALocalClassWithinATemplateFunction())) { |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 114 | |
| 115 | if (FnD) { |
Francois Pichet | e1fca50 | 2011-12-08 09:11:52 +0000 | [diff] [blame] | 116 | LateParsedTemplatedFunction *LPT = new LateParsedTemplatedFunction(FnD); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 117 | |
| 118 | FunctionDecl *FD = 0; |
| 119 | if (FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(FnD)) |
| 120 | FD = FunTmpl->getTemplatedDecl(); |
| 121 | else |
| 122 | FD = cast<FunctionDecl>(FnD); |
Chandler Carruth | 81542fd | 2011-04-25 07:09:43 +0000 | [diff] [blame] | 123 | Actions.CheckForFunctionRedefinition(FD); |
Francois Pichet | 8387e2a | 2011-04-22 22:18:13 +0000 | [diff] [blame] | 124 | |
| 125 | LateParsedTemplateMap[FD] = LPT; |
| 126 | Actions.MarkAsLateParsedTemplate(FD); |
| 127 | LexTemplateFunctionForLateParsing(LPT->Toks); |
| 128 | } else { |
| 129 | CachedTokens Toks; |
| 130 | LexTemplateFunctionForLateParsing(Toks); |
| 131 | } |
| 132 | |
| 133 | return FnD; |
| 134 | } |
| 135 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 136 | // Consume the tokens and store them for later parsing. |
| 137 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 138 | LexedMethod* LM = new LexedMethod(this, FnD); |
| 139 | getCurrentClass().LateParsedDeclarations.push_back(LM); |
| 140 | LM->TemplateScope = getCurScope()->isTemplateParamScope(); |
| 141 | CachedTokens &Toks = LM->Toks; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 142 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 143 | tok::TokenKind kind = Tok.getKind(); |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 144 | // Consume everything up to (and including) the left brace of the |
| 145 | // function body. |
| 146 | if (ConsumeAndStoreFunctionPrologue(Toks)) { |
| 147 | // We didn't find the left-brace we expected after the |
| 148 | // constructor initializer. |
| 149 | if (Tok.is(tok::semi)) { |
| 150 | // We found a semicolon; complain, consume the semicolon, and |
| 151 | // don't try to parse this method later. |
| 152 | Diag(Tok.getLocation(), diag::err_expected_lbrace); |
| 153 | ConsumeAnyToken(); |
| 154 | delete getCurrentClass().LateParsedDeclarations.back(); |
| 155 | getCurrentClass().LateParsedDeclarations.pop_back(); |
| 156 | return FnD; |
Douglas Gregor | 3f08d18 | 2008-11-10 16:59:40 +0000 | [diff] [blame] | 157 | } |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 158 | } else { |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 159 | // Consume everything up to (and including) the matching right brace. |
| 160 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Douglas Gregor | 7ad8390 | 2008-11-05 04:29:56 +0000 | [diff] [blame] | 161 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 162 | |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 163 | // If we're in a function-try-block, we need to store all the catch blocks. |
| 164 | if (kind == tok::kw_try) { |
| 165 | while (Tok.is(tok::kw_catch)) { |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 166 | ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false); |
| 167 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Sebastian Redl | d3a413d | 2009-04-26 20:35:05 +0000 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Douglas Gregor | 87f1064 | 2011-04-14 23:19:27 +0000 | [diff] [blame] | 171 | |
| 172 | if (!FnD) { |
| 173 | // If semantic analysis could not build a function declaration, |
| 174 | // just throw away the late-parsed declaration. |
| 175 | delete getCurrentClass().LateParsedDeclarations.back(); |
| 176 | getCurrentClass().LateParsedDeclarations.pop_back(); |
| 177 | } |
| 178 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 179 | return FnD; |
| 180 | } |
| 181 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 182 | /// ParseCXXNonStaticMemberInitializer - We parsed and verified that the |
| 183 | /// specified Declarator is a well formed C++ non-static data member |
| 184 | /// declaration. Now lex its initializer and store its tokens for parsing |
| 185 | /// after the class is complete. |
| 186 | void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) { |
| 187 | assert((Tok.is(tok::l_brace) || Tok.is(tok::equal)) && |
| 188 | "Current token not a '{' or '='!"); |
| 189 | |
| 190 | LateParsedMemberInitializer *MI = |
| 191 | new LateParsedMemberInitializer(this, VarD); |
| 192 | getCurrentClass().LateParsedDeclarations.push_back(MI); |
| 193 | CachedTokens &Toks = MI->Toks; |
| 194 | |
| 195 | tok::TokenKind kind = Tok.getKind(); |
| 196 | if (kind == tok::equal) { |
| 197 | Toks.push_back(Tok); |
| 198 | ConsumeAnyToken(); |
| 199 | } |
| 200 | |
| 201 | if (kind == tok::l_brace) { |
| 202 | // Begin by storing the '{' token. |
| 203 | Toks.push_back(Tok); |
| 204 | ConsumeBrace(); |
| 205 | |
| 206 | // Consume everything up to (and including) the matching right brace. |
| 207 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/true); |
| 208 | } else { |
| 209 | // Consume everything up to (but excluding) the comma or semicolon. |
| 210 | ConsumeAndStoreUntil(tok::comma, Toks, /*StopAtSemi=*/true, |
| 211 | /*ConsumeFinalToken=*/false); |
| 212 | } |
| 213 | |
| 214 | // Store an artificial EOF token to ensure that we don't run off the end of |
| 215 | // the initializer when we come to parse it. |
| 216 | Token Eof; |
| 217 | Eof.startToken(); |
| 218 | Eof.setKind(tok::eof); |
| 219 | Eof.setLocation(Tok.getLocation()); |
| 220 | Toks.push_back(Eof); |
| 221 | } |
| 222 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 223 | Parser::LateParsedDeclaration::~LateParsedDeclaration() {} |
| 224 | void Parser::LateParsedDeclaration::ParseLexedMethodDeclarations() {} |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 225 | void Parser::LateParsedDeclaration::ParseLexedMemberInitializers() {} |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 226 | void Parser::LateParsedDeclaration::ParseLexedMethodDefs() {} |
| 227 | |
| 228 | Parser::LateParsedClass::LateParsedClass(Parser *P, ParsingClass *C) |
| 229 | : Self(P), Class(C) {} |
| 230 | |
| 231 | Parser::LateParsedClass::~LateParsedClass() { |
| 232 | Self->DeallocateParsedClasses(Class); |
| 233 | } |
| 234 | |
| 235 | void Parser::LateParsedClass::ParseLexedMethodDeclarations() { |
| 236 | Self->ParseLexedMethodDeclarations(*Class); |
| 237 | } |
| 238 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 239 | void Parser::LateParsedClass::ParseLexedMemberInitializers() { |
| 240 | Self->ParseLexedMemberInitializers(*Class); |
| 241 | } |
| 242 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 243 | void Parser::LateParsedClass::ParseLexedMethodDefs() { |
| 244 | Self->ParseLexedMethodDefs(*Class); |
| 245 | } |
| 246 | |
| 247 | void Parser::LateParsedMethodDeclaration::ParseLexedMethodDeclarations() { |
| 248 | Self->ParseLexedMethodDeclaration(*this); |
| 249 | } |
| 250 | |
| 251 | void Parser::LexedMethod::ParseLexedMethodDefs() { |
| 252 | Self->ParseLexedMethodDef(*this); |
| 253 | } |
| 254 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 255 | void Parser::LateParsedMemberInitializer::ParseLexedMemberInitializers() { |
| 256 | Self->ParseLexedMemberInitializer(*this); |
| 257 | } |
| 258 | |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 259 | /// ParseLexedMethodDeclarations - We finished parsing the member |
| 260 | /// specification of a top (non-nested) C++ class. Now go over the |
| 261 | /// stack of method declarations with some parts for which parsing was |
| 262 | /// delayed (such as default arguments) and parse them. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 263 | void Parser::ParseLexedMethodDeclarations(ParsingClass &Class) { |
| 264 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 265 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 266 | if (HasTemplateScope) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 267 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 268 | |
John McCall | 7a1dc56 | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 269 | // The current scope is still active if we're the top-level class. |
| 270 | // Otherwise we'll need to push and enter a new scope. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 271 | bool HasClassScope = !Class.TopLevelClass; |
Sean Hunt | 4cd8494 | 2010-04-14 23:07:37 +0000 | [diff] [blame] | 272 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
| 273 | HasClassScope); |
John McCall | 7a1dc56 | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 274 | if (HasClassScope) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 275 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 276 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 277 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 278 | Class.LateParsedDeclarations[i]->ParseLexedMethodDeclarations(); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 279 | } |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 280 | |
John McCall | 7a1dc56 | 2009-12-19 10:49:29 +0000 | [diff] [blame] | 281 | if (HasClassScope) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 282 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), Class.TagOrTemplate); |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 285 | void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) { |
| 286 | // If this is a member template, introduce the template parameter scope. |
| 287 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
| 288 | if (LM.TemplateScope) |
| 289 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.Method); |
| 290 | |
| 291 | // Start the delayed C++ method declaration |
| 292 | Actions.ActOnStartDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
| 293 | |
| 294 | // Introduce the parameters into scope and parse their default |
| 295 | // arguments. |
| 296 | ParseScope PrototypeScope(this, |
| 297 | Scope::FunctionPrototypeScope|Scope::DeclScope); |
| 298 | for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) { |
| 299 | // Introduce the parameter into scope. |
| 300 | Actions.ActOnDelayedCXXMethodParameter(getCurScope(), LM.DefaultArgs[I].Param); |
| 301 | |
| 302 | if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) { |
| 303 | // Save the current token position. |
| 304 | SourceLocation origLoc = Tok.getLocation(); |
| 305 | |
| 306 | // Parse the default argument from its saved token stream. |
| 307 | Toks->push_back(Tok); // So that the current token doesn't get lost |
| 308 | PP.EnterTokenStream(&Toks->front(), Toks->size(), true, false); |
| 309 | |
| 310 | // Consume the previously-pushed token. |
| 311 | ConsumeAnyToken(); |
| 312 | |
| 313 | // Consume the '='. |
| 314 | assert(Tok.is(tok::equal) && "Default argument not starting with '='"); |
| 315 | SourceLocation EqualLoc = ConsumeToken(); |
| 316 | |
| 317 | // The argument isn't actually potentially evaluated unless it is |
| 318 | // used. |
| 319 | EnterExpressionEvaluationContext Eval(Actions, |
| 320 | Sema::PotentiallyEvaluatedIfUsed); |
| 321 | |
| 322 | ExprResult DefArgResult(ParseAssignmentExpression()); |
| 323 | if (DefArgResult.isInvalid()) |
| 324 | Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param); |
| 325 | else { |
| 326 | if (Tok.is(tok::cxx_defaultarg_end)) |
| 327 | ConsumeToken(); |
| 328 | else |
| 329 | Diag(Tok.getLocation(), diag::err_default_arg_unparsed); |
| 330 | Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc, |
| 331 | DefArgResult.take()); |
| 332 | } |
| 333 | |
| 334 | assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, |
| 335 | Tok.getLocation()) && |
| 336 | "ParseAssignmentExpression went over the default arg tokens!"); |
| 337 | // There could be leftover tokens (e.g. because of an error). |
| 338 | // Skip through until we reach the original token position. |
| 339 | while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) |
| 340 | ConsumeAnyToken(); |
| 341 | |
| 342 | delete Toks; |
| 343 | LM.DefaultArgs[I].Toks = 0; |
| 344 | } |
| 345 | } |
| 346 | PrototypeScope.Exit(); |
| 347 | |
| 348 | // Finish the delayed C++ method declaration. |
| 349 | Actions.ActOnFinishDelayedCXXMethodDeclaration(getCurScope(), LM.Method); |
| 350 | } |
| 351 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 352 | /// ParseLexedMethodDefs - We finished parsing the member specification of a top |
| 353 | /// (non-nested) C++ class. Now go over the stack of lexed methods that were |
| 354 | /// collected during its parsing and parse them all. |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 355 | void Parser::ParseLexedMethodDefs(ParsingClass &Class) { |
| 356 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 357 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, HasTemplateScope); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 358 | if (HasTemplateScope) |
Douglas Gregor | 23c94db | 2010-07-02 17:43:08 +0000 | [diff] [blame] | 359 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
Douglas Gregor | 6569d68 | 2009-05-27 23:11:45 +0000 | [diff] [blame] | 360 | |
| 361 | bool HasClassScope = !Class.TopLevelClass; |
| 362 | ParseScope ClassScope(this, Scope::ClassScope|Scope::DeclScope, |
| 363 | HasClassScope); |
| 364 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 365 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 366 | Class.LateParsedDeclarations[i]->ParseLexedMethodDefs(); |
| 367 | } |
| 368 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 369 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 370 | void Parser::ParseLexedMethodDef(LexedMethod &LM) { |
| 371 | // If this is a member template, introduce the template parameter scope. |
| 372 | ParseScope TemplateScope(this, Scope::TemplateParamScope, LM.TemplateScope); |
| 373 | if (LM.TemplateScope) |
| 374 | Actions.ActOnReenterTemplateScope(getCurScope(), LM.D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 376 | // Save the current token position. |
| 377 | SourceLocation origLoc = Tok.getLocation(); |
Argyrios Kyrtzidis | c50a5e0 | 2010-03-31 00:38:09 +0000 | [diff] [blame] | 378 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 379 | assert(!LM.Toks.empty() && "Empty body!"); |
| 380 | // Append the current token at the end of the new token stream so that it |
| 381 | // doesn't get lost. |
| 382 | LM.Toks.push_back(Tok); |
| 383 | PP.EnterTokenStream(LM.Toks.data(), LM.Toks.size(), true, false); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 384 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 385 | // Consume the previously pushed token. |
| 386 | ConsumeAnyToken(); |
| 387 | assert((Tok.is(tok::l_brace) || Tok.is(tok::colon) || Tok.is(tok::kw_try)) |
| 388 | && "Inline method not starting with '{', ':' or 'try'"); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 389 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 390 | // Parse the method body. Function body parsing code is similar enough |
| 391 | // to be re-used for method bodies as well. |
| 392 | ParseScope FnScope(this, Scope::FnScope|Scope::DeclScope); |
| 393 | Actions.ActOnStartOfFunctionDef(getCurScope(), LM.D); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 394 | |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 395 | if (Tok.is(tok::kw_try)) { |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 396 | ParseFunctionTryBlock(LM.D, FnScope); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 397 | assert(!PP.getSourceManager().isBeforeInTranslationUnit(origLoc, |
| 398 | Tok.getLocation()) && |
| 399 | "ParseFunctionTryBlock went over the cached tokens!"); |
| 400 | // There could be leftover tokens (e.g. because of an error). |
| 401 | // Skip through until we reach the original token position. |
| 402 | while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) |
| 403 | ConsumeAnyToken(); |
| 404 | return; |
| 405 | } |
| 406 | if (Tok.is(tok::colon)) { |
| 407 | ParseConstructorInitializer(LM.D); |
| 408 | |
| 409 | // Error recovery. |
| 410 | if (!Tok.is(tok::l_brace)) { |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 411 | FnScope.Exit(); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 412 | Actions.ActOnFinishFunctionBody(LM.D, 0); |
Matt Beaumont-Gay | 1090452 | 2011-09-23 22:39:23 +0000 | [diff] [blame] | 413 | while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) |
| 414 | ConsumeAnyToken(); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 415 | return; |
| 416 | } |
| 417 | } else |
| 418 | Actions.ActOnDefaultCtorInitializers(LM.D); |
| 419 | |
Douglas Gregor | c9977d0 | 2011-03-16 17:05:57 +0000 | [diff] [blame] | 420 | ParseFunctionStatementBody(LM.D, FnScope); |
Douglas Gregor | d54eb44 | 2010-10-12 16:25:54 +0000 | [diff] [blame] | 421 | |
| 422 | if (Tok.getLocation() != origLoc) { |
| 423 | // Due to parsing error, we either went over the cached tokens or |
| 424 | // there are still cached tokens left. If it's the latter case skip the |
| 425 | // leftover tokens. |
| 426 | // Since this is an uncommon situation that should be avoided, use the |
| 427 | // expensive isBeforeInTranslationUnit call. |
| 428 | if (PP.getSourceManager().isBeforeInTranslationUnit(Tok.getLocation(), |
| 429 | origLoc)) |
Argyrios Kyrtzidis | 8f9359f | 2010-06-19 19:58:34 +0000 | [diff] [blame] | 430 | while (Tok.getLocation() != origLoc && Tok.isNot(tok::eof)) |
Argyrios Kyrtzidis | 7558cd0 | 2010-06-17 10:52:22 +0000 | [diff] [blame] | 431 | ConsumeAnyToken(); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 435 | /// ParseLexedMemberInitializers - We finished parsing the member specification |
| 436 | /// of a top (non-nested) C++ class. Now go over the stack of lexed data member |
| 437 | /// initializers that were collected during its parsing and parse them all. |
| 438 | void Parser::ParseLexedMemberInitializers(ParsingClass &Class) { |
| 439 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
| 440 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, |
| 441 | HasTemplateScope); |
| 442 | if (HasTemplateScope) |
| 443 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
| 444 | |
| 445 | // Set or update the scope flags to include Scope::ThisScope. |
| 446 | bool AlreadyHasClassScope = Class.TopLevelClass; |
| 447 | unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope|Scope::ThisScope; |
| 448 | ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); |
| 449 | ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); |
| 450 | |
| 451 | if (!AlreadyHasClassScope) |
| 452 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), |
| 453 | Class.TagOrTemplate); |
| 454 | |
| 455 | for (size_t i = 0; i < Class.LateParsedDeclarations.size(); ++i) { |
| 456 | Class.LateParsedDeclarations[i]->ParseLexedMemberInitializers(); |
| 457 | } |
| 458 | |
| 459 | if (!AlreadyHasClassScope) |
| 460 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), |
| 461 | Class.TagOrTemplate); |
| 462 | |
| 463 | Actions.ActOnFinishDelayedMemberInitializers(Class.TagOrTemplate); |
| 464 | } |
| 465 | |
| 466 | void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) { |
Richard Smith | 1991b71 | 2011-09-29 19:42:27 +0000 | [diff] [blame] | 467 | if (!MI.Field || MI.Field->isInvalidDecl()) |
Richard Smith | 7a614d8 | 2011-06-11 17:19:42 +0000 | [diff] [blame] | 468 | return; |
| 469 | |
| 470 | // Append the current token at the end of the new token stream so that it |
| 471 | // doesn't get lost. |
| 472 | MI.Toks.push_back(Tok); |
| 473 | PP.EnterTokenStream(MI.Toks.data(), MI.Toks.size(), true, false); |
| 474 | |
| 475 | // Consume the previously pushed token. |
| 476 | ConsumeAnyToken(); |
| 477 | |
| 478 | SourceLocation EqualLoc; |
| 479 | ExprResult Init = ParseCXXMemberInitializer(/*IsFunction=*/false, EqualLoc); |
| 480 | |
| 481 | Actions.ActOnCXXInClassMemberInitializer(MI.Field, EqualLoc, Init.release()); |
| 482 | |
| 483 | // The next token should be our artificial terminating EOF token. |
| 484 | if (Tok.isNot(tok::eof)) { |
| 485 | SourceLocation EndLoc = PP.getLocForEndOfToken(PrevTokLocation); |
| 486 | if (!EndLoc.isValid()) |
| 487 | EndLoc = Tok.getLocation(); |
| 488 | // No fixit; we can't recover as if there were a semicolon here. |
| 489 | Diag(EndLoc, diag::err_expected_semi_decl_list); |
| 490 | |
| 491 | // Consume tokens until we hit the artificial EOF. |
| 492 | while (Tok.isNot(tok::eof)) |
| 493 | ConsumeAnyToken(); |
| 494 | } |
| 495 | ConsumeAnyToken(); |
| 496 | } |
| 497 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 498 | /// ConsumeAndStoreUntil - Consume and store the token at the passed token |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 499 | /// container until the token 'T' is reached (which gets |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 500 | /// consumed/stored too, if ConsumeFinalToken). |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 501 | /// If StopAtSemi is true, then we will stop early at a ';' character. |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 502 | /// Returns true if token 'T1' or 'T2' was found. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 503 | /// NOTE: This is a specialized version of Parser::SkipUntil. |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 504 | bool Parser::ConsumeAndStoreUntil(tok::TokenKind T1, tok::TokenKind T2, |
| 505 | CachedTokens &Toks, |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 506 | bool StopAtSemi, bool ConsumeFinalToken) { |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 507 | // We always want this function to consume at least one token if the first |
| 508 | // token isn't T and if not at EOF. |
| 509 | bool isFirstTokenConsumed = true; |
| 510 | while (1) { |
| 511 | // If we found one of the tokens, stop and return true. |
Douglas Gregor | 72b505b | 2008-12-16 21:30:33 +0000 | [diff] [blame] | 512 | if (Tok.is(T1) || Tok.is(T2)) { |
| 513 | if (ConsumeFinalToken) { |
| 514 | Toks.push_back(Tok); |
| 515 | ConsumeAnyToken(); |
| 516 | } |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 517 | return true; |
| 518 | } |
| 519 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 520 | switch (Tok.getKind()) { |
| 521 | case tok::eof: |
| 522 | // Ran out of tokens. |
| 523 | return false; |
| 524 | |
| 525 | case tok::l_paren: |
| 526 | // Recursively consume properly-nested parens. |
| 527 | Toks.push_back(Tok); |
| 528 | ConsumeParen(); |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 529 | ConsumeAndStoreUntil(tok::r_paren, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 530 | break; |
| 531 | case tok::l_square: |
| 532 | // Recursively consume properly-nested square brackets. |
| 533 | Toks.push_back(Tok); |
| 534 | ConsumeBracket(); |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 535 | ConsumeAndStoreUntil(tok::r_square, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 536 | break; |
| 537 | case tok::l_brace: |
| 538 | // Recursively consume properly-nested braces. |
| 539 | Toks.push_back(Tok); |
| 540 | ConsumeBrace(); |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 541 | ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false); |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 542 | break; |
| 543 | |
| 544 | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
| 545 | // Since the user wasn't looking for this token (if they were, it would |
| 546 | // already be handled), this isn't balanced. If there is a LHS token at a |
| 547 | // higher level, we will assume that this matches the unbalanced token |
| 548 | // and return it. Otherwise, this is a spurious RHS token, which we skip. |
| 549 | case tok::r_paren: |
| 550 | if (ParenCount && !isFirstTokenConsumed) |
| 551 | return false; // Matches something. |
| 552 | Toks.push_back(Tok); |
| 553 | ConsumeParen(); |
| 554 | break; |
| 555 | case tok::r_square: |
| 556 | if (BracketCount && !isFirstTokenConsumed) |
| 557 | return false; // Matches something. |
| 558 | Toks.push_back(Tok); |
| 559 | ConsumeBracket(); |
| 560 | break; |
| 561 | case tok::r_brace: |
| 562 | if (BraceCount && !isFirstTokenConsumed) |
| 563 | return false; // Matches something. |
| 564 | Toks.push_back(Tok); |
| 565 | ConsumeBrace(); |
| 566 | break; |
| 567 | |
Argyrios Kyrtzidis | 7d10087 | 2011-09-04 03:32:15 +0000 | [diff] [blame] | 568 | case tok::code_completion: |
| 569 | Toks.push_back(Tok); |
| 570 | ConsumeCodeCompletionToken(); |
| 571 | break; |
| 572 | |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 573 | case tok::string_literal: |
| 574 | case tok::wide_string_literal: |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 575 | case tok::utf8_string_literal: |
| 576 | case tok::utf16_string_literal: |
| 577 | case tok::utf32_string_literal: |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 578 | Toks.push_back(Tok); |
| 579 | ConsumeStringToken(); |
| 580 | break; |
Argyrios Kyrtzidis | 14b9162 | 2010-04-23 21:20:12 +0000 | [diff] [blame] | 581 | case tok::semi: |
| 582 | if (StopAtSemi) |
| 583 | return false; |
| 584 | // FALL THROUGH. |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 585 | default: |
| 586 | // consume this token. |
| 587 | Toks.push_back(Tok); |
| 588 | ConsumeToken(); |
| 589 | break; |
| 590 | } |
| 591 | isFirstTokenConsumed = false; |
| 592 | } |
| 593 | } |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 594 | |
| 595 | /// \brief Consume tokens and store them in the passed token container until |
| 596 | /// we've passed the try keyword and constructor initializers and have consumed |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 597 | /// the opening brace of the function body. The opening brace will be consumed |
| 598 | /// if and only if there was no error. |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 599 | /// |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 600 | /// \return True on error. |
| 601 | bool Parser::ConsumeAndStoreFunctionPrologue(CachedTokens &Toks) { |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 602 | if (Tok.is(tok::kw_try)) { |
| 603 | Toks.push_back(Tok); |
| 604 | ConsumeToken(); |
| 605 | } |
| 606 | if (Tok.is(tok::colon)) { |
| 607 | // Initializers can contain braces too. |
| 608 | Toks.push_back(Tok); |
| 609 | ConsumeToken(); |
| 610 | |
| 611 | while (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) { |
| 612 | if (Tok.is(tok::eof) || Tok.is(tok::semi)) |
| 613 | return true; |
| 614 | |
| 615 | // Grab the identifier. |
| 616 | if (!ConsumeAndStoreUntil(tok::l_paren, tok::l_brace, Toks, |
| 617 | /*StopAtSemi=*/true, |
| 618 | /*ConsumeFinalToken=*/false)) |
| 619 | return true; |
| 620 | |
| 621 | tok::TokenKind kind = Tok.getKind(); |
| 622 | Toks.push_back(Tok); |
| 623 | if (kind == tok::l_paren) |
| 624 | ConsumeParen(); |
| 625 | else { |
| 626 | assert(kind == tok::l_brace && "Must be left paren or brace here."); |
| 627 | ConsumeBrace(); |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 628 | // In C++03, this has to be the start of the function body, which |
| 629 | // means the initializer is malformed. |
| 630 | if (!getLang().CPlusPlus0x) |
| 631 | return false; |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | // Grab the initializer |
| 635 | if (!ConsumeAndStoreUntil(kind == tok::l_paren ? tok::r_paren : |
| 636 | tok::r_brace, |
| 637 | Toks, /*StopAtSemi=*/true)) |
| 638 | return true; |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 639 | |
| 640 | // Grab the separating comma, if any. |
| 641 | if (Tok.is(tok::comma)) { |
| 642 | Toks.push_back(Tok); |
| 643 | ConsumeToken(); |
| 644 | } |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
Sebastian Redl | a891a32 | 2011-09-30 08:32:17 +0000 | [diff] [blame] | 648 | // Grab any remaining garbage to be diagnosed later. We stop when we reach a |
| 649 | // brace: an opening one is the function body, while a closing one probably |
| 650 | // means we've reached the end of the class. |
| 651 | if (!ConsumeAndStoreUntil(tok::l_brace, tok::r_brace, Toks, |
| 652 | /*StopAtSemi=*/true, /*ConsumeFinalToken=*/false)) |
| 653 | return true; |
| 654 | if(Tok.isNot(tok::l_brace)) |
| 655 | return true; |
| 656 | |
| 657 | Toks.push_back(Tok); |
| 658 | ConsumeBrace(); |
| 659 | return false; |
Sebastian Redl | 6df6548 | 2011-09-24 17:48:25 +0000 | [diff] [blame] | 660 | } |