OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/kernel_binary_flowgraph.h" | 5 #include "vm/kernel_binary_flowgraph.h" |
6 | 6 |
7 #include "vm/compiler.h" | 7 #include "vm/compiler.h" |
8 #include "vm/longjump.h" | 8 #include "vm/longjump.h" |
9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 LocalVariable* context_var = parsed_function->current_context_var(); | 112 LocalVariable* context_var = parsed_function->current_context_var(); |
113 context_var->set_is_forced_stack(); | 113 context_var->set_is_forced_stack(); |
114 scope_->AddVariable(context_var); | 114 scope_->AddVariable(context_var); |
115 | 115 |
116 parsed_function->SetNodeSequence( | 116 parsed_function->SetNodeSequence( |
117 new SequenceNode(TokenPosition::kNoSource, scope_)); | 117 new SequenceNode(TokenPosition::kNoSource, scope_)); |
118 | 118 |
119 intptr_t parent_offset = -1; | 119 intptr_t parent_offset = -1; |
120 builder_->SetOffset(kernel_offset_); | 120 builder_->SetOffset(kernel_offset_); |
121 | 121 |
| 122 FunctionNodeHelper function_node_helper(builder_); |
| 123 |
122 switch (function.kind()) { | 124 switch (function.kind()) { |
123 case RawFunction::kClosureFunction: | 125 case RawFunction::kClosureFunction: |
124 case RawFunction::kRegularFunction: | 126 case RawFunction::kRegularFunction: |
125 case RawFunction::kGetterFunction: | 127 case RawFunction::kGetterFunction: |
126 case RawFunction::kSetterFunction: | 128 case RawFunction::kSetterFunction: |
127 case RawFunction::kConstructor: { | 129 case RawFunction::kConstructor: { |
128 const Tag tag = builder_->PeekTag(); | 130 const Tag tag = builder_->PeekTag(); |
129 parent_offset = builder_->ReadUntilFunctionNode(); | 131 parent_offset = builder_->ReadUntilFunctionNode(); |
130 word async_marker_word; | 132 function_node_helper.ReadUntilExcluding( |
131 builder_->ReadFunctionNodeUntilTypeParameters( | 133 FunctionNodeHelper::kPositionalParameters); |
132 &unused_tokenposition, &unused_tokenposition, &async_marker_word, | 134 current_function_async_marker_ = function_node_helper.async_marker_; |
133 &unused_word); // read first part of function node. | 135 // NOTE: FunctionNode is read further below the if. |
134 current_function_async_marker_ = | |
135 static_cast<FunctionNode::AsyncMarker>(async_marker_word); | |
136 // NOTE: FunctionNode is not read entirely yet! It continues below the if. | |
137 | 136 |
138 intptr_t pos = 0; | 137 intptr_t pos = 0; |
139 if (function.IsClosureFunction()) { | 138 if (function.IsClosureFunction()) { |
140 LocalVariable* variable = MakeVariable( | 139 LocalVariable* variable = MakeVariable( |
141 TokenPosition::kNoSource, TokenPosition::kNoSource, | 140 TokenPosition::kNoSource, TokenPosition::kNoSource, |
142 Symbols::ClosureParameter(), AbstractType::dynamic_type()); | 141 Symbols::ClosureParameter(), AbstractType::dynamic_type()); |
143 variable->set_is_forced_stack(); | 142 variable->set_is_forced_stack(); |
144 scope_->InsertParameterAt(pos++, variable); | 143 scope_->InsertParameterAt(pos++, variable); |
145 } else if (!function.is_static()) { | 144 } else if (!function.is_static()) { |
146 // We use [is_static] instead of [IsStaticFunction] because the latter | 145 // We use [is_static] instead of [IsStaticFunction] because the latter |
147 // returns `false` for constructors. | 146 // returns `false` for constructors. |
148 dart::Class& klass = dart::Class::Handle(Z, function.Owner()); | 147 dart::Class& klass = dart::Class::Handle(Z, function.Owner()); |
149 Type& klass_type = H.GetCanonicalType(klass); | 148 Type& klass_type = H.GetCanonicalType(klass); |
150 LocalVariable* variable = | 149 LocalVariable* variable = |
151 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, | 150 MakeVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, |
152 Symbols::This(), klass_type); | 151 Symbols::This(), klass_type); |
153 scope_->InsertParameterAt(pos++, variable); | 152 scope_->InsertParameterAt(pos++, variable); |
154 result_->this_variable = variable; | 153 result_->this_variable = variable; |
155 | 154 |
156 // We visit instance field initializers because they might contain | 155 // We visit instance field initializers because they might contain |
157 // [Let] expressions and we need to have a mapping. | 156 // [Let] expressions and we need to have a mapping. |
158 if (tag == kConstructor) { | 157 if (tag == kConstructor) { |
159 ASSERT(parent_offset >= 0); | 158 ASSERT(parent_offset >= 0); |
160 AlternativeReadingScope alt(builder_->reader_, parent_offset); | 159 AlternativeReadingScope alt(builder_->reader_, parent_offset); |
161 builder_->ReadClassUntilFields(); // read first part of class. | 160 ClassHelper class_helper(builder_); |
| 161 class_helper.ReadUntilExcluding(ClassHelper::kFields); |
162 intptr_t list_length = | 162 intptr_t list_length = |
163 builder_->ReadListLength(); // read fields list length. | 163 builder_->ReadListLength(); // read fields list length. |
164 for (intptr_t i = 0; i < list_length; i++) { | 164 for (intptr_t i = 0; i < list_length; i++) { |
165 intptr_t field_offset = builder_->ReaderOffset(); | 165 intptr_t field_offset = builder_->ReaderOffset(); |
166 TokenPosition position; | 166 FieldHelper field_helper(builder_); |
167 TokenPosition end_position; | 167 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
168 word flags; | |
169 builder_->ReadFieldUntilAnnotation(&unused_nameindex, &position, | |
170 &end_position, &flags, | |
171 &unused_intptr); | |
172 bool is_static = (flags & Field::kFlagStatic) == Field::kFlagStatic; | |
173 builder_->SkipListOfExpressions(); // read annotations. | |
174 builder_->SkipDartType(); // read type. | |
175 Tag initializer_tag = | 168 Tag initializer_tag = |
176 builder_->ReadTag(); // read first part of initializer. | 169 builder_->ReadTag(); // read first part of initializer. |
177 if (!is_static && initializer_tag == kSomething) { | 170 if (!field_helper.IsStatic() && initializer_tag == kSomething) { |
178 EnterScope(field_offset); | 171 EnterScope(field_offset); |
179 VisitExpression(); // read initializer. | 172 VisitExpression(); // read initializer. |
180 ExitScope(position, end_position); | 173 ExitScope(field_helper.position_, field_helper.end_position_); |
181 } else if (initializer_tag == kSomething) { | 174 } else if (initializer_tag == kSomething) { |
182 builder_->SkipExpression(); // read initializer. | 175 builder_->SkipExpression(); // read initializer. |
183 } | 176 } |
184 } | 177 } |
185 } | 178 } |
186 } else if (function.IsFactory()) { | 179 } else if (function.IsFactory()) { |
187 LocalVariable* variable = MakeVariable( | 180 LocalVariable* variable = MakeVariable( |
188 TokenPosition::kNoSource, TokenPosition::kNoSource, | 181 TokenPosition::kNoSource, TokenPosition::kNoSource, |
189 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); | 182 Symbols::TypeArgumentsParameter(), AbstractType::dynamic_type()); |
190 scope_->InsertParameterAt(pos++, variable); | 183 scope_->InsertParameterAt(pos++, variable); |
191 result_->type_arguments_variable = variable; | 184 result_->type_arguments_variable = variable; |
192 } | 185 } |
193 | 186 |
194 // Continue reading FunctionNode. | 187 // Continue reading FunctionNode: |
195 builder_->SkipTypeParametersList(); // read type_parameters. | 188 // read positional_parameters and named_parameters. |
196 builder_->ReadUInt(); // read total parameter count. | 189 AddPositionalAndNamedParameters(pos); |
197 builder_->ReadUInt(); // read required_parameter_count. | |
198 AddPositionalAndNamedParameters( | |
199 pos); // read positional_parameters and named_parameters. | |
200 | 190 |
201 // We generate a syntethic body for implicit closure functions - which | 191 // We generate a syntethic body for implicit closure functions - which |
202 // will forward the call to the real function. | 192 // will forward the call to the real function. |
203 // -> see BuildGraphOfImplicitClosureFunction | 193 // -> see BuildGraphOfImplicitClosureFunction |
204 if (!function.IsImplicitClosureFunction()) { | 194 if (!function.IsImplicitClosureFunction()) { |
205 builder_->SetOffset(kernel_offset_); | 195 builder_->SetOffset(kernel_offset_); |
206 first_body_token_position_ = TokenPosition::kNoSource; | 196 first_body_token_position_ = TokenPosition::kNoSource; |
207 VisitNode(); | 197 VisitNode(); |
208 | 198 |
209 // TODO(jensj): HACK: Push the begin token to after any parameters to | 199 // TODO(jensj): HACK: Push the begin token to after any parameters to |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 return; | 297 return; |
308 } | 298 } |
309 } | 299 } |
310 | 300 |
311 void StreamingScopeBuilder::VisitConstructor() { | 301 void StreamingScopeBuilder::VisitConstructor() { |
312 // Field initializers that come from non-static field declarations are | 302 // Field initializers that come from non-static field declarations are |
313 // compiled as if they appear in the constructor initializer list. This is | 303 // compiled as if they appear in the constructor initializer list. This is |
314 // important for closure-valued field initializers because the VM expects the | 304 // important for closure-valued field initializers because the VM expects the |
315 // corresponding closure functions to appear as if they were nested inside the | 305 // corresponding closure functions to appear as if they were nested inside the |
316 // constructor. | 306 // constructor. |
317 intptr_t parent_offset = builder_->ReadConstructorUntilFunctionNode(); | 307 ConstructorHelper constructor_helper(builder_); |
| 308 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); |
| 309 intptr_t parent_offset = constructor_helper.parent_class_binary_offset_; |
318 ASSERT(parent_offset >= 0); | 310 ASSERT(parent_offset >= 0); |
319 { | 311 { |
320 AlternativeReadingScope alt(builder_->reader_, parent_offset); | 312 AlternativeReadingScope alt(builder_->reader_, parent_offset); |
321 builder_->ReadClassUntilFields(); // read first part of class. | 313 ClassHelper class_helper(builder_); |
| 314 class_helper.ReadUntilExcluding(ClassHelper::kFields); |
322 | 315 |
323 intptr_t list_length = | 316 intptr_t list_length = |
324 builder_->ReadListLength(); // read fields list length. | 317 builder_->ReadListLength(); // read fields list length. |
325 for (intptr_t i = 0; i < list_length; i++) { | 318 for (intptr_t i = 0; i < list_length; i++) { |
326 word flags; | 319 FieldHelper field_helper(builder_); |
327 builder_->ReadFieldUntilAnnotation( | 320 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
328 &unused_nameindex, &unused_tokenposition, &unused_tokenposition, | |
329 &flags, &unused_intptr); | |
330 bool is_static = (flags & Field::kFlagStatic) == Field::kFlagStatic; | |
331 builder_->SkipListOfExpressions(); // read annotations. | |
332 builder_->SkipDartType(); // read type. | |
333 Tag initializer_tag = builder_->ReadTag(); | 321 Tag initializer_tag = builder_->ReadTag(); |
334 if (!is_static && initializer_tag == kSomething) { | 322 if (!field_helper.IsStatic() && initializer_tag == kSomething) { |
335 VisitExpression(); // read initializer. | 323 VisitExpression(); // read initializer. |
336 } else if (initializer_tag == kSomething) { | 324 } else if (initializer_tag == kSomething) { |
337 builder_->SkipExpression(); // read initializer. | 325 builder_->SkipExpression(); // read initializer. |
338 } | 326 } |
339 } | 327 } |
340 } | 328 } |
341 | 329 |
342 // Visit children (note that there's no reason to visit the name). | 330 // Visit children (note that there's no reason to visit the name). |
343 VisitFunctionNode(); | 331 VisitFunctionNode(); |
344 intptr_t list_length = | 332 intptr_t list_length = |
345 builder_->ReadListLength(); // read initializers list length. | 333 builder_->ReadListLength(); // read initializers list length. |
346 for (intptr_t i = 0; i < list_length; i++) { | 334 for (intptr_t i = 0; i < list_length; i++) { |
347 VisitInitializer(); | 335 VisitInitializer(); |
348 } | 336 } |
349 } | 337 } |
350 | 338 |
351 void StreamingScopeBuilder::VisitProcedure() { | 339 void StreamingScopeBuilder::VisitProcedure() { |
352 Tag function_node = builder_->ReadProcedureUntilFunctionNode( | 340 ProcedureHelper procedure_helper(builder_); |
353 &unused_word, &unused_intptr); // read first part of procedure. | 341 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
354 if (function_node == kSomething) { | 342 if (builder_->ReadTag() == kSomething) { |
355 VisitFunctionNode(); | 343 VisitFunctionNode(); |
356 } | 344 } |
357 } | 345 } |
358 | 346 |
359 void StreamingScopeBuilder::VisitField() { | 347 void StreamingScopeBuilder::VisitField() { |
360 builder_->ReadFieldUntilAnnotation( | 348 FieldHelper field_helper(builder_); |
361 &unused_nameindex, &unused_tokenposition, &unused_tokenposition, | 349 field_helper.ReadUntilExcluding(FieldHelper::kType); |
362 &unused_intptr, &unused_word); // read first part of field. | |
363 builder_->SkipListOfExpressions(); // read annotations. | |
364 VisitDartType(); // read type. | 350 VisitDartType(); // read type. |
365 Tag tag = builder_->ReadTag(); // read initializer (part 1). | 351 Tag tag = builder_->ReadTag(); // read initializer (part 1). |
366 if (tag == kSomething) { | 352 if (tag == kSomething) { |
367 VisitExpression(); // read initializer (part 2). | 353 VisitExpression(); // read initializer (part 2). |
368 } | 354 } |
369 } | 355 } |
370 | 356 |
371 void StreamingScopeBuilder::VisitFunctionNode() { | 357 void StreamingScopeBuilder::VisitFunctionNode() { |
372 word async_marker_word; | 358 FunctionNodeHelper function_node_helper(builder_); |
373 word dart_async_marker_word; | 359 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kTypeParameters); |
374 builder_->ReadFunctionNodeUntilTypeParameters( | |
375 &unused_tokenposition, &unused_tokenposition, &async_marker_word, | |
376 &dart_async_marker_word); | |
377 FunctionNode::AsyncMarker async_marker = | |
378 static_cast<FunctionNode::AsyncMarker>(async_marker_word); | |
379 FunctionNode::AsyncMarker dart_async_marker = | |
380 static_cast<FunctionNode::AsyncMarker>(dart_async_marker_word); | |
381 | 360 |
382 intptr_t list_length = | 361 intptr_t list_length = |
383 builder_->ReadListLength(); // read type_parameters list length. | 362 builder_->ReadListLength(); // read type_parameters list length. |
384 for (intptr_t i = 0; i < list_length; ++i) { | 363 for (intptr_t i = 0; i < list_length; ++i) { |
385 builder_->SkipStringReference(); // read ith name index. | 364 builder_->SkipStringReference(); // read ith name index. |
386 VisitDartType(); // read ith bound. | 365 VisitDartType(); // read ith bound. |
387 } | 366 } |
| 367 function_node_helper.SetJustRead(FunctionNodeHelper::kTypeParameters); |
388 | 368 |
389 if (FLAG_causal_async_stacks && | 369 if (FLAG_causal_async_stacks && |
390 (dart_async_marker == FunctionNode::kAsync || | 370 (function_node_helper.dart_async_marker_ == FunctionNode::kAsync || |
391 dart_async_marker == FunctionNode::kAsyncStar)) { | 371 function_node_helper.dart_async_marker_ == FunctionNode::kAsyncStar)) { |
392 LocalVariable* asyncStackTraceVar = MakeVariable( | 372 LocalVariable* asyncStackTraceVar = MakeVariable( |
393 TokenPosition::kNoSource, TokenPosition::kNoSource, | 373 TokenPosition::kNoSource, TokenPosition::kNoSource, |
394 Symbols::AsyncStackTraceVar(), AbstractType::dynamic_type()); | 374 Symbols::AsyncStackTraceVar(), AbstractType::dynamic_type()); |
395 scope_->AddVariable(asyncStackTraceVar); | 375 scope_->AddVariable(asyncStackTraceVar); |
396 } | 376 } |
397 | 377 |
398 if (async_marker == FunctionNode::kSyncYielding) { | 378 if (function_node_helper.async_marker_ == FunctionNode::kSyncYielding) { |
399 LocalScope* scope = parsed_function_->node_sequence()->scope(); | 379 LocalScope* scope = parsed_function_->node_sequence()->scope(); |
400 intptr_t offset = parsed_function_->function().num_fixed_parameters(); | 380 intptr_t offset = parsed_function_->function().num_fixed_parameters(); |
401 for (intptr_t i = 0; | 381 for (intptr_t i = 0; |
402 i < parsed_function_->function().NumOptionalPositionalParameters(); | 382 i < parsed_function_->function().NumOptionalPositionalParameters(); |
403 i++) { | 383 i++) { |
404 scope->VariableAt(offset + i)->set_is_forced_stack(); | 384 scope->VariableAt(offset + i)->set_is_forced_stack(); |
405 } | 385 } |
406 } | 386 } |
407 | 387 |
408 // Read (but don't visit) the positional and named parameters, because they've | 388 // Read (but don't visit) the positional and named parameters, because they've |
409 // already been added to the scope. | 389 // already been added to the scope. |
410 | 390 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kBody); |
411 builder_->ReadUInt(); // read total parameter count. | |
412 builder_->ReadUInt(); // read required_parameter_count. | |
413 | |
414 builder_->SkipListOfVariableDeclarations(); // read list of positionals. | |
415 builder_->SkipListOfVariableDeclarations(); // read list of named. | |
416 builder_->SkipDartType(); // read return type. | |
417 | 391 |
418 if (builder_->ReadTag() == kSomething) { | 392 if (builder_->ReadTag() == kSomething) { |
419 PositionScope scope(builder_->reader_); | 393 PositionScope scope(builder_->reader_); |
420 VisitStatement(); // Read body | 394 VisitStatement(); // Read body |
421 first_body_token_position_ = builder_->reader_->min_position(); | 395 first_body_token_position_ = builder_->reader_->min_position(); |
422 } | 396 } |
423 | 397 |
424 // Ensure that :await_jump_var, :await_ctx_var, :async_op and | 398 // Ensure that :await_jump_var, :await_ctx_var, :async_op and |
425 // :async_stack_trace are captured. | 399 // :async_stack_trace are captured. |
426 if (async_marker == FunctionNode::kSyncYielding) { | 400 if (function_node_helper.async_marker_ == FunctionNode::kSyncYielding) { |
427 { | 401 { |
428 LocalVariable* temp = NULL; | 402 LocalVariable* temp = NULL; |
429 LookupCapturedVariableByName( | 403 LookupCapturedVariableByName( |
430 (depth_.function_ == 0) ? &result_->yield_jump_variable : &temp, | 404 (depth_.function_ == 0) ? &result_->yield_jump_variable : &temp, |
431 Symbols::AwaitJumpVar()); | 405 Symbols::AwaitJumpVar()); |
432 } | 406 } |
433 { | 407 { |
434 LocalVariable* temp = NULL; | 408 LocalVariable* temp = NULL; |
435 LookupCapturedVariableByName( | 409 LookupCapturedVariableByName( |
436 (depth_.function_ == 0) ? &result_->yield_context_variable : &temp, | 410 (depth_.function_ == 0) ? &result_->yield_context_variable : &temp, |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 for (intptr_t i = 0; i < list_length; ++i) { | 950 for (intptr_t i = 0; i < list_length; ++i) { |
977 builder_->SkipStringReference(); // read ith name index. | 951 builder_->SkipStringReference(); // read ith name index. |
978 VisitExpression(); // read ith expression. | 952 VisitExpression(); // read ith expression. |
979 } | 953 } |
980 } | 954 } |
981 | 955 |
982 void StreamingScopeBuilder::VisitVariableDeclaration() { | 956 void StreamingScopeBuilder::VisitVariableDeclaration() { |
983 PositionScope scope(builder_->reader_); | 957 PositionScope scope(builder_->reader_); |
984 | 958 |
985 intptr_t kernel_offset_no_tag = builder_->ReaderOffset(); | 959 intptr_t kernel_offset_no_tag = builder_->ReaderOffset(); |
986 TokenPosition position = builder_->ReadPosition(); // read position. | 960 VariableDeclarationHelper helper(builder_); |
987 builder_->ReadPosition(); // read equals position. | 961 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
988 word flags = builder_->ReadFlags(); // read flags. | |
989 bool is_final = (flags & VariableDeclaration::kFlagFinal) == | |
990 VariableDeclaration::kFlagFinal; | |
991 StringIndex name_index = builder_->ReadStringReference(); // read name index. | |
992 intptr_t offset_for_type = builder_->ReaderOffset(); | 962 intptr_t offset_for_type = builder_->ReaderOffset(); |
993 AbstractType& type = T.BuildVariableType(); // read type. | 963 AbstractType& type = T.BuildVariableType(); // read type. |
994 | 964 |
995 // In case `declaration->IsConst()` the flow graph building will take care of | 965 // In case `declaration->IsConst()` the flow graph building will take care of |
996 // evaluating the constant and setting it via | 966 // evaluating the constant and setting it via |
997 // `declaration->SetConstantValue()`. | 967 // `declaration->SetConstantValue()`. |
998 const dart::String& name = (H.StringSize(name_index) == 0) | 968 const dart::String& name = (H.StringSize(helper.name_index_) == 0) |
999 ? GenerateName(":var", name_index_++) | 969 ? GenerateName(":var", name_index_++) |
1000 : H.DartSymbol(name_index); | 970 : H.DartSymbol(helper.name_index_); |
1001 // We also need to visit the type. | 971 // We also need to visit the type. |
1002 builder_->SetOffset(offset_for_type); | 972 builder_->SetOffset(offset_for_type); |
1003 VisitDartType(); // read type. | 973 VisitDartType(); // read type. |
1004 | 974 |
1005 Tag tag = builder_->ReadTag(); // read (first part of) initializer. | 975 Tag tag = builder_->ReadTag(); // read (first part of) initializer. |
1006 if (tag == kSomething) { | 976 if (tag == kSomething) { |
1007 VisitExpression(); // read (actual) initializer. | 977 VisitExpression(); // read (actual) initializer. |
1008 } | 978 } |
1009 | 979 |
1010 // Go to next token position so it ends *after* the last potentially | 980 // Go to next token position so it ends *after* the last potentially |
1011 // debuggable position in the initializer. | 981 // debuggable position in the initializer. |
1012 TokenPosition end_position = builder_->reader_->max_position(); | 982 TokenPosition end_position = builder_->reader_->max_position(); |
1013 if (end_position.IsReal()) { | 983 if (end_position.IsReal()) { |
1014 end_position.Next(); | 984 end_position.Next(); |
1015 } | 985 } |
1016 LocalVariable* variable = MakeVariable(position, end_position, name, type); | 986 LocalVariable* variable = |
1017 if (is_final) { | 987 MakeVariable(helper.position_, end_position, name, type); |
| 988 if (helper.IsFinal()) { |
1018 variable->set_is_final(); | 989 variable->set_is_final(); |
1019 } | 990 } |
1020 scope_->AddVariable(variable); | 991 scope_->AddVariable(variable); |
1021 result_->locals.Insert(kernel_offset_no_tag, variable); | 992 result_->locals.Insert(kernel_offset_no_tag, variable); |
1022 } | 993 } |
1023 | 994 |
1024 void StreamingScopeBuilder::VisitDartType() { | 995 void StreamingScopeBuilder::VisitDartType() { |
1025 Tag tag = builder_->ReadTag(); | 996 Tag tag = builder_->ReadTag(); |
1026 switch (tag) { | 997 switch (tag) { |
1027 case kInvalidType: | 998 case kInvalidType: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 | 1081 |
1111 builder_->ReadUInt(); // read index for parameter. | 1082 builder_->ReadUInt(); // read index for parameter. |
1112 builder_->ReadUInt(); // read binary offset. | 1083 builder_->ReadUInt(); // read binary offset. |
1113 builder_->SkipOptionalDartType(); // read bound bound. | 1084 builder_->SkipOptionalDartType(); // read bound bound. |
1114 } | 1085 } |
1115 | 1086 |
1116 void StreamingScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) { | 1087 void StreamingScopeBuilder::HandleLocalFunction(intptr_t parent_kernel_offset) { |
1117 // "Peek" ahead into the function node | 1088 // "Peek" ahead into the function node |
1118 intptr_t offset = builder_->ReaderOffset(); | 1089 intptr_t offset = builder_->ReaderOffset(); |
1119 | 1090 |
1120 Tag tag = builder_->ReadTag(); // read tag. | 1091 FunctionNodeHelper function_node_helper(builder_); |
1121 ASSERT(tag == kFunctionNode); | 1092 function_node_helper.ReadUntilExcluding( |
1122 TokenPosition position = builder_->ReadPosition(); // read position. | 1093 FunctionNodeHelper::kPositionalParameters); |
1123 TokenPosition end_position = builder_->ReadPosition(); // read end position. | |
1124 FunctionNode::AsyncMarker async_marker = | |
1125 static_cast<FunctionNode::AsyncMarker>( | |
1126 builder_->ReadByte()); // read async marker. | |
1127 builder_->ReadByte(); // read dart async marker. | |
1128 builder_->SkipTypeParametersList(); // read type_parameters. | |
1129 | 1094 |
1130 LocalScope* saved_function_scope = current_function_scope_; | 1095 LocalScope* saved_function_scope = current_function_scope_; |
1131 FunctionNode::AsyncMarker saved_function_async_marker = | 1096 FunctionNode::AsyncMarker saved_function_async_marker = |
1132 current_function_async_marker_; | 1097 current_function_async_marker_; |
1133 StreamingScopeBuilder::DepthState saved_depth_state = depth_; | 1098 StreamingScopeBuilder::DepthState saved_depth_state = depth_; |
1134 depth_ = DepthState(depth_.function_ + 1); | 1099 depth_ = DepthState(depth_.function_ + 1); |
1135 EnterScope(parent_kernel_offset); | 1100 EnterScope(parent_kernel_offset); |
1136 current_function_scope_ = scope_; | 1101 current_function_scope_ = scope_; |
1137 current_function_async_marker_ = async_marker; | 1102 current_function_async_marker_ = function_node_helper.async_marker_; |
1138 if (depth_.function_ == 1) { | 1103 if (depth_.function_ == 1) { |
1139 FunctionScope function_scope = {offset, scope_}; | 1104 FunctionScope function_scope = {offset, scope_}; |
1140 result_->function_scopes.Add(function_scope); | 1105 result_->function_scopes.Add(function_scope); |
1141 } | 1106 } |
1142 | 1107 |
1143 builder_->ReadUInt(); // read total parameter count. | |
1144 builder_->ReadUInt(); // read required_parameter_count. | |
1145 // read positional_parameters and named_parameters. | 1108 // read positional_parameters and named_parameters. |
1146 AddPositionalAndNamedParameters(); | 1109 AddPositionalAndNamedParameters(); |
1147 | 1110 |
1148 // "Peek" is now done. | 1111 // "Peek" is now done. |
1149 builder_->SetOffset(offset); | 1112 builder_->SetOffset(offset); |
1150 | 1113 |
1151 VisitFunctionNode(); // read function node. | 1114 VisitFunctionNode(); // read function node. |
1152 | 1115 |
1153 ExitScope(position, end_position); | 1116 ExitScope(function_node_helper.position_, function_node_helper.end_position_); |
1154 depth_ = saved_depth_state; | 1117 depth_ = saved_depth_state; |
1155 current_function_scope_ = saved_function_scope; | 1118 current_function_scope_ = saved_function_scope; |
1156 current_function_async_marker_ = saved_function_async_marker; | 1119 current_function_async_marker_ = saved_function_async_marker; |
1157 } | 1120 } |
1158 | 1121 |
1159 void StreamingScopeBuilder::EnterScope(intptr_t kernel_offset) { | 1122 void StreamingScopeBuilder::EnterScope(intptr_t kernel_offset) { |
1160 scope_ = new (Z) LocalScope(scope_, depth_.function_, depth_.loop_); | 1123 scope_ = new (Z) LocalScope(scope_, depth_.function_, depth_.loop_); |
1161 ASSERT(kernel_offset >= 0); | 1124 ASSERT(kernel_offset >= 0); |
1162 result_->scopes.Insert(kernel_offset, scope_); | 1125 result_->scopes.Insert(kernel_offset, scope_); |
1163 } | 1126 } |
(...skipping 15 matching lines...) Expand all Loading... |
1179 | 1142 |
1180 // List of named. | 1143 // List of named. |
1181 list_length = builder_->ReadListLength(); // read list length. | 1144 list_length = builder_->ReadListLength(); // read list length. |
1182 for (intptr_t i = 0; i < list_length; ++i) { | 1145 for (intptr_t i = 0; i < list_length; ++i) { |
1183 AddVariableDeclarationParameter(pos++); // read ith named parameter. | 1146 AddVariableDeclarationParameter(pos++); // read ith named parameter. |
1184 } | 1147 } |
1185 } | 1148 } |
1186 | 1149 |
1187 void StreamingScopeBuilder::AddVariableDeclarationParameter(intptr_t pos) { | 1150 void StreamingScopeBuilder::AddVariableDeclarationParameter(intptr_t pos) { |
1188 intptr_t kernel_offset = builder_->ReaderOffset(); // no tag. | 1151 intptr_t kernel_offset = builder_->ReaderOffset(); // no tag. |
1189 TokenPosition position = builder_->ReadPosition(); // read position. | 1152 VariableDeclarationHelper helper(builder_); |
1190 builder_->ReadPosition(); // read equals position. | 1153 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
1191 word flags = builder_->ReadFlags(); // read flags. | 1154 String& name = H.DartSymbol(helper.name_index_); |
1192 bool is_final = (flags & VariableDeclaration::kFlagFinal) == | |
1193 VariableDeclaration::kFlagFinal; | |
1194 String& name = H.DartSymbol(builder_->ReadStringReference()); // read name. | |
1195 AbstractType& type = T.BuildVariableType(); // read type. | 1155 AbstractType& type = T.BuildVariableType(); // read type. |
| 1156 helper.SetJustRead(VariableDeclarationHelper::kType); |
| 1157 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
1196 | 1158 |
1197 LocalVariable* variable = MakeVariable(position, position, name, type); | 1159 LocalVariable* variable = |
1198 if (is_final) { | 1160 MakeVariable(helper.position_, helper.position_, name, type); |
| 1161 if (helper.IsFinal()) { |
1199 variable->set_is_final(); | 1162 variable->set_is_final(); |
1200 } | 1163 } |
1201 if (variable->name().raw() == Symbols::IteratorParameter().raw()) { | 1164 if (variable->name().raw() == Symbols::IteratorParameter().raw()) { |
1202 variable->set_is_forced_stack(); | 1165 variable->set_is_forced_stack(); |
1203 } | 1166 } |
1204 scope_->InsertParameterAt(pos, variable); | 1167 scope_->InsertParameterAt(pos, variable); |
1205 result_->locals.Insert(kernel_offset, variable); | 1168 result_->locals.Insert(kernel_offset, variable); |
1206 | 1169 |
1207 // The default value may contain 'let' bindings for which the constant | 1170 // The default value may contain 'let' bindings for which the constant |
1208 // evaluator needs scope bindings. | 1171 // evaluator needs scope bindings. |
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 result_.SetTypeArguments(type_arguments); | 2231 result_.SetTypeArguments(type_arguments); |
2269 result_.SetField(field, const_kv_array); | 2232 result_.SetField(field, const_kv_array); |
2270 result_ = H.Canonicalize(result_); | 2233 result_ = H.Canonicalize(result_); |
2271 } | 2234 } |
2272 | 2235 |
2273 void StreamingConstantEvaluator::EvaluateLet() { | 2236 void StreamingConstantEvaluator::EvaluateLet() { |
2274 intptr_t kernel_position = builder_->ReaderOffset(); | 2237 intptr_t kernel_position = builder_->ReaderOffset(); |
2275 LocalVariable* local = builder_->LookupVariable(kernel_position); | 2238 LocalVariable* local = builder_->LookupVariable(kernel_position); |
2276 | 2239 |
2277 // read variable declaration. | 2240 // read variable declaration. |
2278 builder_->ReadPosition(); // read position. | 2241 VariableDeclarationHelper helper(builder_); |
2279 builder_->ReadPosition(); // read equals position. | 2242 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
2280 builder_->ReadFlags(); // read flags. | |
2281 builder_->SkipStringReference(); // read name index. | |
2282 builder_->SkipDartType(); // read type. | |
2283 Tag tag = builder_->ReadTag(); // read (first part of) initializer. | 2243 Tag tag = builder_->ReadTag(); // read (first part of) initializer. |
2284 if (tag == kNothing) { | 2244 if (tag == kNothing) { |
2285 local->SetConstValue(Instance::ZoneHandle(Z, dart::Instance::null())); | 2245 local->SetConstValue(Instance::ZoneHandle(Z, dart::Instance::null())); |
2286 } else { | 2246 } else { |
2287 local->SetConstValue(EvaluateExpression( | 2247 local->SetConstValue(EvaluateExpression( |
2288 builder_->ReaderOffset(), false)); // read rest of initializer. | 2248 builder_->ReaderOffset(), false)); // read rest of initializer. |
2289 } | 2249 } |
2290 | 2250 |
2291 EvaluateExpression(builder_->ReaderOffset(), false); // read body | 2251 EvaluateExpression(builder_->ReaderOffset(), false); // read body |
2292 } | 2252 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 if (outermost_function->kernel_offset() > 0) { | 2487 if (outermost_function->kernel_offset() > 0) { |
2528 *outermost_kernel_offset = outermost_function->kernel_offset(); | 2488 *outermost_kernel_offset = outermost_function->kernel_offset(); |
2529 *parent_class_offset = GetParentOffset(*outermost_kernel_offset); | 2489 *parent_class_offset = GetParentOffset(*outermost_kernel_offset); |
2530 } | 2490 } |
2531 } | 2491 } |
2532 | 2492 |
2533 intptr_t StreamingFlowGraphBuilder::GetParentOffset(intptr_t offset) { | 2493 intptr_t StreamingFlowGraphBuilder::GetParentOffset(intptr_t offset) { |
2534 AlternativeReadingScope alt(reader_, offset); | 2494 AlternativeReadingScope alt(reader_, offset); |
2535 | 2495 |
2536 Tag tag = PeekTag(); | 2496 Tag tag = PeekTag(); |
2537 intptr_t parent_offset = -1; | |
2538 switch (tag) { | 2497 switch (tag) { |
2539 case kConstructor: | 2498 case kConstructor: { |
2540 return ReadConstructorUntilFunctionNode(); | 2499 ConstructorHelper constructor_helper(this); |
2541 case kProcedure: | 2500 constructor_helper.ReadUntilIncluding( |
2542 ReadProcedureUntilFunctionNode( | 2501 ConstructorHelper::kParentClassBinaryOffset); |
2543 &unused_word, &parent_offset); // read first part of procedure. | 2502 return constructor_helper.parent_class_binary_offset_; |
2544 return parent_offset; | 2503 } |
2545 case kField: | 2504 case kProcedure: { |
2546 ReadFieldUntilAnnotation(&unused_nameindex, &unused_tokenposition, | 2505 ProcedureHelper procedure_helper(this); |
2547 &unused_tokenposition, &unused_word, | 2506 procedure_helper.ReadUntilIncluding( |
2548 &parent_offset); | 2507 ProcedureHelper::kParentClassBinaryOffset); |
2549 return parent_offset; | 2508 return procedure_helper.parent_class_binary_offset_; |
| 2509 } |
| 2510 case kField: { |
| 2511 FieldHelper field_helper(this); |
| 2512 field_helper.ReadUntilIncluding(FieldHelper::kParentClassBinaryOffset); |
| 2513 return field_helper.parent_class_binary_offset_; |
| 2514 } |
2550 default: | 2515 default: |
2551 UNIMPLEMENTED(); | 2516 UNIMPLEMENTED(); |
2552 return -1; | 2517 return -1; |
2553 } | 2518 } |
2554 } | 2519 } |
2555 | 2520 |
2556 void StreamingFlowGraphBuilder::GetTypeParameterInfoForClass( | 2521 void StreamingFlowGraphBuilder::GetTypeParameterInfoForClass( |
2557 intptr_t class_offset, | 2522 intptr_t class_offset, |
2558 intptr_t* type_paremeter_counts, | 2523 intptr_t* type_paremeter_counts, |
2559 intptr_t* type_paremeter_offset) { | 2524 intptr_t* type_paremeter_offset) { |
2560 AlternativeReadingScope alt(reader_, class_offset); | 2525 AlternativeReadingScope alt(reader_, class_offset); |
2561 | 2526 |
2562 ReadClassUntilTypeParameters(); | 2527 ClassHelper class_helper(this); |
| 2528 class_helper.ReadUntilExcluding(ClassHelper::kTypeParameters); |
2563 *type_paremeter_counts = | 2529 *type_paremeter_counts = |
2564 ReadListLength(); // read type_parameters list length. | 2530 ReadListLength(); // read type_parameters list length. |
2565 *type_paremeter_offset = ReaderOffset(); | 2531 *type_paremeter_offset = ReaderOffset(); |
2566 } | 2532 } |
2567 | 2533 |
2568 void StreamingFlowGraphBuilder::ReadClassUntilFields() { | |
2569 ReadClassUntilTypeParameters(); | |
2570 SkipTypeParametersList(); // read type_parameters. | |
2571 Tag type_tag = ReadTag(); // read type (part 1). | |
2572 if (type_tag == kSomething) { | |
2573 SkipDartType(); // read type (part 2). | |
2574 } | |
2575 type_tag = ReadTag(); // read Mixed-in type (part 1). | |
2576 if (type_tag == kSomething) { | |
2577 SkipDartType(); // read Mixed-in type (part 2). | |
2578 } | |
2579 SkipListOfDartTypes(); // read implemented_classes. | |
2580 } | |
2581 | |
2582 void StreamingFlowGraphBuilder::ReadClassUntilTypeParameters() { | |
2583 Tag class_tag = ReadTag(); | |
2584 ASSERT(class_tag == kClass); | |
2585 SkipCanonicalNameReference(); // read canonical_name. | |
2586 ReadPosition(); // read position. | |
2587 ReadBool(); // read is_abstract. | |
2588 SkipStringReference(); // read name index. | |
2589 ReadUInt(); // read source_uri_index. | |
2590 SkipListOfExpressions(); // read annotations. | |
2591 } | |
2592 | |
2593 intptr_t StreamingFlowGraphBuilder::ReadConstructorUntilFunctionNode() { | |
2594 Tag tag = ReadTag(); | |
2595 ASSERT(tag == kConstructor); | |
2596 SkipCanonicalNameReference(); // read canonical name reference. | |
2597 ReadPosition(); // read position. | |
2598 ReadPosition(); // read end position. | |
2599 ReadFlags(); // read flags. | |
2600 intptr_t parent_offset = ReadUInt(); // parent class binary offset. | |
2601 SkipName(); // read name. | |
2602 SkipListOfExpressions(); // read annotations. | |
2603 return parent_offset; | |
2604 } | |
2605 | |
2606 Tag StreamingFlowGraphBuilder::ReadProcedureUntilFunctionNode( | |
2607 word* kind, | |
2608 intptr_t* parent_offset) { | |
2609 Tag tag = ReadTag(); // read tag. | |
2610 ASSERT(tag == kProcedure); | |
2611 SkipCanonicalNameReference(); // read canonical name reference. | |
2612 ReadPosition(); // read position. | |
2613 ReadPosition(); // read end position. | |
2614 *kind = ReadByte(); // read kind. | |
2615 ReadFlags(); // read flags. | |
2616 *parent_offset = ReadUInt(); // read parent class binary offset. | |
2617 SkipName(); // read name, | |
2618 ReadUInt(); // read source_uri_index. | |
2619 SkipListOfExpressions(); // read annotations. | |
2620 return ReadTag(); // read tag for optional function node. | |
2621 } | |
2622 | |
2623 void StreamingFlowGraphBuilder::ReadFieldUntilAnnotation( | |
2624 NameIndex* canonical_name, | |
2625 TokenPosition* position, | |
2626 TokenPosition* end_position, | |
2627 word* flags, | |
2628 intptr_t* parent_offset) { | |
2629 Tag tag = ReadTag(); | |
2630 ASSERT(tag == kField); | |
2631 | |
2632 *canonical_name = ReadCanonicalNameReference(); // read canonical_name. | |
2633 *position = ReadPosition(); // read position. | |
2634 *end_position = ReadPosition(); // read end position. | |
2635 *flags = ReadFlags(); // read flags. | |
2636 *parent_offset = ReadUInt(); // read parent class binary offset. | |
2637 SkipName(); // read name. | |
2638 ReadUInt(); // source_uri_index. | |
2639 } | |
2640 | |
2641 void StreamingFlowGraphBuilder::GetTypeParameterInfoForPossibleProcedure( | 2534 void StreamingFlowGraphBuilder::GetTypeParameterInfoForPossibleProcedure( |
2642 intptr_t outermost_kernel_offset, | 2535 intptr_t outermost_kernel_offset, |
2643 bool* member_is_procedure, | 2536 bool* member_is_procedure, |
2644 bool* is_factory_procedure, | 2537 bool* is_factory_procedure, |
2645 intptr_t* member_type_parameters, | 2538 intptr_t* member_type_parameters, |
2646 intptr_t* member_type_parameters_offset_start) { | 2539 intptr_t* member_type_parameters_offset_start) { |
2647 if (outermost_kernel_offset >= 0) { | 2540 if (outermost_kernel_offset >= 0) { |
2648 AlternativeReadingScope alt(reader_, outermost_kernel_offset); | 2541 AlternativeReadingScope alt(reader_, outermost_kernel_offset); |
2649 Tag tag = PeekTag(); | 2542 Tag tag = PeekTag(); |
2650 if (tag == kProcedure) { | 2543 if (tag == kProcedure) { |
2651 *member_is_procedure = true; | 2544 *member_is_procedure = true; |
2652 | 2545 |
2653 word kind; | 2546 ProcedureHelper procedure_helper(this); |
2654 tag = ReadProcedureUntilFunctionNode( | 2547 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
2655 &kind, &unused_intptr); // read first part of procedure. | 2548 *is_factory_procedure = procedure_helper.kind_ == Procedure::kFactory; |
2656 *is_factory_procedure = | 2549 if (ReadTag() == kSomething) { |
2657 static_cast<Procedure::ProcedureKind>(kind) == Procedure::kFactory; | 2550 FunctionNodeHelper function_node_helper(this); |
| 2551 function_node_helper.ReadUntilExcluding( |
| 2552 FunctionNodeHelper::kTypeParameters); |
2658 | 2553 |
2659 if (tag == kSomething) { | 2554 // read type_parameters list length. |
2660 ReadFunctionNodeUntilTypeParameters( | 2555 intptr_t list_length = ReadListLength(); |
2661 &unused_tokenposition, &unused_tokenposition, &unused_word, | |
2662 &unused_word); // read first part of function node. | |
2663 | |
2664 intptr_t list_length = | |
2665 ReadListLength(); // read type_parameters list length. | |
2666 if (list_length > 0) { | 2556 if (list_length > 0) { |
2667 *member_type_parameters = list_length; | 2557 *member_type_parameters = list_length; |
2668 *member_type_parameters_offset_start = ReaderOffset(); | 2558 *member_type_parameters_offset_start = ReaderOffset(); |
2669 } | 2559 } |
2670 } | 2560 } |
2671 } | 2561 } |
2672 } | 2562 } |
2673 } | 2563 } |
2674 | 2564 |
2675 void StreamingFlowGraphBuilder::ReadFunctionNodeUntilTypeParameters( | |
2676 TokenPosition* position, | |
2677 TokenPosition* end_position, | |
2678 word* async_marker, | |
2679 word* dart_async_marker) { | |
2680 Tag tag = ReadTag(); // read tag. | |
2681 ASSERT(tag == kFunctionNode); | |
2682 | |
2683 *position = ReadPosition(); // read position. | |
2684 *end_position = ReadPosition(); // read end position. | |
2685 *async_marker = ReadByte(); // read async marker. | |
2686 *dart_async_marker = ReadByte(); // read dart async marker. | |
2687 } | |
2688 | |
2689 intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() { | 2565 intptr_t StreamingFlowGraphBuilder::ReadUntilFunctionNode() { |
2690 const Tag tag = PeekTag(); | 2566 const Tag tag = PeekTag(); |
2691 if (tag == kProcedure) { | 2567 if (tag == kProcedure) { |
2692 Tag has_function_node = ReadProcedureUntilFunctionNode( | 2568 ProcedureHelper procedure_helper(this); |
2693 &unused_word, &unused_intptr); // read first part of procedure. | 2569 procedure_helper.ReadUntilExcluding(ProcedureHelper::kFunction); |
2694 if (has_function_node == kNothing) { | 2570 if (ReadTag() == kNothing) { // read function node tag. |
2695 // Running a procedure without a function node doesn't make sense. | 2571 // Running a procedure without a function node doesn't make sense. |
2696 UNREACHABLE(); | 2572 UNREACHABLE(); |
2697 } | 2573 } |
2698 return -1; | 2574 return -1; |
2699 // Now at start of FunctionNode. | 2575 // Now at start of FunctionNode. |
2700 } else if (tag == kConstructor) { | 2576 } else if (tag == kConstructor) { |
2701 // read first part of constructor. | 2577 ConstructorHelper constructor_helper(this); |
2702 return ReadConstructorUntilFunctionNode(); | 2578 constructor_helper.ReadUntilExcluding(ConstructorHelper::kFunction); |
| 2579 return constructor_helper.parent_class_binary_offset_; |
2703 // Now at start of FunctionNode. | 2580 // Now at start of FunctionNode. |
2704 // Notice that we also have a list of initializers after that! | 2581 // Notice that we also have a list of initializers after that! |
2705 } else if (tag == kFunctionNode) { | 2582 } else if (tag == kFunctionNode) { |
2706 // Already at start of FunctionNode. | 2583 // Already at start of FunctionNode. |
2707 } else { | 2584 } else { |
2708 UNREACHABLE(); | 2585 UNREACHABLE(); |
2709 } | 2586 } |
2710 return -1; | 2587 return -1; |
2711 } | 2588 } |
2712 | 2589 |
2713 StringIndex StreamingFlowGraphBuilder::GetNameFromVariableDeclaration( | 2590 StringIndex StreamingFlowGraphBuilder::GetNameFromVariableDeclaration( |
2714 intptr_t kernel_offset) { | 2591 intptr_t kernel_offset) { |
2715 // Temporarily go to the variable declaration, read the name. | 2592 // Temporarily go to the variable declaration, read the name. |
2716 AlternativeReadingScope alt(reader_, kernel_offset); | 2593 AlternativeReadingScope alt(reader_, kernel_offset); |
2717 ReadPosition(); // read position. | 2594 VariableDeclarationHelper helper(this); |
2718 ReadPosition(); // read equals position. | 2595 helper.ReadUntilIncluding(VariableDeclarationHelper::kNameIndex); |
2719 ReadFlags(); // read flags. | 2596 return helper.name_index_; |
2720 return ReadStringReference(); // read name index. | |
2721 } | 2597 } |
2722 | 2598 |
2723 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfStaticFieldInitializer() { | 2599 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfStaticFieldInitializer() { |
2724 TokenPosition position; | 2600 FieldHelper field_helper(this); |
2725 TokenPosition end_position; | 2601 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
2726 word flags; | 2602 ASSERT(field_helper.IsStatic()); |
2727 ReadFieldUntilAnnotation(&unused_nameindex, &position, &end_position, &flags, | |
2728 &unused_intptr); | |
2729 bool is_static = (flags & Field::kFlagStatic) == Field::kFlagStatic; | |
2730 bool is_const = (flags & Field::kFlagConst) == Field::kFlagConst; | |
2731 ASSERT(is_static); | |
2732 | 2603 |
2733 SkipListOfExpressions(); // read annotations. | |
2734 SkipDartType(); // read type. | |
2735 Tag initializer_tag = ReadTag(); // read first part of initializer. | 2604 Tag initializer_tag = ReadTag(); // read first part of initializer. |
2736 if (initializer_tag != kSomething) { | 2605 if (initializer_tag != kSomething) { |
2737 UNREACHABLE(); | 2606 UNREACHABLE(); |
2738 } | 2607 } |
2739 | 2608 |
2740 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); | 2609 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); |
2741 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( | 2610 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( |
2742 *parsed_function(), normal_entry, Compiler::kNoOSRDeoptId); | 2611 *parsed_function(), normal_entry, Compiler::kNoOSRDeoptId); |
2743 | 2612 |
2744 Fragment body(normal_entry); | 2613 Fragment body(normal_entry); |
2745 body += flow_graph_builder_->CheckStackOverflowInPrologue(); | 2614 body += flow_graph_builder_->CheckStackOverflowInPrologue(); |
2746 if (is_const) { | 2615 if (field_helper.IsConst()) { |
2747 // this will (potentially) read the initializer, but reset the position. | 2616 // this will (potentially) read the initializer, but reset the position. |
2748 body += Constant(constant_evaluator_.EvaluateExpression(ReaderOffset())); | 2617 body += Constant(constant_evaluator_.EvaluateExpression(ReaderOffset())); |
2749 SkipExpression(); // read the initializer. | 2618 SkipExpression(); // read the initializer. |
2750 } else { | 2619 } else { |
2751 body += BuildExpression(); // read initializer. | 2620 body += BuildExpression(); // read initializer. |
2752 } | 2621 } |
2753 body += Return(TokenPosition::kNoSource); | 2622 body += Return(TokenPosition::kNoSource); |
2754 | 2623 |
2755 return new (Z) | 2624 return new (Z) |
2756 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, | 2625 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, |
2757 flow_graph_builder_->next_block_id_ - 1); | 2626 flow_graph_builder_->next_block_id_ - 1); |
2758 } | 2627 } |
2759 | 2628 |
2760 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFieldAccessor( | 2629 FlowGraph* StreamingFlowGraphBuilder::BuildGraphOfFieldAccessor( |
2761 LocalVariable* setter_value) { | 2630 LocalVariable* setter_value) { |
2762 NameIndex canonical_name; | 2631 FieldHelper field_helper(this); |
2763 ReadFieldUntilAnnotation(&canonical_name, &unused_tokenposition, | 2632 field_helper.ReadUntilIncluding(FieldHelper::kCanonicalName); |
2764 &unused_tokenposition, &unused_word, &unused_intptr); | |
2765 SkipListOfExpressions(); // read annotations. | |
2766 SkipDartType(); // read type. | |
2767 Tag initializer_tag = ReadTag(); // read first part of initializer. | |
2768 | 2633 |
2769 const Function& function = parsed_function()->function(); | 2634 const Function& function = parsed_function()->function(); |
2770 | 2635 |
2771 bool is_setter = function.IsImplicitSetterFunction(); | 2636 bool is_setter = function.IsImplicitSetterFunction(); |
2772 bool is_method = !function.IsStaticFunction(); | 2637 bool is_method = !function.IsStaticFunction(); |
2773 dart::Field& field = | 2638 dart::Field& field = dart::Field::ZoneHandle( |
2774 dart::Field::ZoneHandle(Z, H.LookupFieldByKernelField(canonical_name)); | 2639 Z, H.LookupFieldByKernelField(field_helper.canonical_name_)); |
2775 | 2640 |
2776 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); | 2641 TargetEntryInstr* normal_entry = flow_graph_builder_->BuildTargetEntry(); |
2777 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( | 2642 flow_graph_builder_->graph_entry_ = new (Z) GraphEntryInstr( |
2778 *parsed_function(), normal_entry, Compiler::kNoOSRDeoptId); | 2643 *parsed_function(), normal_entry, Compiler::kNoOSRDeoptId); |
2779 | 2644 |
2780 Fragment body(normal_entry); | 2645 Fragment body(normal_entry); |
2781 if (is_setter) { | 2646 if (is_setter) { |
2782 if (is_method) { | 2647 if (is_method) { |
2783 body += LoadLocal(scopes()->this_variable); | 2648 body += LoadLocal(scopes()->this_variable); |
2784 body += LoadLocal(setter_value); | 2649 body += LoadLocal(setter_value); |
2785 body += flow_graph_builder_->StoreInstanceFieldGuarded(field, false); | 2650 body += flow_graph_builder_->StoreInstanceFieldGuarded(field, false); |
2786 } else { | 2651 } else { |
2787 body += LoadLocal(setter_value); | 2652 body += LoadLocal(setter_value); |
2788 body += StoreStaticField(TokenPosition::kNoSource, field); | 2653 body += StoreStaticField(TokenPosition::kNoSource, field); |
2789 } | 2654 } |
2790 body += NullConstant(); | 2655 body += NullConstant(); |
2791 } else if (is_method) { | 2656 } else if (is_method) { |
2792 body += LoadLocal(scopes()->this_variable); | 2657 body += LoadLocal(scopes()->this_variable); |
2793 body += flow_graph_builder_->LoadField(field); | 2658 body += flow_graph_builder_->LoadField(field); |
2794 } else if (field.is_const()) { | 2659 } else if (field.is_const()) { |
| 2660 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
| 2661 Tag initializer_tag = ReadTag(); // read first part of initializer. |
| 2662 |
2795 // If the parser needs to know the value of an uninitialized constant field | 2663 // If the parser needs to know the value of an uninitialized constant field |
2796 // it will set the value to the transition sentinel (used to detect circular | 2664 // it will set the value to the transition sentinel (used to detect circular |
2797 // initialization) and then call the implicit getter. Thus, the getter | 2665 // initialization) and then call the implicit getter. Thus, the getter |
2798 // cannot contain the InitStaticField instruction that normal static getters | 2666 // cannot contain the InitStaticField instruction that normal static getters |
2799 // contain because it would detect spurious circular initialization when it | 2667 // contain because it would detect spurious circular initialization when it |
2800 // checks for the transition sentinel. | 2668 // checks for the transition sentinel. |
2801 ASSERT(initializer_tag == kSomething); | 2669 ASSERT(initializer_tag == kSomething); |
2802 // this will (potentially) read the initializer, but reset the position. | |
2803 body += Constant(constant_evaluator_.EvaluateExpression(ReaderOffset())); | 2670 body += Constant(constant_evaluator_.EvaluateExpression(ReaderOffset())); |
2804 SkipExpression(); // read the initializer. | |
2805 } else { | 2671 } else { |
2806 // The field always has an initializer because static fields without | 2672 // The field always has an initializer because static fields without |
2807 // initializers are initialized eagerly and do not have implicit getters. | 2673 // initializers are initialized eagerly and do not have implicit getters. |
2808 ASSERT(field.has_initializer()); | 2674 ASSERT(field.has_initializer()); |
2809 body += Constant(field); | 2675 body += Constant(field); |
2810 body += flow_graph_builder_->InitStaticField(field); | 2676 body += flow_graph_builder_->InitStaticField(field); |
2811 body += Constant(field); | 2677 body += Constant(field); |
2812 body += LoadStaticField(); | 2678 body += LoadStaticField(); |
2813 } | 2679 } |
2814 body += Return(TokenPosition::kNoSource); | 2680 body += Return(TokenPosition::kNoSource); |
2815 | 2681 |
2816 return new (Z) | 2682 return new (Z) |
2817 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, | 2683 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, |
2818 flow_graph_builder_->next_block_id_ - 1); | 2684 flow_graph_builder_->next_block_id_ - 1); |
2819 } | 2685 } |
2820 | 2686 |
2821 void StreamingFlowGraphBuilder::SetupDefaultParameterValues() { | 2687 void StreamingFlowGraphBuilder::SetupDefaultParameterValues() { |
2822 intptr_t num_optional_parameters = | 2688 intptr_t num_optional_parameters = |
2823 parsed_function()->function().NumOptionalParameters(); | 2689 parsed_function()->function().NumOptionalParameters(); |
2824 if (num_optional_parameters > 0) { | 2690 if (num_optional_parameters > 0) { |
2825 ZoneGrowableArray<const Instance*>* default_values = | 2691 ZoneGrowableArray<const Instance*>* default_values = |
2826 new ZoneGrowableArray<const Instance*>(Z, num_optional_parameters); | 2692 new ZoneGrowableArray<const Instance*>(Z, num_optional_parameters); |
2827 | 2693 |
2828 AlternativeReadingScope alt(reader_); | 2694 AlternativeReadingScope alt(reader_); |
2829 ReadFunctionNodeUntilTypeParameters( | 2695 FunctionNodeHelper function_node_helper(this); |
2830 &unused_tokenposition, &unused_tokenposition, &unused_word, | 2696 function_node_helper.ReadUntilExcluding( |
2831 &unused_word); // read first part of function node. | 2697 FunctionNodeHelper::kPositionalParameters); |
2832 SkipTypeParametersList(); // read type_parameters. | |
2833 ReadUInt(); // read total parameter count. | |
2834 intptr_t required = ReadUInt(); // read required_parameter_count. | |
2835 | 2698 |
2836 if (parsed_function()->function().HasOptionalNamedParameters()) { | 2699 if (parsed_function()->function().HasOptionalNamedParameters()) { |
2837 // List of positional. | 2700 // List of positional. |
2838 intptr_t list_length = ReadListLength(); // read list length. | 2701 intptr_t list_length = ReadListLength(); // read list length. |
2839 for (intptr_t i = 0; i < list_length; ++i) { | 2702 for (intptr_t i = 0; i < list_length; ++i) { |
2840 SkipVariableDeclaration(); // read ith variable declaration. | 2703 SkipVariableDeclaration(); // read ith variable declaration. |
2841 } | 2704 } |
2842 | 2705 |
2843 // List of named. | 2706 // List of named. |
2844 list_length = ReadListLength(); // read list length. | 2707 list_length = ReadListLength(); // read list length. |
2845 ASSERT(num_optional_parameters == list_length); | 2708 ASSERT(num_optional_parameters == list_length); |
2846 ASSERT(!parsed_function()->function().HasOptionalPositionalParameters()); | 2709 ASSERT(!parsed_function()->function().HasOptionalPositionalParameters()); |
2847 for (intptr_t i = 0; i < list_length; ++i) { | 2710 for (intptr_t i = 0; i < list_length; ++i) { |
2848 Instance* default_value; | 2711 Instance* default_value; |
2849 | 2712 |
2850 // Read ith variable declaration | 2713 // Read ith variable declaration |
2851 ReadPosition(); // read position. | 2714 VariableDeclarationHelper helper(this); |
2852 ReadPosition(); // read equals position. | 2715 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
2853 ReadFlags(); // read flags. | |
2854 SkipStringReference(); // read name index. | |
2855 SkipDartType(); // read type. | |
2856 Tag tag = ReadTag(); // read (first part of) initializer. | 2716 Tag tag = ReadTag(); // read (first part of) initializer. |
2857 if (tag == kSomething) { | 2717 if (tag == kSomething) { |
2858 // this will (potentially) read the initializer, | 2718 // this will (potentially) read the initializer, |
2859 // but reset the position. | 2719 // but reset the position. |
2860 default_value = | 2720 default_value = |
2861 &constant_evaluator_.EvaluateExpression(ReaderOffset()); | 2721 &constant_evaluator_.EvaluateExpression(ReaderOffset()); |
2862 SkipExpression(); // read (actual) initializer. | 2722 SkipExpression(); // read (actual) initializer. |
2863 } else { | 2723 } else { |
2864 default_value = &Instance::ZoneHandle(Z, Instance::null()); | 2724 default_value = &Instance::ZoneHandle(Z, Instance::null()); |
2865 } | 2725 } |
2866 default_values->Add(default_value); | 2726 default_values->Add(default_value); |
2867 } | 2727 } |
2868 } else { | 2728 } else { |
2869 // List of positional. | 2729 // List of positional. |
2870 intptr_t list_length = ReadListLength(); // read list length. | 2730 intptr_t list_length = ReadListLength(); // read list length. |
2871 ASSERT(list_length == required + num_optional_parameters); | 2731 ASSERT(list_length == function_node_helper.required_parameter_count_ + |
| 2732 num_optional_parameters); |
2872 ASSERT(parsed_function()->function().HasOptionalPositionalParameters()); | 2733 ASSERT(parsed_function()->function().HasOptionalPositionalParameters()); |
2873 for (intptr_t i = 0; i < required; ++i) { | 2734 for (intptr_t i = 0; i < function_node_helper.required_parameter_count_; |
| 2735 ++i) { |
2874 SkipVariableDeclaration(); // read ith variable declaration. | 2736 SkipVariableDeclaration(); // read ith variable declaration. |
2875 } | 2737 } |
2876 for (intptr_t i = 0; i < num_optional_parameters; ++i) { | 2738 for (intptr_t i = 0; i < num_optional_parameters; ++i) { |
2877 Instance* default_value; | 2739 Instance* default_value; |
2878 | 2740 |
2879 // Read ith variable declaration | 2741 // Read ith variable declaration |
2880 ReadPosition(); // read position. | 2742 VariableDeclarationHelper helper(this); |
2881 ReadPosition(); // read equals position. | 2743 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
2882 ReadFlags(); // read flags. | |
2883 SkipStringReference(); // read name index. | |
2884 SkipDartType(); // read type. | |
2885 Tag tag = ReadTag(); // read (first part of) initializer. | 2744 Tag tag = ReadTag(); // read (first part of) initializer. |
2886 if (tag == kSomething) { | 2745 if (tag == kSomething) { |
2887 // this will (potentially) read the initializer, | 2746 // this will (potentially) read the initializer, |
2888 // but reset the position. | 2747 // but reset the position. |
2889 default_value = | 2748 default_value = |
2890 &constant_evaluator_.EvaluateExpression(ReaderOffset()); | 2749 &constant_evaluator_.EvaluateExpression(ReaderOffset()); |
2891 SkipExpression(); // read (actual) initializer. | 2750 SkipExpression(); // read (actual) initializer. |
2892 } else { | 2751 } else { |
2893 default_value = &Instance::ZoneHandle(Z, Instance::null()); | 2752 default_value = &Instance::ZoneHandle(Z, Instance::null()); |
2894 } | 2753 } |
(...skipping 28 matching lines...) Expand all Loading... |
2923 Fragment StreamingFlowGraphBuilder::BuildInitializers( | 2782 Fragment StreamingFlowGraphBuilder::BuildInitializers( |
2924 intptr_t constructor_class_parent_offset) { | 2783 intptr_t constructor_class_parent_offset) { |
2925 Fragment instructions; | 2784 Fragment instructions; |
2926 | 2785 |
2927 // These come from: | 2786 // These come from: |
2928 // class A { | 2787 // class A { |
2929 // var x = (expr); | 2788 // var x = (expr); |
2930 // } | 2789 // } |
2931 { | 2790 { |
2932 AlternativeReadingScope alt(reader_, constructor_class_parent_offset); | 2791 AlternativeReadingScope alt(reader_, constructor_class_parent_offset); |
2933 ReadClassUntilFields(); // read first part of class. | 2792 ClassHelper class_helper(this); |
| 2793 class_helper.ReadUntilExcluding(ClassHelper::kFields); |
2934 intptr_t list_length = ReadListLength(); // read fields list length. | 2794 intptr_t list_length = ReadListLength(); // read fields list length. |
2935 | 2795 |
2936 for (intptr_t i = 0; i < list_length; ++i) { | 2796 for (intptr_t i = 0; i < list_length; ++i) { |
2937 intptr_t field_offset = ReaderOffset(); | 2797 intptr_t field_offset = ReaderOffset(); |
2938 NameIndex canonical_name; | 2798 FieldHelper field_helper(this); |
2939 TokenPosition position; | 2799 field_helper.ReadUntilExcluding(FieldHelper::kInitializer); |
2940 TokenPosition end_position; | |
2941 word flags; | |
2942 ReadFieldUntilAnnotation(&canonical_name, &position, &end_position, | |
2943 &flags, &unused_intptr); | |
2944 bool is_static = (flags & Field::kFlagStatic) == Field::kFlagStatic; | |
2945 SkipListOfExpressions(); // read annotations. | |
2946 SkipDartType(); // read type. | |
2947 Tag initializer_tag = ReadTag(); // read first part of initializer. | 2800 Tag initializer_tag = ReadTag(); // read first part of initializer. |
2948 if (!is_static && initializer_tag == kSomething) { | 2801 if (!field_helper.IsStatic() && initializer_tag == kSomething) { |
2949 EnterScope(field_offset); | 2802 EnterScope(field_offset); |
2950 instructions += | 2803 instructions += BuildFieldInitializer( |
2951 BuildFieldInitializer(canonical_name); // read initializer. | 2804 field_helper.canonical_name_); // read initializer. |
2952 ExitScope(field_offset); | 2805 ExitScope(field_offset); |
2953 } else if (initializer_tag == kSomething) { | 2806 } else if (initializer_tag == kSomething) { |
2954 SkipExpression(); // read initializer. | 2807 SkipExpression(); // read initializer. |
2955 } | 2808 } |
2956 } | 2809 } |
2957 } | 2810 } |
2958 | 2811 |
2959 // These to come from: | 2812 // These to come from: |
2960 // class A { | 2813 // class A { |
2961 // var x; | 2814 // var x; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3039 // class A { | 2892 // class A { |
3040 // var x; | 2893 // var x; |
3041 // A(a, b) : tmp = a + b, x = 2*b, super(tmp) {} | 2894 // A(a, b) : tmp = a + b, x = 2*b, super(tmp) {} |
3042 // } | 2895 // } |
3043 // | 2896 // |
3044 // (This is strictly speaking not what one should do in terms of the | 2897 // (This is strictly speaking not what one should do in terms of the |
3045 // specification but that is how it is currently implemented.) | 2898 // specification but that is how it is currently implemented.) |
3046 LocalVariable* variable = LookupVariable(ReaderOffset()); | 2899 LocalVariable* variable = LookupVariable(ReaderOffset()); |
3047 | 2900 |
3048 // Variable declaration | 2901 // Variable declaration |
3049 ReadPosition(); // read position. | 2902 VariableDeclarationHelper helper(this); |
3050 ReadPosition(); // read equals position. | 2903 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
3051 word flags = ReadFlags(); // read flags. | 2904 ASSERT(!helper.IsConst()); |
3052 ASSERT((flags & VariableDeclaration::kFlagConst) != | |
3053 VariableDeclaration::kFlagConst); | |
3054 SkipStringReference(); // read name index. | |
3055 SkipDartType(); // read type. | |
3056 Tag tag = ReadTag(); // read (first part of) initializer. | 2905 Tag tag = ReadTag(); // read (first part of) initializer. |
3057 if (tag != kSomething) { | 2906 if (tag != kSomething) { |
3058 UNREACHABLE(); | 2907 UNREACHABLE(); |
3059 } | 2908 } |
3060 | 2909 |
3061 instructions += BuildExpression(); // read initializer. | 2910 instructions += BuildExpression(); // read initializer. |
3062 instructions += StoreLocal(TokenPosition::kNoSource, variable); | 2911 instructions += StoreLocal(TokenPosition::kNoSource, variable); |
3063 instructions += Drop(); | 2912 instructions += Drop(); |
3064 break; | 2913 break; |
3065 } | 2914 } |
(...skipping 19 matching lines...) Expand all Loading... |
3085 | 2934 |
3086 // Load all the arguments. | 2935 // Load all the arguments. |
3087 if (!target.is_static()) { | 2936 if (!target.is_static()) { |
3088 // The context has a fixed shape: a single variable which is the | 2937 // The context has a fixed shape: a single variable which is the |
3089 // closed-over receiver. | 2938 // closed-over receiver. |
3090 body += LoadLocal(parsed_function()->current_context_var()); | 2939 body += LoadLocal(parsed_function()->current_context_var()); |
3091 body += flow_graph_builder_->LoadField(Context::variable_offset(0)); | 2940 body += flow_graph_builder_->LoadField(Context::variable_offset(0)); |
3092 body += PushArgument(); | 2941 body += PushArgument(); |
3093 } | 2942 } |
3094 | 2943 |
3095 TokenPosition end_position; | 2944 FunctionNodeHelper function_node_helper(this); |
3096 ReadFunctionNodeUntilTypeParameters( | 2945 function_node_helper.ReadUntilExcluding( |
3097 &unused_tokenposition, &end_position, &unused_word, | 2946 FunctionNodeHelper::kPositionalParameters); |
3098 &unused_word); // read first part of function node. | |
3099 SkipTypeParametersList(); // read type parameter list. | |
3100 ReadUInt(); // read total parameter count. | |
3101 ReadUInt(); // read required_parameter_count. | |
3102 | 2947 |
3103 // Positional. | 2948 // Positional. |
3104 intptr_t positional_argument_count = ReadListLength(); | 2949 intptr_t positional_argument_count = ReadListLength(); |
3105 for (intptr_t i = 0; i < positional_argument_count; ++i) { | 2950 for (intptr_t i = 0; i < positional_argument_count; ++i) { |
3106 body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 2951 body += LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. |
3107 body += PushArgument(); | 2952 body += PushArgument(); |
3108 SkipVariableDeclaration(); // read ith variable. | 2953 SkipVariableDeclaration(); // read ith variable. |
3109 } | 2954 } |
3110 | 2955 |
3111 // Named. | 2956 // Named. |
3112 intptr_t named_argument_count = ReadListLength(); | 2957 intptr_t named_argument_count = ReadListLength(); |
3113 Array& argument_names = Array::ZoneHandle(Z); | 2958 Array& argument_names = Array::ZoneHandle(Z); |
3114 if (named_argument_count > 0) { | 2959 if (named_argument_count > 0) { |
3115 argument_names = Array::New(named_argument_count); | 2960 argument_names = Array::New(named_argument_count); |
3116 for (intptr_t i = 0; i < named_argument_count; ++i) { | 2961 for (intptr_t i = 0; i < named_argument_count; ++i) { |
3117 body += | 2962 // ith variable offset. |
3118 LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 2963 body += LoadLocal(LookupVariable(ReaderOffset())); |
3119 body += PushArgument(); | 2964 body += PushArgument(); |
3120 argument_names.SetAt( | 2965 StringIndex name = GetNameFromVariableDeclaration(ReaderOffset()); |
3121 i, H.DartSymbol(GetNameFromVariableDeclaration(ReaderOffset()))); | 2966 argument_names.SetAt(i, H.DartSymbol(name)); |
3122 SkipVariableDeclaration(); // read ith variable. | 2967 SkipVariableDeclaration(); // read ith variable. |
3123 } | 2968 } |
3124 } | 2969 } |
3125 | 2970 |
3126 // Forward them to the target. | 2971 // Forward them to the target. |
3127 intptr_t argument_count = positional_argument_count + named_argument_count; | 2972 intptr_t argument_count = positional_argument_count + named_argument_count; |
3128 if (!target.is_static()) ++argument_count; | 2973 if (!target.is_static()) ++argument_count; |
3129 body += StaticCall(TokenPosition::kNoSource, target, argument_count, | 2974 body += StaticCall(TokenPosition::kNoSource, target, argument_count, |
3130 argument_names); | 2975 argument_names); |
3131 | 2976 |
3132 // Return the result. | 2977 // Return the result. |
3133 body += Return(end_position); | 2978 body += Return(function_node_helper.end_position_); |
3134 | 2979 |
3135 return new (Z) | 2980 return new (Z) |
3136 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, | 2981 FlowGraph(*parsed_function(), flow_graph_builder_->graph_entry_, |
3137 flow_graph_builder_->next_block_id_ - 1); | 2982 flow_graph_builder_->next_block_id_ - 1); |
3138 } | 2983 } |
3139 | 2984 |
3140 static bool IsGetMainClosure(const String& name) { | 2985 static bool IsGetMainClosure(const String& name) { |
3141 if (name.Length() < 16) return false; | 2986 if (name.Length() < 16) return false; |
3142 const char* cstr = "_getMainClosure@"; | 2987 const char* cstr = "_getMainClosure@"; |
3143 for (intptr_t i = 0; i < 16; ++i) { | 2988 for (intptr_t i = 0; i < 16; ++i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3197 } | 3042 } |
3198 body += Drop(); // The context. | 3043 body += Drop(); // The context. |
3199 } | 3044 } |
3200 if (constructor_class_parent_offset > 0) { | 3045 if (constructor_class_parent_offset > 0) { |
3201 // TODO(27590): Currently the [VariableDeclaration]s from the | 3046 // TODO(27590): Currently the [VariableDeclaration]s from the |
3202 // initializers will be visible inside the entire body of the constructor. | 3047 // initializers will be visible inside the entire body of the constructor. |
3203 // We should make a separate scope for them. | 3048 // We should make a separate scope for them. |
3204 body += BuildInitializers(constructor_class_parent_offset); | 3049 body += BuildInitializers(constructor_class_parent_offset); |
3205 } | 3050 } |
3206 | 3051 |
3207 TokenPosition position; | 3052 FunctionNodeHelper function_node_helper(this); |
3208 ReadFunctionNodeUntilTypeParameters( | 3053 function_node_helper.ReadUntilExcluding( |
3209 &position, &unused_tokenposition, &unused_word, | 3054 FunctionNodeHelper::kPositionalParameters); |
3210 &unused_word); // read first part of function node. | |
3211 SkipTypeParametersList(); // read type parameter list. | |
3212 ReadUInt(); // read total parameter count | |
3213 ReadUInt(); // read required_parameter_count. | |
3214 intptr_t first_parameter_offset = -1; | 3055 intptr_t first_parameter_offset = -1; |
3215 { | 3056 { |
3216 AlternativeReadingScope alt(reader_); | 3057 AlternativeReadingScope alt(reader_); |
3217 intptr_t list_length = ReadListLength(); // read number of positionals. | 3058 intptr_t list_length = ReadListLength(); // read number of positionals. |
3218 if (list_length > 0) { | 3059 if (list_length > 0) { |
3219 first_parameter_offset = ReaderOffset(); | 3060 first_parameter_offset = ReaderOffset(); |
3220 } | 3061 } |
3221 } | 3062 } |
3222 // Current position: About to read list of positionals. | 3063 // Current position: About to read list of positionals. |
3223 | 3064 |
(...skipping 28 matching lines...) Expand all Loading... |
3252 | 3093 |
3253 body = Fragment(body.entry, non_null_entry); | 3094 body = Fragment(body.entry, non_null_entry); |
3254 } | 3095 } |
3255 | 3096 |
3256 // If we run in checked mode, we have to check the type of the passed | 3097 // If we run in checked mode, we have to check the type of the passed |
3257 // arguments. | 3098 // arguments. |
3258 if (I->type_checks()) { | 3099 if (I->type_checks()) { |
3259 // Positional. | 3100 // Positional. |
3260 intptr_t list_length = ReadListLength(); | 3101 intptr_t list_length = ReadListLength(); |
3261 for (intptr_t i = 0; i < list_length; ++i) { | 3102 for (intptr_t i = 0; i < list_length; ++i) { |
3262 body += | 3103 // ith variable offset. |
3263 LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 3104 body += LoadLocal(LookupVariable(ReaderOffset())); |
3264 body += CheckVariableTypeInCheckedMode(ReaderOffset()); | 3105 body += CheckVariableTypeInCheckedMode(ReaderOffset()); |
3265 body += Drop(); | 3106 body += Drop(); |
3266 SkipVariableDeclaration(); // read ith variable. | 3107 SkipVariableDeclaration(); // read ith variable. |
3267 } | 3108 } |
3268 | 3109 |
3269 // Named. | 3110 // Named. |
3270 list_length = ReadListLength(); | 3111 list_length = ReadListLength(); |
3271 for (intptr_t i = 0; i < list_length; ++i) { | 3112 for (intptr_t i = 0; i < list_length; ++i) { |
3272 body += | 3113 // ith variable offset. |
3273 LoadLocal(LookupVariable(ReaderOffset())); // ith variable offset. | 3114 body += LoadLocal(LookupVariable(ReaderOffset())); |
3274 body += CheckVariableTypeInCheckedMode(ReaderOffset()); | 3115 body += CheckVariableTypeInCheckedMode(ReaderOffset()); |
3275 body += Drop(); | 3116 body += Drop(); |
3276 SkipVariableDeclaration(); // read ith variable. | 3117 SkipVariableDeclaration(); // read ith variable. |
3277 } | 3118 } |
3278 } else { | 3119 |
3279 // Still skip past the parameters. | 3120 function_node_helper.SetJustRead(FunctionNodeHelper::kNamedParameters); |
3280 SkipListOfVariableDeclarations(); // read list of positionals. | |
3281 SkipListOfVariableDeclarations(); // read list of named. | |
3282 } | 3121 } |
3283 | 3122 |
3284 SkipDartType(); // read return type. | 3123 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kBody); |
3285 | 3124 |
3286 if (FLAG_causal_async_stacks && | 3125 if (FLAG_causal_async_stacks && |
3287 (dart_function.IsAsyncFunction() || dart_function.IsAsyncGenerator())) { | 3126 (dart_function.IsAsyncFunction() || dart_function.IsAsyncGenerator())) { |
3288 LocalScope* scope = parsed_function()->node_sequence()->scope(); | 3127 LocalScope* scope = parsed_function()->node_sequence()->scope(); |
3289 // :async_stack_trace = _asyncStackTraceHelper(:async_op); | 3128 // :async_stack_trace = _asyncStackTraceHelper(:async_op); |
3290 const dart::Library& async_lib = | 3129 const dart::Library& async_lib = |
3291 dart::Library::Handle(dart::Library::AsyncLibrary()); | 3130 dart::Library::Handle(dart::Library::AsyncLibrary()); |
3292 const Function& target = Function::ZoneHandle( | 3131 const Function& target = Function::ZoneHandle( |
3293 Z, | 3132 Z, |
3294 async_lib.LookupFunctionAllowPrivate(Symbols::AsyncStackTraceHelper())); | 3133 async_lib.LookupFunctionAllowPrivate(Symbols::AsyncStackTraceHelper())); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3425 | 3264 |
3426 // Call _asyncSetThreadStackTrace | 3265 // Call _asyncSetThreadStackTrace |
3427 instructions += StaticCall(TokenPosition::kNoSource, target, 1); | 3266 instructions += StaticCall(TokenPosition::kNoSource, target, 1); |
3428 instructions += Drop(); | 3267 instructions += Drop(); |
3429 | 3268 |
3430 // TODO(29737): This sequence should be generated in order. | 3269 // TODO(29737): This sequence should be generated in order. |
3431 body = instructions + body; | 3270 body = instructions + body; |
3432 flow_graph_builder_->context_depth_ = current_context_depth; | 3271 flow_graph_builder_->context_depth_ = current_context_depth; |
3433 } | 3272 } |
3434 | 3273 |
3435 if (NeedsDebugStepCheck(dart_function, position)) { | 3274 if (NeedsDebugStepCheck(dart_function, function_node_helper.position_)) { |
3436 const intptr_t current_context_depth = flow_graph_builder_->context_depth_; | 3275 const intptr_t current_context_depth = flow_graph_builder_->context_depth_; |
3437 flow_graph_builder_->context_depth_ = 0; | 3276 flow_graph_builder_->context_depth_ = 0; |
3438 | |
3439 // If a switch was added above: Start the switch by injecting a debuggable | 3277 // If a switch was added above: Start the switch by injecting a debuggable |
3440 // safepoint so stepping over an await works. | 3278 // safepoint so stepping over an await works. |
3441 // If not, still start the body with a debuggable safepoint to ensure | 3279 // If not, still start the body with a debuggable safepoint to ensure |
3442 // breaking on a method always happens, even if there are no | 3280 // breaking on a method always happens, even if there are no |
3443 // assignments/calls/runtimecalls in the first basic block. | 3281 // assignments/calls/runtimecalls in the first basic block. |
3444 // Place this check at the last parameter to ensure parameters | 3282 // Place this check at the last parameter to ensure parameters |
3445 // are in scope in the debugger at method entry. | 3283 // are in scope in the debugger at method entry. |
3446 const int num_params = dart_function.NumParameters(); | 3284 const int num_params = dart_function.NumParameters(); |
3447 TokenPosition check_pos = TokenPosition::kNoSource; | 3285 TokenPosition check_pos = TokenPosition::kNoSource; |
3448 if (num_params > 0) { | 3286 if (num_params > 0) { |
3449 LocalScope* scope = parsed_function()->node_sequence()->scope(); | 3287 LocalScope* scope = parsed_function()->node_sequence()->scope(); |
3450 const LocalVariable& parameter = *scope->VariableAt(num_params - 1); | 3288 const LocalVariable& parameter = *scope->VariableAt(num_params - 1); |
3451 check_pos = parameter.token_pos(); | 3289 check_pos = parameter.token_pos(); |
3452 } | 3290 } |
3453 if (!check_pos.IsDebugPause()) { | 3291 if (!check_pos.IsDebugPause()) { |
3454 // No parameters or synthetic parameters. | 3292 // No parameters or synthetic parameters. |
3455 check_pos = position; | 3293 check_pos = function_node_helper.position_; |
3456 ASSERT(check_pos.IsDebugPause()); | 3294 ASSERT(check_pos.IsDebugPause()); |
3457 } | 3295 } |
3458 | 3296 |
3459 // TODO(29737): This sequence should be generated in order. | 3297 // TODO(29737): This sequence should be generated in order. |
3460 body = DebugStepCheck(check_pos) + body; | 3298 body = DebugStepCheck(check_pos) + body; |
3461 flow_graph_builder_->context_depth_ = current_context_depth; | 3299 flow_graph_builder_->context_depth_ = current_context_depth; |
3462 } | 3300 } |
3463 | 3301 |
3464 normal_entry->LinkTo(body.entry); | 3302 normal_entry->LinkTo(body.entry); |
3465 | 3303 |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4246 ReadPosition(); // read position. | 4084 ReadPosition(); // read position. |
4247 SkipVariableDeclaration(); // read variable. | 4085 SkipVariableDeclaration(); // read variable. |
4248 SkipFunctionNode(); // read function node. | 4086 SkipFunctionNode(); // read function node. |
4249 return; | 4087 return; |
4250 default: | 4088 default: |
4251 UNREACHABLE(); | 4089 UNREACHABLE(); |
4252 } | 4090 } |
4253 } | 4091 } |
4254 | 4092 |
4255 void StreamingFlowGraphBuilder::SkipFunctionNode() { | 4093 void StreamingFlowGraphBuilder::SkipFunctionNode() { |
4256 Tag tag = ReadTag(); // read tag. | 4094 FunctionNodeHelper function_node_helper(this); |
4257 ASSERT(tag == kFunctionNode); | 4095 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
4258 | |
4259 ReadPosition(); // read position. | |
4260 ReadPosition(); // read end position. | |
4261 ReadByte(); // read async marker. | |
4262 ReadByte(); // read dart async marker. | |
4263 SkipTypeParametersList(); // read type_parameters. | |
4264 ReadUInt(); // read total parameter count. | |
4265 ReadUInt(); // read required_parameter_count. | |
4266 | |
4267 SkipListOfVariableDeclarations(); // read list of positionals. | |
4268 SkipListOfVariableDeclarations(); // read list of named. | |
4269 SkipDartType(); // read return type. | |
4270 | |
4271 if (ReadTag() == kSomething) { | |
4272 SkipStatement(); // Read body | |
4273 } | |
4274 } | 4096 } |
4275 | 4097 |
4276 void StreamingFlowGraphBuilder::SkipName() { | 4098 void StreamingFlowGraphBuilder::SkipName() { |
4277 StringIndex name_index = ReadStringReference(); // read name index. | 4099 StringIndex name_index = ReadStringReference(); // read name index. |
4278 if ((H.StringSize(name_index) >= 1) && H.CharacterAt(name_index, 0) == '_') { | 4100 if ((H.StringSize(name_index) >= 1) && H.CharacterAt(name_index, 0) == '_') { |
4279 SkipCanonicalNameReference(); // read library index. | 4101 SkipCanonicalNameReference(); // read library index. |
4280 } | 4102 } |
4281 } | 4103 } |
4282 | 4104 |
4283 void StreamingFlowGraphBuilder::SkipArguments() { | 4105 void StreamingFlowGraphBuilder::SkipArguments() { |
4284 ReadUInt(); // read argument count. | 4106 ReadUInt(); // read argument count. |
4285 | 4107 |
4286 SkipListOfDartTypes(); // read list of types. | 4108 SkipListOfDartTypes(); // read list of types. |
4287 SkipListOfExpressions(); // read positionals. | 4109 SkipListOfExpressions(); // read positionals. |
4288 | 4110 |
4289 // List of named. | 4111 // List of named. |
4290 intptr_t list_length = ReadListLength(); // read list length. | 4112 intptr_t list_length = ReadListLength(); // read list length. |
4291 for (intptr_t i = 0; i < list_length; ++i) { | 4113 for (intptr_t i = 0; i < list_length; ++i) { |
4292 SkipStringReference(); // read ith name index. | 4114 SkipStringReference(); // read ith name index. |
4293 SkipExpression(); // read ith expression. | 4115 SkipExpression(); // read ith expression. |
4294 } | 4116 } |
4295 } | 4117 } |
4296 | 4118 |
4297 void StreamingFlowGraphBuilder::SkipVariableDeclaration() { | 4119 void StreamingFlowGraphBuilder::SkipVariableDeclaration() { |
4298 ReadPosition(); // read position. | 4120 VariableDeclarationHelper helper(this); |
4299 ReadPosition(); // read equals position. | 4121 helper.ReadUntilExcluding(VariableDeclarationHelper::kEnd); |
4300 ReadFlags(); // read flags. | |
4301 SkipStringReference(); // read name index. | |
4302 SkipDartType(); // read type. | |
4303 Tag tag = ReadTag(); // read (first part of) initializer. | |
4304 if (tag == kSomething) { | |
4305 SkipExpression(); // read (actual) initializer. | |
4306 } | |
4307 } | 4122 } |
4308 | 4123 |
4309 TokenPosition StreamingFlowGraphBuilder::ReadPosition(bool record) { | 4124 TokenPosition StreamingFlowGraphBuilder::ReadPosition(bool record) { |
4310 return reader_->ReadPosition(record); | 4125 return reader_->ReadPosition(record); |
4311 } | 4126 } |
4312 | 4127 |
4313 Tag StreamingFlowGraphBuilder::ReadTag(uint8_t* payload) { | 4128 Tag StreamingFlowGraphBuilder::ReadTag(uint8_t* payload) { |
4314 return reader_->ReadTag(payload); | 4129 return reader_->ReadTag(payload); |
4315 } | 4130 } |
4316 | 4131 |
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6194 head_instructions += Drop(); | 6009 head_instructions += Drop(); |
6195 | 6010 |
6196 num_cases = ReadListLength(); // read number of cases. | 6011 num_cases = ReadListLength(); // read number of cases. |
6197 | 6012 |
6198 // Phase 1: Generate bodies and try to find out whether a body will be target | 6013 // Phase 1: Generate bodies and try to find out whether a body will be target |
6199 // of a jump due to: | 6014 // of a jump due to: |
6200 // * `continue case_label` | 6015 // * `continue case_label` |
6201 // * `case e1: case e2: body` | 6016 // * `case e1: case e2: body` |
6202 Fragment* body_fragments = new Fragment[num_cases]; | 6017 Fragment* body_fragments = new Fragment[num_cases]; |
6203 intptr_t* case_expression_offsets = new intptr_t[num_cases]; | 6018 intptr_t* case_expression_offsets = new intptr_t[num_cases]; |
6204 bool* case_is_default = new bool[num_cases]; | 6019 int default_case = -1; |
6205 | 6020 |
6206 for (intptr_t i = 0; i < num_cases; ++i) { | 6021 for (intptr_t i = 0; i < num_cases; ++i) { |
6207 case_expression_offsets[i] = ReaderOffset(); | 6022 case_expression_offsets[i] = ReaderOffset(); |
6208 int num_expressions = ReadListLength(); // read number of expressions. | 6023 int num_expressions = ReadListLength(); // read number of expressions. |
6209 for (intptr_t j = 0; j < num_expressions; ++j) { | 6024 for (intptr_t j = 0; j < num_expressions; ++j) { |
6210 ReadPosition(); // read jth position. | 6025 ReadPosition(); // read jth position. |
6211 SkipExpression(); // read jth expression. | 6026 SkipExpression(); // read jth expression. |
6212 } | 6027 } |
6213 bool is_default = ReadBool(); // read is_default. | 6028 bool is_default = ReadBool(); // read is_default. |
6214 case_is_default[i] = is_default; | 6029 if (is_default) default_case = i; |
6215 Fragment& body_fragment = body_fragments[i] = | 6030 Fragment& body_fragment = body_fragments[i] = |
6216 BuildStatement(); // read body. | 6031 BuildStatement(); // read body. |
6217 | 6032 |
6218 if (body_fragment.entry == NULL) { | 6033 if (body_fragment.entry == NULL) { |
6219 // Make a NOP in order to ensure linking works properly. | 6034 // Make a NOP in order to ensure linking works properly. |
6220 body_fragment = NullConstant(); | 6035 body_fragment = NullConstant(); |
6221 body_fragment += Drop(); | 6036 body_fragment += Drop(); |
6222 } | 6037 } |
6223 | 6038 |
6224 // The Dart language specification mandates fall-throughs in [SwitchCase]es | 6039 // The Dart language specification mandates fall-throughs in [SwitchCase]es |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6278 intptr_t end_offset = ReaderOffset(); | 6093 intptr_t end_offset = ReaderOffset(); |
6279 | 6094 |
6280 // Phase 2: Generate everything except the real bodies: | 6095 // Phase 2: Generate everything except the real bodies: |
6281 // * jump directly to a body (if there is no jumper) | 6096 // * jump directly to a body (if there is no jumper) |
6282 // * jump to a wrapper block which jumps to the body (if there is a jumper) | 6097 // * jump to a wrapper block which jumps to the body (if there is a jumper) |
6283 Fragment current_instructions = head_instructions; | 6098 Fragment current_instructions = head_instructions; |
6284 for (intptr_t i = 0; i < num_cases; ++i) { | 6099 for (intptr_t i = 0; i < num_cases; ++i) { |
6285 SetOffset(case_expression_offsets[i]); | 6100 SetOffset(case_expression_offsets[i]); |
6286 int num_expressions = ReadListLength(); // read length of expressions. | 6101 int num_expressions = ReadListLength(); // read length of expressions. |
6287 | 6102 |
6288 if (case_is_default[i]) { | 6103 if (i == default_case) { |
6289 ASSERT(i == (num_cases - 1)); | 6104 ASSERT(i == (num_cases - 1)); |
6290 | 6105 |
6291 // Evaluate the conditions for the default [SwitchCase] just for the | 6106 // Evaluate the conditions for the default [SwitchCase] just for the |
6292 // purpose of potentially triggering a compile-time error. | 6107 // purpose of potentially triggering a compile-time error. |
6293 | 6108 |
6294 for (intptr_t j = 0; j < num_expressions; ++j) { | 6109 for (intptr_t j = 0; j < num_expressions; ++j) { |
6295 ReadPosition(); // read jth position. | 6110 ReadPosition(); // read jth position. |
6296 // this reads the expression, but doesn't skip past it. | 6111 // this reads the expression, but doesn't skip past it. |
6297 constant_evaluator_.EvaluateExpression(ReaderOffset()); | 6112 constant_evaluator_.EvaluateExpression(ReaderOffset()); |
6298 SkipExpression(); // read jth expression. | 6113 SkipExpression(); // read jth expression. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6344 // There is only a signle branch to the body, so we will just append | 6159 // There is only a signle branch to the body, so we will just append |
6345 // the body fragment. | 6160 // the body fragment. |
6346 then_fragment += body_fragments[i]; | 6161 then_fragment += body_fragments[i]; |
6347 } | 6162 } |
6348 | 6163 |
6349 current_instructions = Fragment(otherwise); | 6164 current_instructions = Fragment(otherwise); |
6350 } | 6165 } |
6351 } | 6166 } |
6352 } | 6167 } |
6353 | 6168 |
6354 bool has_no_default = num_cases > 0 && !case_is_default[num_cases - 1]; | 6169 if (num_cases > 0 && default_case < 0) { |
6355 if (has_no_default) { | |
6356 // There is no default, which means we have an open [current_instructions] | 6170 // There is no default, which means we have an open [current_instructions] |
6357 // (which is a [TargetEntryInstruction] for the last "otherwise" branch). | 6171 // (which is a [TargetEntryInstruction] for the last "otherwise" branch). |
6358 // | 6172 // |
6359 // Furthermore the last [SwitchCase] can be open as well. If so, we need | 6173 // Furthermore the last [SwitchCase] can be open as well. If so, we need |
6360 // to join these two. | 6174 // to join these two. |
6361 Fragment& last_body = body_fragments[num_cases - 1]; | 6175 Fragment& last_body = body_fragments[num_cases - 1]; |
6362 if (last_body.is_open()) { | 6176 if (last_body.is_open()) { |
6363 ASSERT(current_instructions.is_open()); | 6177 ASSERT(current_instructions.is_open()); |
6364 ASSERT(current_instructions.current->IsTargetEntry()); | 6178 ASSERT(current_instructions.current->IsTargetEntry()); |
6365 | 6179 |
6366 // Join the last "otherwise" branch and the last [SwitchCase] fragment. | 6180 // Join the last "otherwise" branch and the last [SwitchCase] fragment. |
6367 JoinEntryInstr* join = BuildJoinEntry(); | 6181 JoinEntryInstr* join = BuildJoinEntry(); |
6368 current_instructions += Goto(join); | 6182 current_instructions += Goto(join); |
6369 last_body += Goto(join); | 6183 last_body += Goto(join); |
6370 | 6184 |
6371 current_instructions = Fragment(join); | 6185 current_instructions = Fragment(join); |
6372 } | 6186 } |
6373 } else { | 6187 } else { |
6374 // All non-default cases will be closed (i.e. break/continue/throw/return) | 6188 // All non-default cases will be closed (i.e. break/continue/throw/return) |
6375 // So it is fine to just let more statements after the switch append to the | 6189 // So it is fine to just let more statements after the switch append to the |
6376 // default case. | 6190 // default case. |
6377 } | 6191 } |
6378 | 6192 |
6379 delete[] body_fragments; | 6193 delete[] body_fragments; |
| 6194 delete[] case_expression_offsets; |
6380 | 6195 |
6381 SetOffset(end_offset); | 6196 SetOffset(end_offset); |
6382 return Fragment(head_instructions.entry, current_instructions.current); | 6197 return Fragment(head_instructions.entry, current_instructions.current); |
6383 } | 6198 } |
6384 | 6199 |
6385 Fragment StreamingFlowGraphBuilder::BuildContinueSwitchStatement() { | 6200 Fragment StreamingFlowGraphBuilder::BuildContinueSwitchStatement() { |
6386 intptr_t target_index = ReadUInt(); // read target index. | 6201 intptr_t target_index = ReadUInt(); // read target index. |
6387 | 6202 |
6388 TryFinallyBlock* outer_finally = NULL; | 6203 TryFinallyBlock* outer_finally = NULL; |
6389 intptr_t target_context_depth = -1; | 6204 intptr_t target_context_depth = -1; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6741 continuation = Fragment(continuation.entry, no_error); | 6556 continuation = Fragment(continuation.entry, no_error); |
6742 } | 6557 } |
6743 | 6558 |
6744 return continuation; | 6559 return continuation; |
6745 } | 6560 } |
6746 | 6561 |
6747 Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() { | 6562 Fragment StreamingFlowGraphBuilder::BuildVariableDeclaration() { |
6748 intptr_t kernel_position_no_tag = ReaderOffset(); | 6563 intptr_t kernel_position_no_tag = ReaderOffset(); |
6749 LocalVariable* variable = LookupVariable(kernel_position_no_tag); | 6564 LocalVariable* variable = LookupVariable(kernel_position_no_tag); |
6750 | 6565 |
6751 TokenPosition position = ReadPosition(); // read position. | 6566 VariableDeclarationHelper helper(this); |
6752 TokenPosition equals_position = ReadPosition(); // read equals position. | 6567 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
6753 word flags = ReadFlags(); // read flags. | 6568 dart::String& name = H.DartSymbol(helper.name_index_); |
6754 dart::String& name = H.DartSymbol(ReadStringReference()); // read name index. | |
6755 AbstractType& type = T.BuildType(); // read type. | 6569 AbstractType& type = T.BuildType(); // read type. |
6756 Tag tag = ReadTag(); // read (first part of) initializer. | 6570 Tag tag = ReadTag(); // read (first part of) initializer. |
6757 | 6571 |
6758 Fragment instructions; | 6572 Fragment instructions; |
6759 if (tag == kNothing) { | 6573 if (tag == kNothing) { |
6760 instructions += NullConstant(); | 6574 instructions += NullConstant(); |
6761 } else { | 6575 } else { |
6762 if ((flags & VariableDeclaration::kFlagConst) == | 6576 if (helper.IsConst()) { |
6763 VariableDeclaration::kFlagConst) { | |
6764 // Const! | |
6765 const Instance& constant_value = constant_evaluator_.EvaluateExpression( | 6577 const Instance& constant_value = constant_evaluator_.EvaluateExpression( |
6766 ReaderOffset()); // read initializer form current position. | 6578 ReaderOffset()); // read initializer form current position. |
6767 variable->SetConstValue(constant_value); | 6579 variable->SetConstValue(constant_value); |
6768 instructions += Constant(constant_value); | 6580 instructions += Constant(constant_value); |
6769 SkipExpression(); // skip initializer. | 6581 SkipExpression(); // skip initializer. |
6770 } else { | 6582 } else { |
6771 // Initializer | 6583 // Initializer |
6772 instructions += BuildExpression(); // read (actual) initializer. | 6584 instructions += BuildExpression(); // read (actual) initializer. |
6773 instructions += CheckVariableTypeInCheckedMode(type, name); | 6585 instructions += CheckVariableTypeInCheckedMode(type, name); |
6774 } | 6586 } |
6775 } | 6587 } |
6776 | 6588 |
6777 // Use position of equal sign if it exists. If the equal sign does not exist | 6589 // Use position of equal sign if it exists. If the equal sign does not exist |
6778 // use the position of the identifier. | 6590 // use the position of the identifier. |
6779 TokenPosition debug_position = Utils::Maximum(position, equals_position); | 6591 TokenPosition debug_position = |
| 6592 Utils::Maximum(helper.position_, helper.equals_position_); |
6780 if (NeedsDebugStepCheck(stack(), debug_position)) { | 6593 if (NeedsDebugStepCheck(stack(), debug_position)) { |
6781 instructions = DebugStepCheck(debug_position) + instructions; | 6594 instructions = DebugStepCheck(debug_position) + instructions; |
6782 } | 6595 } |
6783 instructions += StoreLocal(position, variable); | 6596 instructions += StoreLocal(helper.position_, variable); |
6784 instructions += Drop(); | 6597 instructions += Drop(); |
6785 return instructions; | 6598 return instructions; |
6786 } | 6599 } |
6787 | 6600 |
6788 Fragment StreamingFlowGraphBuilder::BuildFunctionDeclaration() { | 6601 Fragment StreamingFlowGraphBuilder::BuildFunctionDeclaration() { |
6789 intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte. | 6602 intptr_t offset = ReaderOffset() - 1; // -1 to include tag byte. |
6790 TokenPosition position = ReadPosition(); // read position. | 6603 TokenPosition position = ReadPosition(); // read position. |
6791 intptr_t variable_offeset = ReaderOffset(); | 6604 intptr_t variable_offeset = ReaderOffset(); |
6792 SkipVariableDeclaration(); // read variable declaration. | 6605 SkipVariableDeclaration(); // read variable declaration. |
6793 | 6606 |
6794 Fragment instructions = DebugStepCheck(position); | 6607 Fragment instructions = DebugStepCheck(position); |
6795 instructions += BuildFunctionNode(offset, position, true, variable_offeset); | 6608 instructions += BuildFunctionNode(offset, position, true, variable_offeset); |
6796 instructions += StoreLocal(position, LookupVariable(variable_offeset)); | 6609 instructions += StoreLocal(position, LookupVariable(variable_offeset)); |
6797 instructions += Drop(); | 6610 instructions += Drop(); |
6798 return instructions; | 6611 return instructions; |
6799 } | 6612 } |
6800 | 6613 |
6801 Fragment StreamingFlowGraphBuilder::BuildFunctionNode( | 6614 Fragment StreamingFlowGraphBuilder::BuildFunctionNode( |
6802 intptr_t parent_kernel_offset, | 6615 intptr_t parent_kernel_offset, |
6803 TokenPosition parent_position, | 6616 TokenPosition parent_position, |
6804 bool declaration, | 6617 bool declaration, |
6805 intptr_t variable_offeset) { | 6618 intptr_t variable_offeset) { |
6806 intptr_t offset = ReaderOffset(); | 6619 intptr_t offset = ReaderOffset(); |
6807 | 6620 |
6808 TokenPosition position; | 6621 FunctionNodeHelper function_node_helper(this); |
6809 TokenPosition end_position; | 6622 function_node_helper.ReadUntilExcluding( |
6810 word async_marker_word; | 6623 FunctionNodeHelper::kTotalParameterCount); |
6811 word dart_async_marker_word; | 6624 TokenPosition position = function_node_helper.position_; |
6812 ReadFunctionNodeUntilTypeParameters( | |
6813 &position, &end_position, &async_marker_word, | |
6814 &dart_async_marker_word); // read first part of function node. | |
6815 FunctionNode::AsyncMarker async_marker = | |
6816 static_cast<FunctionNode::AsyncMarker>(async_marker_word); | |
6817 FunctionNode::AsyncMarker dart_async_marker = | |
6818 static_cast<FunctionNode::AsyncMarker>(dart_async_marker_word); | |
6819 | 6625 |
6820 if (declaration) { | 6626 if (declaration) { |
6821 position = parent_position; | 6627 position = parent_position; |
6822 } | 6628 } |
6823 if (!position.IsReal()) { | 6629 if (!position.IsReal()) { |
6824 // Positions has to be unique in regards to the parent. | 6630 // Positions has to be unique in regards to the parent. |
6825 // A non-real at this point is probably -1, we cannot blindly use that | 6631 // A non-real at this point is probably -1, we cannot blindly use that |
6826 // as others might use it too. Create a new dummy non-real TokenPosition. | 6632 // as others might use it too. Create a new dummy non-real TokenPosition. |
6827 position = TokenPosition(offset).ToSynthetic(); | 6633 position = TokenPosition(offset).ToSynthetic(); |
6828 } | 6634 } |
6829 | 6635 |
6830 SkipTypeParametersList(); // read type parameters. | |
6831 | |
6832 // The VM has a per-isolate table of functions indexed by the enclosing | 6636 // The VM has a per-isolate table of functions indexed by the enclosing |
6833 // function and token position. | 6637 // function and token position. |
6834 Function& function = Function::ZoneHandle(Z); | 6638 Function& function = Function::ZoneHandle(Z); |
6835 bool read_rest_of_function_node = false; | |
6836 | 6639 |
6837 // NOTE: This is not TokenPosition in the general sense! | 6640 // NOTE: This is not TokenPosition in the general sense! |
6838 function = I->LookupClosureFunction(parsed_function()->function(), position); | 6641 function = I->LookupClosureFunction(parsed_function()->function(), position); |
6839 if (function.IsNull()) { | 6642 if (function.IsNull()) { |
6840 for (intptr_t i = 0; i < scopes()->function_scopes.length(); ++i) { | 6643 for (intptr_t i = 0; i < scopes()->function_scopes.length(); ++i) { |
6841 if (scopes()->function_scopes[i].kernel_offset != offset) { | 6644 if (scopes()->function_scopes[i].kernel_offset != offset) { |
6842 continue; | 6645 continue; |
6843 } | 6646 } |
6844 | 6647 |
6845 const dart::String* name; | 6648 const dart::String* name; |
6846 if (!declaration) { | 6649 if (!declaration) { |
6847 name = &Symbols::AnonymousClosure(); | 6650 name = &Symbols::AnonymousClosure(); |
6848 } else { | 6651 } else { |
6849 name = &H.DartSymbol(GetNameFromVariableDeclaration(variable_offeset)); | 6652 name = &H.DartSymbol(GetNameFromVariableDeclaration(variable_offeset)); |
6850 } | 6653 } |
6851 // NOTE: This is not TokenPosition in the general sense! | 6654 // NOTE: This is not TokenPosition in the general sense! |
6852 function = Function::NewClosureFunction( | 6655 function = Function::NewClosureFunction( |
6853 *name, parsed_function()->function(), position); | 6656 *name, parsed_function()->function(), position); |
6854 | 6657 |
6855 function.set_is_debuggable(dart_async_marker == FunctionNode::kSync); | 6658 function.set_is_debuggable(function_node_helper.dart_async_marker_ == |
6856 switch (dart_async_marker) { | 6659 FunctionNode::kSync); |
| 6660 switch (function_node_helper.dart_async_marker_) { |
6857 case FunctionNode::kSyncStar: | 6661 case FunctionNode::kSyncStar: |
6858 function.set_modifier(RawFunction::kSyncGen); | 6662 function.set_modifier(RawFunction::kSyncGen); |
6859 break; | 6663 break; |
6860 case FunctionNode::kAsync: | 6664 case FunctionNode::kAsync: |
6861 function.set_modifier(RawFunction::kAsync); | 6665 function.set_modifier(RawFunction::kAsync); |
6862 function.set_is_inlinable(!FLAG_causal_async_stacks); | 6666 function.set_is_inlinable(!FLAG_causal_async_stacks); |
6863 break; | 6667 break; |
6864 case FunctionNode::kAsyncStar: | 6668 case FunctionNode::kAsyncStar: |
6865 function.set_modifier(RawFunction::kAsyncGen); | 6669 function.set_modifier(RawFunction::kAsyncGen); |
6866 function.set_is_inlinable(!FLAG_causal_async_stacks); | 6670 function.set_is_inlinable(!FLAG_causal_async_stacks); |
6867 break; | 6671 break; |
6868 default: | 6672 default: |
6869 // no special modifier | 6673 // no special modifier |
6870 break; | 6674 break; |
6871 } | 6675 } |
6872 function.set_is_generated_body(async_marker == | 6676 function.set_is_generated_body(function_node_helper.async_marker_ == |
6873 FunctionNode::kSyncYielding); | 6677 FunctionNode::kSyncYielding); |
6874 if (function.IsAsyncClosure() || function.IsAsyncGenClosure()) { | 6678 if (function.IsAsyncClosure() || function.IsAsyncGenClosure()) { |
6875 function.set_is_inlinable(!FLAG_causal_async_stacks); | 6679 function.set_is_inlinable(!FLAG_causal_async_stacks); |
6876 } | 6680 } |
6877 | 6681 |
6878 function.set_end_token_pos(end_position); | 6682 function.set_end_token_pos(function_node_helper.end_position_); |
6879 LocalScope* scope = scopes()->function_scopes[i].scope; | 6683 LocalScope* scope = scopes()->function_scopes[i].scope; |
6880 const ContextScope& context_scope = ContextScope::Handle( | 6684 const ContextScope& context_scope = ContextScope::Handle( |
6881 Z, scope->PreserveOuterScope(flow_graph_builder_->context_depth_)); | 6685 Z, scope->PreserveOuterScope(flow_graph_builder_->context_depth_)); |
6882 function.set_context_scope(context_scope); | 6686 function.set_context_scope(context_scope); |
6883 function.set_kernel_offset(offset); | 6687 function.set_kernel_offset(offset); |
6884 // Read rest of function node. | |
6885 SetupFunctionParameters(dart::Class::Handle(Z), function, | 6688 SetupFunctionParameters(dart::Class::Handle(Z), function, |
6886 false, // is_method | 6689 false, // is_method |
6887 true); // is_closure | 6690 true, // is_closure |
6888 read_rest_of_function_node = true; | 6691 &function_node_helper); |
| 6692 |
6889 // Finalize function type. | 6693 // Finalize function type. |
6890 Type& signature_type = Type::Handle(Z, function.SignatureType()); | 6694 Type& signature_type = Type::Handle(Z, function.SignatureType()); |
6891 signature_type ^= | 6695 signature_type ^= |
6892 ClassFinalizer::FinalizeType(*active_class()->klass, signature_type); | 6696 ClassFinalizer::FinalizeType(*active_class()->klass, signature_type); |
6893 function.SetSignatureType(signature_type); | 6697 function.SetSignatureType(signature_type); |
6894 | 6698 |
6895 I->AddClosureFunction(function); | 6699 I->AddClosureFunction(function); |
6896 break; | 6700 break; |
6897 } | 6701 } |
6898 } | 6702 } |
6899 | 6703 |
6900 if (!read_rest_of_function_node) { | 6704 function_node_helper.ReadUntilExcluding(FunctionNodeHelper::kEnd); |
6901 ReadUInt(); // read total parameter count. | |
6902 ReadUInt(); // read required_parameter_count. | |
6903 SkipListOfVariableDeclarations(); // read list of positionals. | |
6904 SkipListOfVariableDeclarations(); // read list of named. | |
6905 SkipDartType(); // read return type. | |
6906 if (ReadTag() == kSomething) { // read first part of body. | |
6907 SkipStatement(); // read body. | |
6908 } | |
6909 } | |
6910 | 6705 |
6911 const dart::Class& closure_class = | 6706 const dart::Class& closure_class = |
6912 dart::Class::ZoneHandle(Z, I->object_store()->closure_class()); | 6707 dart::Class::ZoneHandle(Z, I->object_store()->closure_class()); |
6913 ASSERT(!closure_class.IsNull()); | 6708 ASSERT(!closure_class.IsNull()); |
6914 Fragment instructions = | 6709 Fragment instructions = |
6915 flow_graph_builder_->AllocateObject(closure_class, function); | 6710 flow_graph_builder_->AllocateObject(closure_class, function); |
6916 LocalVariable* closure = MakeTemporary(); | 6711 LocalVariable* closure = MakeTemporary(); |
6917 | 6712 |
6918 // The function signature can have uninstantiated class type parameters. | 6713 // The function signature can have uninstantiated class type parameters. |
6919 // | 6714 // |
(...skipping 19 matching lines...) Expand all Loading... |
6939 TokenPosition::kNoSource, Closure::context_offset()); | 6734 TokenPosition::kNoSource, Closure::context_offset()); |
6940 | 6735 |
6941 return instructions; | 6736 return instructions; |
6942 } | 6737 } |
6943 | 6738 |
6944 | 6739 |
6945 void StreamingFlowGraphBuilder::SetupFunctionParameters( | 6740 void StreamingFlowGraphBuilder::SetupFunctionParameters( |
6946 const dart::Class& klass, | 6741 const dart::Class& klass, |
6947 const dart::Function& function, | 6742 const dart::Function& function, |
6948 bool is_method, | 6743 bool is_method, |
6949 bool is_closure) { | 6744 bool is_closure, |
| 6745 FunctionNodeHelper* function_node_helper) { |
6950 ASSERT(!(is_method && is_closure)); | 6746 ASSERT(!(is_method && is_closure)); |
6951 bool is_factory = function.IsFactory(); | 6747 bool is_factory = function.IsFactory(); |
6952 intptr_t extra_parameters = (is_method || is_closure || is_factory) ? 1 : 0; | 6748 intptr_t extra_parameters = (is_method || is_closure || is_factory) ? 1 : 0; |
6953 | 6749 |
6954 intptr_t total_parameter_count = ReadUInt(); // read total parameter count. | 6750 function_node_helper->ReadUntilExcluding( |
| 6751 FunctionNodeHelper::kPositionalParameters); |
| 6752 |
6955 intptr_t required_parameter_count = | 6753 intptr_t required_parameter_count = |
6956 ReadUInt(); // read required_parameter_count. | 6754 function_node_helper->required_parameter_count_; |
| 6755 intptr_t total_parameter_count = function_node_helper->total_parameter_count_; |
| 6756 |
6957 intptr_t positional_parameters_count = ReadListLength(); // read list length. | 6757 intptr_t positional_parameters_count = ReadListLength(); // read list length. |
| 6758 |
6958 intptr_t named_parameters_count = | 6759 intptr_t named_parameters_count = |
6959 total_parameter_count - positional_parameters_count; | 6760 total_parameter_count - positional_parameters_count; |
6960 | 6761 |
6961 function.set_num_fixed_parameters(extra_parameters + | 6762 function.set_num_fixed_parameters(extra_parameters + |
6962 required_parameter_count); | 6763 required_parameter_count); |
6963 if (named_parameters_count > 0) { | 6764 if (named_parameters_count > 0) { |
6964 function.SetNumOptionalParameters(named_parameters_count, false); | 6765 function.SetNumOptionalParameters(named_parameters_count, false); |
6965 } else { | 6766 } else { |
6966 function.SetNumOptionalParameters( | 6767 function.SetNumOptionalParameters( |
6967 positional_parameters_count - required_parameter_count, true); | 6768 positional_parameters_count - required_parameter_count, true); |
(...skipping 14 matching lines...) Expand all Loading... |
6982 function.SetParameterNameAt(pos, Symbols::ClosureParameter()); | 6783 function.SetParameterNameAt(pos, Symbols::ClosureParameter()); |
6983 pos++; | 6784 pos++; |
6984 } else if (is_factory) { | 6785 } else if (is_factory) { |
6985 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); | 6786 function.SetParameterTypeAt(pos, AbstractType::dynamic_type()); |
6986 function.SetParameterNameAt(pos, Symbols::TypeArgumentsParameter()); | 6787 function.SetParameterNameAt(pos, Symbols::TypeArgumentsParameter()); |
6987 pos++; | 6788 pos++; |
6988 } | 6789 } |
6989 | 6790 |
6990 for (intptr_t i = 0; i < positional_parameters_count; ++i, ++pos) { | 6791 for (intptr_t i = 0; i < positional_parameters_count; ++i, ++pos) { |
6991 // Read ith variable declaration. | 6792 // Read ith variable declaration. |
6992 ReadPosition(); // read position. | 6793 VariableDeclarationHelper helper(this); |
6993 ReadPosition(); // read equals position. | 6794 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
6994 ReadFlags(); // read flags. | |
6995 StringIndex name = ReadStringReference(); // read name index. | |
6996 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. | 6795 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. |
6997 Tag tag = ReadTag(); // read (first part of) initializer. | 6796 Tag tag = ReadTag(); // read (first part of) initializer. |
6998 if (tag == kSomething) { | 6797 if (tag == kSomething) { |
6999 SkipExpression(); // read (actual) initializer. | 6798 SkipExpression(); // read (actual) initializer. |
7000 } | 6799 } |
7001 | 6800 |
7002 function.SetParameterTypeAt( | 6801 function.SetParameterTypeAt( |
7003 pos, type.IsMalformed() ? Type::dynamic_type() : type); | 6802 pos, type.IsMalformed() ? Type::dynamic_type() : type); |
7004 function.SetParameterNameAt(pos, H.DartSymbol(name)); | 6803 function.SetParameterNameAt(pos, H.DartSymbol(helper.name_index_)); |
7005 } | 6804 } |
7006 | 6805 |
7007 intptr_t named_parameters_count_check = | 6806 intptr_t named_parameters_count_check = |
7008 ReadListLength(); // read list length. | 6807 ReadListLength(); // read list length. |
7009 ASSERT(named_parameters_count_check == named_parameters_count); | 6808 ASSERT(named_parameters_count_check == named_parameters_count); |
7010 for (intptr_t i = 0; i < named_parameters_count; ++i, ++pos) { | 6809 for (intptr_t i = 0; i < named_parameters_count; ++i, ++pos) { |
7011 // Read ith variable declaration. | 6810 // Read ith variable declaration. |
7012 ReadPosition(); // read position. | 6811 VariableDeclarationHelper helper(this); |
7013 ReadPosition(); // read equals position. | 6812 helper.ReadUntilExcluding(VariableDeclarationHelper::kType); |
7014 ReadFlags(); // read flags. | |
7015 StringIndex name = ReadStringReference(); // read name index. | |
7016 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. | 6813 const AbstractType& type = T.BuildTypeWithoutFinalization(); // read type. |
7017 Tag tag = ReadTag(); // read (first part of) initializer. | 6814 Tag tag = ReadTag(); // read (first part of) initializer. |
7018 if (tag == kSomething) { | 6815 if (tag == kSomething) { |
7019 SkipExpression(); // read (actual) initializer. | 6816 SkipExpression(); // read (actual) initializer. |
7020 } | 6817 } |
7021 | 6818 |
7022 function.SetParameterTypeAt( | 6819 function.SetParameterTypeAt( |
7023 pos, type.IsMalformed() ? Type::dynamic_type() : type); | 6820 pos, type.IsMalformed() ? Type::dynamic_type() : type); |
7024 function.SetParameterNameAt(pos, H.DartSymbol(name)); | 6821 function.SetParameterNameAt(pos, H.DartSymbol(helper.name_index_)); |
7025 } | 6822 } |
7026 | 6823 |
| 6824 function_node_helper->SetJustRead(FunctionNodeHelper::kNamedParameters); |
| 6825 |
7027 // The result type for generative constructors has already been set. | 6826 // The result type for generative constructors has already been set. |
7028 if (!function.IsGenerativeConstructor()) { | 6827 if (!function.IsGenerativeConstructor()) { |
7029 const AbstractType& return_type = | 6828 const AbstractType& return_type = |
7030 T.BuildTypeWithoutFinalization(); // read return type. | 6829 T.BuildTypeWithoutFinalization(); // read return type. |
7031 function.set_result_type(return_type.IsMalformed() ? Type::dynamic_type() | 6830 function.set_result_type(return_type.IsMalformed() ? Type::dynamic_type() |
7032 : return_type); | 6831 : return_type); |
7033 } else { | 6832 function_node_helper->SetJustRead(FunctionNodeHelper::kReturnType); |
7034 SkipDartType(); // read return type. | |
7035 } | |
7036 | |
7037 if (ReadTag() == kSomething) { // read first part of body. | |
7038 SkipStatement(); // read body. | |
7039 } | 6833 } |
7040 } | 6834 } |
7041 | 6835 |
7042 RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor( | 6836 RawObject* StreamingFlowGraphBuilder::BuildParameterDescriptor( |
7043 intptr_t kernel_offset) { | 6837 intptr_t kernel_offset) { |
7044 SetOffset(kernel_offset); | 6838 SetOffset(kernel_offset); |
7045 ReadUntilFunctionNode(); // read until function node. | 6839 ReadUntilFunctionNode(); // read until function node. |
7046 ReadFunctionNodeUntilTypeParameters( | 6840 FunctionNodeHelper function_node_helper(this); |
7047 &unused_tokenposition, &unused_tokenposition, &unused_word, | 6841 function_node_helper.ReadUntilExcluding( |
7048 &unused_word); // read first part of function node. | 6842 FunctionNodeHelper::kPositionalParameters); |
7049 SkipTypeParametersList(); // read type_parameters. | 6843 intptr_t param_count = function_node_helper.total_parameter_count_; |
7050 | |
7051 intptr_t param_count = ReadUInt(); // read total parameter count. | |
7052 ReadUInt(); // read required_parameter_count. | |
7053 intptr_t positional_count = ReadListLength(); // read list length. | 6844 intptr_t positional_count = ReadListLength(); // read list length. |
7054 intptr_t named_parameters_count = param_count - positional_count; | 6845 intptr_t named_parameters_count = param_count - positional_count; |
7055 | 6846 |
7056 const Array& param_descriptor = Array::Handle( | 6847 const Array& param_descriptor = Array::Handle( |
7057 Array::New(param_count * Parser::kParameterEntrySize, Heap::kOld)); | 6848 Array::New(param_count * Parser::kParameterEntrySize, Heap::kOld)); |
7058 for (intptr_t i = 0; i < param_count; ++i) { | 6849 for (intptr_t i = 0; i < param_count; ++i) { |
7059 const intptr_t entry_start = i * Parser::kParameterEntrySize; | 6850 const intptr_t entry_start = i * Parser::kParameterEntrySize; |
7060 | 6851 |
7061 if (i == positional_count) { | 6852 if (i == positional_count) { |
7062 intptr_t named_parameters_count_check = | 6853 intptr_t named_parameters_count_check = |
7063 ReadListLength(); // read list length. | 6854 ReadListLength(); // read list length. |
7064 ASSERT(named_parameters_count_check == named_parameters_count); | 6855 ASSERT(named_parameters_count_check == named_parameters_count); |
7065 } | 6856 } |
7066 | 6857 |
7067 // Read ith variable declaration. | 6858 // Read ith variable declaration. |
7068 ReadPosition(); // read position. | 6859 VariableDeclarationHelper helper(this); |
7069 ReadPosition(); // read equals position. | 6860 helper.ReadUntilExcluding(VariableDeclarationHelper::kInitializer); |
7070 word flags = ReadFlags(); // read flags. | |
7071 bool is_final = (flags & VariableDeclaration::kFlagFinal) == | |
7072 VariableDeclaration::kFlagFinal; | |
7073 param_descriptor.SetAt(entry_start + Parser::kParameterIsFinalOffset, | 6861 param_descriptor.SetAt(entry_start + Parser::kParameterIsFinalOffset, |
7074 is_final ? Bool::True() : Bool::False()); | 6862 helper.IsFinal() ? Bool::True() : Bool::False()); |
7075 | 6863 |
7076 SkipStringReference(); // read name index. | |
7077 SkipDartType(); // read type. | |
7078 Tag tag = ReadTag(); // read (first part of) initializer. | 6864 Tag tag = ReadTag(); // read (first part of) initializer. |
7079 if (tag == kSomething) { | 6865 if (tag == kSomething) { |
7080 // this will (potentially) read the initializer, but reset the position. | 6866 // this will (potentially) read the initializer, but reset the position. |
7081 Instance& constant = | 6867 Instance& constant = |
7082 constant_evaluator_.EvaluateExpression(ReaderOffset()); | 6868 constant_evaluator_.EvaluateExpression(ReaderOffset()); |
7083 SkipExpression(); // read (actual) initializer. | 6869 SkipExpression(); // read (actual) initializer. |
7084 param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, | 6870 param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, |
7085 constant); | 6871 constant); |
7086 } else { | 6872 } else { |
7087 param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, | 6873 param_descriptor.SetAt(entry_start + Parser::kParameterDefaultValueOffset, |
7088 Object::null_instance()); | 6874 Object::null_instance()); |
7089 } | 6875 } |
7090 | 6876 |
7091 param_descriptor.SetAt(entry_start + Parser::kParameterMetadataOffset, | 6877 param_descriptor.SetAt(entry_start + Parser::kParameterMetadataOffset, |
7092 /* Issue(28434): Missing parameter metadata. */ | 6878 /* Issue(28434): Missing parameter metadata. */ |
7093 Object::null_instance()); | 6879 Object::null_instance()); |
7094 } | 6880 } |
7095 return param_descriptor.raw(); | 6881 return param_descriptor.raw(); |
7096 } | 6882 } |
7097 | 6883 |
7098 RawObject* StreamingFlowGraphBuilder::EvaluateMetadata(intptr_t kernel_offset) { | 6884 RawObject* StreamingFlowGraphBuilder::EvaluateMetadata(intptr_t kernel_offset) { |
7099 SetOffset(kernel_offset); | 6885 SetOffset(kernel_offset); |
7100 const Tag tag = PeekTag(); | 6886 const Tag tag = PeekTag(); |
7101 | 6887 |
7102 if (tag == kClass) { | 6888 if (tag == kClass) { |
7103 Tag tag = ReadTag(); // read tag. | 6889 ClassHelper class_helper(this); |
7104 ASSERT(tag == kClass); | 6890 class_helper.ReadUntilExcluding(ClassHelper::kAnnotations); |
7105 SkipCanonicalNameReference(); // read canonical name reference. | |
7106 ReadPosition(); // read position. | |
7107 ReadByte(); // read is_abstract | |
7108 SkipStringReference(); // read name_index. | |
7109 ReadUInt(); // read source_uri_index. | |
7110 // SkipListOfExpressions(); // read annotations. | |
7111 } else if (tag == kProcedure) { | 6891 } else if (tag == kProcedure) { |
7112 Tag tag = ReadTag(); // read tag. | 6892 ProcedureHelper procedure_helper(this); |
7113 ASSERT(tag == kProcedure); | 6893 procedure_helper.ReadUntilExcluding(ProcedureHelper::kAnnotations); |
7114 SkipCanonicalNameReference(); // read canonical name reference. | |
7115 ReadPosition(); // read position. | |
7116 ReadPosition(); // read end position. | |
7117 ReadByte(); // read kind. | |
7118 ReadFlags(); // read flags. | |
7119 ReadUInt(); // read parent class binary offset. | |
7120 SkipName(); // read name, | |
7121 ReadUInt(); // read source_uri_index. | |
7122 // SkipListOfExpressions(); // read annotations. | |
7123 } else if (tag == kField) { | 6894 } else if (tag == kField) { |
7124 ReadFieldUntilAnnotation(&unused_nameindex, &unused_tokenposition, | 6895 FieldHelper field_helper(this); |
7125 &unused_tokenposition, &unused_word, | 6896 field_helper.ReadUntilExcluding(FieldHelper::kAnnotations); |
7126 &unused_intptr); | |
7127 // SkipListOfExpressions(); // read annotations. | |
7128 } else if (tag == kConstructor) { | 6897 } else if (tag == kConstructor) { |
7129 Tag tag = ReadTag(); | 6898 ConstructorHelper constructor_helper(this); |
7130 ASSERT(tag == kConstructor); | 6899 constructor_helper.ReadUntilExcluding(ConstructorHelper::kAnnotations); |
7131 SkipCanonicalNameReference(); // read canonical name reference. | |
7132 ReadPosition(); // read position. | |
7133 ReadPosition(); // read end position. | |
7134 ReadFlags(); // read flags. | |
7135 ReadUInt(); // parent class binary offset. | |
7136 SkipName(); // read name. | |
7137 // SkipListOfExpressions(); // read annotations. | |
7138 } else { | 6900 } else { |
7139 FATAL("No support for metadata on this type of kernel node\n"); | 6901 FATAL("No support for metadata on this type of kernel node\n"); |
7140 } | 6902 } |
7141 | 6903 |
7142 intptr_t list_length = ReadListLength(); // read list length. | 6904 intptr_t list_length = ReadListLength(); // read list length. |
7143 const Array& metadata_values = Array::Handle(Z, Array::New(list_length)); | 6905 const Array& metadata_values = Array::Handle(Z, Array::New(list_length)); |
7144 for (intptr_t i = 0; i < list_length; ++i) { | 6906 for (intptr_t i = 0; i < list_length; ++i) { |
7145 // this will (potentially) read the expression, but reset the position. | 6907 // this will (potentially) read the expression, but reset the position. |
7146 Instance& value = constant_evaluator_.EvaluateExpression(ReaderOffset()); | 6908 Instance& value = constant_evaluator_.EvaluateExpression(ReaderOffset()); |
7147 SkipExpression(); // read (actual) initializer. | 6909 SkipExpression(); // read (actual) initializer. |
7148 metadata_values.SetAt(i, value); | 6910 metadata_values.SetAt(i, value); |
7149 } | 6911 } |
7150 | 6912 |
7151 return metadata_values.raw(); | 6913 return metadata_values.raw(); |
7152 } | 6914 } |
7153 | 6915 |
7154 } // namespace kernel | 6916 } // namespace kernel |
7155 } // namespace dart | 6917 } // namespace dart |
7156 | 6918 |
7157 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6919 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |