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