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

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

Issue 8602004: Fix code generation issue with new factory syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 592
593 if ((node_sequence->length() == 0) || 593 if ((node_sequence->length() == 0) ||
594 !node_sequence->NodeAt(node_sequence->length() - 1)->IsReturnNode()) { 594 !node_sequence->NodeAt(node_sequence->length() - 1)->IsReturnNode()) {
595 // Add implicit return node. 595 // Add implicit return node.
596 node_sequence->Add(new ReturnNode(parser.token_index_)); 596 node_sequence->Add(new ReturnNode(parser.token_index_));
597 } 597 }
598 parsed_function->set_node_sequence(node_sequence); 598 parsed_function->set_node_sequence(node_sequence);
599 599
600 // The instantiator may be required at run time for generic type checks or 600 // The instantiator may be required at run time for generic type checks or
601 // allocation of generic types. 601 // allocation of generic types.
602 if ((parser.current_class().NumTypeParameters() > 0) && 602 if (parser.IsInstantiatorRequired()) {
603 (!parser.current_function().is_static() ||
604 parser.current_function().IsInFactoryScope())) {
605 // In the case of a local function, only set the instantiator if the 603 // In the case of a local function, only set the instantiator if the
606 // receiver was captured. 604 // receiver was captured.
607 const bool kTestOnly = true; 605 const bool kTestOnly = true;
608 LocalVariable* receiver = 606 LocalVariable* receiver =
609 parser.LookupReceiver(node_sequence->scope(), 607 parser.LookupReceiver(node_sequence->scope(),
610 kTestOnly); 608 kTestOnly);
611 if (!parser.current_function().IsLocalFunction() || 609 if (!parser.current_function().IsLocalFunction() ||
612 ((receiver != NULL) && receiver->is_captured())) { 610 ((receiver != NULL) && receiver->is_captured())) {
613 parsed_function->set_instantiator( 611 parsed_function->set_instantiator(
614 new LoadLocalNode(node_sequence->token_index(), *receiver)); 612 new LoadLocalNode(node_sequence->token_index(), *receiver));
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 } 1818 }
1821 } 1819 }
1822 } 1820 }
1823 // Populate function scope with the formal parameters. 1821 // Populate function scope with the formal parameters.
1824 AddFormalParamsToScope(&params, current_block_->scope); 1822 AddFormalParamsToScope(&params, current_block_->scope);
1825 1823
1826 if (FLAG_enable_type_checks && 1824 if (FLAG_enable_type_checks &&
1827 (current_block_->scope->function_level() > 0)) { 1825 (current_block_->scope->function_level() > 0)) {
1828 // We are parsing, but not compiling, a local function. 1826 // We are parsing, but not compiling, a local function.
1829 // The instantiator may be required at run time for generic type checks. 1827 // The instantiator may be required at run time for generic type checks.
1830 if ((current_class().NumTypeParameters() > 0) && 1828 if (IsInstantiatorRequired()) {
1831 (!current_function().is_static() ||
1832 current_function().IsInFactoryScope())) {
1833 // Make sure that the receiver of the enclosing instance function 1829 // Make sure that the receiver of the enclosing instance function
1834 // (or implicit first parameter of an enclosing factory) is marked as 1830 // (or implicit first parameter of an enclosing factory) is marked as
1835 // captured if type checks are enabled, because they may access the 1831 // captured if type checks are enabled, because they may access the
1836 // receiver to instantiate types. 1832 // receiver to instantiate types.
1837 CaptureReceiver(); 1833 CaptureReceiver();
1838 } 1834 }
1839 } 1835 }
1840 1836
1841 if (CurrentToken() == Token::kLBRACE) { 1837 if (CurrentToken() == Token::kLBRACE) {
1842 ConsumeToken(); 1838 ConsumeToken();
(...skipping 4218 matching lines...) Expand 10 before | Expand all | Expand 10 after
6061 } 6057 }
6062 if (!outer_function.is_static()) { 6058 if (!outer_function.is_static()) {
6063 return current_class().raw(); 6059 return current_class().raw();
6064 } 6060 }
6065 } 6061 }
6066 } 6062 }
6067 return Class::null(); 6063 return Class::null();
6068 } 6064 }
6069 6065
6070 6066
6067 bool Parser::IsInstantiatorRequired() {
srdjan 2011/11/18 17:42:30 Can this method be const?
regis 2011/11/18 17:45:46 Yes. Done.
6068 ASSERT(!current_function().IsNull());
6069 Function& outer_function = Function::Handle(current_function().raw());
6070 while (outer_function.IsLocalFunction()) {
6071 outer_function = outer_function.parent_function();
6072 }
6073 if (outer_function.IsFactory()) {
6074 const Class& signature_class =
6075 Class::Handle(outer_function.signature_class());
6076 return signature_class.NumTypeParameters() > 0;
6077 }
6078 if (!outer_function.is_static()) {
6079 return current_class().NumTypeParameters() > 0;
6080 }
6081 return false;
6082 }
6083
6084
6071 void Parser::RunStaticFieldInitializer(const Field& field) { 6085 void Parser::RunStaticFieldInitializer(const Field& field) {
6072 ASSERT(field.is_static()); 6086 ASSERT(field.is_static());
6073 const Instance& value = Instance::Handle(field.value()); 6087 const Instance& value = Instance::Handle(field.value());
6074 if (value.raw() == Object::transition_sentinel()) { 6088 if (value.raw() == Object::transition_sentinel()) {
6075 ErrorMsg("circular dependency while initializing static field '%s'", 6089 ErrorMsg("circular dependency while initializing static field '%s'",
6076 String::Handle(field.name()).ToCString()); 6090 String::Handle(field.name()).ToCString());
6077 6091
6078 } else if (value.raw() == Object::sentinel()) { 6092 } else if (value.raw() == Object::sentinel()) {
6079 // This field has not been referenced yet and thus the value has 6093 // This field has not been referenced yet and thus the value has
6080 // not been evaluated. Call the static getter method to evaluate 6094 // not been evaluated. Call the static getter method to evaluate
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
7362 } 7376 }
7363 7377
7364 7378
7365 void Parser::SkipNestedExpr() { 7379 void Parser::SkipNestedExpr() {
7366 const bool saved_mode = SetAllowFunctionLiterals(true); 7380 const bool saved_mode = SetAllowFunctionLiterals(true);
7367 SkipExpr(); 7381 SkipExpr();
7368 SetAllowFunctionLiterals(saved_mode); 7382 SetAllowFunctionLiterals(saved_mode);
7369 } 7383 }
7370 7384
7371 } // namespace dart 7385 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698