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

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

Issue 8475005: Address Regis' review feedback (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/code_generator_ia32.cc ('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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) { 1224 if (super_class.IsNull() || (super_class.num_native_fields() > 0)) {
1225 return; 1225 return;
1226 } 1226 }
1227 String& ctor_name = String::Handle(super_class.Name()); 1227 String& ctor_name = String::Handle(super_class.Name());
1228 String& ctor_suffix = String::Handle(String::NewSymbol(".")); 1228 String& ctor_suffix = String::Handle(String::NewSymbol("."));
1229 ctor_name = String::Concat(ctor_name, ctor_suffix); 1229 ctor_name = String::Concat(ctor_name, ctor_suffix);
1230 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1230 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1231 // Implicit 'this' parameter is the first argument. 1231 // Implicit 'this' parameter is the first argument.
1232 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); 1232 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver);
1233 arguments->Add(implicit_argument); 1233 arguments->Add(implicit_argument);
1234 // Implicit constructor phase parameter is second argument. 1234 // Implicit construction phase parameter is second argument.
1235 AstNode* phase_parameter = 1235 AstNode* phase_parameter =
1236 new LiteralNode(supercall_pos, 1236 new LiteralNode(supercall_pos,
1237 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 1237 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
1238 arguments->Add(phase_parameter); 1238 arguments->Add(phase_parameter);
1239 const Function& super_ctor = Function::ZoneHandle( 1239 const Function& super_ctor = Function::ZoneHandle(
1240 super_class.LookupConstructor(ctor_name)); 1240 super_class.LookupConstructor(ctor_name));
1241 if (super_ctor.IsNull() || 1241 if (super_ctor.IsNull() ||
1242 !super_ctor.AreValidArguments(arguments->length(), 1242 !super_ctor.AreValidArguments(arguments->length(),
1243 arguments->names())) { 1243 arguments->names())) {
1244 ErrorMsg(supercall_pos, 1244 ErrorMsg(supercall_pos,
(...skipping 23 matching lines...) Expand all
1268 } 1268 }
1269 ctor_name = String::Concat(ctor_name, ctor_suffix); 1269 ctor_name = String::Concat(ctor_name, ctor_suffix);
1270 if (CurrentToken() != Token::kLPAREN) { 1270 if (CurrentToken() != Token::kLPAREN) {
1271 ErrorMsg("parameter list expected"); 1271 ErrorMsg("parameter list expected");
1272 } 1272 }
1273 1273
1274 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); 1274 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos);
1275 // 'this' parameter is the first argument to super class constructor. 1275 // 'this' parameter is the first argument to super class constructor.
1276 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver); 1276 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, *receiver);
1277 arguments->Add(implicit_argument); 1277 arguments->Add(implicit_argument);
1278 // Second implicit parameter is the constructor phase. We optimistically 1278 // Second implicit parameter is the construction phase. We optimistically
1279 // assume that we can execute both the super initializer and the super 1279 // assume that we can execute both the super initializer and the super
1280 // constructor body. We may later change this to only execute the 1280 // constructor body. We may later change this to only execute the
1281 // super initializer. 1281 // super initializer.
1282 AstNode* phase_parameter = 1282 AstNode* phase_parameter =
1283 new LiteralNode(supercall_pos, 1283 new LiteralNode(supercall_pos,
1284 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll))); 1284 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseAll)));
1285 arguments->Add(phase_parameter); 1285 arguments->Add(phase_parameter);
1286 // 'this' parameter must not be accessible to the other super call arguments. 1286 // 'this' parameter must not be accessible to the other super call arguments.
1287 receiver->set_invisible(true); 1287 receiver->set_invisible(true);
1288 ParseActualParameters(arguments, kAllowConst); 1288 ParseActualParameters(arguments, kAllowConst);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 } 1446 }
1447 ctor_name = String::Concat(ctor_name, ctor_suffix); 1447 ctor_name = String::Concat(ctor_name, ctor_suffix);
1448 if (CurrentToken() != Token::kLPAREN) { 1448 if (CurrentToken() != Token::kLPAREN) {
1449 ErrorMsg("parameter list expected"); 1449 ErrorMsg("parameter list expected");
1450 } 1450 }
1451 1451
1452 ArgumentListNode* arguments = new ArgumentListNode(call_pos); 1452 ArgumentListNode* arguments = new ArgumentListNode(call_pos);
1453 // 'this' parameter is the first argument to constructor. 1453 // 'this' parameter is the first argument to constructor.
1454 AstNode* implicit_argument = new LoadLocalNode(call_pos, *receiver); 1454 AstNode* implicit_argument = new LoadLocalNode(call_pos, *receiver);
1455 arguments->Add(implicit_argument); 1455 arguments->Add(implicit_argument);
1456 // Constructor phase parameter is second argument. 1456 // Construction phase parameter is second argument.
1457 LocalVariable* phase_param = LookupPhaseParameter(); 1457 LocalVariable* phase_param = LookupPhaseParameter();
1458 ASSERT(phase_param != NULL); 1458 ASSERT(phase_param != NULL);
1459 AstNode* phase_argument = new LoadLocalNode(call_pos, *phase_param); 1459 AstNode* phase_argument = new LoadLocalNode(call_pos, *phase_param);
1460 arguments->Add(phase_argument); 1460 arguments->Add(phase_argument);
1461 ParseActualParameters(arguments, kAllowConst); 1461 ParseActualParameters(arguments, kAllowConst);
1462 1462
1463 // Resolve the constructor. 1463 // Resolve the constructor.
1464 const Function& redirect_ctor = Function::ZoneHandle( 1464 const Function& redirect_ctor = Function::ZoneHandle(
1465 cls.LookupConstructor(ctor_name)); 1465 cls.LookupConstructor(ctor_name));
1466 if (redirect_ctor.IsNull() || 1466 if (redirect_ctor.IsNull() ||
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 SequenceNode* Parser::ParseConstructor(const Function& func, 1527 SequenceNode* Parser::ParseConstructor(const Function& func,
1528 Array& default_parameter_values) { 1528 Array& default_parameter_values) {
1529 ASSERT(func.IsConstructor()); 1529 ASSERT(func.IsConstructor());
1530 ASSERT(!func.IsFactory()); 1530 ASSERT(!func.IsFactory());
1531 ASSERT(!func.is_static()); 1531 ASSERT(!func.is_static());
1532 ASSERT(!func.IsLocalFunction()); 1532 ASSERT(!func.IsLocalFunction());
1533 const Class& cls = Class::Handle(func.owner()); 1533 const Class& cls = Class::Handle(func.owner());
1534 ASSERT(!cls.IsNull()); 1534 ASSERT(!cls.IsNull());
1535 1535
1536 if (IsLiteral("class")) { 1536 if (IsLiteral("class")) {
1537 // Special case: implicit constructor. There is no source text to 1537 // Special case: implicit constructor.
1538 // parse. We just build the sequence node by hand. 1538 // The parser adds an implicit default constructor when a class
1539 // does not have any explicit constructor or factory (see
1540 // Parser::CheckConstructors). The token position of this implicit
1541 // constructor points to the 'class' keyword, which is followed
1542 // by the name of the class (which is also the constructor name).
1543 // There is no source text to parse. We just build the
1544 // sequence node by hand.
1539 return MakeImplicitConstructor(func); 1545 return MakeImplicitConstructor(func);
1540 } 1546 }
1541 1547
1542 OpenFunctionBlock(func); 1548 OpenFunctionBlock(func);
1543 ParamList params; 1549 ParamList params;
1544 const bool allow_explicit_default_values = true; 1550 const bool allow_explicit_default_values = true;
1545 ASSERT(CurrentToken() == Token::kLPAREN); 1551 ASSERT(CurrentToken() == Token::kLPAREN);
1546 1552
1547 // Add implicit receiver parameter which is passed the allocated 1553 // Add implicit receiver parameter which is passed the allocated
1548 // but uninitialized instance to construct. 1554 // but uninitialized instance to construct.
1549 params.AddReceiver(token_index_); 1555 params.AddReceiver(token_index_);
1550 1556
1551 // Add implicit parameter for constructor phase. 1557 // Add implicit parameter for construction phase.
1552 params.AddFinalParameter(token_index_, kPhaseParameterName, 1558 params.AddFinalParameter(token_index_, kPhaseParameterName,
1553 &Type::ZoneHandle(Type::DynamicType())); 1559 &Type::ZoneHandle(Type::DynamicType()));
1554 1560
1555 if (func.is_const()) { 1561 if (func.is_const()) {
1556 params.SetImplicitlyFinal(); 1562 params.SetImplicitlyFinal();
1557 } 1563 }
1558 ParseFormalParameterList(allow_explicit_default_values, &params); 1564 ParseFormalParameterList(allow_explicit_default_values, &params);
1559 1565
1560 SetupDefaultsForOptionalParams(&params, default_parameter_values); 1566 SetupDefaultsForOptionalParams(&params, default_parameter_values);
1561 ASSERT(Type::Handle(func.result_type()).IsResolved()); 1567 ASSERT(Type::Handle(func.result_type()).IsResolved());
1562 ASSERT(func.NumberOfParameters() == params.parameters->length()); 1568 ASSERT(func.NumberOfParameters() == params.parameters->length());
1563 1569
1564 // Initialize instance fields that have an explicit initializer expression. 1570 // Initialize instance fields that have an explicit initializer expression.
1565 // This has to be done before code for field initializer parameters 1571 // This has to be done before code for field initializer parameters
1566 // are is generated. 1572 // is generated.
1567 // NB: the instance field initializers have to be compiled before 1573 // NB: the instance field initializers have to be compiled before
1568 // the parameters are added to the scope, so that a parameter 1574 // the parameters are added to the scope, so that a parameter
1569 // name cannot shadow a name used in the field initializer expression. 1575 // name cannot shadow a name used in the field initializer expression.
1570 GrowableArray<FieldInitExpression> initializers; 1576 GrowableArray<FieldInitExpression> initializers;
1571 ParseInitializedInstanceFields(cls, &initializers); 1577 ParseInitializedInstanceFields(cls, &initializers);
1572 1578
1573 // Now populate function scope with the formal parameters. 1579 // Now populate function scope with the formal parameters.
1574 AddFormalParamsToScope(&params, current_block_->scope); 1580 AddFormalParamsToScope(&params, current_block_->scope);
1575 LocalVariable* receiver = current_block_->scope->VariableAt(0); 1581 LocalVariable* receiver = current_block_->scope->VariableAt(0);
1576 1582
1577 // Now that the "this" parameter is in scope, we can generate the code 1583 // Now that the "this" parameter is in scope, we can generate the code
1578 // to strore the initializer expressions in the respective instance fields. 1584 // to store the initializer expressions in the respective instance fields.
1579 // We do this before the field parameters and the initializers from the 1585 // We do this before the field parameters and the initializers from the
1580 // constructor's initializer list get compiled. 1586 // constructor's initializer list get compiled.
1581 OpenBlock(); 1587 OpenBlock();
1582 for (int i = 0; i < initializers.length(); i++) { 1588 for (int i = 0; i < initializers.length(); i++) {
1583 const Field* field = initializers[i].inst_field; 1589 const Field* field = initializers[i].inst_field;
1584 AstNode* instance = new LoadLocalNode(field->token_index(), *receiver); 1590 AstNode* instance = new LoadLocalNode(field->token_index(), *receiver);
1585 AstNode* field_init = 1591 AstNode* field_init =
1586 new StoreInstanceFieldNode(field->token_index(), 1592 new StoreInstanceFieldNode(field->token_index(),
1587 instance, 1593 instance,
1588 *field, 1594 *field,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 new ComparisonNode(token_index_, Token::kNE_STRICT, 1639 new ComparisonNode(token_index_, Token::kNE_STRICT,
1634 phase_check, 1640 phase_check,
1635 new LiteralNode(token_index_, 1641 new LiteralNode(token_index_,
1636 Smi::ZoneHandle(Smi::New(0)))); 1642 Smi::ZoneHandle(Smi::New(0))));
1637 AstNode* guarded_init_statements = 1643 AstNode* guarded_init_statements =
1638 new IfNode(token_index_, comparison, init_statements, NULL); 1644 new IfNode(token_index_, comparison, init_statements, NULL);
1639 current_block_->statements->Add(guarded_init_statements); 1645 current_block_->statements->Add(guarded_init_statements);
1640 } 1646 }
1641 1647
1642 // Parsing of initializers done. Now we parse the constructor body 1648 // Parsing of initializers done. Now we parse the constructor body
1643 // and add the implicit super call to the super construcotr's body 1649 // and add the implicit super call to the super constructor's body
1644 // if necessary. 1650 // if necessary.
1645 StaticCallNode* super_call = NULL; 1651 StaticCallNode* super_call = NULL;
1646 // Look for the super initializer call in the sequence of initializer 1652 // Look for the super initializer call in the sequence of initializer
1647 // statements. If it exists and is not the last initializer statement, 1653 // statements. If it exists and is not the last initializer statement,
1648 // we need to create an implicit super call to the super constructor's 1654 // we need to create an implicit super call to the super constructor's
1649 // body. 1655 // body.
1650 // Thus, iterate over all but the last initializer to see whether 1656 // Thus, iterate over all but the last initializer to see whether
1651 // it's a super constructor call. 1657 // it's a super constructor call.
1652 for (int i = 0; i < init_statements->length() - 1; i++) { 1658 for (int i = 0; i < init_statements->length() - 1; i++) {
1653 if (init_statements->NodeAt(i)->IsStaticCallNode()) { 1659 if (init_statements->NodeAt(i)->IsStaticCallNode()) {
1654 StaticCallNode* static_call = 1660 StaticCallNode* static_call =
1655 init_statements->NodeAt(i)->AsStaticCallNode(); 1661 init_statements->NodeAt(i)->AsStaticCallNode();
1656 if (static_call->function().IsConstructor()) { 1662 if (static_call->function().IsConstructor()) {
1657 super_call = static_call; 1663 super_call = static_call;
1658 break; 1664 break;
1659 } 1665 }
1660 } 1666 }
1661 } 1667 }
1662 if (super_call != NULL) { 1668 if (super_call != NULL) {
1663 // Generate an implicit call to the super constructor's body. 1669 // Generate an implicit call to the super constructor's body.
1664 // We need to patch the super _initializer_ call so that it 1670 // We need to patch the super _initializer_ call so that it
1665 // saves the evaluated actual arguments in temporary variables. 1671 // saves the evaluated actual arguments in temporary variables.
1666 // The temporary variables are necessary so that the argument 1672 // The temporary variables are necessary so that the argument
1667 // expressions are not evaluated twice. 1673 // expressions are not evaluated twice.
1668 ArgumentListNode* ctor_args = super_call->arguments(); 1674 ArgumentListNode* ctor_args = super_call->arguments();
1669 // The super initializer call has at least 2 arguments: the 1675 // The super initializer call has at least 2 arguments: the
1670 // implicit receiver, and the hidden constructor phase. 1676 // implicit receiver, and the hidden construction phase.
1671 ASSERT(ctor_args->length() >= 2); 1677 ASSERT(ctor_args->length() >= 2);
1672 for (int i = 2; i < ctor_args->length(); i++) { 1678 for (int i = 2; i < ctor_args->length(); i++) {
1673 AstNode* arg = ctor_args->NodeAt(i); 1679 AstNode* arg = ctor_args->NodeAt(i);
1674 if (!arg->IsLoadLocalNode() && !arg->IsLiteralNode()) { 1680 if (!arg->IsLoadLocalNode() && !arg->IsLiteralNode()) {
1675 LocalVariable* temp = 1681 LocalVariable* temp =
1676 CreateTempConstVariable(arg->token_index(), arg->id(), "sca"); 1682 CreateTempConstVariable(arg->token_index(), arg->id(), "sca");
1677 AstNode* save_temp = 1683 AstNode* save_temp =
1678 new StoreLocalNode(arg->token_index(), *temp, arg); 1684 new StoreLocalNode(arg->token_index(), *temp, arg);
1679 ctor_args->SetNodeAt(i, save_temp); 1685 ctor_args->SetNodeAt(i, save_temp);
1680 } 1686 }
1681 } 1687 }
1682 } 1688 }
1683 OpenBlock(); // Block to collect constructor body nodes. 1689 OpenBlock(); // Block to collect constructor body nodes.
1684 1690
1685 // Insert the implicit super call to the super constructor body. 1691 // Insert the implicit super call to the super constructor body.
1686 if (super_call != NULL) { 1692 if (super_call != NULL) {
1687 ArgumentListNode* initializer_args = super_call->arguments(); 1693 ArgumentListNode* initializer_args = super_call->arguments();
1688 const Function& super_ctor = super_call->function(); 1694 const Function& super_ctor = super_call->function();
1689 // Patch the initializer call so it only executes the super 1695 // Patch the initializer call so it only executes the super initializer.
1690 // initializer.
1691 initializer_args->SetNodeAt(1, 1696 initializer_args->SetNodeAt(1,
1692 new LiteralNode(token_index_, 1697 new LiteralNode(token_index_,
1693 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit)))); 1698 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseInit))));
1694 1699
1695 ArgumentListNode* super_call_args = new ArgumentListNode(token_index_); 1700 ArgumentListNode* super_call_args = new ArgumentListNode(token_index_);
1696 // First argument is the receiver. 1701 // First argument is the receiver.
1697 super_call_args->Add(new LoadLocalNode(token_index_, *receiver)); 1702 super_call_args->Add(new LoadLocalNode(token_index_, *receiver));
1698 // Second argument is the constructor phase argument. 1703 // Second argument is the construction phase argument.
1699 AstNode* phase_parameter = 1704 AstNode* phase_parameter =
1700 new LiteralNode(token_index_, 1705 new LiteralNode(token_index_,
1701 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody))); 1706 Smi::ZoneHandle(Smi::New(Function::kCtorPhaseBody)));
1702 super_call_args->Add(phase_parameter); 1707 super_call_args->Add(phase_parameter);
1703 super_call_args->set_names(initializer_args->names()); 1708 super_call_args->set_names(initializer_args->names());
1704 for (int i = 2; i < initializer_args->length(); i++) { 1709 for (int i = 2; i < initializer_args->length(); i++) {
1705 AstNode* arg = initializer_args->NodeAt(i); 1710 AstNode* arg = initializer_args->NodeAt(i);
1706 if (arg->IsLiteralNode()) { 1711 if (arg->IsLiteralNode()) {
1707 LiteralNode* lit = arg->AsLiteralNode(); 1712 LiteralNode* lit = arg->AsLiteralNode();
1708 super_call_args->Add(new LiteralNode(token_index_, lit->literal())); 1713 super_call_args->Add(new LiteralNode(token_index_, lit->literal()));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 const bool has_this_param = 1988 const bool has_this_param =
1984 !method->has_static || method->IsConstructor() || method->has_factory; 1989 !method->has_static || method->IsConstructor() || method->has_factory;
1985 const bool are_implicitly_final = method->has_const; 1990 const bool are_implicitly_final = method->has_const;
1986 const bool allow_explicit_default_values = 1991 const bool allow_explicit_default_values =
1987 (!method->has_abstract && !members->is_interface()); 1992 (!method->has_abstract && !members->is_interface());
1988 const intptr_t formal_param_pos = token_index_; 1993 const intptr_t formal_param_pos = token_index_;
1989 method->params.Clear(); 1994 method->params.Clear();
1990 if (has_this_param) { 1995 if (has_this_param) {
1991 method->params.AddReceiver(formal_param_pos); 1996 method->params.AddReceiver(formal_param_pos);
1992 } 1997 }
1993 // Constructors have an implicit parameter for the constructor phase. 1998 // Constructors have an implicit parameter for the construction phase.
1994 if (method->IsConstructor()) { 1999 if (method->IsConstructor()) {
1995 method->params.AddFinalParameter(token_index_, kPhaseParameterName, 2000 method->params.AddFinalParameter(token_index_, kPhaseParameterName,
1996 &Type::ZoneHandle(Type::DynamicType())); 2001 &Type::ZoneHandle(Type::DynamicType()));
1997 } 2002 }
1998 if (are_implicitly_final) { 2003 if (are_implicitly_final) {
1999 method->params.SetImplicitlyFinal(); 2004 method->params.SetImplicitlyFinal();
2000 } 2005 }
2001 ParseFormalParameterList(allow_explicit_default_values, &method->params); 2006 ParseFormalParameterList(allow_explicit_default_values, &method->params);
2002 if (method->IsGetter() || method->IsSetter()) { 2007 if (method->IsGetter() || method->IsSetter()) {
2003 int expected_num_parameters = 0; 2008 int expected_num_parameters = 0;
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
2505 // 2. Check for cycles in constructor redirection. 2510 // 2. Check for cycles in constructor redirection.
2506 void Parser::CheckConstructors(ClassDesc* class_desc) { 2511 void Parser::CheckConstructors(ClassDesc* class_desc) {
2507 // Add an implicit constructor if no explicit constructor is present. 2512 // Add an implicit constructor if no explicit constructor is present.
2508 if (!class_desc->has_constructor()) { 2513 if (!class_desc->has_constructor()) {
2509 // The implicit constructor is unnamed, has no explicit parameter, 2514 // The implicit constructor is unnamed, has no explicit parameter,
2510 // and contains a supercall in the initializer list. 2515 // and contains a supercall in the initializer list.
2511 String& ctor_name = String::ZoneHandle( 2516 String& ctor_name = String::ZoneHandle(
2512 String::Concat(class_desc->class_name(), 2517 String::Concat(class_desc->class_name(),
2513 String::Handle(String::NewSymbol(".")))); 2518 String::Handle(String::NewSymbol("."))));
2514 ctor_name = String::NewSymbol(ctor_name); 2519 ctor_name = String::NewSymbol(ctor_name);
2520 // The token position for the implicit constructor is the 'class'
2521 // keyword of the constructor's class.
2515 Function& ctor = Function::ZoneHandle( 2522 Function& ctor = Function::ZoneHandle(
2516 Function::New(ctor_name, 2523 Function::New(ctor_name,
2517 RawFunction::kConstructor, 2524 RawFunction::kConstructor,
2518 /* is_static = */ false, 2525 /* is_static = */ false,
2519 /* is_const = */ false, 2526 /* is_const = */ false,
2520 class_desc->token_pos())); 2527 class_desc->token_pos()));
2521 ParamList params; 2528 ParamList params;
2522 // Add implicit 'this' parameter. 2529 // Add implicit 'this' parameter.
2523 params.AddReceiver(token_index_); 2530 params.AddReceiver(token_index_);
2524 // Add implicit parameter for constructor phase. 2531 // Add implicit parameter for construction phase.
2525 params.AddFinalParameter(token_index_, kPhaseParameterName, 2532 params.AddFinalParameter(token_index_, kPhaseParameterName,
2526 &Type::ZoneHandle(Type::DynamicType())); 2533 &Type::ZoneHandle(Type::DynamicType()));
2527 2534
2528 AddFormalParamsToFunction(&params, ctor); 2535 AddFormalParamsToFunction(&params, ctor);
2529 // TODO(regis): What are the type arguments? 2536 // TODO(regis): What are the type arguments?
2530 Type& result_type = Type::ZoneHandle( 2537 Type& result_type = Type::ZoneHandle(
2531 Type::NewRawType(Class::Handle(class_desc->clazz()))); 2538 Type::NewRawType(Class::Handle(class_desc->clazz())));
2532 ctor.set_result_type(result_type); 2539 ctor.set_result_type(result_type);
2533 class_desc->AddFunction(&ctor); 2540 class_desc->AddFunction(&ctor);
2534 } 2541 }
(...skipping 3485 matching lines...) Expand 10 before | Expand all | Expand 10 after
6020 field.set_value(const_value); 6027 field.set_value(const_value);
6021 } 6028 }
6022 } 6029 }
6023 6030
6024 6031
6025 RawInstance* Parser::EvaluateConstConstructorCall( 6032 RawInstance* Parser::EvaluateConstConstructorCall(
6026 const Class& type_class, 6033 const Class& type_class,
6027 const TypeArguments& type_arguments, 6034 const TypeArguments& type_arguments,
6028 const Function& constructor, 6035 const Function& constructor,
6029 ArgumentListNode* arguments) { 6036 ArgumentListNode* arguments) {
6030 // +2 for implicit receiver and constructor phase arguments. 6037 // +2 for implicit receiver and construction phase arguments.
6031 GrowableArray<const Object*> arg_values(arguments->length() + 2); 6038 GrowableArray<const Object*> arg_values(arguments->length() + 2);
6032 Instance& instance = Instance::Handle(); 6039 Instance& instance = Instance::Handle();
6033 if (!constructor.IsFactory()) { 6040 if (!constructor.IsFactory()) {
6034 instance = Instance::New(type_class); 6041 instance = Instance::New(type_class);
6035 if (!type_arguments.IsNull()) { 6042 if (!type_arguments.IsNull()) {
6036 // TODO(regis): Where should we check the constraints on type parameters? 6043 // TODO(regis): Where should we check the constraints on type parameters?
6037 if (!type_arguments.IsInstantiated()) { 6044 if (!type_arguments.IsInstantiated()) {
6038 ErrorMsg("type must be constant in const constructor"); 6045 ErrorMsg("type must be constant in const constructor");
6039 } 6046 }
6040 instance.SetTypeArguments(type_arguments); 6047 instance.SetTypeArguments(type_arguments);
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after
7247 } 7254 }
7248 7255
7249 7256
7250 void Parser::SkipNestedExpr() { 7257 void Parser::SkipNestedExpr() {
7251 const bool saved_mode = SetAllowFunctionLiterals(true); 7258 const bool saved_mode = SetAllowFunctionLiterals(true);
7252 SkipExpr(); 7259 SkipExpr();
7253 SetAllowFunctionLiterals(saved_mode); 7260 SetAllowFunctionLiterals(saved_mode);
7254 } 7261 }
7255 7262
7256 } // namespace dart 7263 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698