OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
6 | 6 |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/longjump.h" | 8 #include "vm/longjump.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 ASSERT(scope_ == NULL && depth_.loop_ == 0 && depth_.function_ == 0); | 60 ASSERT(scope_ == NULL && depth_.loop_ == 0 && depth_.function_ == 0); |
61 result_ = new (Z) ScopeBuildingResult(); | 61 result_ = new (Z) ScopeBuildingResult(); |
62 | 62 |
63 ParsedFunction* parsed_function = parsed_function_; | 63 ParsedFunction* parsed_function = parsed_function_; |
64 const Function& function = parsed_function->function(); | 64 const Function& function = parsed_function->function(); |
65 | 65 |
66 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used | 66 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used |
67 // e.g. for type translation. | 67 // e.g. for type translation. |
68 const dart::Class& klass = | 68 const dart::Class& klass = |
69 dart::Class::Handle(zone_, parsed_function_->function().Owner()); | 69 dart::Class::Handle(zone_, parsed_function_->function().Owner()); |
70 | |
70 Function& outermost_function = Function::Handle(Z); | 71 Function& outermost_function = Function::Handle(Z); |
71 intptr_t outermost_kernel_offset = -1; | 72 builder_->DiscoverEnclosingElements(Z, function, &outermost_function); |
72 intptr_t parent_class_offset = -1; | |
73 builder_->DiscoverEnclosingElements(Z, function, &outermost_function, | |
74 &outermost_kernel_offset, | |
75 &parent_class_offset); | |
76 // Use [klass]/[kernel_class] as active class. Type parameters will get | |
77 // resolved via [kernel_class] unless we are nested inside a static factory | |
78 // in which case we will use [member]. | |
79 intptr_t class_type_parameters = 0; | |
80 intptr_t class_type_parameters_offset_start = -1; | |
81 if (parent_class_offset > 0) { | |
82 builder_->GetTypeParameterInfoForClass(parent_class_offset, | |
83 &class_type_parameters, | |
84 &class_type_parameters_offset_start); | |
85 } | |
86 ActiveClassScope active_class_scope(&active_class_, class_type_parameters, | |
87 class_type_parameters_offset_start, | |
88 &klass); | |
89 | 73 |
90 bool member_is_procedure = false; | 74 ActiveClassScope active_class_scope(&active_class_, &klass); |
91 bool is_factory_procedure = false; | 75 ActiveMemberScope active_member(&active_class_, &outermost_function); |
92 intptr_t member_type_parameters = 0; | |
93 intptr_t member_type_parameters_offset_start = -1; | |
94 builder_->GetTypeParameterInfoForPossibleProcedure( | |
95 outermost_kernel_offset, &member_is_procedure, &is_factory_procedure, | |
96 &member_type_parameters, &member_type_parameters_offset_start); | |
97 | |
98 ActiveMemberScope active_member(&active_class_, member_is_procedure, | |
99 is_factory_procedure, member_type_parameters, | |
100 member_type_parameters_offset_start); | |
101 | 76 |
102 LocalScope* enclosing_scope = NULL; | 77 LocalScope* enclosing_scope = NULL; |
103 if (function.IsLocalFunction()) { | 78 if (function.IsLocalFunction()) { |
104 enclosing_scope = LocalScope::RestoreOuterScope( | 79 enclosing_scope = LocalScope::RestoreOuterScope( |
105 ContextScope::Handle(Z, function.context_scope())); | 80 ContextScope::Handle(Z, function.context_scope())); |
106 } | 81 } |
107 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); | 82 current_function_scope_ = scope_ = new (Z) LocalScope(enclosing_scope, 0, 0); |
108 scope_->set_begin_token_pos(function.token_pos()); | 83 scope_->set_begin_token_pos(function.token_pos()); |
109 scope_->set_end_token_pos(function.end_token_pos()); | 84 scope_->set_end_token_pos(function.end_token_pos()); |
110 | 85 |
111 // Add function type arguments variable before current context variable. | 86 // Add function type arguments variable before current context variable. |
112 if (FLAG_reify_generic_functions && function.IsGeneric()) { | 87 if (FLAG_reify_generic_functions && function.IsGeneric()) { |
113 LocalVariable* type_args_var = MakeVariable( | 88 LocalVariable* type_args_var = MakeVariable( |
114 TokenPosition::kNoSource, TokenPosition::kNoSource, | 89 TokenPosition::kNoSource, TokenPosition::kNoSource, |
115 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type()); | 90 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type()); |
116 scope_->AddVariable(type_args_var); | 91 scope_->AddVariable(type_args_var); |
117 parsed_function_->set_function_type_arguments(type_args_var); | 92 parsed_function_->set_function_type_arguments(type_args_var); |
118 } | 93 } |
119 | 94 |
120 LocalVariable* context_var = parsed_function->current_context_var(); | 95 LocalVariable* context_var = parsed_function->current_context_var(); |
121 context_var->set_is_forced_stack(); | 96 context_var->set_is_forced_stack(); |
122 scope_->AddVariable(context_var); | 97 scope_->AddVariable(context_var); |
123 | 98 |
124 parsed_function->SetNodeSequence( | 99 parsed_function->SetNodeSequence( |
125 new SequenceNode(TokenPosition::kNoSource, scope_)); | 100 new SequenceNode(TokenPosition::kNoSource, scope_)); |
126 | 101 |
127 intptr_t parent_offset = -1; | |
128 builder_->SetOffset(kernel_offset_); | 102 builder_->SetOffset(kernel_offset_); |
129 | 103 |
130 FunctionNodeHelper function_node_helper(builder_); | 104 FunctionNodeHelper function_node_helper(builder_); |
131 | 105 |
132 switch (function.kind()) { | 106 switch (function.kind()) { |
133 case RawFunction::kClosureFunction: | 107 case RawFunction::kClosureFunction: |
134 case RawFunction::kImplicitClosureFunction: | 108 case RawFunction::kImplicitClosureFunction: |
135 case RawFunction::kConvertedClosureFunction: | 109 case RawFunction::kConvertedClosureFunction: |
136 case RawFunction::kRegularFunction: | 110 case RawFunction::kRegularFunction: |
137 case RawFunction::kGetterFunction: | 111 case RawFunction::kGetterFunction: |
138 case RawFunction::kSetterFunction: | 112 case RawFunction::kSetterFunction: |
139 case RawFunction::kConstructor: { | 113 case RawFunction::kConstructor: { |
140 const Tag tag = builder_->PeekTag(); | 114 const Tag tag = builder_->PeekTag(); |
141 parent_offset = builder_->ReadUntilFunctionNode(); | 115 intptr_t parent_offset = builder_->ReadUntilFunctionNode(); |
142 function_node_helper.ReadUntilExcluding( | 116 function_node_helper.ReadUntilExcluding( |
143 FunctionNodeHelper::kPositionalParameters); | 117 FunctionNodeHelper::kPositionalParameters); |
144 current_function_async_marker_ = function_node_helper.async_marker_; | 118 current_function_async_marker_ = function_node_helper.async_marker_; |
145 // NOTE: FunctionNode is read further below the if. | 119 // NOTE: FunctionNode is read further below the if. |
146 | 120 |
147 intptr_t pos = 0; | 121 intptr_t pos = 0; |
148 if (function.IsClosureFunction()) { | 122 if (function.IsClosureFunction()) { |
149 LocalVariable* variable = MakeVariable( | 123 LocalVariable* variable = MakeVariable( |
150 TokenPosition::kNoSource, TokenPosition::kNoSource, | 124 TokenPosition::kNoSource, TokenPosition::kNoSource, |
151 Symbols::ClosureParameter(), AbstractType::dynamic_type()); | 125 Symbols::ClosureParameter(), AbstractType::dynamic_type()); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 intptr_t list_length = builder_->ReadListLength(); // read list length. | 605 intptr_t list_length = builder_->ReadListLength(); // read list length. |
632 for (intptr_t i = 0; i < list_length; ++i) { | 606 for (intptr_t i = 0; i < list_length; ++i) { |
633 VisitExpression(); // read ith key. | 607 VisitExpression(); // read ith key. |
634 VisitExpression(); // read ith value. | 608 VisitExpression(); // read ith value. |
635 } | 609 } |
636 return; | 610 return; |
637 } | 611 } |
638 case kFunctionExpression: { | 612 case kFunctionExpression: { |
639 intptr_t offset = | 613 intptr_t offset = |
640 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 614 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
641 HandleLocalFunction(offset); | 615 HandleLocalFunction(offset); // read function node. |
642 return; | 616 return; |
643 } | 617 } |
644 case kLet: { | 618 case kLet: { |
645 PositionScope scope(builder_->reader_); | 619 PositionScope scope(builder_->reader_); |
646 intptr_t offset = | 620 intptr_t offset = |
647 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 621 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
648 | 622 |
649 EnterScope(offset); | 623 EnterScope(offset); |
650 | 624 |
651 VisitVariableDeclaration(); // read variable declaration. | 625 VisitVariableDeclaration(); // read variable declaration. |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 // factory constructor function. | 1084 // factory constructor function. |
1111 HandleSpecialLoad(&result_->type_arguments_variable, | 1085 HandleSpecialLoad(&result_->type_arguments_variable, |
1112 Symbols::TypeArgumentsParameter()); | 1086 Symbols::TypeArgumentsParameter()); |
1113 } else { | 1087 } else { |
1114 // The type argument vector is stored on the instance object. We therefore | 1088 // The type argument vector is stored on the instance object. We therefore |
1115 // need to capture `this`. | 1089 // need to capture `this`. |
1116 HandleSpecialLoad(&result_->this_variable, Symbols::This()); | 1090 HandleSpecialLoad(&result_->this_variable, Symbols::This()); |
1117 } | 1091 } |
1118 | 1092 |
1119 builder_->ReadUInt(); // read index for parameter. | 1093 builder_->ReadUInt(); // read index for parameter. |
1120 builder_->ReadUInt(); // read list binary offset. | |
1121 builder_->ReadUInt(); // read index in list. | |
1122 builder_->SkipOptionalDartType(); // read bound bound. | 1094 builder_->SkipOptionalDartType(); // read bound bound. |
1123 } | 1095 } |
1124 | 1096 |
1125 void StreamingScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) { | 1097 void StreamingScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) { |
1126 // "Peek" ahead into the function node | 1098 // "Peek" ahead into the function node |
1127 intptr_t offset = builder_->ReaderOffset(); | 1099 intptr_t offset = builder_->ReaderOffset(); |
1128 | 1100 |
1129 FunctionNodeHelper function_node_helper(builder_); | 1101 FunctionNodeHelper function_node_helper(builder_); |
1130 function_node_helper.ReadUntilExcluding( | 1102 function_node_helper.ReadUntilExcluding( |
1131 FunctionNodeHelper::kPositionalParameters); | 1103 FunctionNodeHelper::kPositionalParameters); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 ClassFinalizer::FinalizeType(*active_class_->klass, signature_type); | 1559 ClassFinalizer::FinalizeType(*active_class_->klass, signature_type); |
1588 // Do not refer to signature_function anymore, since it may have been | 1560 // Do not refer to signature_function anymore, since it may have been |
1589 // replaced during canonicalization. | 1561 // replaced during canonicalization. |
1590 signature_function = Function::null(); | 1562 signature_function = Function::null(); |
1591 } | 1563 } |
1592 | 1564 |
1593 result_ = signature_type.raw(); | 1565 result_ = signature_type.raw(); |
1594 } | 1566 } |
1595 | 1567 |
1596 void StreamingDartTypeTranslator::BuildTypeParameterType() { | 1568 void StreamingDartTypeTranslator::BuildTypeParameterType() { |
1597 builder_->ReadUInt(); // read parameter index. | 1569 intptr_t parameter_index = builder_->ReadUInt(); // read parameter index. |
1598 intptr_t binary_offset = builder_->ReadUInt(); // read lists binary offset. | 1570 builder_->SkipOptionalDartType(); // read bound. |
1599 intptr_t list_index = builder_->ReadUInt(); // read index in list. | |
1600 builder_->SkipOptionalDartType(); // read bound. | |
1601 | 1571 |
1602 ASSERT(binary_offset > 0); | 1572 TypeArguments& class_types = |
1573 dart::TypeArguments::Handle(Z, active_class_->klass->type_parameters()); | |
1574 if (class_types.Length() > parameter_index) { | |
Kevin Millikin (Google)
2017/08/08 14:08:51
It doesn't really matter but I find this and the c
jensj
2017/08/09 08:39:46
Done.
| |
1575 // The index of the type parameter in [parameters] is | |
1576 // the same index into the `klass->type_parameters()` array. | |
1577 result_ ^= class_types.TypeAt(parameter_index); | |
1578 return; | |
1579 } | |
1580 parameter_index -= class_types.Length(); | |
1581 | |
1582 if (active_class_->MemberIsFactoryProcedure()) { | |
Kevin Millikin (Google)
2017/08/08 14:08:51
It's kind of hard to reason about it, but I think
jensj
2017/08/09 08:39:47
Actually, a FactoryProcedure is always a procedure
| |
1583 // | |
1584 // WARNING: This is a little hackish: | |
1585 // | |
1586 // We have a static factory constructor. The kernel IR gives the factory | |
1587 // constructor function it's own type parameters (which are equal in name | |
1588 // and number to the ones of the enclosing class). | |
1589 // I.e., | |
1590 // | |
1591 // class A<T> { | |
1592 // factory A.x() { return new B<T>(); } | |
1593 // } | |
1594 // | |
1595 // is basically translated to this: | |
1596 // | |
1597 // class A<T> { | |
1598 // static A.x<T'>() { return new B<T'>(); } | |
1599 // } | |
1600 // | |
1601 if (class_types.Length() > parameter_index) { | |
1602 result_ ^= class_types.TypeAt(parameter_index); | |
1603 return; | |
1604 } | |
1605 parameter_index -= class_types.Length(); | |
1606 } | |
1607 | |
1608 bool member_is_procedure = active_class_->MemberIsProcedure(); | |
Kevin Millikin (Google)
2017/08/08 14:08:51
It seems weird to name it when there is only one u
jensj
2017/08/09 08:39:47
Fixed.
| |
1609 intptr_t procedure_type_parameter_count = | |
1610 member_is_procedure ? active_class_->MemberTypeParameterCount(Z) : 0; | |
1611 if (procedure_type_parameter_count > 0) { | |
1612 if (procedure_type_parameter_count > parameter_index) { | |
1613 // Here we technically could load the correct one via something like | |
1614 // result_ ^= dart::TypeArguments::Handle( | |
1615 // Z, active_class_->member->type_parameters()) | |
1616 // .TypeAt(parameter_index); | |
1617 // but that isn't currently supported elsewhere | |
1618 // (FlowGraphBuilder::LoadFunctionTypeArguments()). | |
1619 result_ ^= dart::Type::DynamicType(); | |
1620 return; | |
1621 } | |
1622 parameter_index -= procedure_type_parameter_count; | |
1623 } | |
1603 | 1624 |
1604 for (TypeParameterScope* scope = type_parameter_scope_; scope != NULL; | 1625 for (TypeParameterScope* scope = type_parameter_scope_; scope != NULL; |
Kevin Millikin (Google)
2017/08/08 14:08:51
This code just return DynamicType unless the binar
jensj
2017/08/09 08:39:47
While I'm not quite sure what you mean by longjmp
| |
1605 scope = scope->outer()) { | 1626 scope = scope->outer()) { |
1606 if (scope->parameters_offset() == binary_offset) { | 1627 if (parameter_index - scope->summed_outer_parameters_count() >= 0) { |
1628 if (parameter_index - scope->summed_outer_parameters_count() >= | |
1629 scope->parameters_count()) { | |
1630 UNREACHABLE(); | |
1631 } | |
1632 parameter_index -= scope->summed_outer_parameters_count(); | |
1607 result_ ^= dart::Type::DynamicType(); | 1633 result_ ^= dart::Type::DynamicType(); |
1608 return; | 1634 return; |
1609 } | 1635 } |
1610 } | 1636 } |
1611 | 1637 |
1612 if (active_class_->member_is_procedure) { | |
1613 if (active_class_->member_type_parameters > 0) { | |
1614 // | |
1615 // WARNING: This is a little hackish: | |
1616 // | |
1617 // We have a static factory constructor. The kernel IR gives the factory | |
1618 // constructor function it's own type parameters (which are equal in name | |
1619 // and number to the ones of the enclosing class). | |
1620 // I.e., | |
1621 // | |
1622 // class A<T> { | |
1623 // factory A.x() { return new B<T>(); } | |
1624 // } | |
1625 // | |
1626 // is basically translated to this: | |
1627 // | |
1628 // class A<T> { | |
1629 // static A.x<T'>() { return new B<T'>(); } | |
1630 // } | |
1631 // | |
1632 if (active_class_->member_type_parameters_offset_start == binary_offset) { | |
1633 if (active_class_->member_is_factory_procedure) { | |
1634 // The index of the type parameter in [parameters] is | |
1635 // the same index into the `klass->type_parameters()` array. | |
1636 result_ ^= dart::TypeArguments::Handle( | |
1637 Z, active_class_->klass->type_parameters()) | |
1638 .TypeAt(list_index); | |
1639 } else { | |
1640 result_ ^= dart::Type::DynamicType(); | |
1641 } | |
1642 return; | |
1643 } | |
1644 } | |
1645 } | |
1646 | |
1647 if (active_class_->class_type_parameters_offset_start == binary_offset) { | |
1648 // The index of the type parameter in [parameters] is | |
1649 // the same index into the `klass->type_parameters()` array. | |
1650 result_ ^= | |
1651 dart::TypeArguments::Handle(Z, active_class_->klass->type_parameters()) | |
1652 .TypeAt(list_index); | |
1653 return; | |
1654 } | |
1655 | |
1656 UNREACHABLE(); | 1638 UNREACHABLE(); |
1657 } | 1639 } |
1658 | 1640 |
1659 const TypeArguments& StreamingDartTypeTranslator::BuildTypeArguments( | 1641 const TypeArguments& StreamingDartTypeTranslator::BuildTypeArguments( |
1660 intptr_t length) { | 1642 intptr_t length) { |
1661 bool only_dynamic = true; | 1643 bool only_dynamic = true; |
1662 intptr_t offset = builder_->ReaderOffset(); | 1644 intptr_t offset = builder_->ReaderOffset(); |
1663 for (intptr_t i = 0; i < length; ++i) { | 1645 for (intptr_t i = 0; i < length; ++i) { |
1664 if (builder_->ReadTag() != kDynamicType) { // Read the ith types tag. | 1646 if (builder_->ReadTag() != kDynamicType) { // Read the ith types tag. |
1665 only_dynamic = false; | 1647 only_dynamic = false; |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2485 script_.set_compile_time_constants(array); | 2467 script_.set_compile_time_constants(array); |
2486 } | 2468 } |
2487 KernelConstantsMap constants(script_.compile_time_constants()); | 2469 KernelConstantsMap constants(script_.compile_time_constants()); |
2488 constants.InsertNewOrGetValue(kernel_offset, value); | 2470 constants.InsertNewOrGetValue(kernel_offset, value); |
2489 script_.set_compile_time_constants(constants.Release()); | 2471 script_.set_compile_time_constants(constants.Release()); |
2490 } | 2472 } |
2491 | 2473 |
2492 void StreamingFlowGraphBuilder::DiscoverEnclosingElements( | 2474 void StreamingFlowGraphBuilder::DiscoverEnclosingElements( |
2493 Zone* zone, | 2475 Zone* zone, |
2494 const Function& function, | 2476 const Function& function, |
2495 Function* outermost_function, | 2477 Function* outermost_function) { |
2496 intptr_t* outermost_kernel_offset, | |
2497 intptr_t* parent_class_offset) { | |
2498 // Find out if there is an enclosing kernel class (which will be used to | 2478 // Find out if there is an enclosing kernel class (which will be used to |
2499 // resolve type parameters). | 2479 // resolve type parameters). |
2500 *outermost_function = function.raw(); | 2480 *outermost_function = function.raw(); |
2501 while (outermost_function->parent_function() != Object::null()) { | 2481 while (outermost_function->parent_function() != Object::null()) { |
2502 *outermost_function = outermost_function->parent_function(); | 2482 *outermost_function = outermost_function->parent_function(); |
2503 } | 2483 } |
2504 | |
2505 if (outermost_function->kernel_offset() > 0) { | |
2506 *outermost_kernel_offset = outermost_function->kernel_offset(); | |
2507 *parent_class_offset = GetParentOffset(*outermost_kernel_offset); | |
2508 } | |
2509 } | |
2510 | |
2511 intptr_t StreamingFlowGraphBuilder::GetParentOffset(intptr_t offset) { | |
2512 AlternativeReadingScope alt(reader_, offset); | |
2513 | |
2514 Tag tag = PeekTag(); | |
2515 switch (tag) { | |
2516 case kConstructor: { | |
2517 ConstructorHelper constructor_helper(this); | |
2518 constructor_helper.ReadUntilIncluding( | |
2519 ConstructorHelper::kParentClassBinaryOffset); | |
2520 return constructor_helper.parent_class_binary_offset_; | |
2521 } | |
2522 case kProcedure: { | |
2523 ProcedureHelper procedure_helper(this); | |
2524 procedure_helper.ReadUntilIncluding( | |
2525 ProcedureHelper::kParentClassBinaryOffset); | |
2526 return procedure_helper.parent_class_binary_offset_; | |
2527 } | |
2528 case kField: { | |
2529 FieldHelper field_helper(this); | |
2530 field_helper.ReadUntilIncluding(FieldHelper::kParentClassBinaryOffset); | |
2531 return field_helper.parent_class_binary_offset_; | |
2532 } | |
2533 default: | |
2534 UNIMPLEMENTED(); | |
2535 return -1; | |
2536 } | |
2537 } | |
2538 | |
2539 void StreamingFlowGraphBuilder::GetTypeParameterInfoForClass( | |
2540 intptr_t class_offset, | |
2541 intptr_t* type_paremeter_counts, | |
2542 intptr_t* type_paremeter_offset) { | |
2543 AlternativeReadingScope alt(reader_, class_offset); | |
2544 | |
2545 ClassHelper class_helper(this); | |
2546 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); | |
2547 *type_paremeter_counts = | |
2548 ReadListLength(); // read type_parameters list length. | |
2549 *type_paremeter_offset = ReaderOffset(); | |
2550 } | |
2551 | |
2552 void StreamingFlowGraphBuilder::GetTypeParameterInfoForPossibleProcedure( | |
2553 intptr_t outermost_kernel_offset, | |
2554 bool* member_is_procedure, | |
2555 bool* is_factory_procedure, | |
2556 intptr_t* member_type_parameters, | |
2557 intptr_t* member_type_parameters_offset_start) { | |
2558 if (outermost_kernel_offset >= 0) { | |
2559 AlternativeReadingScope alt(reader_, outermost_kernel_offset); | |
2560 Tag tag = PeekTag(); | |
2561 if (tag == kProcedure) { | |
2562 *member_is_procedure = true; | |
2563 | |
2564 ProcedureHelper procedure_helper(this); | |
2565 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); | |
2566 *is_factory_procedure = procedure_helper.kind_ == Procedure::kFactory; | |
2567 if (ReadTag() == kSomething) { | |
2568 FunctionNodeHelper function_node_helper(this); | |
2569 function_node_helper.ReadUntilExcluding( | |
2570 FunctionNodeHelper::kTypeParameters); | |
2571 | |
2572 // read type_parameters list length. | |
2573 intptr_t list_length = ReadListLength(); | |
2574 if (list_length > 0) { | |
2575 *member_type_parameters = list_length; | |
2576 *member_type_parameters_offset_start = ReaderOffset(); | |
2577 } | |
2578 } | |
2579 } | |
2580 } | |
2581 } | 2484 } |
2582 | 2485 |
2583 intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() { | 2486 intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() { |
2584 const Tag tag = PeekTag(); | 2487 const Tag tag = PeekTag(); |
2585 if (tag == kProcedure) { | 2488 if (tag == kProcedure) { |
2586 ProcedureHelper procedure_helper(this); | 2489 ProcedureHelper procedure_helper(this); |
2587 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); | 2490 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
2588 if (ReadTag() == kNothing) { // read function node tag. | 2491 if (ReadTag() == kNothing) { // read function node tag. |
2589 // Running a procedure without a function node doesn't make sense. | 2492 // Running a procedure without a function node doesn't make sense. |
2590 UNREACHABLE(); | 2493 UNREACHABLE(); |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3384 | 3287 |
3385 FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) { | 3288 FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) { |
3386 const Function& function = parsed_function()->function(); | 3289 const Function& function = parsed_function()->function(); |
3387 | 3290 |
3388 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used | 3291 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used |
3389 // e.g. for type translation. | 3292 // e.g. for type translation. |
3390 const dart::Class& klass = | 3293 const dart::Class& klass = |
3391 dart::Class::Handle(zone_, parsed_function()->function().Owner()); | 3294 dart::Class::Handle(zone_, parsed_function()->function().Owner()); |
3392 | 3295 |
3393 Function& outermost_function = Function::Handle(Z); | 3296 Function& outermost_function = Function::Handle(Z); |
3394 intptr_t outermost_kernel_offset = -1; | 3297 DiscoverEnclosingElements(Z, function, &outermost_function); |
3395 intptr_t parent_class_offset = -1; | |
3396 DiscoverEnclosingElements(Z, function, &outermost_function, | |
3397 &outermost_kernel_offset, &parent_class_offset); | |
3398 // Use [klass]/[kernel_class] as active class. Type parameters will get | |
3399 // resolved via [kernel_class] unless we are nested inside a static factory | |
3400 // in which case we will use [member]. | |
3401 intptr_t class_type_parameters = 0; | |
3402 intptr_t class_type_parameters_offset_start = -1; | |
3403 if (parent_class_offset > 0) { | |
3404 GetTypeParameterInfoForClass(parent_class_offset, &class_type_parameters, | |
3405 &class_type_parameters_offset_start); | |
3406 } | |
3407 | 3298 |
3408 ActiveClassScope active_class_scope(active_class(), class_type_parameters, | 3299 ActiveClassScope active_class_scope(active_class(), &klass); |
3409 class_type_parameters_offset_start, | 3300 ActiveMemberScope active_member(active_class(), &outermost_function); |
3410 &klass); | |
3411 | |
3412 bool member_is_procedure = false; | |
3413 bool is_factory_procedure = false; | |
3414 intptr_t member_type_parameters = 0; | |
3415 intptr_t member_type_parameters_offset_start = -1; | |
3416 GetTypeParameterInfoForPossibleProcedure( | |
3417 outermost_kernel_offset, &member_is_procedure, &is_factory_procedure, | |
3418 &member_type_parameters, &member_type_parameters_offset_start); | |
3419 | |
3420 ActiveMemberScope active_member(active_class(), member_is_procedure, | |
3421 is_factory_procedure, member_type_parameters, | |
3422 member_type_parameters_offset_start); | |
3423 | 3301 |
3424 // The IR builder will create its own local variables and scopes, and it | 3302 // The IR builder will create its own local variables and scopes, and it |
3425 // will not need an AST. The code generator will assume that there is a | 3303 // will not need an AST. The code generator will assume that there is a |
3426 // local variable stack slot allocated for the current context and (I | 3304 // local variable stack slot allocated for the current context and (I |
3427 // think) that the runtime will expect it to be at a fixed offset which | 3305 // think) that the runtime will expect it to be at a fixed offset which |
3428 // requires allocating an unused expression temporary variable. | 3306 // requires allocating an unused expression temporary variable. |
3429 set_scopes(parsed_function()->EnsureKernelScopes()); | 3307 set_scopes(parsed_function()->EnsureKernelScopes()); |
3430 | 3308 |
3431 SetOffset(kernel_offset); | 3309 SetOffset(kernel_offset); |
3432 | 3310 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3758 SkipInterfaceType(true); | 3636 SkipInterfaceType(true); |
3759 return; | 3637 return; |
3760 case kFunctionType: | 3638 case kFunctionType: |
3761 SkipFunctionType(false); | 3639 SkipFunctionType(false); |
3762 return; | 3640 return; |
3763 case kSimpleFunctionType: | 3641 case kSimpleFunctionType: |
3764 SkipFunctionType(true); | 3642 SkipFunctionType(true); |
3765 return; | 3643 return; |
3766 case kTypeParameterType: | 3644 case kTypeParameterType: |
3767 ReadUInt(); // read index for parameter. | 3645 ReadUInt(); // read index for parameter. |
3768 ReadUInt(); // read list binary offset. | |
3769 ReadUInt(); // read index in list. | |
3770 SkipOptionalDartType(); // read bound bound. | 3646 SkipOptionalDartType(); // read bound bound. |
3771 return; | 3647 return; |
3772 default: | 3648 default: |
3773 UNREACHABLE(); | 3649 UNREACHABLE(); |
3774 } | 3650 } |
3775 } | 3651 } |
3776 | 3652 |
3777 void StreamingFlowGraphBuilder::SkipOptionalDartType() { | 3653 void StreamingFlowGraphBuilder::SkipOptionalDartType() { |
3778 Tag tag = ReadTag(); // read tag. | 3654 Tag tag = ReadTag(); // read tag. |
3779 if (tag == kNothing) { | 3655 if (tag == kNothing) { |
(...skipping 3512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7292 } | 7168 } |
7293 } | 7169 } |
7294 | 7170 |
7295 return Array::Handle(Array::null()); | 7171 return Array::Handle(Array::null()); |
7296 } | 7172 } |
7297 | 7173 |
7298 } // namespace kernel | 7174 } // namespace kernel |
7299 } // namespace dart | 7175 } // namespace dart |
7300 | 7176 |
7301 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 7177 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |