OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 5 #ifndef RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 6 #define RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 class StreamingFlowGraphBuilder { | 302 class StreamingFlowGraphBuilder { |
303 public: | 303 public: |
304 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, | 304 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, |
305 const uint8_t* buffer, | 305 const uint8_t* buffer, |
306 intptr_t buffer_length) | 306 intptr_t buffer_length) |
307 : flow_graph_builder_(flow_graph_builder), | 307 : flow_graph_builder_(flow_graph_builder), |
308 translation_helper_(flow_graph_builder->translation_helper_), | 308 translation_helper_(flow_graph_builder->translation_helper_), |
309 zone_(flow_graph_builder->zone_), | 309 zone_(flow_graph_builder->zone_), |
310 reader_(new Reader(buffer, buffer_length)), | 310 reader_(new Reader(buffer, buffer_length)), |
311 constant_evaluator_(this), | 311 constant_evaluator_(this), |
312 type_translator_(this, /* finalize= */ true) {} | 312 type_translator_(this, /* finalize= */ true), |
| 313 current_script_id_(-1), |
| 314 record_for_script_id_(-1), |
| 315 record_token_positions_into_(NULL), |
| 316 record_yield_positions_into_(NULL) {} |
313 | 317 |
314 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, | 318 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, |
315 Zone* zone, | 319 Zone* zone, |
316 const uint8_t* buffer, | 320 const uint8_t* buffer, |
317 intptr_t buffer_length) | 321 intptr_t buffer_length) |
318 : flow_graph_builder_(NULL), | 322 : flow_graph_builder_(NULL), |
319 translation_helper_(*translation_helper), | 323 translation_helper_(*translation_helper), |
320 zone_(zone), | 324 zone_(zone), |
321 reader_(new Reader(buffer, buffer_length)), | 325 reader_(new Reader(buffer, buffer_length)), |
322 constant_evaluator_(this), | 326 constant_evaluator_(this), |
323 type_translator_(this, /* finalize= */ true) {} | 327 type_translator_(this, /* finalize= */ true), |
| 328 current_script_id_(-1), |
| 329 record_for_script_id_(-1), |
| 330 record_token_positions_into_(NULL), |
| 331 record_yield_positions_into_(NULL) {} |
324 | 332 |
325 ~StreamingFlowGraphBuilder() { delete reader_; } | 333 ~StreamingFlowGraphBuilder() { delete reader_; } |
326 | 334 |
327 FlowGraph* BuildGraph(intptr_t kernel_offset); | 335 FlowGraph* BuildGraph(intptr_t kernel_offset); |
328 | 336 |
329 Fragment BuildStatementAt(intptr_t kernel_offset); | 337 Fragment BuildStatementAt(intptr_t kernel_offset); |
330 RawObject* BuildParameterDescriptor(intptr_t kernel_offset); | 338 RawObject* BuildParameterDescriptor(intptr_t kernel_offset); |
331 RawObject* EvaluateMetadata(intptr_t kernel_offset); | 339 RawObject* EvaluateMetadata(intptr_t kernel_offset); |
| 340 void CollectTokenPositionsFor( |
| 341 intptr_t script_index, |
| 342 GrowableArray<intptr_t>* record_token_positions_in, |
| 343 GrowableArray<intptr_t>* record_yield_positions_in); |
| 344 intptr_t SourceTableSize(); |
| 345 String& SourceTableUriFor(intptr_t index); |
| 346 String& GetSourceFor(intptr_t index); |
| 347 Array& GetLineStartsFor(intptr_t index); |
332 | 348 |
333 private: | 349 private: |
334 void DiscoverEnclosingElements(Zone* zone, | 350 void DiscoverEnclosingElements(Zone* zone, |
335 const Function& function, | 351 const Function& function, |
336 Function* outermost_function, | 352 Function* outermost_function, |
337 intptr_t* outermost_kernel_offset, | 353 intptr_t* outermost_kernel_offset, |
338 intptr_t* parent_class_offset); | 354 intptr_t* parent_class_offset); |
339 intptr_t GetParentOffset(intptr_t offset); | 355 intptr_t GetParentOffset(intptr_t offset); |
340 void GetTypeParameterInfoForClass(intptr_t class_offset, | 356 void GetTypeParameterInfoForClass(intptr_t class_offset, |
341 intptr_t* type_paremeter_counts, | 357 intptr_t* type_paremeter_counts, |
(...skipping 12 matching lines...) Expand all Loading... |
354 intptr_t ReadUntilFunctionNode(); | 370 intptr_t ReadUntilFunctionNode(); |
355 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset); | 371 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset); |
356 | 372 |
357 FlowGraph* BuildGraphOfStaticFieldInitializer(); | 373 FlowGraph* BuildGraphOfStaticFieldInitializer(); |
358 FlowGraph* BuildGraphOfFieldAccessor(LocalVariable* setter_value); | 374 FlowGraph* BuildGraphOfFieldAccessor(LocalVariable* setter_value); |
359 void SetupDefaultParameterValues(); | 375 void SetupDefaultParameterValues(); |
360 Fragment BuildFieldInitializer(NameIndex canonical_name); | 376 Fragment BuildFieldInitializer(NameIndex canonical_name); |
361 Fragment BuildInitializers(intptr_t constructor_class_parent_offset); | 377 Fragment BuildInitializers(intptr_t constructor_class_parent_offset); |
362 FlowGraph* BuildGraphOfImplicitClosureFunction(const Function& function); | 378 FlowGraph* BuildGraphOfImplicitClosureFunction(const Function& function); |
363 FlowGraph* BuildGraphOfFunction( | 379 FlowGraph* BuildGraphOfFunction( |
364 bool is_in_builtin_library_toplevel, | |
365 intptr_t constructor_class_parent_offset = -1); | 380 intptr_t constructor_class_parent_offset = -1); |
366 Fragment BuildGetMainClosure(); | |
367 | 381 |
368 Fragment BuildExpression(TokenPosition* position = NULL); | 382 Fragment BuildExpression(TokenPosition* position = NULL); |
369 Fragment BuildStatement(); | 383 Fragment BuildStatement(); |
370 | 384 |
371 intptr_t ReaderOffset(); | 385 intptr_t ReaderOffset(); |
372 void SetOffset(intptr_t offset); | 386 void SetOffset(intptr_t offset); |
373 void SkipBytes(intptr_t skip); | 387 void SkipBytes(intptr_t skip); |
374 bool ReadBool(); | 388 bool ReadBool(); |
375 uint8_t ReadByte(); | 389 uint8_t ReadByte(); |
376 uint32_t ReadUInt(); | 390 uint32_t ReadUInt(); |
(...skipping 15 matching lines...) Expand all Loading... |
392 void SkipListOfExpressions(); | 406 void SkipListOfExpressions(); |
393 void SkipListOfDartTypes(); | 407 void SkipListOfDartTypes(); |
394 void SkipListOfVariableDeclarations(); | 408 void SkipListOfVariableDeclarations(); |
395 void SkipTypeParametersList(); | 409 void SkipTypeParametersList(); |
396 void SkipExpression(); | 410 void SkipExpression(); |
397 void SkipStatement(); | 411 void SkipStatement(); |
398 void SkipFunctionNode(); | 412 void SkipFunctionNode(); |
399 void SkipName(); | 413 void SkipName(); |
400 void SkipArguments(); | 414 void SkipArguments(); |
401 void SkipVariableDeclaration(); | 415 void SkipVariableDeclaration(); |
| 416 void SkipLibraryCombinator(); |
| 417 void SkipLibraryDependency(); |
| 418 void SkipLibraryTypedef(); |
402 TokenPosition ReadPosition(bool record = true); | 419 TokenPosition ReadPosition(bool record = true); |
| 420 void record_token_position(TokenPosition position); |
| 421 void record_yield_position(TokenPosition position); |
403 Tag ReadTag(uint8_t* payload = NULL); | 422 Tag ReadTag(uint8_t* payload = NULL); |
404 Tag PeekTag(uint8_t* payload = NULL); | 423 Tag PeekTag(uint8_t* payload = NULL); |
405 word ReadFlags(); | 424 word ReadFlags(); |
406 | 425 |
407 void loop_depth_inc(); | 426 void loop_depth_inc(); |
408 void loop_depth_dec(); | 427 void loop_depth_dec(); |
409 intptr_t for_in_depth(); | 428 intptr_t for_in_depth(); |
410 void for_in_depth_inc(); | 429 void for_in_depth_inc(); |
411 void for_in_depth_dec(); | 430 void for_in_depth_dec(); |
412 void catch_depth_inc(); | 431 void catch_depth_inc(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const Function& target, | 478 const Function& target, |
460 intptr_t argument_count); | 479 intptr_t argument_count); |
461 Fragment StaticCall(TokenPosition position, | 480 Fragment StaticCall(TokenPosition position, |
462 const Function& target, | 481 const Function& target, |
463 intptr_t argument_count, | 482 intptr_t argument_count, |
464 const Array& argument_names); | 483 const Array& argument_names); |
465 Fragment InstanceCall(TokenPosition position, | 484 Fragment InstanceCall(TokenPosition position, |
466 const dart::String& name, | 485 const dart::String& name, |
467 Token::Kind kind, | 486 Token::Kind kind, |
468 intptr_t argument_count, | 487 intptr_t argument_count, |
469 intptr_t num_args_checked = 1); | 488 intptr_t checked_argument_count = 1); |
470 Fragment InstanceCall(TokenPosition position, | 489 Fragment InstanceCall(TokenPosition position, |
471 const dart::String& name, | 490 const dart::String& name, |
472 Token::Kind kind, | 491 Token::Kind kind, |
473 intptr_t argument_count, | 492 intptr_t argument_count, |
474 const Array& argument_names, | 493 const Array& argument_names, |
475 intptr_t num_args_checked); | 494 intptr_t checked_argument_count); |
476 Fragment ThrowException(TokenPosition position); | 495 Fragment ThrowException(TokenPosition position); |
477 Fragment BooleanNegate(); | 496 Fragment BooleanNegate(); |
478 Fragment TranslateInstantiatedTypeArguments( | 497 Fragment TranslateInstantiatedTypeArguments( |
479 const TypeArguments& type_arguments); | 498 const TypeArguments& type_arguments); |
480 Fragment StrictCompare(Token::Kind kind, bool number_check = false); | 499 Fragment StrictCompare(Token::Kind kind, bool number_check = false); |
481 Fragment AllocateObject(TokenPosition position, | 500 Fragment AllocateObject(TokenPosition position, |
482 const dart::Class& klass, | 501 const dart::Class& klass, |
483 intptr_t argument_count); | 502 intptr_t argument_count); |
484 Fragment StoreLocal(TokenPosition position, LocalVariable* variable); | 503 Fragment StoreLocal(TokenPosition position, LocalVariable* variable); |
485 Fragment StoreStaticField(TokenPosition position, const dart::Field& field); | 504 Fragment StoreStaticField(TokenPosition position, const dart::Field& field); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 bool is_method, | 619 bool is_method, |
601 bool is_closure, | 620 bool is_closure, |
602 FunctionNodeHelper* function_node_helper); | 621 FunctionNodeHelper* function_node_helper); |
603 | 622 |
604 FlowGraphBuilder* flow_graph_builder_; | 623 FlowGraphBuilder* flow_graph_builder_; |
605 TranslationHelper& translation_helper_; | 624 TranslationHelper& translation_helper_; |
606 Zone* zone_; | 625 Zone* zone_; |
607 Reader* reader_; | 626 Reader* reader_; |
608 StreamingConstantEvaluator constant_evaluator_; | 627 StreamingConstantEvaluator constant_evaluator_; |
609 StreamingDartTypeTranslator type_translator_; | 628 StreamingDartTypeTranslator type_translator_; |
| 629 intptr_t current_script_id_; |
| 630 intptr_t record_for_script_id_; |
| 631 GrowableArray<intptr_t>* record_token_positions_into_; |
| 632 GrowableArray<intptr_t>* record_yield_positions_into_; |
610 | 633 |
611 friend class StreamingConstantEvaluator; | 634 friend class StreamingConstantEvaluator; |
612 friend class StreamingDartTypeTranslator; | 635 friend class StreamingDartTypeTranslator; |
613 friend class StreamingScopeBuilder; | 636 friend class StreamingScopeBuilder; |
614 friend class FunctionNodeHelper; | 637 friend class FunctionNodeHelper; |
615 friend class VariableDeclarationHelper; | 638 friend class VariableDeclarationHelper; |
616 friend class FieldHelper; | 639 friend class FieldHelper; |
617 friend class ProcedureHelper; | 640 friend class ProcedureHelper; |
618 friend class ClassHelper; | 641 friend class ClassHelper; |
| 642 friend class LibraryHelper; |
619 friend class ConstructorHelper; | 643 friend class ConstructorHelper; |
620 friend class SimpleExpressionConverter; | 644 friend class SimpleExpressionConverter; |
621 friend class KernelReader; | 645 friend class KernelReader; |
622 }; | 646 }; |
623 | 647 |
624 // Helper class that reads a kernel FunctionNode from binary. | 648 // Helper class that reads a kernel FunctionNode from binary. |
625 // | 649 // |
626 // Use ReadUntilExcluding to read up to but not including a field. | 650 // Use ReadUntilExcluding to read up to but not including a field. |
627 // One can then for instance read the field from the call-site (and remember to | 651 // One can then for instance read the field from the call-site (and remember to |
628 // call SetAt to inform this helper class), and then use this to read more. | 652 // call SetAt to inform this helper class), and then use this to read more. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 case kStart: { | 873 case kStart: { |
850 Tag tag = builder_->ReadTag(); // read tag. | 874 Tag tag = builder_->ReadTag(); // read tag. |
851 ASSERT(tag == kField); | 875 ASSERT(tag == kField); |
852 if (++next_read_ == field) return; | 876 if (++next_read_ == field) return; |
853 } | 877 } |
854 case kCanonicalName: | 878 case kCanonicalName: |
855 canonical_name_ = | 879 canonical_name_ = |
856 builder_->ReadCanonicalNameReference(); // read canonical_name. | 880 builder_->ReadCanonicalNameReference(); // read canonical_name. |
857 if (++next_read_ == field) return; | 881 if (++next_read_ == field) return; |
858 case kPosition: | 882 case kPosition: |
859 position_ = builder_->ReadPosition(); // read position. | 883 position_ = builder_->ReadPosition(false); // read position. |
860 if (++next_read_ == field) return; | 884 if (++next_read_ == field) return; |
861 case kEndPosition: | 885 case kEndPosition: |
862 end_position_ = builder_->ReadPosition(); // read end position. | 886 end_position_ = builder_->ReadPosition(false); // read end position. |
863 if (++next_read_ == field) return; | 887 if (++next_read_ == field) return; |
864 case kFlags: | 888 case kFlags: |
865 flags_ = builder_->ReadFlags(); // read flags. | 889 flags_ = builder_->ReadFlags(); // read flags. |
866 if (++next_read_ == field) return; | 890 if (++next_read_ == field) return; |
867 case kParentClassBinaryOffset: | 891 case kParentClassBinaryOffset: |
868 parent_class_binary_offset_ = | 892 parent_class_binary_offset_ = |
869 builder_->ReadUInt(); // read parent class binary offset. | 893 builder_->ReadUInt(); // read parent class binary offset. |
870 if (++next_read_ == field) return; | 894 if (++next_read_ == field) return; |
871 case kName: | 895 case kName: |
872 builder_->SkipName(); // read name. | 896 builder_->SkipName(); // read name. |
873 if (++next_read_ == field) return; | 897 if (++next_read_ == field) return; |
874 case kSourceUriIndex: | 898 case kSourceUriIndex: |
875 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. | 899 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 900 builder_->current_script_id_ = source_uri_index_; |
| 901 builder_->record_token_position(position_); |
| 902 builder_->record_token_position(end_position_); |
876 if (++next_read_ == field) return; | 903 if (++next_read_ == field) return; |
877 case kAnnotations: | 904 case kAnnotations: |
878 builder_->SkipListOfExpressions(); // read annotations. | 905 builder_->SkipListOfExpressions(); // read annotations. |
879 if (++next_read_ == field) return; | 906 if (++next_read_ == field) return; |
880 case kType: | 907 case kType: |
881 builder_->SkipDartType(); // read type. | 908 builder_->SkipDartType(); // read type. |
882 if (++next_read_ == field) return; | 909 if (++next_read_ == field) return; |
883 case kInitializer: | 910 case kInitializer: |
884 if (builder_->ReadTag() == kSomething) | 911 if (builder_->ReadTag() == kSomething) |
885 builder_->SkipExpression(); // read initializer. | 912 builder_->SkipExpression(); // read initializer. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 case kStart: { | 982 case kStart: { |
956 Tag tag = builder_->ReadTag(); // read tag. | 983 Tag tag = builder_->ReadTag(); // read tag. |
957 ASSERT(tag == kProcedure); | 984 ASSERT(tag == kProcedure); |
958 if (++next_read_ == field) return; | 985 if (++next_read_ == field) return; |
959 } | 986 } |
960 case kCanonicalName: | 987 case kCanonicalName: |
961 canonical_name_ = | 988 canonical_name_ = |
962 builder_->ReadCanonicalNameReference(); // read canonical_name. | 989 builder_->ReadCanonicalNameReference(); // read canonical_name. |
963 if (++next_read_ == field) return; | 990 if (++next_read_ == field) return; |
964 case kPosition: | 991 case kPosition: |
965 position_ = builder_->ReadPosition(); // read position. | 992 position_ = builder_->ReadPosition(false); // read position. |
966 if (++next_read_ == field) return; | 993 if (++next_read_ == field) return; |
967 case kEndPosition: | 994 case kEndPosition: |
968 end_position_ = builder_->ReadPosition(); // read end position. | 995 end_position_ = builder_->ReadPosition(false); // read end position. |
969 if (++next_read_ == field) return; | 996 if (++next_read_ == field) return; |
970 case kKind: | 997 case kKind: |
971 kind_ = static_cast<Procedure::ProcedureKind>( | 998 kind_ = static_cast<Procedure::ProcedureKind>( |
972 builder_->ReadByte()); // read kind. | 999 builder_->ReadByte()); // read kind. |
973 if (++next_read_ == field) return; | 1000 if (++next_read_ == field) return; |
974 case kFlags: | 1001 case kFlags: |
975 flags_ = builder_->ReadFlags(); // read flags. | 1002 flags_ = builder_->ReadFlags(); // read flags. |
976 if (++next_read_ == field) return; | 1003 if (++next_read_ == field) return; |
977 case kParentClassBinaryOffset: | 1004 case kParentClassBinaryOffset: |
978 parent_class_binary_offset_ = | 1005 parent_class_binary_offset_ = |
979 builder_->ReadUInt(); // read parent class binary offset. | 1006 builder_->ReadUInt(); // read parent class binary offset. |
980 if (++next_read_ == field) return; | 1007 if (++next_read_ == field) return; |
981 case kName: | 1008 case kName: |
982 builder_->SkipName(); // read name. | 1009 builder_->SkipName(); // read name. |
983 if (++next_read_ == field) return; | 1010 if (++next_read_ == field) return; |
984 case kSourceUriIndex: | 1011 case kSourceUriIndex: |
985 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. | 1012 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 1013 builder_->current_script_id_ = source_uri_index_; |
| 1014 builder_->record_token_position(position_); |
| 1015 builder_->record_token_position(end_position_); |
986 if (++next_read_ == field) return; | 1016 if (++next_read_ == field) return; |
987 case kAnnotations: | 1017 case kAnnotations: |
988 builder_->SkipListOfExpressions(); // read annotations. | 1018 builder_->SkipListOfExpressions(); // read annotations. |
989 if (++next_read_ == field) return; | 1019 if (++next_read_ == field) return; |
990 case kFunction: | 1020 case kFunction: |
991 if (builder_->ReadTag() == kSomething) | 1021 if (builder_->ReadTag() == kSomething) |
992 builder_->SkipFunctionNode(); // read function node. | 1022 builder_->SkipFunctionNode(); // read function node. |
993 if (++next_read_ == field) return; | 1023 if (++next_read_ == field) return; |
994 case kEnd: | 1024 case kEnd: |
995 return; | 1025 return; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 case kStart: { | 1228 case kStart: { |
1199 Tag tag = builder_->ReadTag(); // read tag. | 1229 Tag tag = builder_->ReadTag(); // read tag. |
1200 ASSERT(tag == kClass); | 1230 ASSERT(tag == kClass); |
1201 if (++next_read_ == field) return; | 1231 if (++next_read_ == field) return; |
1202 } | 1232 } |
1203 case kCanonicalName: | 1233 case kCanonicalName: |
1204 canonical_name_ = | 1234 canonical_name_ = |
1205 builder_->ReadCanonicalNameReference(); // read canonical_name. | 1235 builder_->ReadCanonicalNameReference(); // read canonical_name. |
1206 if (++next_read_ == field) return; | 1236 if (++next_read_ == field) return; |
1207 case kPosition: | 1237 case kPosition: |
1208 position_ = builder_->ReadPosition(); // read position. | 1238 position_ = builder_->ReadPosition(false); // read position. |
1209 if (++next_read_ == field) return; | 1239 if (++next_read_ == field) return; |
1210 case kIsAbstract: | 1240 case kIsAbstract: |
1211 is_abstract_ = builder_->ReadBool(); // read is_abstract. | 1241 is_abstract_ = builder_->ReadBool(); // read is_abstract. |
1212 if (++next_read_ == field) return; | 1242 if (++next_read_ == field) return; |
1213 case kNameIndex: | 1243 case kNameIndex: |
1214 name_index_ = builder_->ReadStringReference(); // read name index. | 1244 name_index_ = builder_->ReadStringReference(); // read name index. |
1215 if (++next_read_ == field) return; | 1245 if (++next_read_ == field) return; |
1216 case kSourceUriIndex: | 1246 case kSourceUriIndex: |
1217 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. | 1247 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 1248 builder_->current_script_id_ = source_uri_index_; |
| 1249 builder_->record_token_position(position_); |
1218 if (++next_read_ == field) return; | 1250 if (++next_read_ == field) return; |
1219 case kAnnotations: | 1251 case kAnnotations: |
1220 builder_->SkipListOfExpressions(); // read annotations. | 1252 builder_->SkipListOfExpressions(); // read annotations. |
1221 if (++next_read_ == field) return; | 1253 if (++next_read_ == field) return; |
1222 case kTypeParameters: | 1254 case kTypeParameters: |
1223 builder_->SkipTypeParametersList(); // read type parameters. | 1255 builder_->SkipTypeParametersList(); // read type parameters. |
1224 if (++next_read_ == field) return; | 1256 if (++next_read_ == field) return; |
1225 case kSuperClass: { | 1257 case kSuperClass: { |
1226 Tag type_tag = builder_->ReadTag(); // read super class type (part 1). | 1258 Tag type_tag = builder_->ReadTag(); // read super class type (part 1). |
1227 if (type_tag == kSomething) { | 1259 if (type_tag == kSomething) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 TokenPosition position_; | 1315 TokenPosition position_; |
1284 bool is_abstract_; | 1316 bool is_abstract_; |
1285 StringIndex name_index_; | 1317 StringIndex name_index_; |
1286 intptr_t source_uri_index_; | 1318 intptr_t source_uri_index_; |
1287 | 1319 |
1288 private: | 1320 private: |
1289 StreamingFlowGraphBuilder* builder_; | 1321 StreamingFlowGraphBuilder* builder_; |
1290 intptr_t next_read_; | 1322 intptr_t next_read_; |
1291 }; | 1323 }; |
1292 | 1324 |
| 1325 // Helper class that reads a kernel Library from binary. |
| 1326 // |
| 1327 // Use ReadUntilExcluding to read up to but not including a field. |
| 1328 // One can then for instance read the field from the call-site (and remember to |
| 1329 // call SetAt to inform this helper class), and then use this to read more. |
| 1330 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. |
| 1331 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. |
| 1332 class LibraryHelper { |
| 1333 public: |
| 1334 enum Fields { |
| 1335 kFlags, |
| 1336 kCanonicalName, |
| 1337 kName, |
| 1338 kSourceUriIndex, |
| 1339 kAnnotations, |
| 1340 kDependencies, |
| 1341 kTypedefs, |
| 1342 kClasses, |
| 1343 kToplevelField, |
| 1344 kToplevelProcedures, |
| 1345 kEnd |
| 1346 }; |
| 1347 |
| 1348 explicit LibraryHelper(StreamingFlowGraphBuilder* builder) { |
| 1349 builder_ = builder; |
| 1350 next_read_ = kFlags; |
| 1351 } |
| 1352 |
| 1353 void ReadUntilIncluding(Fields field) { |
| 1354 ReadUntilExcluding(static_cast<Fields>(static_cast<int>(field) + 1)); |
| 1355 } |
| 1356 |
| 1357 void ReadUntilExcluding(Fields field) { |
| 1358 if (field <= next_read_) return; |
| 1359 |
| 1360 // Ordered with fall-through. |
| 1361 switch (next_read_) { |
| 1362 case kFlags: { |
| 1363 word flags = builder_->ReadFlags(); // read flags. |
| 1364 ASSERT(flags == 0); // external libraries not supported |
| 1365 if (++next_read_ == field) return; |
| 1366 } |
| 1367 case kCanonicalName: |
| 1368 canonical_name_ = |
| 1369 builder_->ReadCanonicalNameReference(); // read canonical_name. |
| 1370 if (++next_read_ == field) return; |
| 1371 case kName: |
| 1372 name_index_ = builder_->ReadStringReference(); // read name index. |
| 1373 if (++next_read_ == field) return; |
| 1374 case kSourceUriIndex: |
| 1375 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
| 1376 builder_->current_script_id_ = source_uri_index_; |
| 1377 if (++next_read_ == field) return; |
| 1378 case kAnnotations: |
| 1379 builder_->SkipListOfExpressions(); // read annotations. |
| 1380 if (++next_read_ == field) return; |
| 1381 case kDependencies: { |
| 1382 intptr_t dependency_count = builder_->ReadUInt(); // read list length. |
| 1383 for (intptr_t i = 0; i < dependency_count; ++i) { |
| 1384 builder_->SkipLibraryDependency(); |
| 1385 } |
| 1386 if (++next_read_ == field) return; |
| 1387 } |
| 1388 case kTypedefs: { |
| 1389 intptr_t typedef_count = |
| 1390 builder_->ReadListLength(); // read list length. |
| 1391 for (intptr_t i = 0; i < typedef_count; i++) { |
| 1392 builder_->SkipLibraryTypedef(); |
| 1393 } |
| 1394 if (++next_read_ == field) return; |
| 1395 } |
| 1396 case kClasses: { |
| 1397 int class_count = builder_->ReadListLength(); // read list length. |
| 1398 for (intptr_t i = 0; i < class_count; ++i) { |
| 1399 ClassHelper class_helper(builder_); |
| 1400 class_helper.ReadUntilExcluding(ClassHelper::kEnd); |
| 1401 } |
| 1402 if (++next_read_ == field) return; |
| 1403 } |
| 1404 case kToplevelField: { |
| 1405 intptr_t field_count = builder_->ReadListLength(); // read list length. |
| 1406 for (intptr_t i = 0; i < field_count; ++i) { |
| 1407 FieldHelper field_helper(builder_); |
| 1408 field_helper.ReadUntilExcluding(FieldHelper::kEnd); |
| 1409 } |
| 1410 if (++next_read_ == field) return; |
| 1411 } |
| 1412 case kToplevelProcedures: { |
| 1413 intptr_t procedure_count = |
| 1414 builder_->ReadListLength(); // read list length. |
| 1415 for (intptr_t i = 0; i < procedure_count; ++i) { |
| 1416 ProcedureHelper procedure_helper(builder_); |
| 1417 procedure_helper.ReadUntilExcluding(ProcedureHelper::kEnd); |
| 1418 } |
| 1419 if (++next_read_ == field) return; |
| 1420 } |
| 1421 case kEnd: |
| 1422 return; |
| 1423 } |
| 1424 } |
| 1425 |
| 1426 void SetNext(Fields field) { next_read_ = field; } |
| 1427 void SetJustRead(Fields field) { |
| 1428 next_read_ = field; |
| 1429 ++next_read_; |
| 1430 } |
| 1431 |
| 1432 NameIndex canonical_name_; |
| 1433 StringIndex name_index_; |
| 1434 intptr_t source_uri_index_; |
| 1435 |
| 1436 private: |
| 1437 StreamingFlowGraphBuilder* builder_; |
| 1438 intptr_t next_read_; |
| 1439 }; |
| 1440 |
1293 // A helper class that saves the current reader position, goes to another reader | 1441 // A helper class that saves the current reader position, goes to another reader |
1294 // position, and upon destruction, resets to the original reader position. | 1442 // position, and upon destruction, resets to the original reader position. |
1295 class AlternativeReadingScope { | 1443 class AlternativeReadingScope { |
1296 public: | 1444 public: |
1297 AlternativeReadingScope(Reader* reader, intptr_t new_position) | 1445 AlternativeReadingScope(Reader* reader, intptr_t new_position) |
1298 : reader_(reader), saved_offset_(reader_->offset()) { | 1446 : reader_(reader), saved_offset_(reader_->offset()) { |
1299 reader_->set_offset(new_position); | 1447 reader_->set_offset(new_position); |
1300 } | 1448 } |
1301 | 1449 |
1302 explicit AlternativeReadingScope(Reader* reader) | 1450 explicit AlternativeReadingScope(Reader* reader) |
1303 : reader_(reader), saved_offset_(reader_->offset()) {} | 1451 : reader_(reader), saved_offset_(reader_->offset()) {} |
1304 | 1452 |
1305 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); } | 1453 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); } |
1306 | 1454 |
1307 intptr_t saved_offset() { return saved_offset_; } | 1455 intptr_t saved_offset() { return saved_offset_; } |
1308 | 1456 |
1309 private: | 1457 private: |
1310 Reader* reader_; | 1458 Reader* reader_; |
1311 intptr_t saved_offset_; | 1459 intptr_t saved_offset_; |
1312 }; | 1460 }; |
1313 | 1461 |
1314 } // namespace kernel | 1462 } // namespace kernel |
1315 } // namespace dart | 1463 } // namespace dart |
1316 | 1464 |
1317 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1465 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1318 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 1466 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
OLD | NEW |