Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: runtime/vm/parser.cc

Issue 1436243005: Collect closure functions in isolate (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 6563 matching lines...) Expand 10 before | Expand all | Expand 10 after
6574 Function& body = Function::Handle(Z); 6574 Function& body = Function::Handle(Z);
6575 String& body_closure_name = String::Handle(Z); 6575 String& body_closure_name = String::Handle(Z);
6576 bool is_new_closure = false; 6576 bool is_new_closure = false;
6577 6577
6578 AddContinuationVariables(); 6578 AddContinuationVariables();
6579 6579
6580 // Check whether a function for the body of this generator 6580 // Check whether a function for the body of this generator
6581 // function has already been created by a previous 6581 // function has already been created by a previous
6582 // compilation. 6582 // compilation.
6583 const Function& found_func = Function::Handle( 6583 const Function& found_func = Function::Handle(
6584 Z, current_class().LookupClosureFunction(func_pos)); 6584 Z, I->LookupClosureFunction(innermost_function(), func_pos));
6585 if (!found_func.IsNull() && 6585 if (!found_func.IsNull()) {
6586 (found_func.token_pos() == func_pos) &&
6587 (found_func.script() == innermost_function().script()) &&
6588 (found_func.parent_function() == innermost_function().raw())) {
6589 ASSERT(found_func.IsSyncGenClosure()); 6586 ASSERT(found_func.IsSyncGenClosure());
6590 body = found_func.raw(); 6587 body = found_func.raw();
6591 body_closure_name = body.name(); 6588 body_closure_name = body.name();
6592 } else { 6589 } else {
6593 // Create the closure containing the body of this generator function. 6590 // Create the closure containing the body of this generator function.
6594 String& generator_name = String::Handle(Z, innermost_function().name()); 6591 String& generator_name = String::Handle(Z, innermost_function().name());
6595 body_closure_name = 6592 body_closure_name =
6596 Symbols::NewFormatted("<%s_sync_body>", generator_name.ToCString()); 6593 Symbols::NewFormatted("<%s_sync_body>", generator_name.ToCString());
6597 body_closure_name = Symbols::New(body_closure_name); 6594 body_closure_name = Symbols::New(body_closure_name);
6598 body = Function::NewClosureFunction(body_closure_name, 6595 body = Function::NewClosureFunction(body_closure_name,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
6715 TRACE_PARSER("OpenAsyncFunction"); 6712 TRACE_PARSER("OpenAsyncFunction");
6716 AddContinuationVariables(); 6713 AddContinuationVariables();
6717 AddAsyncClosureVariables(); 6714 AddAsyncClosureVariables();
6718 Function& closure = Function::Handle(Z); 6715 Function& closure = Function::Handle(Z);
6719 bool is_new_closure = false; 6716 bool is_new_closure = false;
6720 6717
6721 // Check whether a function for the asynchronous function body of 6718 // Check whether a function for the asynchronous function body of
6722 // this async function has already been created by a previous 6719 // this async function has already been created by a previous
6723 // compilation of this function. 6720 // compilation of this function.
6724 const Function& found_func = Function::Handle( 6721 const Function& found_func = Function::Handle(
6725 Z, current_class().LookupClosureFunction(async_func_pos)); 6722 Z, I->LookupClosureFunction(innermost_function(), async_func_pos));
6726 if (!found_func.IsNull() && 6723 if (!found_func.IsNull()) {
6727 (found_func.token_pos() == async_func_pos) &&
6728 (found_func.script() == innermost_function().script()) &&
6729 (found_func.parent_function() == innermost_function().raw())) {
6730 ASSERT(found_func.IsAsyncClosure()); 6724 ASSERT(found_func.IsAsyncClosure());
6731 closure = found_func.raw(); 6725 closure = found_func.raw();
6732 } else { 6726 } else {
6733 // Create the closure containing the body of this async function. 6727 // Create the closure containing the body of this async function.
6734 const String& async_func_name = 6728 const String& async_func_name =
6735 String::Handle(Z, innermost_function().name()); 6729 String::Handle(Z, innermost_function().name());
6736 String& closure_name = String::Handle(Z, 6730 String& closure_name = String::Handle(Z,
6737 Symbols::NewFormatted("<%s_async_body>", async_func_name.ToCString())); 6731 Symbols::NewFormatted("<%s_async_body>", async_func_name.ToCString()));
6738 closure = Function::NewClosureFunction( 6732 closure = Function::NewClosureFunction(
6739 closure_name, 6733 closure_name,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6851 AddContinuationVariables(); 6845 AddContinuationVariables();
6852 AddAsyncGeneratorVariables(); 6846 AddAsyncGeneratorVariables();
6853 6847
6854 Function& closure = Function::Handle(Z); 6848 Function& closure = Function::Handle(Z);
6855 bool is_new_closure = false; 6849 bool is_new_closure = false;
6856 6850
6857 // Check whether a function for the asynchronous function body of 6851 // Check whether a function for the asynchronous function body of
6858 // this async generator has already been created by a previous 6852 // this async generator has already been created by a previous
6859 // compilation of this function. 6853 // compilation of this function.
6860 const Function& found_func = Function::Handle( 6854 const Function& found_func = Function::Handle(
6861 Z, current_class().LookupClosureFunction(async_func_pos)); 6855 Z, I->LookupClosureFunction(innermost_function(), async_func_pos));
6862 if (!found_func.IsNull() && 6856 if (!found_func.IsNull()) {
6863 (found_func.token_pos() == async_func_pos) &&
6864 (found_func.script() == innermost_function().script()) &&
6865 (found_func.parent_function() == innermost_function().raw())) {
6866 ASSERT(found_func.IsAsyncGenClosure()); 6857 ASSERT(found_func.IsAsyncGenClosure());
6867 closure = found_func.raw(); 6858 closure = found_func.raw();
6868 } else { 6859 } else {
6869 // Create the closure containing the body of this async generator function. 6860 // Create the closure containing the body of this async generator function.
6870 const String& async_generator_name = 6861 const String& async_generator_name =
6871 String::Handle(Z, innermost_function().name()); 6862 String::Handle(Z, innermost_function().name());
6872 String& closure_name = String::Handle(Z, 6863 String& closure_name = String::Handle(Z,
6873 Symbols::NewFormatted("<%s_async_gen_body>", 6864 Symbols::NewFormatted("<%s_async_gen_body>",
6874 async_generator_name.ToCString())); 6865 async_generator_name.ToCString()));
6875 closure = Function::NewClosureFunction( 6866 closure = Function::NewClosureFunction(
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
7622 // Check whether we have parsed this closure function before, in a previous 7613 // Check whether we have parsed this closure function before, in a previous
7623 // compilation. If so, reuse the function object, else create a new one 7614 // compilation. If so, reuse the function object, else create a new one
7624 // and register it in the current class. 7615 // and register it in the current class.
7625 // Note that we cannot share the same closure function between the closurized 7616 // Note that we cannot share the same closure function between the closurized
7626 // and non-closurized versions of the same parent function. 7617 // and non-closurized versions of the same parent function.
7627 Function& function = Function::ZoneHandle(Z); 7618 Function& function = Function::ZoneHandle(Z);
7628 bool is_new_closure = false; 7619 bool is_new_closure = false;
7629 // TODO(hausner): There could be two different closures at the given 7620 // TODO(hausner): There could be two different closures at the given
7630 // function_pos, one enclosed in a closurized function and one enclosed in the 7621 // function_pos, one enclosed in a closurized function and one enclosed in the
7631 // non-closurized version of this same function. 7622 // non-closurized version of this same function.
7632 function = current_class().LookupClosureFunction(function_pos); 7623 function = I->LookupClosureFunction(innermost_function(), function_pos);
7633 if (function.IsNull() || (function.token_pos() != function_pos) || 7624 if (function.IsNull()) {
7634 (function.parent_function() != innermost_function().raw())) {
7635 // The function will be registered in the lookup table by the 7625 // The function will be registered in the lookup table by the
7636 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure 7626 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure
7637 // function has been properly setup. 7627 // function has been properly setup.
7638 is_new_closure = true; 7628 is_new_closure = true;
7639 function = Function::NewClosureFunction(*function_name, 7629 function = Function::NewClosureFunction(*function_name,
7640 innermost_function(), 7630 innermost_function(),
7641 function_pos); 7631 function_pos);
7642 function.set_result_type(result_type); 7632 function.set_result_type(result_type);
7643 if (metadata_pos >= 0) { 7633 if (metadata_pos >= 0) {
7644 library_.AddFunctionMetadata(function, metadata_pos); 7634 library_.AddFunctionMetadata(function, metadata_pos);
(...skipping 5479 matching lines...) Expand 10 before | Expand all | Expand 10 after
13124 symbol_instance ^= result.raw(); 13114 symbol_instance ^= result.raw();
13125 CacheConstantValue(symbol_pos, symbol_instance); 13115 CacheConstantValue(symbol_pos, symbol_instance);
13126 return new(Z) LiteralNode(symbol_pos, symbol_instance); 13116 return new(Z) LiteralNode(symbol_pos, symbol_instance);
13127 } 13117 }
13128 13118
13129 13119
13130 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr, 13120 RawFunction* Parser::BuildConstructorClosureFunction(const Function& ctr,
13131 intptr_t token_pos) { 13121 intptr_t token_pos) {
13132 ASSERT(ctr.kind() == RawFunction::kConstructor); 13122 ASSERT(ctr.kind() == RawFunction::kConstructor);
13133 Function& closure = Function::Handle(Z); 13123 Function& closure = Function::Handle(Z);
13134 closure = current_class().LookupClosureFunction(token_pos); 13124 closure = I->LookupClosureFunction(innermost_function(), token_pos);
13135 if (!closure.IsNull()) { 13125 if (!closure.IsNull()) {
13136 ASSERT(closure.IsConstructorClosureFunction()); 13126 ASSERT(closure.IsConstructorClosureFunction());
13137 return closure.raw(); 13127 return closure.raw();
13138 } 13128 }
13139 13129
13140 String& closure_name = String::Handle(Z, ctr.name()); 13130 String& closure_name = String::Handle(Z, ctr.name());
13141 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(), 13131 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(),
13142 closure_name); 13132 closure_name);
13143 13133
13144 ParamList params; 13134 ParamList params;
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
14342 void Parser::SkipQualIdent() { 14332 void Parser::SkipQualIdent() {
14343 ASSERT(IsIdentifier()); 14333 ASSERT(IsIdentifier());
14344 ConsumeToken(); 14334 ConsumeToken();
14345 if (CurrentToken() == Token::kPERIOD) { 14335 if (CurrentToken() == Token::kPERIOD) {
14346 ConsumeToken(); // Consume the kPERIOD token. 14336 ConsumeToken(); // Consume the kPERIOD token.
14347 ExpectIdentifier("identifier expected after '.'"); 14337 ExpectIdentifier("identifier expected after '.'");
14348 } 14338 }
14349 } 14339 }
14350 14340
14351 } // namespace dart 14341 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object_test.cc ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698