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