| 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 |
| 11 #if !defined(DART_PRECOMPILED_RUNTIME) | 11 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 namespace kernel { | 14 namespace kernel { |
| 15 | 15 |
| 16 #define Z (zone_) | 16 #define Z (zone_) |
| 17 #define H (translation_helper_) | 17 #define H (translation_helper_) |
| 18 #define T (type_translator_) | 18 #define T (type_translator_) |
| 19 #define I Isolate::Current() | 19 #define I Isolate::Current() |
| 20 | 20 |
| 21 static bool IsStaticInitializer(const Function& function, Zone* zone) { | 21 static bool IsStaticInitializer(const Function& function, Zone* zone) { |
| 22 return (function.kind() == RawFunction::kImplicitStaticFinalGetter) && | 22 return (function.kind() == RawFunction::kImplicitStaticFinalGetter) && |
| 23 dart::String::Handle(zone, function.name()) | 23 dart::String::Handle(zone, function.name()) |
| 24 .StartsWith(Symbols::InitPrefix()); | 24 .StartsWith(Symbols::InitPrefix()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function, | 27 StreamingScopeBuilder::StreamingScopeBuilder(ParsedFunction* parsed_function, |
| 28 intptr_t kernel_offset, | 28 intptr_t relative_kernel_offset, |
| 29 const uint8_t* buffer, | 29 const TypedData& data) |
| 30 intptr_t buffer_length) | |
| 31 : result_(NULL), | 30 : result_(NULL), |
| 32 parsed_function_(parsed_function), | 31 parsed_function_(parsed_function), |
| 33 kernel_offset_(kernel_offset), | 32 relative_kernel_offset_(relative_kernel_offset), |
| 34 translation_helper_(Thread::Current()), | 33 translation_helper_(Thread::Current()), |
| 35 zone_(translation_helper_.zone()), | 34 zone_(translation_helper_.zone()), |
| 36 current_function_scope_(NULL), | 35 current_function_scope_(NULL), |
| 37 scope_(NULL), | 36 scope_(NULL), |
| 38 depth_(0), | 37 depth_(0), |
| 39 name_index_(0), | 38 name_index_(0), |
| 40 needs_expr_temp_(false), | 39 needs_expr_temp_(false), |
| 41 builder_(new StreamingFlowGraphBuilder(&translation_helper_, | 40 builder_(new StreamingFlowGraphBuilder(&translation_helper_, |
| 42 zone_, | 41 zone_, |
| 43 buffer, | 42 relative_kernel_offset, |
| 44 buffer_length)), | 43 data)), |
| 45 type_translator_(builder_, /*finalize=*/true) { | 44 type_translator_(builder_, /*finalize=*/true) { |
| 46 Script& script = Script::Handle(Z, parsed_function->function().script()); | 45 Script& script = Script::Handle(Z, parsed_function->function().script()); |
| 47 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); | 46 H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets())); |
| 48 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); | 47 H.SetStringData(TypedData::Handle(Z, script.kernel_string_data())); |
| 49 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names())); | 48 H.SetCanonicalNames(TypedData::Handle(Z, script.kernel_canonical_names())); |
| 50 type_translator_.active_class_ = &active_class_; | 49 type_translator_.active_class_ = &active_class_; |
| 51 } | 50 } |
| 52 | 51 |
| 53 StreamingScopeBuilder::~StreamingScopeBuilder() { | 52 StreamingScopeBuilder::~StreamingScopeBuilder() { |
| 54 delete builder_; | 53 delete builder_; |
| 55 } | 54 } |
| 56 | 55 |
| 57 ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() { | 56 ScopeBuildingResult* StreamingScopeBuilder::BuildScopes() { |
| 58 if (result_ != NULL) return result_; | 57 if (result_ != NULL) return result_; |
| 59 | 58 |
| 60 ASSERT(scope_ == NULL && depth_.loop_ == 0 && depth_.function_ == 0); | 59 ASSERT(scope_ == NULL && depth_.loop_ == 0 && depth_.function_ == 0); |
| 61 result_ = new (Z) ScopeBuildingResult(); | 60 result_ = new (Z) ScopeBuildingResult(); |
| 62 | 61 |
| 63 ParsedFunction* parsed_function = parsed_function_; | 62 const Function& function = parsed_function_->function(); |
| 64 const Function& function = parsed_function->function(); | |
| 65 | 63 |
| 66 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used | 64 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used |
| 67 // e.g. for type translation. | 65 // e.g. for type translation. |
| 68 const dart::Class& klass = | 66 const dart::Class& klass = |
| 69 dart::Class::Handle(zone_, parsed_function_->function().Owner()); | 67 dart::Class::Handle(zone_, parsed_function_->function().Owner()); |
| 70 | 68 |
| 71 Function& outermost_function = Function::Handle(Z); | 69 Function& outermost_function = Function::Handle(Z); |
| 72 builder_->DiscoverEnclosingElements(Z, function, &outermost_function); | 70 builder_->DiscoverEnclosingElements(Z, function, &outermost_function); |
| 73 | 71 |
| 74 ActiveClassScope active_class_scope(&active_class_, &klass); | 72 ActiveClassScope active_class_scope(&active_class_, &klass); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 | 83 |
| 86 // Add function type arguments variable before current context variable. | 84 // Add function type arguments variable before current context variable. |
| 87 if (FLAG_reify_generic_functions && function.IsGeneric()) { | 85 if (FLAG_reify_generic_functions && function.IsGeneric()) { |
| 88 LocalVariable* type_args_var = MakeVariable( | 86 LocalVariable* type_args_var = MakeVariable( |
| 89 TokenPosition::kNoSource, TokenPosition::kNoSource, | 87 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 90 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type()); | 88 Symbols::FunctionTypeArgumentsVar(), AbstractType::dynamic_type()); |
| 91 scope_->AddVariable(type_args_var); | 89 scope_->AddVariable(type_args_var); |
| 92 parsed_function_->set_function_type_arguments(type_args_var); | 90 parsed_function_->set_function_type_arguments(type_args_var); |
| 93 } | 91 } |
| 94 | 92 |
| 95 LocalVariable* context_var = parsed_function->current_context_var(); | 93 LocalVariable* context_var = parsed_function_->current_context_var(); |
| 96 context_var->set_is_forced_stack(); | 94 context_var->set_is_forced_stack(); |
| 97 scope_->AddVariable(context_var); | 95 scope_->AddVariable(context_var); |
| 98 | 96 |
| 99 parsed_function->SetNodeSequence( | 97 parsed_function_->SetNodeSequence( |
| 100 new SequenceNode(TokenPosition::kNoSource, scope_)); | 98 new SequenceNode(TokenPosition::kNoSource, scope_)); |
| 101 | 99 |
| 102 builder_->SetOffset(kernel_offset_); | 100 builder_->SetOffset(0); |
| 103 | 101 |
| 104 FunctionNodeHelper function_node_helper(builder_); | 102 FunctionNodeHelper function_node_helper(builder_); |
| 105 | 103 |
| 106 switch (function.kind()) { | 104 switch (function.kind()) { |
| 107 case RawFunction::kClosureFunction: | 105 case RawFunction::kClosureFunction: |
| 108 case RawFunction::kImplicitClosureFunction: | 106 case RawFunction::kImplicitClosureFunction: |
| 109 case RawFunction::kConvertedClosureFunction: | 107 case RawFunction::kConvertedClosureFunction: |
| 110 case RawFunction::kRegularFunction: | 108 case RawFunction::kRegularFunction: |
| 111 case RawFunction::kGetterFunction: | 109 case RawFunction::kGetterFunction: |
| 112 case RawFunction::kSetterFunction: | 110 case RawFunction::kSetterFunction: |
| 113 case RawFunction::kConstructor: { | 111 case RawFunction::kConstructor: { |
| 114 const Tag tag = builder_->PeekTag(); | 112 const Tag tag = builder_->PeekTag(); |
| 115 intptr_t parent_offset = builder_->ReadUntilFunctionNode(); | 113 builder_->ReadUntilFunctionNode(); |
| 116 function_node_helper.ReadUntilExcluding( | 114 function_node_helper.ReadUntilExcluding( |
| 117 FunctionNodeHelper::kPositionalParameters); | 115 FunctionNodeHelper::kPositionalParameters); |
| 118 current_function_async_marker_ = function_node_helper.async_marker_; | 116 current_function_async_marker_ = function_node_helper.async_marker_; |
| 119 // NOTE: FunctionNode is read further below the if. | 117 // NOTE: FunctionNode is read further below the if. |
| 120 | 118 |
| 121 intptr_t pos = 0; | 119 intptr_t pos = 0; |
| 122 if (function.IsClosureFunction()) { | 120 if (function.IsClosureFunction()) { |
| 123 LocalVariable* variable = MakeVariable( | 121 LocalVariable* variable = MakeVariable( |
| 124 TokenPosition::kNoSource, TokenPosition::kNoSource, | 122 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 125 Symbols::ClosureParameter(), AbstractType::dynamic_type()); | 123 Symbols::ClosureParameter(), AbstractType::dynamic_type()); |
| 126 variable->set_is_forced_stack(); | 124 variable->set_is_forced_stack(); |
| 127 scope_->InsertParameterAt(pos++, variable); | 125 scope_->InsertParameterAt(pos++, variable); |
| 128 } else if (!function.is_static()) { | 126 } else if (!function.is_static()) { |
| 129 // We use [is_static] instead of [IsStaticFunction] because the latter | 127 // We use [is_static] instead of [IsStaticFunction] because the latter |
| 130 // returns `false` for constructors. | 128 // returns `false` for constructors. |
| 131 dart::Class& klass = dart::Class::Handle(Z, function.Owner()); | 129 dart::Class& klass = dart::Class::Handle(Z, function.Owner()); |
| 132 Type& klass_type = H.GetCanonicalType(klass); | 130 Type& klass_type = H.GetCanonicalType(klass); |
| 133 LocalVariable* variable = | 131 LocalVariable* variable = |
| 134 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, | 132 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 135 Symbols::This(), klass_type); | 133 Symbols::This(), klass_type); |
| 136 scope_->InsertParameterAt(pos++, variable); | 134 scope_->InsertParameterAt(pos++, variable); |
| 137 result_->this_variable = variable; | 135 result_->this_variable = variable; |
| 138 | 136 |
| 139 // We visit instance field initializers because they might contain | 137 // We visit instance field initializers because they might contain |
| 140 // [Let] expressions and we need to have a mapping. | 138 // [Let] expressions and we need to have a mapping. |
| 141 if (tag == kConstructor) { | 139 if (tag == kConstructor) { |
| 142 ASSERT(parent_offset >= 0); | 140 Class& parent_class = Class::Handle(Z, function.Owner()); |
| 143 AlternativeReadingScope alt(builder_->reader_, parent_offset); | 141 Array& class_fields = Array::Handle(Z, parent_class.fields()); |
| 144 ClassHelper class_helper(builder_); | 142 dart::Field& class_field = dart::Field::Handle(Z); |
| 145 class_helper.ReadUntilExcluding(ClassHelper::kFields); | 143 for (intptr_t i = 0; i < class_fields.Length(); ++i) { |
| 146 intptr_t list_length = | 144 class_field ^= class_fields.At(i); |
| 147 builder_->ReadListLength(); // read fields list length. | 145 if (!class_field.is_static()) { |
| 148 for (intptr_t i = 0; i < list_length; i++) { | 146 TypedData& kernel_data = |
| 149 intptr_t field_offset = builder_->ReaderOffset(); | 147 TypedData::Handle(Z, class_field.kernel_data()); |
| 150 FieldHelper field_helper(builder_); | 148 ASSERT(!kernel_data.IsNull()); |
| 151 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 149 AlternativeReadingScope alt(builder_->reader_, &kernel_data, 0); |
| 152 Tag initializer_tag = | 150 intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_; |
| 153 builder_->ReadTag(); // read first part of initializer. | 151 relative_kernel_offset_ = class_field.kernel_offset(); |
| 154 if (!field_helper.IsStatic() && initializer_tag == kSomething) { | 152 FieldHelper field_helper(builder_); |
| 155 EnterScope(field_offset); | 153 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 156 VisitExpression(); // read initializer. | 154 Tag initializer_tag = |
| 157 ExitScope(field_helper.position_, field_helper.end_position_); | 155 builder_->ReadTag(); // read first part of initializer. |
| 158 } else if (initializer_tag == kSomething) { | 156 if (initializer_tag == kSomething) { |
| 159 builder_->SkipExpression(); // read initializer. | 157 EnterScope(class_field.kernel_offset()); |
| 158 VisitExpression(); // read initializer. |
| 159 ExitScope(field_helper.position_, field_helper.end_position_); |
| 160 } |
| 161 relative_kernel_offset_ = saved_relative_kernel_offset_; |
| 160 } | 162 } |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 } else if (function.IsFactory()) { | 165 } else if (function.IsFactory()) { |
| 164 LocalVariable* variable = MakeVariable( | 166 LocalVariable* variable = MakeVariable( |
| 165 TokenPosition::kNoSource, TokenPosition::kNoSource, | 167 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 166 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); | 168 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); |
| 167 scope_->InsertParameterAt(pos++, variable); | 169 scope_->InsertParameterAt(pos++, variable); |
| 168 result_->type_arguments_variable = variable; | 170 result_->type_arguments_variable = variable; |
| 169 } | 171 } |
| 170 | 172 |
| 171 // Continue reading FunctionNode: | 173 // Continue reading FunctionNode: |
| 172 // read positional_parameters and named_parameters. | 174 // read positional_parameters and named_parameters. |
| 173 AddPositionalAndNamedParameters(pos); | 175 AddPositionalAndNamedParameters(pos); |
| 174 | 176 |
| 175 // We generate a syntethic body for implicit closure functions - which | 177 // We generate a synthetic body for implicit closure functions - which |
| 176 // will forward the call to the real function. | 178 // will forward the call to the real function. |
| 177 // -> see BuildGraphOfImplicitClosureFunction | 179 // -> see BuildGraphOfImplicitClosureFunction |
| 178 if (!function.IsImplicitClosureFunction()) { | 180 if (!function.IsImplicitClosureFunction()) { |
| 179 builder_->SetOffset(kernel_offset_); | 181 builder_->SetOffset(0); |
| 180 first_body_token_position_ = TokenPosition::kNoSource; | 182 first_body_token_position_ = TokenPosition::kNoSource; |
| 181 VisitNode(); | 183 VisitNode(); |
| 182 | 184 |
| 183 // TODO(jensj): HACK: Push the begin token to after any parameters to | 185 // TODO(jensj): HACK: Push the begin token to after any parameters to |
| 184 // avoid crash when breaking on definition line of async method in | 186 // avoid crash when breaking on definition line of async method in |
| 185 // debugger. It seems that another scope needs to be added | 187 // debugger. It seems that another scope needs to be added |
| 186 // in which captures are made, but I can't make that work. | 188 // in which captures are made, but I can't make that work. |
| 187 // This 'solution' doesn't crash, but I cannot see the parameters at | 189 // This 'solution' doesn't crash, but I cannot see the parameters at |
| 188 // that particular breakpoint either. | 190 // that particular breakpoint either. |
| 189 // Also push the end token to after the "}" to avoid crashing on | 191 // Also push the end token to after the "}" to avoid crashing on |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 scope_->InsertParameterAt(i, variable); | 251 scope_->InsertParameterAt(i, variable); |
| 250 } | 252 } |
| 251 break; | 253 break; |
| 252 case RawFunction::kSignatureFunction: | 254 case RawFunction::kSignatureFunction: |
| 253 case RawFunction::kIrregexpFunction: | 255 case RawFunction::kIrregexpFunction: |
| 254 UNREACHABLE(); | 256 UNREACHABLE(); |
| 255 } | 257 } |
| 256 if (needs_expr_temp_) { | 258 if (needs_expr_temp_) { |
| 257 scope_->AddVariable(parsed_function_->EnsureExpressionTemp()); | 259 scope_->AddVariable(parsed_function_->EnsureExpressionTemp()); |
| 258 } | 260 } |
| 259 parsed_function->AllocateVariables(); | 261 parsed_function_->AllocateVariables(); |
| 260 | 262 |
| 261 return result_; | 263 return result_; |
| 262 } | 264 } |
| 263 | 265 |
| 264 void StreamingScopeBuilder::VisitNode() { | 266 void StreamingScopeBuilder::VisitNode() { |
| 265 Tag tag = builder_->PeekTag(); | 267 Tag tag = builder_->PeekTag(); |
| 266 switch (tag) { | 268 switch (tag) { |
| 267 case kConstructor: | 269 case kConstructor: |
| 268 VisitConstructor(); | 270 VisitConstructor(); |
| 269 return; | 271 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 283 } | 285 } |
| 284 | 286 |
| 285 void StreamingScopeBuilder::VisitConstructor() { | 287 void StreamingScopeBuilder::VisitConstructor() { |
| 286 // Field initializers that come from non-static field declarations are | 288 // Field initializers that come from non-static field declarations are |
| 287 // compiled as if they appear in the constructor initializer list. This is | 289 // compiled as if they appear in the constructor initializer list. This is |
| 288 // important for closure-valued field initializers because the VM expects the | 290 // important for closure-valued field initializers because the VM expects the |
| 289 // corresponding closure functions to appear as if they were nested inside the | 291 // corresponding closure functions to appear as if they were nested inside the |
| 290 // constructor. | 292 // constructor. |
| 291 ConstructorHelper constructor_helper(builder_); | 293 ConstructorHelper constructor_helper(builder_); |
| 292 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); | 294 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); |
| 293 intptr_t parent_offset = constructor_helper.parent_class_binary_offset_; | |
| 294 ASSERT(parent_offset >= 0); | |
| 295 { | 295 { |
| 296 AlternativeReadingScope alt(builder_->reader_, parent_offset); | 296 const Function& function = parsed_function_->function(); |
| 297 ClassHelper class_helper(builder_); | 297 Class& parent_class = Class::Handle(Z, function.Owner()); |
| 298 class_helper.ReadUntilExcluding(ClassHelper::kFields); | 298 Array& class_fields = Array::Handle(Z, parent_class.fields()); |
| 299 | 299 dart::Field& class_field = dart::Field::Handle(Z); |
| 300 intptr_t list_length = | 300 for (intptr_t i = 0; i < class_fields.Length(); ++i) { |
| 301 builder_->ReadListLength(); // read fields list length. | 301 class_field ^= class_fields.At(i); |
| 302 for (intptr_t i = 0; i < list_length; i++) { | 302 if (!class_field.is_static()) { |
| 303 FieldHelper field_helper(builder_); | 303 TypedData& kernel_data = |
| 304 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 304 TypedData::Handle(Z, class_field.kernel_data()); |
| 305 Tag initializer_tag = builder_->ReadTag(); | 305 ASSERT(!kernel_data.IsNull()); |
| 306 if (!field_helper.IsStatic() && initializer_tag == kSomething) { | 306 AlternativeReadingScope alt(builder_->reader_, &kernel_data, 0); |
| 307 VisitExpression(); // read initializer. | 307 intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_; |
| 308 } else if (initializer_tag == kSomething) { | 308 relative_kernel_offset_ = class_field.kernel_offset(); |
| 309 builder_->SkipExpression(); // read initializer. | 309 FieldHelper field_helper(builder_); |
| 310 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 311 Tag initializer_tag = builder_->ReadTag(); |
| 312 if (initializer_tag == kSomething) { |
| 313 VisitExpression(); // read initializer. |
| 314 } |
| 315 relative_kernel_offset_ = saved_relative_kernel_offset_; |
| 310 } | 316 } |
| 311 } | 317 } |
| 312 } | 318 } |
| 313 | 319 |
| 314 // Visit children (note that there's no reason to visit the name). | 320 // Visit children (note that there's no reason to visit the name). |
| 315 VisitFunctionNode(); | 321 VisitFunctionNode(); |
| 316 intptr_t list_length = | 322 intptr_t list_length = |
| 317 builder_->ReadListLength(); // read initializers list length. | 323 builder_->ReadListLength(); // read initializers list length. |
| 318 for (intptr_t i = 0; i < list_length; i++) { | 324 for (intptr_t i = 0; i < list_length; i++) { |
| 319 VisitInitializer(); | 325 VisitInitializer(); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 intptr_t offset = | 619 intptr_t offset = |
| 614 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 620 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 615 HandleLocalFunction(offset); // read function node. | 621 HandleLocalFunction(offset); // read function node. |
| 616 return; | 622 return; |
| 617 } | 623 } |
| 618 case kLet: { | 624 case kLet: { |
| 619 PositionScope scope(builder_->reader_); | 625 PositionScope scope(builder_->reader_); |
| 620 intptr_t offset = | 626 intptr_t offset = |
| 621 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 627 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 622 | 628 |
| 623 EnterScope(offset); | 629 EnterScope(relative_kernel_offset_ + offset); |
| 624 | 630 |
| 625 VisitVariableDeclaration(); // read variable declaration. | 631 VisitVariableDeclaration(); // read variable declaration. |
| 626 VisitExpression(); // read expression. | 632 VisitExpression(); // read expression. |
| 627 | 633 |
| 628 ExitScope(builder_->reader_->min_position(), | 634 ExitScope(builder_->reader_->min_position(), |
| 629 builder_->reader_->max_position()); | 635 builder_->reader_->max_position()); |
| 630 return; | 636 return; |
| 631 } | 637 } |
| 632 case kBigIntLiteral: | 638 case kBigIntLiteral: |
| 633 builder_->SkipStringReference(); // read string reference. | 639 builder_->SkipStringReference(); // read string reference. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 case kInvalidStatement: | 690 case kInvalidStatement: |
| 685 return; | 691 return; |
| 686 case kExpressionStatement: | 692 case kExpressionStatement: |
| 687 VisitExpression(); // read expression. | 693 VisitExpression(); // read expression. |
| 688 return; | 694 return; |
| 689 case kBlock: { | 695 case kBlock: { |
| 690 PositionScope scope(builder_->reader_); | 696 PositionScope scope(builder_->reader_); |
| 691 intptr_t offset = | 697 intptr_t offset = |
| 692 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 698 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 693 | 699 |
| 694 EnterScope(offset); | 700 EnterScope(relative_kernel_offset_ + offset); |
| 695 | 701 |
| 696 intptr_t list_length = | 702 intptr_t list_length = |
| 697 builder_->ReadListLength(); // read number of statements. | 703 builder_->ReadListLength(); // read number of statements. |
| 698 for (intptr_t i = 0; i < list_length; ++i) { | 704 for (intptr_t i = 0; i < list_length; ++i) { |
| 699 VisitStatement(); // read ith statement. | 705 VisitStatement(); // read ith statement. |
| 700 } | 706 } |
| 701 | 707 |
| 702 ExitScope(builder_->reader_->min_position(), | 708 ExitScope(builder_->reader_->min_position(), |
| 703 builder_->reader_->max_position()); | 709 builder_->reader_->max_position()); |
| 704 return; | 710 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 VisitStatement(); // read body. | 751 VisitStatement(); // read body. |
| 746 VisitExpression(); // read condition. | 752 VisitExpression(); // read condition. |
| 747 --depth_.loop_; | 753 --depth_.loop_; |
| 748 return; | 754 return; |
| 749 case kForStatement: { | 755 case kForStatement: { |
| 750 PositionScope scope(builder_->reader_); | 756 PositionScope scope(builder_->reader_); |
| 751 | 757 |
| 752 intptr_t offset = | 758 intptr_t offset = |
| 753 builder_->ReaderOffset() - 1; // -1 to include tag byte. | 759 builder_->ReaderOffset() - 1; // -1 to include tag byte. |
| 754 | 760 |
| 755 EnterScope(offset); | 761 EnterScope(relative_kernel_offset_ + offset); |
| 756 | 762 |
| 757 TokenPosition position = builder_->ReadPosition(); // read position. | 763 TokenPosition position = builder_->ReadPosition(); // read position. |
| 758 intptr_t list_length = | 764 intptr_t list_length = |
| 759 builder_->ReadListLength(); // read number of variables. | 765 builder_->ReadListLength(); // read number of variables. |
| 760 for (intptr_t i = 0; i < list_length; ++i) { | 766 for (intptr_t i = 0; i < list_length; ++i) { |
| 761 VisitVariableDeclaration(); // read ith variable. | 767 VisitVariableDeclaration(); // read ith variable. |
| 762 } | 768 } |
| 763 | 769 |
| 764 ++depth_.loop_; | 770 ++depth_.loop_; |
| 765 | 771 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 791 | 797 |
| 792 // Notice the ordering: We skip the variable, read the iterable, go back, | 798 // Notice the ordering: We skip the variable, read the iterable, go back, |
| 793 // re-read the variable, go forward to after having read the iterable. | 799 // re-read the variable, go forward to after having read the iterable. |
| 794 intptr_t offset = builder_->ReaderOffset(); | 800 intptr_t offset = builder_->ReaderOffset(); |
| 795 builder_->SkipVariableDeclaration(); // read variable. | 801 builder_->SkipVariableDeclaration(); // read variable. |
| 796 VisitExpression(); // read iterable. | 802 VisitExpression(); // read iterable. |
| 797 | 803 |
| 798 ++depth_.for_in_; | 804 ++depth_.for_in_; |
| 799 AddIteratorVariable(); | 805 AddIteratorVariable(); |
| 800 ++depth_.loop_; | 806 ++depth_.loop_; |
| 801 EnterScope(start_offset); | 807 EnterScope(relative_kernel_offset_ + start_offset); |
| 802 | 808 |
| 803 { | 809 { |
| 804 AlternativeReadingScope alt(builder_->reader_, offset); | 810 AlternativeReadingScope alt(builder_->reader_, offset); |
| 805 VisitVariableDeclaration(); // read variable. | 811 VisitVariableDeclaration(); // read variable. |
| 806 } | 812 } |
| 807 VisitStatement(); // read body. | 813 VisitStatement(); // read body. |
| 808 | 814 |
| 809 if (!body_position.IsReal()) { | 815 if (!body_position.IsReal()) { |
| 810 body_position = builder_->reader_->min_position(); | 816 body_position = builder_->reader_->min_position(); |
| 811 } | 817 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 ++depth_.catch_; | 873 ++depth_.catch_; |
| 868 AddCatchVariables(); | 874 AddCatchVariables(); |
| 869 | 875 |
| 870 builder_->ReadBool(); // read any_catch_needs_stack_trace. | 876 builder_->ReadBool(); // read any_catch_needs_stack_trace. |
| 871 intptr_t catch_count = | 877 intptr_t catch_count = |
| 872 builder_->ReadListLength(); // read number of catches. | 878 builder_->ReadListLength(); // read number of catches. |
| 873 for (intptr_t i = 0; i < catch_count; ++i) { | 879 for (intptr_t i = 0; i < catch_count; ++i) { |
| 874 PositionScope scope(builder_->reader_); | 880 PositionScope scope(builder_->reader_); |
| 875 intptr_t offset = builder_->ReaderOffset(); // Catch has no tag. | 881 intptr_t offset = builder_->ReaderOffset(); // Catch has no tag. |
| 876 | 882 |
| 877 EnterScope(offset); | 883 EnterScope(relative_kernel_offset_ + offset); |
| 878 | 884 |
| 879 VisitDartType(); // Read the guard. | 885 VisitDartType(); // Read the guard. |
| 880 tag = builder_->ReadTag(); // read first part of exception. | 886 tag = builder_->ReadTag(); // read first part of exception. |
| 881 if (tag == kSomething) { | 887 if (tag == kSomething) { |
| 882 VisitVariableDeclaration(); // read exception. | 888 VisitVariableDeclaration(); // read exception. |
| 883 } | 889 } |
| 884 tag = builder_->ReadTag(); // read first part of stack trace. | 890 tag = builder_->ReadTag(); // read first part of stack trace. |
| 885 if (tag == kSomething) { | 891 if (tag == kSomething) { |
| 886 VisitVariableDeclaration(); // read stack trace. | 892 VisitVariableDeclaration(); // read stack trace. |
| 887 } | 893 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 TokenPosition end_position = builder_->reader_->max_position(); | 1002 TokenPosition end_position = builder_->reader_->max_position(); |
| 997 if (end_position.IsReal()) { | 1003 if (end_position.IsReal()) { |
| 998 end_position.Next(); | 1004 end_position.Next(); |
| 999 } | 1005 } |
| 1000 LocalVariable* variable = | 1006 LocalVariable* variable = |
| 1001 MakeVariable(helper.position_, end_position, name, type); | 1007 MakeVariable(helper.position_, end_position, name, type); |
| 1002 if (helper.IsFinal()) { | 1008 if (helper.IsFinal()) { |
| 1003 variable->set_is_final(); | 1009 variable->set_is_final(); |
| 1004 } | 1010 } |
| 1005 scope_->AddVariable(variable); | 1011 scope_->AddVariable(variable); |
| 1006 result_->locals.Insert(kernel_offset_no_tag, variable); | 1012 result_->locals.Insert(relative_kernel_offset_ + kernel_offset_no_tag, |
| 1013 variable); |
| 1007 } | 1014 } |
| 1008 | 1015 |
| 1009 void StreamingScopeBuilder::VisitDartType() { | 1016 void StreamingScopeBuilder::VisitDartType() { |
| 1010 Tag tag = builder_->ReadTag(); | 1017 Tag tag = builder_->ReadTag(); |
| 1011 switch (tag) { | 1018 switch (tag) { |
| 1012 case kInvalidType: | 1019 case kInvalidType: |
| 1013 case kDynamicType: | 1020 case kDynamicType: |
| 1014 case kVoidType: | 1021 case kVoidType: |
| 1015 case kBottomType: | 1022 case kBottomType: |
| 1016 case kVectorType: | 1023 case kVectorType: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 | 1117 |
| 1111 FunctionNodeHelper function_node_helper(builder_); | 1118 FunctionNodeHelper function_node_helper(builder_); |
| 1112 function_node_helper.ReadUntilExcluding( | 1119 function_node_helper.ReadUntilExcluding( |
| 1113 FunctionNodeHelper::kPositionalParameters); | 1120 FunctionNodeHelper::kPositionalParameters); |
| 1114 | 1121 |
| 1115 LocalScope* saved_function_scope = current_function_scope_; | 1122 LocalScope* saved_function_scope = current_function_scope_; |
| 1116 FunctionNode::AsyncMarker saved_function_async_marker = | 1123 FunctionNode::AsyncMarker saved_function_async_marker = |
| 1117 current_function_async_marker_; | 1124 current_function_async_marker_; |
| 1118 StreamingScopeBuilder::DepthState saved_depth_state = depth_; | 1125 StreamingScopeBuilder::DepthState saved_depth_state = depth_; |
| 1119 depth_ = DepthState(depth_.function_ + 1); | 1126 depth_ = DepthState(depth_.function_ + 1); |
| 1120 EnterScope(parent_kernel_offset); | 1127 EnterScope(relative_kernel_offset_ + parent_kernel_offset); |
| 1121 current_function_scope_ = scope_; | 1128 current_function_scope_ = scope_; |
| 1122 current_function_async_marker_ = function_node_helper.async_marker_; | 1129 current_function_async_marker_ = function_node_helper.async_marker_; |
| 1123 if (depth_.function_ == 1) { | 1130 if (depth_.function_ == 1) { |
| 1124 FunctionScope function_scope = {offset, scope_}; | 1131 FunctionScope function_scope = {relative_kernel_offset_ + offset, scope_}; |
| 1125 result_->function_scopes.Add(function_scope); | 1132 result_->function_scopes.Add(function_scope); |
| 1126 } | 1133 } |
| 1127 | 1134 |
| 1128 // read positional_parameters and named_parameters. | 1135 // read positional_parameters and named_parameters. |
| 1129 AddPositionalAndNamedParameters(); | 1136 AddPositionalAndNamedParameters(); |
| 1130 | 1137 |
| 1131 // "Peek" is now done. | 1138 // "Peek" is now done. |
| 1132 builder_->SetOffset(offset); | 1139 builder_->SetOffset(offset); |
| 1133 | 1140 |
| 1134 VisitFunctionNode(); // read function node. | 1141 VisitFunctionNode(); // read function node. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 | 1184 |
| 1178 LocalVariable* variable = | 1185 LocalVariable* variable = |
| 1179 MakeVariable(helper.position_, helper.position_, name, type); | 1186 MakeVariable(helper.position_, helper.position_, name, type); |
| 1180 if (helper.IsFinal()) { | 1187 if (helper.IsFinal()) { |
| 1181 variable->set_is_final(); | 1188 variable->set_is_final(); |
| 1182 } | 1189 } |
| 1183 if (variable->name().raw() == Symbols::IteratorParameter().raw()) { | 1190 if (variable->name().raw() == Symbols::IteratorParameter().raw()) { |
| 1184 variable->set_is_forced_stack(); | 1191 variable->set_is_forced_stack(); |
| 1185 } | 1192 } |
| 1186 scope_->InsertParameterAt(pos, variable); | 1193 scope_->InsertParameterAt(pos, variable); |
| 1187 result_->locals.Insert(kernel_offset, variable); | 1194 result_->locals.Insert(relative_kernel_offset_ + kernel_offset, variable); |
| 1188 | 1195 |
| 1189 // The default value may contain 'let' bindings for which the constant | 1196 // The default value may contain 'let' bindings for which the constant |
| 1190 // evaluator needs scope bindings. | 1197 // evaluator needs scope bindings. |
| 1191 Tag tag = builder_->ReadTag(); | 1198 Tag tag = builder_->ReadTag(); |
| 1192 if (tag == kSomething) { | 1199 if (tag == kSomething) { |
| 1193 VisitExpression(); // read initializer. | 1200 VisitExpression(); // read initializer. |
| 1194 } | 1201 } |
| 1195 } | 1202 } |
| 1196 | 1203 |
| 1197 LocalVariable* StreamingScopeBuilder::MakeVariable( | 1204 LocalVariable* StreamingScopeBuilder::MakeVariable( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 if ((depth_.function_ == 0) && (result_->switch_variable == NULL)) { | 1282 if ((depth_.function_ == 0) && (result_->switch_variable == NULL)) { |
| 1276 LocalVariable* variable = | 1283 LocalVariable* variable = |
| 1277 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, | 1284 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 1278 Symbols::SwitchExpr(), AbstractType::dynamic_type()); | 1285 Symbols::SwitchExpr(), AbstractType::dynamic_type()); |
| 1279 variable->set_is_forced_stack(); | 1286 variable->set_is_forced_stack(); |
| 1280 current_function_scope_->AddVariable(variable); | 1287 current_function_scope_->AddVariable(variable); |
| 1281 result_->switch_variable = variable; | 1288 result_->switch_variable = variable; |
| 1282 } | 1289 } |
| 1283 } | 1290 } |
| 1284 | 1291 |
| 1285 void StreamingScopeBuilder::LookupVariable(intptr_t declaration_binary_offest) { | 1292 void StreamingScopeBuilder::LookupVariable(intptr_t declaration_binary_offset) { |
| 1286 LocalVariable* variable = result_->locals.Lookup(declaration_binary_offest); | 1293 LocalVariable* variable = result_->locals.Lookup(declaration_binary_offset); |
| 1287 if (variable == NULL) { | 1294 if (variable == NULL) { |
| 1288 // We have not seen a declaration of the variable, so it must be the | 1295 // We have not seen a declaration of the variable, so it must be the |
| 1289 // case that we are compiling a nested function and the variable is | 1296 // case that we are compiling a nested function and the variable is |
| 1290 // declared in an outer scope. In that case, look it up in the scope by | 1297 // declared in an outer scope. In that case, look it up in the scope by |
| 1291 // name and add it to the variable map to simplify later lookup. | 1298 // name and add it to the variable map to simplify later lookup. |
| 1292 ASSERT(current_function_scope_->parent() != NULL); | 1299 ASSERT(current_function_scope_->parent() != NULL); |
| 1293 | 1300 StringIndex var_name = builder_->GetNameFromVariableDeclaration( |
| 1294 StringIndex var_name = | 1301 declaration_binary_offset, parsed_function_->function()); |
| 1295 builder_->GetNameFromVariableDeclaration(declaration_binary_offest); | |
| 1296 | 1302 |
| 1297 const dart::String& name = H.DartSymbol(var_name); | 1303 const dart::String& name = H.DartSymbol(var_name); |
| 1298 variable = current_function_scope_->parent()->LookupVariable(name, true); | 1304 variable = current_function_scope_->parent()->LookupVariable(name, true); |
| 1299 ASSERT(variable != NULL); | 1305 ASSERT(variable != NULL); |
| 1300 result_->locals.Insert(declaration_binary_offest, variable); | 1306 result_->locals.Insert(declaration_binary_offset, variable); |
| 1301 } | 1307 } |
| 1302 | 1308 |
| 1303 if (variable->owner()->function_level() < scope_->function_level()) { | 1309 if (variable->owner()->function_level() < scope_->function_level()) { |
| 1304 // We call `LocalScope->CaptureVariable(variable)` in two scenarios for two | 1310 // We call `LocalScope->CaptureVariable(variable)` in two scenarios for two |
| 1305 // different reasons: | 1311 // different reasons: |
| 1306 // Scenario 1: | 1312 // Scenario 1: |
| 1307 // We need to know which variables defined in this function | 1313 // We need to know which variables defined in this function |
| 1308 // are closed over by nested closures in order to ensure we will | 1314 // are closed over by nested closures in order to ensure we will |
| 1309 // create a [Context] object of appropriate size and store captured | 1315 // create a [Context] object of appropriate size and store captured |
| 1310 // variables there instead of the stack. | 1316 // variables there instead of the stack. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 dart::Object::Handle(Z, H.LookupClassByKernelClass(klass_name)); | 1472 dart::Object::Handle(Z, H.LookupClassByKernelClass(klass_name)); |
| 1467 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); | 1473 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); |
| 1468 if (finalize_) { | 1474 if (finalize_) { |
| 1469 ASSERT(active_class_->klass != NULL); | 1475 ASSERT(active_class_->klass != NULL); |
| 1470 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_); | 1476 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_); |
| 1471 } | 1477 } |
| 1472 } | 1478 } |
| 1473 | 1479 |
| 1474 void StreamingDartTypeTranslator::BuildFunctionType(bool simple) { | 1480 void StreamingDartTypeTranslator::BuildFunctionType(bool simple) { |
| 1475 intptr_t list_length = 0; | 1481 intptr_t list_length = 0; |
| 1476 intptr_t first_item_offest = -1; | |
| 1477 if (!simple) { | 1482 if (!simple) { |
| 1478 list_length = | 1483 list_length = |
| 1479 builder_->ReadListLength(); // read type_parameters list length | 1484 builder_->ReadListLength(); // read type_parameters list length |
| 1480 first_item_offest = builder_->ReaderOffset(); | |
| 1481 for (int i = 0; i < list_length; ++i) { | 1485 for (int i = 0; i < list_length; ++i) { |
| 1482 builder_->SkipStringReference(); // read string index (name). | 1486 builder_->SkipStringReference(); // read string index (name). |
| 1483 builder_->SkipDartType(); // read dart type. | 1487 builder_->SkipDartType(); // read dart type. |
| 1484 } | 1488 } |
| 1485 } | 1489 } |
| 1486 | 1490 |
| 1487 // The spec describes in section "19.1 Static Types": | 1491 // The spec describes in section "19.1 Static Types": |
| 1488 // | 1492 // |
| 1489 // Any use of a malformed type gives rise to a static warning. A | 1493 // Any use of a malformed type gives rise to a static warning. A |
| 1490 // malformed type is then interpreted as dynamic by the static type | 1494 // malformed type is then interpreted as dynamic by the static type |
| 1491 // checker and the runtime unless explicitly specified otherwise. | 1495 // checker and the runtime unless explicitly specified otherwise. |
| 1492 // | 1496 // |
| 1493 // So we convert malformed return/parameter types to `dynamic`. | 1497 // So we convert malformed return/parameter types to `dynamic`. |
| 1494 TypeParameterScope scope(this, first_item_offest, list_length); | 1498 TypeParameterScope scope(this, list_length); |
| 1495 | 1499 |
| 1496 Function& signature_function = Function::ZoneHandle( | 1500 Function& signature_function = Function::ZoneHandle( |
| 1497 Z, | 1501 Z, |
| 1498 Function::NewSignatureFunction(*active_class_->klass, Function::Handle(Z), | 1502 Function::NewSignatureFunction(*active_class_->klass, Function::Handle(Z), |
| 1499 TokenPosition::kNoSource)); | 1503 TokenPosition::kNoSource)); |
| 1500 | 1504 |
| 1501 intptr_t required_count; | 1505 intptr_t required_count; |
| 1502 intptr_t all_count; | 1506 intptr_t all_count; |
| 1503 intptr_t positional_count; | 1507 intptr_t positional_count; |
| 1504 if (!simple) { | 1508 if (!simple) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 // (FlowGraphBuilder::LoadFunctionTypeArguments()). | 1638 // (FlowGraphBuilder::LoadFunctionTypeArguments()). |
| 1635 result_ ^= dart::Type::DynamicType(); | 1639 result_ ^= dart::Type::DynamicType(); |
| 1636 return; | 1640 return; |
| 1637 } | 1641 } |
| 1638 parameter_index -= procedure_type_parameter_count; | 1642 parameter_index -= procedure_type_parameter_count; |
| 1639 } | 1643 } |
| 1640 } | 1644 } |
| 1641 | 1645 |
| 1642 if (type_parameter_scope_ != NULL && parameter_index >= 0 && | 1646 if (type_parameter_scope_ != NULL && parameter_index >= 0 && |
| 1643 parameter_index < type_parameter_scope_->outer_parameter_count() + | 1647 parameter_index < type_parameter_scope_->outer_parameter_count() + |
| 1644 type_parameter_scope_->parameters_count()) { | 1648 type_parameter_scope_->parameter_count()) { |
| 1645 result_ ^= dart::Type::DynamicType(); | 1649 result_ ^= dart::Type::DynamicType(); |
| 1646 return; | 1650 return; |
| 1647 } | 1651 } |
| 1648 | 1652 |
| 1649 H.ReportError("Unexpected input. Please report this at dartbug.com."); | 1653 H.ReportError("Unexpected input. Please report this at dartbug.com."); |
| 1650 } | 1654 } |
| 1651 | 1655 |
| 1652 const TypeArguments& StreamingDartTypeTranslator::BuildTypeArguments( | 1656 const TypeArguments& StreamingDartTypeTranslator::BuildTypeArguments( |
| 1653 intptr_t length) { | 1657 intptr_t length) { |
| 1654 bool only_dynamic = true; | 1658 bool only_dynamic = true; |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2235 | 2239 |
| 2236 // NOTE: This needs to be kept in sync with `runtime/lib/immutable_map.dart`! | 2240 // NOTE: This needs to be kept in sync with `runtime/lib/immutable_map.dart`! |
| 2237 result_ = Instance::New(map_class, Heap::kOld); | 2241 result_ = Instance::New(map_class, Heap::kOld); |
| 2238 ASSERT(!result_.IsNull()); | 2242 ASSERT(!result_.IsNull()); |
| 2239 result_.SetTypeArguments(type_arguments); | 2243 result_.SetTypeArguments(type_arguments); |
| 2240 result_.SetField(field, const_kv_array); | 2244 result_.SetField(field, const_kv_array); |
| 2241 result_ = H.Canonicalize(result_); | 2245 result_ = H.Canonicalize(result_); |
| 2242 } | 2246 } |
| 2243 | 2247 |
| 2244 void StreamingConstantEvaluator::EvaluateLet() { | 2248 void StreamingConstantEvaluator::EvaluateLet() { |
| 2245 intptr_t kernel_position = builder_->ReaderOffset(); | 2249 intptr_t kernel_position = |
| 2250 builder_->ReaderOffset() + builder_->relative_kernel_offset_; |
| 2246 LocalVariable* local = builder_->LookupVariable(kernel_position); | 2251 LocalVariable* local = builder_->LookupVariable(kernel_position); |
| 2247 | 2252 |
| 2248 // read variable declaration. | 2253 // read variable declaration. |
| 2249 VariableDeclarationHelper helper(builder_); | 2254 VariableDeclarationHelper helper(builder_); |
| 2250 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); | 2255 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
| 2251 Tag tag = builder_->ReadTag(); // read (first part of) initializer. | 2256 Tag tag = builder_->ReadTag(); // read (first part of) initializer. |
| 2252 if (tag == kNothing) { | 2257 if (tag == kNothing) { |
| 2253 local->SetConstValue(Instance::ZoneHandle(Z, dart::Instance::null())); | 2258 local->SetConstValue(Instance::ZoneHandle(Z, dart::Instance::null())); |
| 2254 } else { | 2259 } else { |
| 2255 local->SetConstValue(EvaluateExpression( | 2260 local->SetConstValue(EvaluateExpression( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 if (constructor.IsFactory()) { | 2404 if (constructor.IsFactory()) { |
| 2400 // The factory method returns the allocated object. | 2405 // The factory method returns the allocated object. |
| 2401 instance ^= result.raw(); | 2406 instance ^= result.raw(); |
| 2402 } | 2407 } |
| 2403 return H.Canonicalize(instance); | 2408 return H.Canonicalize(instance); |
| 2404 } | 2409 } |
| 2405 | 2410 |
| 2406 const TypeArguments* StreamingConstantEvaluator::TranslateTypeArguments( | 2411 const TypeArguments* StreamingConstantEvaluator::TranslateTypeArguments( |
| 2407 const Function& target, | 2412 const Function& target, |
| 2408 dart::Class* target_klass) { | 2413 dart::Class* target_klass) { |
| 2409 intptr_t types_count = builder_->ReadListLength(); // read types count. | 2414 intptr_t type_count = builder_->ReadListLength(); // read type count. |
| 2410 | 2415 |
| 2411 const TypeArguments* type_arguments = NULL; | 2416 const TypeArguments* type_arguments = NULL; |
| 2412 if (types_count > 0) { | 2417 if (type_count > 0) { |
| 2413 type_arguments = &T.BuildInstantiatedTypeArguments( | 2418 type_arguments = &T.BuildInstantiatedTypeArguments( |
| 2414 *target_klass, types_count); // read types. | 2419 *target_klass, type_count); // read types. |
| 2415 | 2420 |
| 2416 if (!(type_arguments->IsNull() || type_arguments->IsInstantiated())) { | 2421 if (!(type_arguments->IsNull() || type_arguments->IsInstantiated())) { |
| 2417 H.ReportError("Type must be constant in const constructor."); | 2422 H.ReportError("Type must be constant in const constructor."); |
| 2418 } | 2423 } |
| 2419 } else if (target.IsFactory() && type_arguments == NULL) { | 2424 } else if (target.IsFactory() && type_arguments == NULL) { |
| 2420 // All factories take a type arguments vector as first argument (independent | 2425 // All factories take a type arguments vector as first argument (independent |
| 2421 // of whether the class is generic or not). | 2426 // of whether the class is generic or not). |
| 2422 type_arguments = &TypeArguments::ZoneHandle(Z, TypeArguments::null()); | 2427 type_arguments = &TypeArguments::ZoneHandle(Z, TypeArguments::null()); |
| 2423 } | 2428 } |
| 2424 return type_arguments; | 2429 return type_arguments; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2440 // evaluated only once. | 2445 // evaluated only once. |
| 2441 return false; | 2446 return false; |
| 2442 } | 2447 } |
| 2443 | 2448 |
| 2444 bool is_present = false; | 2449 bool is_present = false; |
| 2445 ASSERT(!script_.InVMHeap()); | 2450 ASSERT(!script_.InVMHeap()); |
| 2446 if (script_.compile_time_constants() == Array::null()) { | 2451 if (script_.compile_time_constants() == Array::null()) { |
| 2447 return false; | 2452 return false; |
| 2448 } | 2453 } |
| 2449 KernelConstantsMap constants(script_.compile_time_constants()); | 2454 KernelConstantsMap constants(script_.compile_time_constants()); |
| 2450 *value ^= constants.GetOrNull(kernel_offset, &is_present); | 2455 *value ^= constants.GetOrNull( |
| 2456 kernel_offset + builder_->relative_kernel_offset_, &is_present); |
| 2451 // Mutator compiler thread may add constants while background compiler | 2457 // Mutator compiler thread may add constants while background compiler |
| 2452 // is running, and thus change the value of 'compile_time_constants'; | 2458 // is running, and thus change the value of 'compile_time_constants'; |
| 2453 // do not assert that 'compile_time_constants' has not changed. | 2459 // do not assert that 'compile_time_constants' has not changed. |
| 2454 constants.Release(); | 2460 constants.Release(); |
| 2455 if (FLAG_compiler_stats && is_present) { | 2461 if (FLAG_compiler_stats && is_present) { |
| 2456 ++H.thread()->compiler_stats()->num_const_cache_hits; | 2462 ++H.thread()->compiler_stats()->num_const_cache_hits; |
| 2457 } | 2463 } |
| 2458 return is_present; | 2464 return is_present; |
| 2459 } | 2465 } |
| 2460 | 2466 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2471 return; | 2477 return; |
| 2472 } | 2478 } |
| 2473 const intptr_t kInitialConstMapSize = 16; | 2479 const intptr_t kInitialConstMapSize = 16; |
| 2474 ASSERT(!script_.InVMHeap()); | 2480 ASSERT(!script_.InVMHeap()); |
| 2475 if (script_.compile_time_constants() == Array::null()) { | 2481 if (script_.compile_time_constants() == Array::null()) { |
| 2476 const Array& array = Array::Handle( | 2482 const Array& array = Array::Handle( |
| 2477 HashTables::New<KernelConstantsMap>(kInitialConstMapSize, Heap::kNew)); | 2483 HashTables::New<KernelConstantsMap>(kInitialConstMapSize, Heap::kNew)); |
| 2478 script_.set_compile_time_constants(array); | 2484 script_.set_compile_time_constants(array); |
| 2479 } | 2485 } |
| 2480 KernelConstantsMap constants(script_.compile_time_constants()); | 2486 KernelConstantsMap constants(script_.compile_time_constants()); |
| 2481 constants.InsertNewOrGetValue(kernel_offset, value); | 2487 constants.InsertNewOrGetValue( |
| 2488 kernel_offset + builder_->relative_kernel_offset_, value); |
| 2482 script_.set_compile_time_constants(constants.Release()); | 2489 script_.set_compile_time_constants(constants.Release()); |
| 2483 } | 2490 } |
| 2484 | 2491 |
| 2485 void StreamingFlowGraphBuilder::DiscoverEnclosingElements( | 2492 void StreamingFlowGraphBuilder::DiscoverEnclosingElements( |
| 2486 Zone* zone, | 2493 Zone* zone, |
| 2487 const Function& function, | 2494 const Function& function, |
| 2488 Function* outermost_function) { | 2495 Function* outermost_function) { |
| 2489 // Find out if there is an enclosing kernel class (which will be used to | 2496 // Find out if there is an enclosing kernel class (which will be used to |
| 2490 // resolve type parameters). | 2497 // resolve type parameters). |
| 2491 *outermost_function = function.raw(); | 2498 *outermost_function = function.raw(); |
| 2492 while (outermost_function->parent_function() != Object::null()) { | 2499 while (outermost_function->parent_function() != Object::null()) { |
| 2493 *outermost_function = outermost_function->parent_function(); | 2500 *outermost_function = outermost_function->parent_function(); |
| 2494 } | 2501 } |
| 2495 } | 2502 } |
| 2496 | 2503 |
| 2497 intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() { | 2504 void StreamingFlowGraphBuilder::ReadUntilFunctionNode() { |
| 2498 const Tag tag = PeekTag(); | 2505 const Tag tag = PeekTag(); |
| 2499 if (tag == kProcedure) { | 2506 if (tag == kProcedure) { |
| 2500 ProcedureHelper procedure_helper(this); | 2507 ProcedureHelper procedure_helper(this); |
| 2501 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); | 2508 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
| 2502 if (ReadTag() == kNothing) { // read function node tag. | 2509 if (ReadTag() == kNothing) { // read function node tag. |
| 2503 // Running a procedure without a function node doesn't make sense. | 2510 // Running a procedure without a function node doesn't make sense. |
| 2504 UNREACHABLE(); | 2511 UNREACHABLE(); |
| 2505 } | 2512 } |
| 2506 return -1; | 2513 return; |
| 2507 // Now at start of FunctionNode. | 2514 // Now at start of FunctionNode. |
| 2508 } else if (tag == kConstructor) { | 2515 } else if (tag == kConstructor) { |
| 2509 ConstructorHelper constructor_helper(this); | 2516 ConstructorHelper constructor_helper(this); |
| 2510 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); | 2517 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); |
| 2511 return constructor_helper.parent_class_binary_offset_; | 2518 return; |
| 2512 // Now at start of FunctionNode. | 2519 // Now at start of FunctionNode. |
| 2513 // Notice that we also have a list of initializers after that! | 2520 // Notice that we also have a list of initializers after that! |
| 2514 } else if (tag == kFunctionNode) { | 2521 } else if (tag == kFunctionNode) { |
| 2515 // Already at start of FunctionNode. | 2522 // Already at start of FunctionNode. |
| 2516 } else { | 2523 } else { |
| 2517 UNREACHABLE(); | 2524 UNREACHABLE(); |
| 2518 } | 2525 } |
| 2519 return -1; | 2526 return; |
| 2520 } | 2527 } |
| 2521 | 2528 |
| 2522 StringIndex StreamingFlowGraphBuilder::GetNameFromVariableDeclaration( | 2529 StringIndex StreamingFlowGraphBuilder::GetNameFromVariableDeclaration( |
| 2523 intptr_t kernel_offset) { | 2530 intptr_t kernel_offset, |
| 2531 const Function& function) { |
| 2532 Function& function_or_parent = Function::Handle(Z, function.raw()); |
| 2533 intptr_t function_start_relative = |
| 2534 function_or_parent.kernel_offset() - kernel_offset; |
| 2535 while (function_start_relative > 0) { |
| 2536 function_or_parent = function_or_parent.parent_function(); |
| 2537 function_start_relative = |
| 2538 function_or_parent.kernel_offset() - kernel_offset; |
| 2539 } |
| 2540 TypedData& kernel_data = |
| 2541 TypedData::Handle(Z, function_or_parent.kernel_data()); |
| 2542 ASSERT(!kernel_data.IsNull()); |
| 2543 |
| 2524 // Temporarily go to the variable declaration, read the name. | 2544 // Temporarily go to the variable declaration, read the name. |
| 2525 AlternativeReadingScope alt(reader_, kernel_offset); | 2545 AlternativeReadingScope alt( |
| 2546 reader_, &kernel_data, |
| 2547 kernel_offset - function_or_parent.kernel_offset()); |
| 2526 VariableDeclarationHelper helper(this); | 2548 VariableDeclarationHelper helper(this); |
| 2527 helper.ReadUntilIncluding(VariableDeclarationHelper::kNameIndex); | 2549 helper.ReadUntilIncluding(VariableDeclarationHelper::kNameIndex); |
| 2528 return helper.name_index_; | 2550 return helper.name_index_; |
| 2529 } | 2551 } |
| 2530 | 2552 |
| 2531 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfStaticFieldInitializer() { | 2553 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfStaticFieldInitializer() { |
| 2532 FieldHelper field_helper(this); | 2554 FieldHelper field_helper(this); |
| 2533 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 2555 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 2534 ASSERT(field_helper.IsStatic()); | 2556 ASSERT(field_helper.IsStatic()); |
| 2535 | 2557 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2705 } | 2727 } |
| 2706 | 2728 |
| 2707 Fragment instructions; | 2729 Fragment instructions; |
| 2708 instructions += LoadLocal(scopes()->this_variable); | 2730 instructions += LoadLocal(scopes()->this_variable); |
| 2709 instructions += BuildExpression(); | 2731 instructions += BuildExpression(); |
| 2710 instructions += flow_graph_builder_->StoreInstanceFieldGuarded(field, true); | 2732 instructions += flow_graph_builder_->StoreInstanceFieldGuarded(field, true); |
| 2711 return instructions; | 2733 return instructions; |
| 2712 } | 2734 } |
| 2713 | 2735 |
| 2714 Fragment StreamingFlowGraphBuilder::BuildInitializers( | 2736 Fragment StreamingFlowGraphBuilder::BuildInitializers( |
| 2715 intptr_t constructor_class_parent_offset) { | 2737 const Class& parent_class) { |
| 2716 Fragment instructions; | 2738 Fragment instructions; |
| 2717 | 2739 |
| 2718 // Start by getting the position of the constructors initializer. | 2740 // Start by getting the position of the constructors initializer. |
| 2719 intptr_t initializers_offset = -1; | 2741 intptr_t initializers_offset = -1; |
| 2720 { | 2742 { |
| 2721 AlternativeReadingScope alt(reader_); | 2743 AlternativeReadingScope alt(reader_); |
| 2722 SkipFunctionNode(); // read constructors function node. | 2744 SkipFunctionNode(); // read constructors function node. |
| 2723 initializers_offset = ReaderOffset(); | 2745 initializers_offset = ReaderOffset(); |
| 2724 } | 2746 } |
| 2725 | 2747 |
| 2726 // These come from: | 2748 // These come from: |
| 2727 // class A { | 2749 // class A { |
| 2728 // var x = (expr); | 2750 // var x = (expr); |
| 2729 // } | 2751 // } |
| 2730 // We don't want to do that when this is a Redirecting Constructors though | 2752 // We don't want to do that when this is a Redirecting Constructors though |
| 2731 // (i.e. has a single initializer being of type kRedirectingInitializer). | 2753 // (i.e. has a single initializer being of type kRedirectingInitializer). |
| 2732 bool is_redirecting_constructor = false; | 2754 bool is_redirecting_constructor = false; |
| 2733 { | 2755 { |
| 2734 AlternativeReadingScope alt(reader_, initializers_offset); | 2756 AlternativeReadingScope alt(reader_, initializers_offset); |
| 2735 intptr_t list_length = ReadListLength(); // read initializers list length. | 2757 intptr_t list_length = ReadListLength(); // read initializers list length. |
| 2736 if (list_length == 1) { | 2758 if (list_length == 1) { |
| 2737 Tag tag = ReadTag(); | 2759 Tag tag = ReadTag(); |
| 2738 if (tag == kRedirectingInitializer) is_redirecting_constructor = true; | 2760 if (tag == kRedirectingInitializer) is_redirecting_constructor = true; |
| 2739 } | 2761 } |
| 2740 } | 2762 } |
| 2741 | 2763 |
| 2742 if (!is_redirecting_constructor) { | 2764 if (!is_redirecting_constructor) { |
| 2743 AlternativeReadingScope alt(reader_, constructor_class_parent_offset); | 2765 Array& class_fields = Array::Handle(Z, parent_class.fields()); |
| 2744 ClassHelper class_helper(this); | 2766 dart::Field& class_field = dart::Field::Handle(Z); |
| 2745 class_helper.ReadUntilExcluding(ClassHelper::kFields); | 2767 for (intptr_t i = 0; i < class_fields.Length(); ++i) { |
| 2746 intptr_t list_length = ReadListLength(); // read fields list length. | 2768 class_field ^= class_fields.At(i); |
| 2747 | 2769 if (!class_field.is_static()) { |
| 2748 for (intptr_t i = 0; i < list_length; ++i) { | 2770 TypedData& kernel_data = |
| 2749 intptr_t field_offset = ReaderOffset(); | 2771 TypedData::Handle(Z, class_field.kernel_data()); |
| 2750 FieldHelper field_helper(this); | 2772 ASSERT(!kernel_data.IsNull()); |
| 2751 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); | 2773 AlternativeReadingScope alt(reader_, &kernel_data, 0); |
| 2752 Tag initializer_tag = ReadTag(); // read first part of initializer. | 2774 intptr_t saved_relative_kernel_offset_ = relative_kernel_offset_; |
| 2753 if (!field_helper.IsStatic() && initializer_tag == kSomething) { | 2775 relative_kernel_offset_ = class_field.kernel_offset(); |
| 2754 EnterScope(field_offset); | 2776 FieldHelper field_helper(this); |
| 2755 instructions += BuildFieldInitializer( | 2777 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 2756 field_helper.canonical_name_); // read initializer. | 2778 Tag initializer_tag = ReadTag(); // read first part of initializer. |
| 2757 ExitScope(field_offset); | 2779 if (initializer_tag == kSomething) { |
| 2758 } else if (initializer_tag == kSomething) { | 2780 EnterScope(class_field.kernel_offset()); |
| 2759 SkipExpression(); // read initializer. | 2781 instructions += BuildFieldInitializer( |
| 2782 field_helper.canonical_name_); // read initializer. |
| 2783 ExitScope(class_field.kernel_offset()); |
| 2784 } |
| 2785 relative_kernel_offset_ = saved_relative_kernel_offset_; |
| 2760 } | 2786 } |
| 2761 } | 2787 } |
| 2762 } | 2788 } |
| 2763 | 2789 |
| 2764 // These to come from: | 2790 // These to come from: |
| 2765 // class A { | 2791 // class A { |
| 2766 // var x; | 2792 // var x; |
| 2767 // var y; | 2793 // var y; |
| 2768 // A(this.x) : super(expr), y = (expr); | 2794 // A(this.x) : super(expr), y = (expr); |
| 2769 // } | 2795 // } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 // | 2867 // |
| 2842 // to | 2868 // to |
| 2843 // | 2869 // |
| 2844 // class A { | 2870 // class A { |
| 2845 // var x; | 2871 // var x; |
| 2846 // A(a, b) : tmp = a + b, x = 2*b, super(tmp) {} | 2872 // A(a, b) : tmp = a + b, x = 2*b, super(tmp) {} |
| 2847 // } | 2873 // } |
| 2848 // | 2874 // |
| 2849 // (This is strictly speaking not what one should do in terms of the | 2875 // (This is strictly speaking not what one should do in terms of the |
| 2850 // specification but that is how it is currently implemented.) | 2876 // specification but that is how it is currently implemented.) |
| 2851 LocalVariable* variable = LookupVariable(ReaderOffset()); | 2877 LocalVariable* variable = |
| 2878 LookupVariable(ReaderOffset() + relative_kernel_offset_); |
| 2852 | 2879 |
| 2853 // Variable declaration | 2880 // Variable declaration |
| 2854 VariableDeclarationHelper helper(this); | 2881 VariableDeclarationHelper helper(this); |
| 2855 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); | 2882 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
| 2856 ASSERT(!helper.IsConst()); | 2883 ASSERT(!helper.IsConst()); |
| 2857 Tag tag = ReadTag(); // read (first part of) initializer. | 2884 Tag tag = ReadTag(); // read (first part of) initializer. |
| 2858 if (tag != kSomething) { | 2885 if (tag != kSomething) { |
| 2859 UNREACHABLE(); | 2886 UNREACHABLE(); |
| 2860 } | 2887 } |
| 2861 | 2888 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2893 body += PushArgument(); | 2920 body += PushArgument(); |
| 2894 } | 2921 } |
| 2895 | 2922 |
| 2896 FunctionNodeHelper function_node_helper(this); | 2923 FunctionNodeHelper function_node_helper(this); |
| 2897 function_node_helper.ReadUntilExcluding( | 2924 function_node_helper.ReadUntilExcluding( |
| 2898 FunctionNodeHelper::kPositionalParameters); | 2925 FunctionNodeHelper::kPositionalParameters); |
| 2899 | 2926 |
| 2900 // Positional. | 2927 // Positional. |
| 2901 intptr_t positional_argument_count = ReadListLength(); | 2928 intptr_t positional_argument_count = ReadListLength(); |
| 2902 for (intptr_t i = 0; i < positional_argument_count; ++i) { | 2929 for (intptr_t i = 0; i < positional_argument_count; ++i) { |
| 2903 body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 2930 body += LoadLocal(LookupVariable( |
| 2931 ReaderOffset() + relative_kernel_offset_)); // ith variable offset. |
| 2904 body += PushArgument(); | 2932 body += PushArgument(); |
| 2905 SkipVariableDeclaration(); // read ith variable. | 2933 SkipVariableDeclaration(); // read ith variable. |
| 2906 } | 2934 } |
| 2907 | 2935 |
| 2908 // Named. | 2936 // Named. |
| 2909 intptr_t named_argument_count = ReadListLength(); | 2937 intptr_t named_argument_count = ReadListLength(); |
| 2910 Array& argument_names = Array::ZoneHandle(Z); | 2938 Array& argument_names = Array::ZoneHandle(Z); |
| 2911 if (named_argument_count > 0) { | 2939 if (named_argument_count > 0) { |
| 2912 argument_names = Array::New(named_argument_count); | 2940 argument_names = Array::New(named_argument_count); |
| 2913 for (intptr_t i = 0; i < named_argument_count; ++i) { | 2941 for (intptr_t i = 0; i < named_argument_count; ++i) { |
| 2914 // ith variable offset. | 2942 // ith variable offset. |
| 2915 body += LoadLocal(LookupVariable(ReaderOffset())); | 2943 body += |
| 2944 LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 2916 body += PushArgument(); | 2945 body += PushArgument(); |
| 2917 StringIndex name = GetNameFromVariableDeclaration(ReaderOffset()); | 2946 |
| 2918 argument_names.SetAt(i, H.DartSymbol(name)); | 2947 // read ith variable. |
| 2919 SkipVariableDeclaration(); // read ith variable. | 2948 VariableDeclarationHelper helper(this); |
| 2949 helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd); |
| 2950 |
| 2951 argument_names.SetAt(i, H.DartSymbol(helper.name_index_)); |
| 2920 } | 2952 } |
| 2921 } | 2953 } |
| 2922 | 2954 |
| 2923 // Forward them to the target. | 2955 // Forward them to the target. |
| 2924 intptr_t argument_count = positional_argument_count + named_argument_count; | 2956 intptr_t argument_count = positional_argument_count + named_argument_count; |
| 2925 if (!target.is_static()) ++argument_count; | 2957 if (!target.is_static()) ++argument_count; |
| 2926 body += StaticCall(TokenPosition::kNoSource, target, argument_count, | 2958 body += StaticCall(TokenPosition::kNoSource, target, argument_count, |
| 2927 argument_names); | 2959 argument_names); |
| 2928 | 2960 |
| 2929 // Return the result. | 2961 // Return the result. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2957 function_node_helper.ReadUntilExcluding( | 2989 function_node_helper.ReadUntilExcluding( |
| 2958 FunctionNodeHelper::kPositionalParameters); | 2990 FunctionNodeHelper::kPositionalParameters); |
| 2959 | 2991 |
| 2960 // Positional. | 2992 // Positional. |
| 2961 const intptr_t positional_argument_count = ReadListLength(); | 2993 const intptr_t positional_argument_count = ReadListLength(); |
| 2962 | 2994 |
| 2963 // The first argument is the instance of the closure class. For converted | 2995 // The first argument is the instance of the closure class. For converted |
| 2964 // closures its context field contains the context vector that is used by the | 2996 // closures its context field contains the context vector that is used by the |
| 2965 // converted top-level function (target) explicitly and that should be passed | 2997 // converted top-level function (target) explicitly and that should be passed |
| 2966 // to that function as the first parameter. | 2998 // to that function as the first parameter. |
| 2967 body += LoadLocal(LookupVariable(ReaderOffset())); // 0th variable offset. | 2999 body += LoadLocal(LookupVariable( |
| 3000 ReaderOffset() + relative_kernel_offset_)); // 0th variable offset. |
| 2968 body += flow_graph_builder_->LoadField(Closure::context_offset()); | 3001 body += flow_graph_builder_->LoadField(Closure::context_offset()); |
| 2969 body += PushArgument(); | 3002 body += PushArgument(); |
| 2970 SkipVariableDeclaration(); // read 0th variable. | 3003 SkipVariableDeclaration(); // read 0th variable. |
| 2971 | 3004 |
| 2972 // The rest of the parameters are the same for the method of the Closure class | 3005 // The rest of the parameters are the same for the method of the Closure class |
| 2973 // being invoked and the top-level function (target). | 3006 // being invoked and the top-level function (target). |
| 2974 for (intptr_t i = 1; i < positional_argument_count; i++) { | 3007 for (intptr_t i = 1; i < positional_argument_count; i++) { |
| 2975 body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 3008 body += LoadLocal(LookupVariable( |
| 3009 ReaderOffset() + relative_kernel_offset_)); // ith variable offset. |
| 2976 body += PushArgument(); | 3010 body += PushArgument(); |
| 2977 SkipVariableDeclaration(); // read ith variable. | 3011 SkipVariableDeclaration(); // read ith variable. |
| 2978 } | 3012 } |
| 2979 | 3013 |
| 2980 // Named. | 3014 // Named. |
| 2981 const intptr_t named_argument_count = ReadListLength(); | 3015 const intptr_t named_argument_count = ReadListLength(); |
| 2982 Array& argument_names = Array::ZoneHandle(Z); | 3016 Array& argument_names = Array::ZoneHandle(Z); |
| 2983 if (named_argument_count > 0) { | 3017 if (named_argument_count > 0) { |
| 2984 argument_names = Array::New(named_argument_count); | 3018 argument_names = Array::New(named_argument_count); |
| 2985 for (intptr_t i = 0; i < named_argument_count; i++) { | 3019 for (intptr_t i = 0; i < named_argument_count; i++) { |
| 3020 // ith variable offset. |
| 2986 body += | 3021 body += |
| 2987 LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 3022 LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 2988 body += PushArgument(); | 3023 body += PushArgument(); |
| 2989 argument_names.SetAt( | 3024 |
| 2990 i, H.DartSymbol(GetNameFromVariableDeclaration(ReaderOffset()))); | 3025 // read ith variable. |
| 2991 SkipVariableDeclaration(); // read ith variable. | 3026 VariableDeclarationHelper helper(this); |
| 3027 helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd); |
| 3028 |
| 3029 argument_names.SetAt(i, H.DartSymbol(helper.name_index_)); |
| 2992 } | 3030 } |
| 2993 } | 3031 } |
| 2994 | 3032 |
| 2995 // Forward them to the target. | 3033 // Forward them to the target. |
| 2996 const intptr_t argument_count = | 3034 const intptr_t argument_count = |
| 2997 positional_argument_count + named_argument_count; | 3035 positional_argument_count + named_argument_count; |
| 2998 body += StaticCall(TokenPosition::kNoSource, target, argument_count, | 3036 body += StaticCall(TokenPosition::kNoSource, target, argument_count, |
| 2999 argument_names); | 3037 argument_names); |
| 3000 | 3038 |
| 3001 // Return the result. | 3039 // Return the result. |
| 3002 body += Return(function_node_helper.end_position_); | 3040 body += Return(function_node_helper.end_position_); |
| 3003 | 3041 |
| 3004 return new (Z) | 3042 return new (Z) |
| 3005 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, | 3043 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, |
| 3006 flow_graph_builder_->next_block_id_ - 1); | 3044 flow_graph_builder_->next_block_id_ - 1); |
| 3007 } | 3045 } |
| 3008 | 3046 |
| 3009 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction( | 3047 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFunction(bool constructor) { |
| 3010 intptr_t constructor_class_parent_offset) { | |
| 3011 const Function& dart_function = parsed_function()->function(); | 3048 const Function& dart_function = parsed_function()->function(); |
| 3012 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); | 3049 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); |
| 3013 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( | 3050 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( |
| 3014 *parsed_function(), normal_entry, flow_graph_builder_->osr_id_); | 3051 *parsed_function(), normal_entry, flow_graph_builder_->osr_id_); |
| 3015 | 3052 |
| 3016 SetupDefaultParameterValues(); | 3053 SetupDefaultParameterValues(); |
| 3017 | 3054 |
| 3018 Fragment body; | 3055 Fragment body; |
| 3019 if (!dart_function.is_native()) | 3056 if (!dart_function.is_native()) |
| 3020 body += flow_graph_builder_->CheckStackOverflowInPrologue(); | 3057 body += flow_graph_builder_->CheckStackOverflowInPrologue(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3049 body += flow_graph_builder_->StoreInstanceField( | 3086 body += flow_graph_builder_->StoreInstanceField( |
| 3050 TokenPosition::kNoSource, | 3087 TokenPosition::kNoSource, |
| 3051 Context::variable_offset(variable->index())); | 3088 Context::variable_offset(variable->index())); |
| 3052 body += NullConstant(); | 3089 body += NullConstant(); |
| 3053 body += StoreLocal(TokenPosition::kNoSource, parameter); | 3090 body += StoreLocal(TokenPosition::kNoSource, parameter); |
| 3054 body += Drop(); | 3091 body += Drop(); |
| 3055 } | 3092 } |
| 3056 } | 3093 } |
| 3057 body += Drop(); // The context. | 3094 body += Drop(); // The context. |
| 3058 } | 3095 } |
| 3059 if (constructor_class_parent_offset > 0) { | 3096 if (constructor) { |
| 3060 // TODO(27590): Currently the [VariableDeclaration]s from the | 3097 // TODO(27590): Currently the [VariableDeclaration]s from the |
| 3061 // initializers will be visible inside the entire body of the constructor. | 3098 // initializers will be visible inside the entire body of the constructor. |
| 3062 // We should make a separate scope for them. | 3099 // We should make a separate scope for them. |
| 3063 body += BuildInitializers(constructor_class_parent_offset); | 3100 body += BuildInitializers(Class::Handle(Z, dart_function.Owner())); |
| 3064 } | 3101 } |
| 3065 | 3102 |
| 3066 FunctionNodeHelper function_node_helper(this); | 3103 FunctionNodeHelper function_node_helper(this); |
| 3067 function_node_helper.ReadUntilExcluding( | 3104 function_node_helper.ReadUntilExcluding( |
| 3068 FunctionNodeHelper::kPositionalParameters); | 3105 FunctionNodeHelper::kPositionalParameters); |
| 3069 intptr_t first_parameter_offset = -1; | 3106 intptr_t first_parameter_offset = -1; |
| 3070 { | 3107 { |
| 3071 AlternativeReadingScope alt(reader_); | 3108 AlternativeReadingScope alt(reader_); |
| 3072 intptr_t list_length = ReadListLength(); // read number of positionals. | 3109 intptr_t list_length = ReadListLength(); // read number of positionals. |
| 3073 if (list_length > 0) { | 3110 if (list_length > 0) { |
| 3074 first_parameter_offset = ReaderOffset(); | 3111 first_parameter_offset = ReaderOffset() + relative_kernel_offset_; |
| 3075 } | 3112 } |
| 3076 } | 3113 } |
| 3077 // Current position: About to read list of positionals. | 3114 // Current position: About to read list of positionals. |
| 3078 | 3115 |
| 3079 // The specification defines the result of `a == b` to be: | 3116 // The specification defines the result of `a == b` to be: |
| 3080 // | 3117 // |
| 3081 // a) if either side is `null` then the result is `identical(a, b)`. | 3118 // a) if either side is `null` then the result is `identical(a, b)`. |
| 3082 // b) else the result is `a.operator==(b)` | 3119 // b) else the result is `a.operator==(b)` |
| 3083 // | 3120 // |
| 3084 // For user-defined implementations of `operator==` we need therefore | 3121 // For user-defined implementations of `operator==` we need therefore |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3108 body = Fragment(body.entry, non_null_entry); | 3145 body = Fragment(body.entry, non_null_entry); |
| 3109 } | 3146 } |
| 3110 | 3147 |
| 3111 // If we run in checked mode, we have to check the type of the passed | 3148 // If we run in checked mode, we have to check the type of the passed |
| 3112 // arguments. | 3149 // arguments. |
| 3113 if (I->type_checks()) { | 3150 if (I->type_checks()) { |
| 3114 // Positional. | 3151 // Positional. |
| 3115 intptr_t list_length = ReadListLength(); | 3152 intptr_t list_length = ReadListLength(); |
| 3116 for (intptr_t i = 0; i < list_length; ++i) { | 3153 for (intptr_t i = 0; i < list_length; ++i) { |
| 3117 // ith variable offset. | 3154 // ith variable offset. |
| 3118 body += LoadLocal(LookupVariable(ReaderOffset())); | 3155 body += |
| 3119 body += CheckVariableTypeInCheckedMode(ReaderOffset()); | 3156 LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 3157 body += CheckVariableTypeInCheckedMode(ReaderOffset() + |
| 3158 relative_kernel_offset_); |
| 3120 body += Drop(); | 3159 body += Drop(); |
| 3121 SkipVariableDeclaration(); // read ith variable. | 3160 SkipVariableDeclaration(); // read ith variable. |
| 3122 } | 3161 } |
| 3123 | 3162 |
| 3124 // Named. | 3163 // Named. |
| 3125 list_length = ReadListLength(); | 3164 list_length = ReadListLength(); |
| 3126 for (intptr_t i = 0; i < list_length; ++i) { | 3165 for (intptr_t i = 0; i < list_length; ++i) { |
| 3127 // ith variable offset. | 3166 // ith variable offset. |
| 3128 body += LoadLocal(LookupVariable(ReaderOffset())); | 3167 body += |
| 3129 body += CheckVariableTypeInCheckedMode(ReaderOffset()); | 3168 LoadLocal(LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 3169 body += CheckVariableTypeInCheckedMode(ReaderOffset() + |
| 3170 relative_kernel_offset_); |
| 3130 body += Drop(); | 3171 body += Drop(); |
| 3131 SkipVariableDeclaration(); // read ith variable. | 3172 SkipVariableDeclaration(); // read ith variable. |
| 3132 } | 3173 } |
| 3133 | 3174 |
| 3134 function_node_helper.SetJustRead(FunctionNodeHelper::kNamedParameters); | 3175 function_node_helper.SetJustRead(FunctionNodeHelper::kNamedParameters); |
| 3135 } | 3176 } |
| 3136 | 3177 |
| 3137 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kBody); | 3178 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kBody); |
| 3138 | 3179 |
| 3139 bool has_body = ReadTag() == kSomething; // read first part of body. | 3180 bool has_body = ReadTag() == kSomething; // read first part of body. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3291 // become unreachable after OSR. | 3332 // become unreachable after OSR. |
| 3292 if (flow_graph_builder_->osr_id_ != Compiler::kNoOSRDeoptId) { | 3333 if (flow_graph_builder_->osr_id_ != Compiler::kNoOSRDeoptId) { |
| 3293 graph_entry->RelinkToOsrEntry(Z, flow_graph_builder_->next_block_id_); | 3334 graph_entry->RelinkToOsrEntry(Z, flow_graph_builder_->next_block_id_); |
| 3294 } | 3335 } |
| 3295 return new (Z) FlowGraph(*parsed_function(), graph_entry, | 3336 return new (Z) FlowGraph(*parsed_function(), graph_entry, |
| 3296 flow_graph_builder_->next_block_id_ - 1); | 3337 flow_graph_builder_->next_block_id_ - 1); |
| 3297 } | 3338 } |
| 3298 | 3339 |
| 3299 FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) { | 3340 FlowGraph* StreamingFlowGraphBuilder::BuildGraph(intptr_t kernel_offset) { |
| 3300 const Function& function = parsed_function()->function(); | 3341 const Function& function = parsed_function()->function(); |
| 3342 TypedData& kernel_data = TypedData::Handle(Z, function.kernel_data()); |
| 3343 if (kernel_data.IsNull() && kernel_offset > 0) { |
| 3344 UNREACHABLE(); |
| 3345 } |
| 3301 | 3346 |
| 3302 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used | 3347 // Setup a [ActiveClassScope] and a [ActiveMemberScope] which will be used |
| 3303 // e.g. for type translation. | 3348 // e.g. for type translation. |
| 3304 const dart::Class& klass = | 3349 const dart::Class& klass = |
| 3305 dart::Class::Handle(zone_, parsed_function()->function().Owner()); | 3350 dart::Class::Handle(zone_, parsed_function()->function().Owner()); |
| 3306 | 3351 |
| 3307 Function& outermost_function = Function::Handle(Z); | 3352 Function& outermost_function = Function::Handle(Z); |
| 3308 DiscoverEnclosingElements(Z, function, &outermost_function); | 3353 DiscoverEnclosingElements(Z, function, &outermost_function); |
| 3309 | 3354 |
| 3310 ActiveClassScope active_class_scope(active_class(), &klass); | 3355 ActiveClassScope active_class_scope(active_class(), &klass); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3325 case RawFunction::kConvertedClosureFunction: | 3370 case RawFunction::kConvertedClosureFunction: |
| 3326 case RawFunction::kRegularFunction: | 3371 case RawFunction::kRegularFunction: |
| 3327 case RawFunction::kGetterFunction: | 3372 case RawFunction::kGetterFunction: |
| 3328 case RawFunction::kSetterFunction: { | 3373 case RawFunction::kSetterFunction: { |
| 3329 ReadUntilFunctionNode(); // read until function node. | 3374 ReadUntilFunctionNode(); // read until function node. |
| 3330 if (function.IsImplicitClosureFunction()) { | 3375 if (function.IsImplicitClosureFunction()) { |
| 3331 return BuildGraphOfImplicitClosureFunction(function); | 3376 return BuildGraphOfImplicitClosureFunction(function); |
| 3332 } else if (function.IsConvertedClosureFunction()) { | 3377 } else if (function.IsConvertedClosureFunction()) { |
| 3333 return BuildGraphOfConvertedClosureFunction(function); | 3378 return BuildGraphOfConvertedClosureFunction(function); |
| 3334 } | 3379 } |
| 3335 return BuildGraphOfFunction(); | 3380 return BuildGraphOfFunction(false); |
| 3336 } | 3381 } |
| 3337 case RawFunction::kConstructor: { | 3382 case RawFunction::kConstructor: { |
| 3338 bool is_factory = function.IsFactory(); | 3383 ReadUntilFunctionNode(); // read until function node. |
| 3339 if (is_factory) { | 3384 return BuildGraphOfFunction(!function.IsFactory()); |
| 3340 ReadUntilFunctionNode(); // read until function node. | |
| 3341 return BuildGraphOfFunction(); | |
| 3342 } else { | |
| 3343 // Constructor: Pass offset to parent class. | |
| 3344 return BuildGraphOfFunction( | |
| 3345 ReadUntilFunctionNode()); // read until function node. | |
| 3346 } | |
| 3347 } | 3385 } |
| 3348 case RawFunction::kImplicitGetter: | 3386 case RawFunction::kImplicitGetter: |
| 3349 case RawFunction::kImplicitStaticFinalGetter: | 3387 case RawFunction::kImplicitStaticFinalGetter: |
| 3350 case RawFunction::kImplicitSetter: { | 3388 case RawFunction::kImplicitSetter: { |
| 3351 return IsStaticInitializer(function, Z) | 3389 return IsStaticInitializer(function, Z) |
| 3352 ? BuildGraphOfStaticFieldInitializer() | 3390 ? BuildGraphOfStaticFieldInitializer() |
| 3353 : BuildGraphOfFieldAccessor(scopes()->setter_value); | 3391 : BuildGraphOfFieldAccessor(scopes()->setter_value); |
| 3354 } | 3392 } |
| 3355 case RawFunction::kMethodExtractor: | 3393 case RawFunction::kMethodExtractor: |
| 3356 return flow_graph_builder_->BuildGraphOfMethodExtractor(function); | 3394 return flow_graph_builder_->BuildGraphOfMethodExtractor(function); |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4636 if (*negate) { | 4674 if (*negate) { |
| 4637 SkipBytes(1); // Skip Not tag, thus go directly to the inner expression. | 4675 SkipBytes(1); // Skip Not tag, thus go directly to the inner expression. |
| 4638 } | 4676 } |
| 4639 Fragment instructions = BuildExpression(); // read expression. | 4677 Fragment instructions = BuildExpression(); // read expression. |
| 4640 instructions += CheckBooleanInCheckedMode(); | 4678 instructions += CheckBooleanInCheckedMode(); |
| 4641 return instructions; | 4679 return instructions; |
| 4642 } | 4680 } |
| 4643 | 4681 |
| 4644 const TypeArguments& StreamingFlowGraphBuilder::BuildTypeArguments() { | 4682 const TypeArguments& StreamingFlowGraphBuilder::BuildTypeArguments() { |
| 4645 ReadUInt(); // read arguments count. | 4683 ReadUInt(); // read arguments count. |
| 4646 intptr_t types_count = ReadListLength(); // read type count. | 4684 intptr_t type_count = ReadListLength(); // read type count. |
| 4647 return T.BuildTypeArguments(types_count); // read types. | 4685 return T.BuildTypeArguments(type_count); // read types. |
| 4648 } | 4686 } |
| 4649 | 4687 |
| 4650 Fragment StreamingFlowGraphBuilder::BuildArguments(Array* argument_names, | 4688 Fragment StreamingFlowGraphBuilder::BuildArguments(Array* argument_names, |
| 4651 intptr_t* argument_count, | 4689 intptr_t* argument_count, |
| 4652 bool skip_push_arguments, | 4690 bool skip_push_arguments, |
| 4653 bool do_drop) { | 4691 bool do_drop) { |
| 4654 intptr_t dummy; | 4692 intptr_t dummy; |
| 4655 if (argument_count == NULL) argument_count = &dummy; | 4693 if (argument_count == NULL) argument_count = &dummy; |
| 4656 *argument_count = ReadUInt(); // read arguments count. | 4694 *argument_count = ReadUInt(); // read arguments count. |
| 4657 | 4695 |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5666 const dart::Class& map_class = | 5704 const dart::Class& map_class = |
| 5667 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::Map())); | 5705 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::Map())); |
| 5668 const Function& factory_method = Function::ZoneHandle( | 5706 const Function& factory_method = Function::ZoneHandle( |
| 5669 Z, map_class.LookupFactory( | 5707 Z, map_class.LookupFactory( |
| 5670 dart::Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); | 5708 dart::Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); |
| 5671 | 5709 |
| 5672 return instructions + StaticCall(position, factory_method, 2); | 5710 return instructions + StaticCall(position, factory_method, 2); |
| 5673 } | 5711 } |
| 5674 | 5712 |
| 5675 Fragment StreamingFlowGraphBuilder::BuildFunctionExpression() { | 5713 Fragment StreamingFlowGraphBuilder::BuildFunctionExpression() { |
| 5676 intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte. | 5714 return BuildFunctionNode(TokenPosition::kNoSource, StringIndex()); |
| 5677 return BuildFunctionNode(offset, TokenPosition::kNoSource, false, -1); | |
| 5678 } | 5715 } |
| 5679 | 5716 |
| 5680 Fragment StreamingFlowGraphBuilder::BuildLet(TokenPosition* position) { | 5717 Fragment StreamingFlowGraphBuilder::BuildLet(TokenPosition* position) { |
| 5681 if (position != NULL) *position = TokenPosition::kNoSource; | 5718 if (position != NULL) *position = TokenPosition::kNoSource; |
| 5682 | 5719 |
| 5683 Fragment instructions = BuildVariableDeclaration(); // read variable. | 5720 Fragment instructions = BuildVariableDeclaration(); // read variable. |
| 5684 instructions += BuildExpression(); // read body. | 5721 instructions += BuildExpression(); // read body. |
| 5685 return instructions; | 5722 return instructions; |
| 5686 } | 5723 } |
| 5687 | 5724 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5841 Fragment instructions = BuildExpression(); // read expression. | 5878 Fragment instructions = BuildExpression(); // read expression. |
| 5842 instructions += Drop(); | 5879 instructions += Drop(); |
| 5843 return instructions; | 5880 return instructions; |
| 5844 } | 5881 } |
| 5845 | 5882 |
| 5846 Fragment StreamingFlowGraphBuilder::BuildBlock() { | 5883 Fragment StreamingFlowGraphBuilder::BuildBlock() { |
| 5847 intptr_t offset = ReaderOffset() - 1; // Include the tag. | 5884 intptr_t offset = ReaderOffset() - 1; // Include the tag. |
| 5848 | 5885 |
| 5849 Fragment instructions; | 5886 Fragment instructions; |
| 5850 | 5887 |
| 5851 instructions += EnterScope(offset); | 5888 instructions += EnterScope(offset + relative_kernel_offset_); |
| 5852 intptr_t list_length = ReadListLength(); // read number of statements. | 5889 intptr_t list_length = ReadListLength(); // read number of statements. |
| 5853 for (intptr_t i = 0; i < list_length; ++i) { | 5890 for (intptr_t i = 0; i < list_length; ++i) { |
| 5854 if (instructions.is_open()) { | 5891 if (instructions.is_open()) { |
| 5855 instructions += BuildStatement(); // read ith statement. | 5892 instructions += BuildStatement(); // read ith statement. |
| 5856 } else { | 5893 } else { |
| 5857 SkipStatement(); // read ith statement. | 5894 SkipStatement(); // read ith statement. |
| 5858 } | 5895 } |
| 5859 } | 5896 } |
| 5860 instructions += ExitScope(offset); | 5897 instructions += ExitScope(offset + relative_kernel_offset_); |
| 5861 | 5898 |
| 5862 return instructions; | 5899 return instructions; |
| 5863 } | 5900 } |
| 5864 | 5901 |
| 5865 Fragment StreamingFlowGraphBuilder::BuildEmptyStatement() { | 5902 Fragment StreamingFlowGraphBuilder::BuildEmptyStatement() { |
| 5866 return Fragment(); | 5903 return Fragment(); |
| 5867 } | 5904 } |
| 5868 | 5905 |
| 5869 Fragment StreamingFlowGraphBuilder::BuildAssertStatement() { | 5906 Fragment StreamingFlowGraphBuilder::BuildAssertStatement() { |
| 5870 if (!I->asserts()) { | 5907 if (!I->asserts()) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6028 } | 6065 } |
| 6029 | 6066 |
| 6030 Fragment StreamingFlowGraphBuilder::BuildForStatement() { | 6067 Fragment StreamingFlowGraphBuilder::BuildForStatement() { |
| 6031 intptr_t offset = ReaderOffset() - 1; // Include the tag. | 6068 intptr_t offset = ReaderOffset() - 1; // Include the tag. |
| 6032 | 6069 |
| 6033 ReadPosition(); // read position. | 6070 ReadPosition(); // read position. |
| 6034 | 6071 |
| 6035 Fragment declarations; | 6072 Fragment declarations; |
| 6036 | 6073 |
| 6037 bool new_context = false; | 6074 bool new_context = false; |
| 6038 declarations += EnterScope(offset, &new_context); | 6075 declarations += EnterScope(offset + relative_kernel_offset_, &new_context); |
| 6039 | 6076 |
| 6040 intptr_t list_length = ReadListLength(); // read number of variables. | 6077 intptr_t list_length = ReadListLength(); // read number of variables. |
| 6041 for (intptr_t i = 0; i < list_length; ++i) { | 6078 for (intptr_t i = 0; i < list_length; ++i) { |
| 6042 declarations += BuildVariableDeclaration(); // read ith variable. | 6079 declarations += BuildVariableDeclaration(); // read ith variable. |
| 6043 } | 6080 } |
| 6044 | 6081 |
| 6045 loop_depth_inc(); | 6082 loop_depth_inc(); |
| 6046 bool negate = false; | 6083 bool negate = false; |
| 6047 Tag tag = ReadTag(); // Read first part of condition. | 6084 Tag tag = ReadTag(); // Read first part of condition. |
| 6048 Fragment condition = | 6085 Fragment condition = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 6078 Fragment loop(join); | 6115 Fragment loop(join); |
| 6079 loop += CheckStackOverflow(); | 6116 loop += CheckStackOverflow(); |
| 6080 loop += condition; | 6117 loop += condition; |
| 6081 } else { | 6118 } else { |
| 6082 declarations += condition; | 6119 declarations += condition; |
| 6083 } | 6120 } |
| 6084 | 6121 |
| 6085 Fragment loop(declarations.entry, loop_exit); | 6122 Fragment loop(declarations.entry, loop_exit); |
| 6086 loop_depth_dec(); | 6123 loop_depth_dec(); |
| 6087 | 6124 |
| 6088 loop += ExitScope(offset); | 6125 loop += ExitScope(offset + relative_kernel_offset_); |
| 6089 | 6126 |
| 6090 return loop; | 6127 return loop; |
| 6091 } | 6128 } |
| 6092 | 6129 |
| 6093 Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) { | 6130 Fragment StreamingFlowGraphBuilder::BuildForInStatement(bool async) { |
| 6094 intptr_t offset = ReaderOffset() - 1; // Include the tag. | 6131 intptr_t offset = ReaderOffset() - 1; // Include the tag. |
| 6095 | 6132 |
| 6096 ReadPosition(); // read position. | 6133 ReadPosition(); // read position. |
| 6097 TokenPosition body_position = ReadPosition(); // read body position. | 6134 TokenPosition body_position = ReadPosition(); // read body position. |
| 6098 intptr_t variable_kernel_position = ReaderOffset(); | 6135 intptr_t variable_kernel_position = ReaderOffset() + relative_kernel_offset_; |
| 6099 SkipVariableDeclaration(); // read variable. | 6136 SkipVariableDeclaration(); // read variable. |
| 6100 | 6137 |
| 6101 TokenPosition iterable_position = TokenPosition::kNoSource; | 6138 TokenPosition iterable_position = TokenPosition::kNoSource; |
| 6102 Fragment instructions = | 6139 Fragment instructions = |
| 6103 BuildExpression(&iterable_position); // read iterable. | 6140 BuildExpression(&iterable_position); // read iterable. |
| 6104 instructions += PushArgument(); | 6141 instructions += PushArgument(); |
| 6105 | 6142 |
| 6106 const dart::String& iterator_getter = dart::String::ZoneHandle( | 6143 const dart::String& iterator_getter = dart::String::ZoneHandle( |
| 6107 Z, dart::Field::GetterSymbol(Symbols::Iterator())); | 6144 Z, dart::Field::GetterSymbol(Symbols::Iterator())); |
| 6108 instructions += | 6145 instructions += |
| 6109 InstanceCall(iterable_position, iterator_getter, Token::kGET, 1); | 6146 InstanceCall(iterable_position, iterator_getter, Token::kGET, 1); |
| 6110 LocalVariable* iterator = scopes()->iterator_variables[for_in_depth()]; | 6147 LocalVariable* iterator = scopes()->iterator_variables[for_in_depth()]; |
| 6111 instructions += StoreLocal(TokenPosition::kNoSource, iterator); | 6148 instructions += StoreLocal(TokenPosition::kNoSource, iterator); |
| 6112 instructions += Drop(); | 6149 instructions += Drop(); |
| 6113 | 6150 |
| 6114 for_in_depth_inc(); | 6151 for_in_depth_inc(); |
| 6115 loop_depth_inc(); | 6152 loop_depth_inc(); |
| 6116 Fragment condition = LoadLocal(iterator); | 6153 Fragment condition = LoadLocal(iterator); |
| 6117 condition += PushArgument(); | 6154 condition += PushArgument(); |
| 6118 condition += | 6155 condition += |
| 6119 InstanceCall(iterable_position, Symbols::MoveNext(), Token::kILLEGAL, 1); | 6156 InstanceCall(iterable_position, Symbols::MoveNext(), Token::kILLEGAL, 1); |
| 6120 TargetEntryInstr* body_entry; | 6157 TargetEntryInstr* body_entry; |
| 6121 TargetEntryInstr* loop_exit; | 6158 TargetEntryInstr* loop_exit; |
| 6122 condition += BranchIfTrue(&body_entry, &loop_exit, false); | 6159 condition += BranchIfTrue(&body_entry, &loop_exit, false); |
| 6123 | 6160 |
| 6124 Fragment body(body_entry); | 6161 Fragment body(body_entry); |
| 6125 body += EnterScope(offset); | 6162 body += EnterScope(offset + relative_kernel_offset_); |
| 6126 body += LoadLocal(iterator); | 6163 body += LoadLocal(iterator); |
| 6127 body += PushArgument(); | 6164 body += PushArgument(); |
| 6128 const dart::String& current_getter = dart::String::ZoneHandle( | 6165 const dart::String& current_getter = dart::String::ZoneHandle( |
| 6129 Z, dart::Field::GetterSymbol(Symbols::Current())); | 6166 Z, dart::Field::GetterSymbol(Symbols::Current())); |
| 6130 body += InstanceCall(body_position, current_getter, Token::kGET, 1); | 6167 body += InstanceCall(body_position, current_getter, Token::kGET, 1); |
| 6131 body += StoreLocal(TokenPosition::kNoSource, | 6168 body += StoreLocal(TokenPosition::kNoSource, |
| 6132 LookupVariable(variable_kernel_position)); | 6169 LookupVariable(variable_kernel_position)); |
| 6133 body += Drop(); | 6170 body += Drop(); |
| 6134 body += BuildStatement(); // read body. | 6171 body += BuildStatement(); // read body. |
| 6135 body += ExitScope(offset); | 6172 body += ExitScope(offset + relative_kernel_offset_); |
| 6136 | 6173 |
| 6137 if (body.is_open()) { | 6174 if (body.is_open()) { |
| 6138 JoinEntryInstr* join = BuildJoinEntry(); | 6175 JoinEntryInstr* join = BuildJoinEntry(); |
| 6139 instructions += Goto(join); | 6176 instructions += Goto(join); |
| 6140 body += Goto(join); | 6177 body += Goto(join); |
| 6141 | 6178 |
| 6142 Fragment loop(join); | 6179 Fragment loop(join); |
| 6143 loop += CheckStackOverflow(); | 6180 loop += CheckStackOverflow(); |
| 6144 loop += condition; | 6181 loop += condition; |
| 6145 } else { | 6182 } else { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6466 Tag tag = PeekTag(); // peek guard type. | 6503 Tag tag = PeekTag(); // peek guard type. |
| 6467 AbstractType* type_guard = NULL; | 6504 AbstractType* type_guard = NULL; |
| 6468 if (tag != kDynamicType) { | 6505 if (tag != kDynamicType) { |
| 6469 type_guard = &T.BuildType(); // read guard. | 6506 type_guard = &T.BuildType(); // read guard. |
| 6470 handler_types.SetAt(i, *type_guard); | 6507 handler_types.SetAt(i, *type_guard); |
| 6471 } else { | 6508 } else { |
| 6472 SkipDartType(); // read guard. | 6509 SkipDartType(); // read guard. |
| 6473 handler_types.SetAt(i, Object::dynamic_type()); | 6510 handler_types.SetAt(i, Object::dynamic_type()); |
| 6474 } | 6511 } |
| 6475 | 6512 |
| 6476 Fragment catch_handler_body = EnterScope(catch_offset); | 6513 Fragment catch_handler_body = |
| 6514 EnterScope(catch_offset + relative_kernel_offset_); |
| 6477 | 6515 |
| 6478 tag = ReadTag(); // read first part of exception. | 6516 tag = ReadTag(); // read first part of exception. |
| 6479 if (tag == kSomething) { | 6517 if (tag == kSomething) { |
| 6480 catch_handler_body += LoadLocal(CurrentException()); | 6518 catch_handler_body += LoadLocal(CurrentException()); |
| 6481 catch_handler_body += | 6519 catch_handler_body += |
| 6482 StoreLocal(TokenPosition::kNoSource, LookupVariable(ReaderOffset())); | 6520 StoreLocal(TokenPosition::kNoSource, |
| 6521 LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 6483 catch_handler_body += Drop(); | 6522 catch_handler_body += Drop(); |
| 6484 SkipVariableDeclaration(); // read exception. | 6523 SkipVariableDeclaration(); // read exception. |
| 6485 } | 6524 } |
| 6486 | 6525 |
| 6487 tag = ReadTag(); // read first part of stack trace. | 6526 tag = ReadTag(); // read first part of stack trace. |
| 6488 if (tag == kSomething) { | 6527 if (tag == kSomething) { |
| 6489 catch_handler_body += LoadLocal(CurrentStackTrace()); | 6528 catch_handler_body += LoadLocal(CurrentStackTrace()); |
| 6490 catch_handler_body += | 6529 catch_handler_body += |
| 6491 StoreLocal(TokenPosition::kNoSource, LookupVariable(ReaderOffset())); | 6530 StoreLocal(TokenPosition::kNoSource, |
| 6531 LookupVariable(ReaderOffset() + relative_kernel_offset_)); |
| 6492 catch_handler_body += Drop(); | 6532 catch_handler_body += Drop(); |
| 6493 SkipVariableDeclaration(); // read stack trace. | 6533 SkipVariableDeclaration(); // read stack trace. |
| 6494 } | 6534 } |
| 6495 | 6535 |
| 6496 { | 6536 { |
| 6497 CatchBlock block(flow_graph_builder_, CurrentException(), | 6537 CatchBlock block(flow_graph_builder_, CurrentException(), |
| 6498 CurrentStackTrace(), try_handler_index); | 6538 CurrentStackTrace(), try_handler_index); |
| 6499 | 6539 |
| 6500 catch_handler_body += BuildStatement(); // read body. | 6540 catch_handler_body += BuildStatement(); // read body. |
| 6501 | 6541 |
| 6502 // Note: ExitScope adjusts context_depth_ so even if catch_handler_body | 6542 // Note: ExitScope adjusts context_depth_ so even if catch_handler_body |
| 6503 // is closed we still need to execute ExitScope for its side effect. | 6543 // is closed we still need to execute ExitScope for its side effect. |
| 6504 catch_handler_body += ExitScope(catch_offset); | 6544 catch_handler_body += ExitScope(catch_offset + relative_kernel_offset_); |
| 6505 if (catch_handler_body.is_open()) { | 6545 if (catch_handler_body.is_open()) { |
| 6506 catch_handler_body += Goto(after_try); | 6546 catch_handler_body += Goto(after_try); |
| 6507 } | 6547 } |
| 6508 } | 6548 } |
| 6509 | 6549 |
| 6510 if (type_guard != NULL) { | 6550 if (type_guard != NULL) { |
| 6511 if (type_guard->IsMalformed()) { | 6551 if (type_guard->IsMalformed()) { |
| 6512 catch_body += ThrowTypeError(); | 6552 catch_body += ThrowTypeError(); |
| 6513 catch_body += Drop(); | 6553 catch_body += Drop(); |
| 6514 } else { | 6554 } else { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6718 rethrow += RethrowException(position, CatchClauseNode::kInvalidTryIndex); | 6758 rethrow += RethrowException(position, CatchClauseNode::kInvalidTryIndex); |
| 6719 Drop(); | 6759 Drop(); |
| 6720 | 6760 |
| 6721 continuation = Fragment(continuation.entry, no_error); | 6761 continuation = Fragment(continuation.entry, no_error); |
| 6722 } | 6762 } |
| 6723 | 6763 |
| 6724 return continuation; | 6764 return continuation; |
| 6725 } | 6765 } |
| 6726 | 6766 |
| 6727 Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() { | 6767 Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() { |
| 6728 intptr_t kernel_position_no_tag = ReaderOffset(); | 6768 intptr_t kernel_position_no_tag = ReaderOffset() + relative_kernel_offset_; |
| 6729 LocalVariable* variable = LookupVariable(kernel_position_no_tag); | 6769 LocalVariable* variable = LookupVariable(kernel_position_no_tag); |
| 6730 | 6770 |
| 6731 VariableDeclarationHelper helper(this); | 6771 VariableDeclarationHelper helper(this); |
| 6732 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); | 6772 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
| 6733 dart::String& name = H.DartSymbol(helper.name_index_); | 6773 dart::String& name = H.DartSymbol(helper.name_index_); |
| 6734 AbstractType& type = T.BuildType(); // read type. | 6774 AbstractType& type = T.BuildType(); // read type. |
| 6735 Tag tag = ReadTag(); // read (first part of) initializer. | 6775 Tag tag = ReadTag(); // read (first part of) initializer. |
| 6736 | 6776 |
| 6737 Fragment instructions; | 6777 Fragment instructions; |
| 6738 if (tag == kNothing) { | 6778 if (tag == kNothing) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 6757 Utils::Maximum(helper.position_, helper.equals_position_); | 6797 Utils::Maximum(helper.position_, helper.equals_position_); |
| 6758 if (NeedsDebugStepCheck(stack(), debug_position)) { | 6798 if (NeedsDebugStepCheck(stack(), debug_position)) { |
| 6759 instructions = DebugStepCheck(debug_position) + instructions; | 6799 instructions = DebugStepCheck(debug_position) + instructions; |
| 6760 } | 6800 } |
| 6761 instructions += StoreLocal(helper.position_, variable); | 6801 instructions += StoreLocal(helper.position_, variable); |
| 6762 instructions += Drop(); | 6802 instructions += Drop(); |
| 6763 return instructions; | 6803 return instructions; |
| 6764 } | 6804 } |
| 6765 | 6805 |
| 6766 Fragment StreamingFlowGraphBuilder::BuildFunctionDeclaration() { | 6806 Fragment StreamingFlowGraphBuilder::BuildFunctionDeclaration() { |
| 6767 intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte. | |
| 6768 TokenPosition position = ReadPosition(); // read position. | 6807 TokenPosition position = ReadPosition(); // read position. |
| 6769 intptr_t variable_offeset = ReaderOffset(); | 6808 intptr_t variable_offset = ReaderOffset() + relative_kernel_offset_; |
| 6770 SkipVariableDeclaration(); // read variable declaration. | 6809 |
| 6810 // read variable declaration. |
| 6811 VariableDeclarationHelper helper(this); |
| 6812 helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd); |
| 6771 | 6813 |
| 6772 Fragment instructions = DebugStepCheck(position); | 6814 Fragment instructions = DebugStepCheck(position); |
| 6773 instructions += BuildFunctionNode(offset, position, true, variable_offeset); | 6815 instructions += BuildFunctionNode(position, helper.name_index_); |
| 6774 instructions += StoreLocal(position, LookupVariable(variable_offeset)); | 6816 instructions += StoreLocal(position, LookupVariable(variable_offset)); |
| 6775 instructions += Drop(); | 6817 instructions += Drop(); |
| 6776 return instructions; | 6818 return instructions; |
| 6777 } | 6819 } |
| 6778 | 6820 |
| 6779 Fragment StreamingFlowGraphBuilder::BuildFunctionNode( | 6821 Fragment StreamingFlowGraphBuilder::BuildFunctionNode( |
| 6780 intptr_t parent_kernel_offset, | |
| 6781 TokenPosition parent_position, | 6822 TokenPosition parent_position, |
| 6782 bool declaration, | 6823 StringIndex name_index) { |
| 6783 intptr_t variable_offeset) { | 6824 intptr_t offset = ReaderOffset() + relative_kernel_offset_; |
| 6784 intptr_t offset = ReaderOffset(); | |
| 6785 | 6825 |
| 6786 FunctionNodeHelper function_node_helper(this); | 6826 FunctionNodeHelper function_node_helper(this); |
| 6787 function_node_helper.ReadUntilExcluding( | 6827 function_node_helper.ReadUntilExcluding( |
| 6788 FunctionNodeHelper::kTotalParameterCount); | 6828 FunctionNodeHelper::kTotalParameterCount); |
| 6789 TokenPosition position = function_node_helper.position_; | 6829 TokenPosition position = function_node_helper.position_; |
| 6790 | 6830 |
| 6831 bool declaration = name_index >= 0; |
| 6832 |
| 6791 if (declaration) { | 6833 if (declaration) { |
| 6792 position = parent_position; | 6834 position = parent_position; |
| 6793 } | 6835 } |
| 6794 if (!position.IsReal()) { | 6836 if (!position.IsReal()) { |
| 6795 // Positions has to be unique in regards to the parent. | 6837 // Positions has to be unique in regards to the parent. |
| 6796 // A non-real at this point is probably -1, we cannot blindly use that | 6838 // A non-real at this point is probably -1, we cannot blindly use that |
| 6797 // as others might use it too. Create a new dummy non-real TokenPosition. | 6839 // as others might use it too. Create a new dummy non-real TokenPosition. |
| 6798 position = TokenPosition(offset).ToSynthetic(); | 6840 position = TokenPosition(offset).ToSynthetic(); |
| 6799 } | 6841 } |
| 6800 | 6842 |
| 6801 // The VM has a per-isolate table of functions indexed by the enclosing | 6843 // The VM has a per-isolate table of functions indexed by the enclosing |
| 6802 // function and token position. | 6844 // function and token position. |
| 6803 Function& function = Function::ZoneHandle(Z); | 6845 Function& function = Function::ZoneHandle(Z); |
| 6804 | 6846 |
| 6805 // NOTE: This is not TokenPosition in the general sense! | 6847 // NOTE: This is not TokenPosition in the general sense! |
| 6806 function = I->LookupClosureFunction(parsed_function()->function(), position); | 6848 function = I->LookupClosureFunction(parsed_function()->function(), position); |
| 6807 if (function.IsNull()) { | 6849 if (function.IsNull()) { |
| 6808 for (intptr_t i = 0; i < scopes()->function_scopes.length(); ++i) { | 6850 for (intptr_t i = 0; i < scopes()->function_scopes.length(); ++i) { |
| 6809 if (scopes()->function_scopes[i].kernel_offset != offset) { | 6851 if (scopes()->function_scopes[i].kernel_offset != offset) { |
| 6810 continue; | 6852 continue; |
| 6811 } | 6853 } |
| 6812 | 6854 |
| 6813 const dart::String* name; | 6855 const dart::String* name; |
| 6814 if (!declaration) { | 6856 if (declaration) { |
| 6857 name = &H.DartSymbol(name_index); |
| 6858 } else { |
| 6815 name = &Symbols::AnonymousClosure(); | 6859 name = &Symbols::AnonymousClosure(); |
| 6816 } else { | |
| 6817 name = &H.DartSymbol(GetNameFromVariableDeclaration(variable_offeset)); | |
| 6818 } | 6860 } |
| 6819 // NOTE: This is not TokenPosition in the general sense! | 6861 // NOTE: This is not TokenPosition in the general sense! |
| 6820 function = Function::NewClosureFunction( | 6862 function = Function::NewClosureFunction( |
| 6821 *name, parsed_function()->function(), position); | 6863 *name, parsed_function()->function(), position); |
| 6822 | 6864 |
| 6823 function.set_is_debuggable(function_node_helper.dart_async_marker_ == | 6865 function.set_is_debuggable(function_node_helper.dart_async_marker_ == |
| 6824 FunctionNode::kSync); | 6866 FunctionNode::kSync); |
| 6825 switch (function_node_helper.dart_async_marker_) { | 6867 switch (function_node_helper.dart_async_marker_) { |
| 6826 case FunctionNode::kSyncStar: | 6868 case FunctionNode::kSyncStar: |
| 6827 function.set_modifier(RawFunction::kSyncGen); | 6869 function.set_modifier(RawFunction::kSyncGen); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6847 function.set_end_token_pos(function_node_helper.end_position_); | 6889 function.set_end_token_pos(function_node_helper.end_position_); |
| 6848 LocalScope* scope = scopes()->function_scopes[i].scope; | 6890 LocalScope* scope = scopes()->function_scopes[i].scope; |
| 6849 const ContextScope& context_scope = ContextScope::Handle( | 6891 const ContextScope& context_scope = ContextScope::Handle( |
| 6850 Z, scope->PreserveOuterScope(flow_graph_builder_->context_depth_)); | 6892 Z, scope->PreserveOuterScope(flow_graph_builder_->context_depth_)); |
| 6851 function.set_context_scope(context_scope); | 6893 function.set_context_scope(context_scope); |
| 6852 function.set_kernel_offset(offset); | 6894 function.set_kernel_offset(offset); |
| 6853 SetupFunctionParameters(dart::Class::Handle(Z), function, | 6895 SetupFunctionParameters(dart::Class::Handle(Z), function, |
| 6854 false, // is_method | 6896 false, // is_method |
| 6855 true, // is_closure | 6897 true, // is_closure |
| 6856 &function_node_helper); | 6898 &function_node_helper); |
| 6899 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
| 6900 TypedData& kernel_data = reader_->CopyDataToVMHeap( |
| 6901 Z, offset - relative_kernel_offset_, ReaderOffset()); |
| 6902 function.set_kernel_data(kernel_data); |
| 6857 | 6903 |
| 6858 // Finalize function type. | 6904 // Finalize function type. |
| 6859 Type& signature_type = Type::Handle(Z, function.SignatureType()); | 6905 Type& signature_type = Type::Handle(Z, function.SignatureType()); |
| 6860 signature_type ^= | 6906 signature_type ^= |
| 6861 ClassFinalizer::FinalizeType(*active_class()->klass, signature_type); | 6907 ClassFinalizer::FinalizeType(*active_class()->klass, signature_type); |
| 6862 function.SetSignatureType(signature_type); | 6908 function.SetSignatureType(signature_type); |
| 6863 | 6909 |
| 6864 I->AddClosureFunction(function); | 6910 I->AddClosureFunction(function); |
| 6865 break; | 6911 break; |
| 6866 } | 6912 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6911 bool is_factory = function.IsFactory(); | 6957 bool is_factory = function.IsFactory(); |
| 6912 intptr_t extra_parameters = (is_method || is_closure || is_factory) ? 1 : 0; | 6958 intptr_t extra_parameters = (is_method || is_closure || is_factory) ? 1 : 0; |
| 6913 | 6959 |
| 6914 function_node_helper->ReadUntilExcluding( | 6960 function_node_helper->ReadUntilExcluding( |
| 6915 FunctionNodeHelper::kPositionalParameters); | 6961 FunctionNodeHelper::kPositionalParameters); |
| 6916 | 6962 |
| 6917 intptr_t required_parameter_count = | 6963 intptr_t required_parameter_count = |
| 6918 function_node_helper->required_parameter_count_; | 6964 function_node_helper->required_parameter_count_; |
| 6919 intptr_t total_parameter_count = function_node_helper->total_parameter_count_; | 6965 intptr_t total_parameter_count = function_node_helper->total_parameter_count_; |
| 6920 | 6966 |
| 6921 intptr_t positional_parameters_count = ReadListLength(); // read list length. | 6967 intptr_t positional_parameter_count = ReadListLength(); // read list length. |
| 6922 | 6968 |
| 6923 intptr_t named_parameters_count = | 6969 intptr_t named_parameter_count = |
| 6924 total_parameter_count - positional_parameters_count; | 6970 total_parameter_count - positional_parameter_count; |
| 6925 | 6971 |
| 6926 function.set_num_fixed_parameters(extra_parameters + | 6972 function.set_num_fixed_parameters(extra_parameters + |
| 6927 required_parameter_count); | 6973 required_parameter_count); |
| 6928 if (named_parameters_count > 0) { | 6974 if (named_parameter_count > 0) { |
| 6929 function.SetNumOptionalParameters(named_parameters_count, false); | 6975 function.SetNumOptionalParameters(named_parameter_count, false); |
| 6930 } else { | 6976 } else { |
| 6931 function.SetNumOptionalParameters( | 6977 function.SetNumOptionalParameters( |
| 6932 positional_parameters_count - required_parameter_count, true); | 6978 positional_parameter_count - required_parameter_count, true); |
| 6933 } | 6979 } |
| 6934 intptr_t parameter_count = extra_parameters + total_parameter_count; | 6980 intptr_t parameter_count = extra_parameters + total_parameter_count; |
| 6935 function.set_parameter_types( | 6981 function.set_parameter_types( |
| 6936 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); | 6982 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); |
| 6937 function.set_parameter_names( | 6983 function.set_parameter_names( |
| 6938 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); | 6984 Array::Handle(Z, Array::New(parameter_count, Heap::kOld))); |
| 6939 intptr_t pos = 0; | 6985 intptr_t pos = 0; |
| 6940 if (is_method) { | 6986 if (is_method) { |
| 6941 ASSERT(!klass.IsNull()); | 6987 ASSERT(!klass.IsNull()); |
| 6942 function.SetParameterTypeAt(pos, H.GetCanonicalType(klass)); | 6988 function.SetParameterTypeAt(pos, H.GetCanonicalType(klass)); |
| 6943 function.SetParameterNameAt(pos, Symbols::This()); | 6989 function.SetParameterNameAt(pos, Symbols::This()); |
| 6944 pos++; | 6990 pos++; |
| 6945 } else if (is_closure) { | 6991 } else if (is_closure) { |
| 6946 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 6992 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
| 6947 function.SetParameterNameAt(pos, Symbols::ClosureParameter()); | 6993 function.SetParameterNameAt(pos, Symbols::ClosureParameter()); |
| 6948 pos++; | 6994 pos++; |
| 6949 } else if (is_factory) { | 6995 } else if (is_factory) { |
| 6950 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 6996 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
| 6951 function.SetParameterNameAt(pos, Symbols::TypeArgumentsParameter()); | 6997 function.SetParameterNameAt(pos, Symbols::TypeArgumentsParameter()); |
| 6952 pos++; | 6998 pos++; |
| 6953 } | 6999 } |
| 6954 | 7000 |
| 6955 for (intptr_t i = 0; i < positional_parameters_count; ++i, ++pos) { | 7001 for (intptr_t i = 0; i < positional_parameter_count; ++i, ++pos) { |
| 6956 // Read ith variable declaration. | 7002 // Read ith variable declaration. |
| 6957 VariableDeclarationHelper helper(this); | 7003 VariableDeclarationHelper helper(this); |
| 6958 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); | 7004 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
| 6959 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. | 7005 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. |
| 6960 Tag tag = ReadTag(); // read (first part of) initializer. | 7006 Tag tag = ReadTag(); // read (first part of) initializer. |
| 6961 if (tag == kSomething) { | 7007 if (tag == kSomething) { |
| 6962 SkipExpression(); // read (actual) initializer. | 7008 SkipExpression(); // read (actual) initializer. |
| 6963 } | 7009 } |
| 6964 | 7010 |
| 6965 function.SetParameterTypeAt( | 7011 function.SetParameterTypeAt( |
| 6966 pos, type.IsMalformed() ? Type::dynamic_type() : type); | 7012 pos, type.IsMalformed() ? Type::dynamic_type() : type); |
| 6967 function.SetParameterNameAt(pos, H.DartSymbol(helper.name_index_)); | 7013 function.SetParameterNameAt(pos, H.DartSymbol(helper.name_index_)); |
| 6968 } | 7014 } |
| 6969 | 7015 |
| 6970 intptr_t named_parameters_count_check = | 7016 intptr_t named_parameter_count_check = ReadListLength(); // read list length. |
| 6971 ReadListLength(); // read list length. | 7017 ASSERT(named_parameter_count_check == named_parameter_count); |
| 6972 ASSERT(named_parameters_count_check == named_parameters_count); | 7018 for (intptr_t i = 0; i < named_parameter_count; ++i, ++pos) { |
| 6973 for (intptr_t i = 0; i < named_parameters_count; ++i, ++pos) { | |
| 6974 // Read ith variable declaration. | 7019 // Read ith variable declaration. |
| 6975 VariableDeclarationHelper helper(this); | 7020 VariableDeclarationHelper helper(this); |
| 6976 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); | 7021 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
| 6977 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. | 7022 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. |
| 6978 Tag tag = ReadTag(); // read (first part of) initializer. | 7023 Tag tag = ReadTag(); // read (first part of) initializer. |
| 6979 if (tag == kSomething) { | 7024 if (tag == kSomething) { |
| 6980 SkipExpression(); // read (actual) initializer. | 7025 SkipExpression(); // read (actual) initializer. |
| 6981 } | 7026 } |
| 6982 | 7027 |
| 6983 function.SetParameterTypeAt( | 7028 function.SetParameterTypeAt( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6999 | 7044 |
| 7000 RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor( | 7045 RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor( |
| 7001 intptr_t kernel_offset) { | 7046 intptr_t kernel_offset) { |
| 7002 SetOffset(kernel_offset); | 7047 SetOffset(kernel_offset); |
| 7003 ReadUntilFunctionNode(); // read until function node. | 7048 ReadUntilFunctionNode(); // read until function node. |
| 7004 FunctionNodeHelper function_node_helper(this); | 7049 FunctionNodeHelper function_node_helper(this); |
| 7005 function_node_helper.ReadUntilExcluding( | 7050 function_node_helper.ReadUntilExcluding( |
| 7006 FunctionNodeHelper::kPositionalParameters); | 7051 FunctionNodeHelper::kPositionalParameters); |
| 7007 intptr_t param_count = function_node_helper.total_parameter_count_; | 7052 intptr_t param_count = function_node_helper.total_parameter_count_; |
| 7008 intptr_t positional_count = ReadListLength(); // read list length. | 7053 intptr_t positional_count = ReadListLength(); // read list length. |
| 7009 intptr_t named_parameters_count = param_count - positional_count; | 7054 intptr_t named_parameter_count = param_count - positional_count; |
| 7010 | 7055 |
| 7011 const Array& param_descriptor = Array::Handle( | 7056 const Array& param_descriptor = Array::Handle( |
| 7012 Array::New(param_count * Parser::kParameterEntrySize, Heap::kOld)); | 7057 Array::New(param_count * Parser::kParameterEntrySize, Heap::kOld)); |
| 7013 for (intptr_t i = 0; i < param_count; ++i) { | 7058 for (intptr_t i = 0; i < param_count; ++i) { |
| 7014 const intptr_t entry_start = i * Parser::kParameterEntrySize; | 7059 const intptr_t entry_start = i * Parser::kParameterEntrySize; |
| 7015 | 7060 |
| 7016 if (i == positional_count) { | 7061 if (i == positional_count) { |
| 7017 intptr_t named_parameters_count_check = | 7062 intptr_t named_parameter_count_check = |
| 7018 ReadListLength(); // read list length. | 7063 ReadListLength(); // read list length. |
| 7019 ASSERT(named_parameters_count_check == named_parameters_count); | 7064 ASSERT(named_parameter_count_check == named_parameter_count); |
| 7020 } | 7065 } |
| 7021 | 7066 |
| 7022 // Read ith variable declaration. | 7067 // Read ith variable declaration. |
| 7023 VariableDeclarationHelper helper(this); | 7068 VariableDeclarationHelper helper(this); |
| 7024 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); | 7069 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
| 7025 param_descriptor.SetAt(entry_start + Parser::kParameterIsFinalOffset, | 7070 param_descriptor.SetAt(entry_start + Parser::kParameterIsFinalOffset, |
| 7026 helper.IsFinal() ? Bool::True() : Bool::False()); | 7071 helper.IsFinal() ? Bool::True() : Bool::False()); |
| 7027 | 7072 |
| 7028 Tag tag = ReadTag(); // read (first part of) initializer. | 7073 Tag tag = ReadTag(); // read (first part of) initializer. |
| 7029 if (tag == kSomething) { | 7074 if (tag == kSomething) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7072 Instance& value = constant_evaluator_.EvaluateExpression(ReaderOffset()); | 7117 Instance& value = constant_evaluator_.EvaluateExpression(ReaderOffset()); |
| 7073 SkipExpression(); // read (actual) initializer. | 7118 SkipExpression(); // read (actual) initializer. |
| 7074 metadata_values.SetAt(i, value); | 7119 metadata_values.SetAt(i, value); |
| 7075 } | 7120 } |
| 7076 | 7121 |
| 7077 return metadata_values.raw(); | 7122 return metadata_values.raw(); |
| 7078 } | 7123 } |
| 7079 | 7124 |
| 7080 void StreamingFlowGraphBuilder::CollectTokenPositionsFor( | 7125 void StreamingFlowGraphBuilder::CollectTokenPositionsFor( |
| 7081 intptr_t script_index, | 7126 intptr_t script_index, |
| 7127 intptr_t initial_script_index, |
| 7082 GrowableArray<intptr_t>* record_token_positions_in, | 7128 GrowableArray<intptr_t>* record_token_positions_in, |
| 7083 GrowableArray<intptr_t>* record_yield_positions_in) { | 7129 GrowableArray<intptr_t>* record_yield_positions_in) { |
| 7084 record_token_positions_into_ = record_token_positions_in; | 7130 record_token_positions_into_ = record_token_positions_in; |
| 7085 record_yield_positions_into_ = record_yield_positions_in; | 7131 record_yield_positions_into_ = record_yield_positions_in; |
| 7086 record_for_script_id_ = script_index; | 7132 record_for_script_id_ = script_index; |
| 7133 current_script_id_ = initial_script_index; |
| 7087 | 7134 |
| 7088 // Get offset for 1st library. | 7135 const Tag tag = PeekTag(); |
| 7089 SetOffset(reader_->size() - 4); | 7136 if (tag == kProcedure) { |
| 7090 intptr_t library_count = reader_->ReadUInt32(); | 7137 ProcedureHelper procedure_helper(this); |
| 7091 | 7138 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); |
| 7092 SetOffset(reader_->size() - 4 - 4 * library_count); | 7139 } else if (tag == kConstructor) { |
| 7093 intptr_t offset = reader_->ReadUInt32(); | 7140 ConstructorHelper constructor_helper(this); |
| 7094 | 7141 constructor_helper.ReadUntilExcluding(ConstructorHelper::kEnd); |
| 7095 SetOffset(offset); | 7142 } else if (tag == kFunctionNode) { |
| 7096 for (intptr_t i = 0; i < library_count; ++i) { | 7143 FunctionNodeHelper function_node_helper(this); |
| 7097 LibraryHelper library_helper(this); | 7144 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
| 7098 library_helper.ReadUntilExcluding(LibraryHelper::kEnd); | 7145 } else if (tag == kField) { |
| 7146 FieldHelper field_helper(this); |
| 7147 field_helper.ReadUntilExcluding(FieldHelper::kEnd); |
| 7148 } else { |
| 7149 UNREACHABLE(); |
| 7099 } | 7150 } |
| 7100 | 7151 |
| 7101 record_token_positions_into_ = NULL; | 7152 record_token_positions_into_ = NULL; |
| 7102 record_yield_positions_into_ = NULL; | 7153 record_yield_positions_into_ = NULL; |
| 7103 record_for_script_id_ = -1; | 7154 record_for_script_id_ = -1; |
| 7104 } | 7155 } |
| 7105 | 7156 |
| 7106 intptr_t StreamingFlowGraphBuilder::SourceTableSize() { | 7157 intptr_t StreamingFlowGraphBuilder::SourceTableSize() { |
| 7107 AlternativeReadingScope alt(reader_); | 7158 AlternativeReadingScope alt(reader_); |
| 7108 SetOffset(reader_->size() - 4); | 7159 SetOffset(reader_->size() - 4); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7123 intptr_t end = -1; | 7174 intptr_t end = -1; |
| 7124 for (intptr_t i = 0; i < size; ++i) { | 7175 for (intptr_t i = 0; i < size; ++i) { |
| 7125 intptr_t offset = ReadUInt(); | 7176 intptr_t offset = ReadUInt(); |
| 7126 if (i == index - 1) { | 7177 if (i == index - 1) { |
| 7127 start = offset; | 7178 start = offset; |
| 7128 } else if (i == index) { | 7179 } else if (i == index) { |
| 7129 end = offset; | 7180 end = offset; |
| 7130 } | 7181 } |
| 7131 } | 7182 } |
| 7132 intptr_t end_offset = ReaderOffset(); | 7183 intptr_t end_offset = ReaderOffset(); |
| 7133 return H.DartString(reader_->buffer() + end_offset + start, end - start, | 7184 return H.DartString( |
| 7134 Heap::kOld); | 7185 reader_->CopyDataIntoZone(Z, end_offset + start, end - start), |
| 7186 end - start, Heap::kOld); |
| 7135 } | 7187 } |
| 7136 | 7188 |
| 7137 String& StreamingFlowGraphBuilder::GetSourceFor(intptr_t index) { | 7189 String& StreamingFlowGraphBuilder::GetSourceFor(intptr_t index) { |
| 7138 AlternativeReadingScope alt(reader_); | 7190 AlternativeReadingScope alt(reader_); |
| 7139 SetOffset(reader_->size() - 4); | 7191 SetOffset(reader_->size() - 4); |
| 7140 intptr_t library_count = reader_->ReadUInt32(); | 7192 intptr_t library_count = reader_->ReadUInt32(); |
| 7141 SetOffset(reader_->size() - 4 - 4 * library_count - 3 * 4); | 7193 SetOffset(reader_->size() - 4 - 4 * library_count - 3 * 4); |
| 7142 SetOffset(reader_->ReadUInt32()); // read source table offset. | 7194 SetOffset(reader_->ReadUInt32()); // read source table offset. |
| 7143 intptr_t size = ReadUInt(); // read source table size. | 7195 intptr_t size = ReadUInt(); // read source table size. |
| 7144 intptr_t uris_size = 0; | 7196 intptr_t uris_size = 0; |
| 7145 for (intptr_t i = 0; i < size; ++i) { | 7197 for (intptr_t i = 0; i < size; ++i) { |
| 7146 uris_size = ReadUInt(); | 7198 uris_size = ReadUInt(); |
| 7147 } | 7199 } |
| 7148 SkipBytes(uris_size); | 7200 SkipBytes(uris_size); |
| 7149 | 7201 |
| 7150 // Read the source code strings and line starts. | 7202 // Read the source code strings and line starts. |
| 7151 for (intptr_t i = 0; i < size; ++i) { | 7203 for (intptr_t i = 0; i < size; ++i) { |
| 7152 intptr_t length = ReadUInt(); | 7204 intptr_t length = ReadUInt(); |
| 7153 if (index == i) { | 7205 if (index == i) { |
| 7154 return H.DartString(reader_->buffer() + ReaderOffset(), length, | 7206 return H.DartString(reader_->CopyDataIntoZone(Z, ReaderOffset(), length), |
| 7155 Heap::kOld); | 7207 length, Heap::kOld); |
| 7156 } | 7208 } |
| 7157 SkipBytes(length); | 7209 SkipBytes(length); |
| 7158 intptr_t line_count = ReadUInt(); | 7210 intptr_t line_count = ReadUInt(); |
| 7159 for (intptr_t j = 0; j < line_count; ++j) { | 7211 for (intptr_t j = 0; j < line_count; ++j) { |
| 7160 ReadUInt(); | 7212 ReadUInt(); |
| 7161 } | 7213 } |
| 7162 } | 7214 } |
| 7163 | 7215 |
| 7164 return String::Handle(String::null()); | 7216 return String::Handle(String::null()); |
| 7165 } | 7217 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7201 } | 7253 } |
| 7202 } | 7254 } |
| 7203 | 7255 |
| 7204 return Array::Handle(Array::null()); | 7256 return Array::Handle(Array::null()); |
| 7205 } | 7257 } |
| 7206 | 7258 |
| 7207 } // namespace kernel | 7259 } // namespace kernel |
| 7208 } // namespace dart | 7260 } // namespace dart |
| 7209 | 7261 |
| 7210 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 7262 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
| OLD | NEW |