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