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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 private: | 44 private: |
45 // Can build a malformed type. | 45 // Can build a malformed type. |
46 void BuildTypeInternal(); | 46 void BuildTypeInternal(); |
47 void BuildInterfaceType(bool simple); | 47 void BuildInterfaceType(bool simple); |
48 void BuildFunctionType(bool simple); | 48 void BuildFunctionType(bool simple); |
49 void BuildTypeParameterType(); | 49 void BuildTypeParameterType(); |
50 | 50 |
51 class TypeParameterScope { | 51 class TypeParameterScope { |
52 public: | 52 public: |
53 TypeParameterScope(StreamingDartTypeTranslator* translator, | 53 TypeParameterScope(StreamingDartTypeTranslator* translator, |
54 intptr_t parameters_offset, | |
55 intptr_t parameters_count) | 54 intptr_t parameters_count) |
56 : parameters_offset_(parameters_offset), | 55 : parameters_count_(parameters_count), |
Kevin Millikin (Google)
2017/08/09 12:08:51
parameter_count_
jensj
2017/08/10 07:37:34
Done.
| |
57 parameters_count_(parameters_count), | |
58 outer_(translator->type_parameter_scope_), | 56 outer_(translator->type_parameter_scope_), |
59 translator_(translator) { | 57 translator_(translator) { |
60 summed_outer_parameters_count_ = 0; | 58 summed_outer_parameters_count_ = 0; |
61 if (outer_ != NULL) { | 59 if (outer_ != NULL) { |
62 summed_outer_parameters_count_ = | 60 summed_outer_parameters_count_ = |
63 outer_->summed_outer_parameters_count_ + outer_->parameters_count_; | 61 outer_->summed_outer_parameters_count_ + outer_->parameters_count_; |
64 } | 62 } |
65 translator_->type_parameter_scope_ = this; | 63 translator_->type_parameter_scope_ = this; |
66 } | 64 } |
67 ~TypeParameterScope() { translator_->type_parameter_scope_ = outer_; } | 65 ~TypeParameterScope() { translator_->type_parameter_scope_ = outer_; } |
68 | 66 |
69 TypeParameterScope* outer() const { return outer_; } | 67 TypeParameterScope* outer() const { return outer_; } |
70 intptr_t parameters_offset() const { return parameters_offset_; } | |
71 intptr_t parameters_count() const { return parameters_count_; } | 68 intptr_t parameters_count() const { return parameters_count_; } |
72 intptr_t summed_outer_parameters_count() const { | 69 intptr_t summed_outer_parameters_count() const { |
73 return summed_outer_parameters_count_; | 70 return summed_outer_parameters_count_; |
74 } | 71 } |
75 | 72 |
76 private: | 73 private: |
77 intptr_t parameters_offset_; | |
78 intptr_t parameters_count_; | 74 intptr_t parameters_count_; |
79 intptr_t summed_outer_parameters_count_; | 75 intptr_t summed_outer_parameters_count_; |
80 TypeParameterScope* outer_; | 76 TypeParameterScope* outer_; |
81 StreamingDartTypeTranslator* translator_; | 77 StreamingDartTypeTranslator* translator_; |
82 }; | 78 }; |
83 | 79 |
84 intptr_t FindTypeParameterIndex(intptr_t parameters_offset, | 80 intptr_t FindTypeParameterIndex(intptr_t parameters_offset, |
85 intptr_t parameters_count, | 81 intptr_t parameters_count, |
86 intptr_t look_for); | 82 intptr_t look_for); |
87 | 83 |
88 StreamingFlowGraphBuilder* builder_; | 84 StreamingFlowGraphBuilder* builder_; |
89 TranslationHelper& translation_helper_; | 85 TranslationHelper& translation_helper_; |
90 ActiveClass* active_class_; | 86 ActiveClass* active_class_; |
91 TypeParameterScope* type_parameter_scope_; | 87 TypeParameterScope* type_parameter_scope_; |
92 Zone* zone_; | 88 Zone* zone_; |
93 AbstractType& result_; | 89 AbstractType& result_; |
94 bool finalize_; | 90 bool finalize_; |
95 | 91 |
96 friend class StreamingScopeBuilder; | 92 friend class StreamingScopeBuilder; |
97 friend class KernelReader; | 93 friend class KernelReader; |
98 }; | 94 }; |
99 | 95 |
100 class StreamingScopeBuilder { | 96 class StreamingScopeBuilder { |
101 public: | 97 public: |
102 StreamingScopeBuilder(ParsedFunction* parsed_function, | 98 StreamingScopeBuilder(ParsedFunction* parsed_function, |
103 intptr_t kernel_offset, | 99 intptr_t relative_kernel_offset, |
104 const uint8_t* buffer, | 100 const TypedData& body); |
105 intptr_t buffer_length); | |
106 | 101 |
107 virtual ~StreamingScopeBuilder(); | 102 virtual ~StreamingScopeBuilder(); |
108 | 103 |
109 ScopeBuildingResult* BuildScopes(); | 104 ScopeBuildingResult* BuildScopes(); |
110 | 105 |
111 private: | 106 private: |
112 void VisitField(); | 107 void VisitField(); |
113 | 108 |
114 void VisitProcedure(); | 109 void VisitProcedure(); |
115 | 110 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 intptr_t nesting_depth); | 148 intptr_t nesting_depth); |
154 | 149 |
155 void AddTryVariables(); | 150 void AddTryVariables(); |
156 void AddCatchVariables(); | 151 void AddCatchVariables(); |
157 void AddIteratorVariable(); | 152 void AddIteratorVariable(); |
158 void AddSwitchVariable(); | 153 void AddSwitchVariable(); |
159 | 154 |
160 // Record an assignment or reference to a variable. If the occurrence is | 155 // Record an assignment or reference to a variable. If the occurrence is |
161 // in a nested function, ensure that the variable is handled properly as a | 156 // in a nested function, ensure that the variable is handled properly as a |
162 // captured variable. | 157 // captured variable. |
163 void LookupVariable(intptr_t declaration_binary_offest); | 158 void LookupVariable(intptr_t declaration_binary_offset); |
164 | 159 |
165 const dart::String& GenerateName(const char* prefix, intptr_t suffix); | 160 const dart::String& GenerateName(const char* prefix, intptr_t suffix); |
166 | 161 |
167 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); | 162 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); |
168 void LookupCapturedVariableByName(LocalVariable** variable, | 163 void LookupCapturedVariableByName(LocalVariable** variable, |
169 const dart::String& name); | 164 const dart::String& name); |
170 | 165 |
171 struct DepthState { | 166 struct DepthState { |
172 explicit DepthState(intptr_t function) | 167 explicit DepthState(intptr_t function) |
173 : loop_(0), | 168 : loop_(0), |
174 function_(function), | 169 function_(function), |
175 try_(0), | 170 try_(0), |
176 catch_(0), | 171 catch_(0), |
177 finally_(0), | 172 finally_(0), |
178 for_in_(0) {} | 173 for_in_(0) {} |
179 | 174 |
180 intptr_t loop_; | 175 intptr_t loop_; |
181 intptr_t function_; | 176 intptr_t function_; |
182 intptr_t try_; | 177 intptr_t try_; |
183 intptr_t catch_; | 178 intptr_t catch_; |
184 intptr_t finally_; | 179 intptr_t finally_; |
185 intptr_t for_in_; | 180 intptr_t for_in_; |
186 }; | 181 }; |
187 | 182 |
188 ScopeBuildingResult* result_; | 183 ScopeBuildingResult* result_; |
189 ParsedFunction* parsed_function_; | 184 ParsedFunction* parsed_function_; |
190 intptr_t kernel_offset_; | 185 intptr_t relative_kernel_offset_; |
191 | 186 |
192 ActiveClass active_class_; | 187 ActiveClass active_class_; |
193 | 188 |
194 TranslationHelper translation_helper_; | 189 TranslationHelper translation_helper_; |
195 Zone* zone_; | 190 Zone* zone_; |
196 | 191 |
197 FunctionNode::AsyncMarker current_function_async_marker_; | 192 FunctionNode::AsyncMarker current_function_async_marker_; |
198 LocalScope* current_function_scope_; | 193 LocalScope* current_function_scope_; |
199 LocalScope* scope_; | 194 LocalScope* scope_; |
200 DepthState depth_; | 195 DepthState depth_; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 296 |
302 Script& script_; | 297 Script& script_; |
303 Instance& result_; | 298 Instance& result_; |
304 }; | 299 }; |
305 | 300 |
306 class FunctionNodeHelper; | 301 class FunctionNodeHelper; |
307 | 302 |
308 class StreamingFlowGraphBuilder { | 303 class StreamingFlowGraphBuilder { |
309 public: | 304 public: |
310 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, | 305 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, |
311 const uint8_t* buffer, | 306 intptr_t relative_kernel_offset, |
312 intptr_t buffer_length) | 307 const TypedData& body) |
313 : flow_graph_builder_(flow_graph_builder), | 308 : flow_graph_builder_(flow_graph_builder), |
314 translation_helper_(flow_graph_builder->translation_helper_), | 309 translation_helper_(flow_graph_builder->translation_helper_), |
315 zone_(flow_graph_builder->zone_), | 310 zone_(flow_graph_builder->zone_), |
316 reader_(new Reader(buffer, buffer_length)), | 311 reader_(new Reader(body)), |
317 constant_evaluator_(this), | 312 constant_evaluator_(this), |
318 type_translator_(this, /* finalize= */ true), | 313 type_translator_(this, /* finalize= */ true), |
314 relative_kernel_offset_(relative_kernel_offset), | |
319 current_script_id_(-1), | 315 current_script_id_(-1), |
320 record_for_script_id_(-1), | 316 record_for_script_id_(-1), |
321 record_token_positions_into_(NULL), | 317 record_token_positions_into_(NULL), |
322 record_yield_positions_into_(NULL) {} | 318 record_yield_positions_into_(NULL) {} |
323 | 319 |
324 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, | 320 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, |
325 Zone* zone, | 321 Zone* zone, |
326 const uint8_t* buffer, | 322 const uint8_t* buffer, |
327 intptr_t buffer_length) | 323 intptr_t buffer_length) |
328 : flow_graph_builder_(NULL), | 324 : flow_graph_builder_(NULL), |
329 translation_helper_(*translation_helper), | 325 translation_helper_(*translation_helper), |
330 zone_(zone), | 326 zone_(zone), |
331 reader_(new Reader(buffer, buffer_length)), | 327 reader_(new Reader(buffer, buffer_length)), |
332 constant_evaluator_(this), | 328 constant_evaluator_(this), |
333 type_translator_(this, /* finalize= */ true), | 329 type_translator_(this, /* finalize= */ true), |
330 relative_kernel_offset_(0), | |
334 current_script_id_(-1), | 331 current_script_id_(-1), |
335 record_for_script_id_(-1), | 332 record_for_script_id_(-1), |
336 record_token_positions_into_(NULL), | 333 record_token_positions_into_(NULL), |
334 record_yield_positions_into_(NULL) {} | |
335 | |
336 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, | |
337 Zone* zone, | |
338 intptr_t relative_kernel_offset, | |
339 const TypedData& body) | |
340 : flow_graph_builder_(NULL), | |
341 translation_helper_(*translation_helper), | |
342 zone_(zone), | |
343 reader_(new Reader(body)), | |
344 constant_evaluator_(this), | |
345 type_translator_(this, /* finalize= */ true), | |
346 relative_kernel_offset_(relative_kernel_offset), | |
347 current_script_id_(-1), | |
348 record_for_script_id_(-1), | |
349 record_token_positions_into_(NULL), | |
337 record_yield_positions_into_(NULL) {} | 350 record_yield_positions_into_(NULL) {} |
338 | 351 |
339 ~StreamingFlowGraphBuilder() { delete reader_; } | 352 ~StreamingFlowGraphBuilder() { delete reader_; } |
340 | 353 |
341 FlowGraph* BuildGraph(intptr_t kernel_offset); | 354 FlowGraph* BuildGraph(intptr_t kernel_offset); |
342 | 355 |
343 Fragment BuildStatementAt(intptr_t kernel_offset); | 356 Fragment BuildStatementAt(intptr_t kernel_offset); |
344 RawObject* BuildParameterDescriptor(intptr_t kernel_offset); | 357 RawObject* BuildParameterDescriptor(intptr_t kernel_offset); |
345 RawObject* EvaluateMetadata(intptr_t kernel_offset); | 358 RawObject* EvaluateMetadata(intptr_t kernel_offset); |
346 void CollectTokenPositionsFor( | 359 void CollectTokenPositionsFor( |
347 intptr_t script_index, | 360 intptr_t script_index, |
361 intptr_t initial_script_index, | |
348 GrowableArray<intptr_t>* record_token_positions_in, | 362 GrowableArray<intptr_t>* record_token_positions_in, |
349 GrowableArray<intptr_t>* record_yield_positions_in); | 363 GrowableArray<intptr_t>* record_yield_positions_in); |
350 intptr_t SourceTableSize(); | 364 intptr_t SourceTableSize(); |
351 String& SourceTableUriFor(intptr_t index); | 365 String& SourceTableUriFor(intptr_t index); |
352 String& GetSourceFor(intptr_t index); | 366 String& GetSourceFor(intptr_t index); |
353 Array& GetLineStartsFor(intptr_t index); | 367 Array& GetLineStartsFor(intptr_t index); |
354 | 368 |
355 private: | 369 private: |
356 void DiscoverEnclosingElements(Zone* zone, | 370 void DiscoverEnclosingElements(Zone* zone, |
357 const Function& function, | 371 const Function& function, |
358 Function* outermost_function); | 372 Function* outermost_function); |
359 | 373 |
360 /** | 374 void ReadUntilFunctionNode(); |
361 * Will return kernel offset for parent class if reading a constructor. | 375 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset, |
362 * Will otherwise return -1. | 376 const Function& function); |
363 */ | |
364 intptr_t ReadUntilFunctionNode(); | |
365 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset); | |
366 | 377 |
367 FlowGraph* BuildGraphOfStaticFieldInitializer(); | 378 FlowGraph* BuildGraphOfStaticFieldInitializer(); |
368 FlowGraph* BuildGraphOfFieldAccessor(LocalVariable* setter_value); | 379 FlowGraph* BuildGraphOfFieldAccessor(LocalVariable* setter_value); |
369 void SetupDefaultParameterValues(); | 380 void SetupDefaultParameterValues(); |
370 Fragment BuildFieldInitializer(NameIndex canonical_name); | 381 Fragment BuildFieldInitializer(NameIndex canonical_name); |
371 Fragment BuildInitializers(intptr_t constructor_class_parent_offset); | 382 Fragment BuildInitializers(const Class& parent_class); |
372 FlowGraph* BuildGraphOfImplicitClosureFunction(const Function& function); | 383 FlowGraph* BuildGraphOfImplicitClosureFunction(const Function& function); |
373 FlowGraph* BuildGraphOfConvertedClosureFunction(const Function& function); | 384 FlowGraph* BuildGraphOfConvertedClosureFunction(const Function& function); |
374 FlowGraph* BuildGraphOfFunction( | 385 FlowGraph* BuildGraphOfFunction(bool constructor); |
375 intptr_t constructor_class_parent_offset = -1); | |
376 | 386 |
377 Fragment BuildExpression(TokenPosition* position = NULL); | 387 Fragment BuildExpression(TokenPosition* position = NULL); |
378 Fragment BuildStatement(); | 388 Fragment BuildStatement(); |
379 | 389 |
380 intptr_t ReaderOffset(); | 390 intptr_t ReaderOffset(); |
381 void SetOffset(intptr_t offset); | 391 void SetOffset(intptr_t offset); |
382 void SkipBytes(intptr_t skip); | 392 void SkipBytes(intptr_t skip); |
383 bool ReadBool(); | 393 bool ReadBool(); |
384 uint8_t ReadByte(); | 394 uint8_t ReadByte(); |
385 uint32_t ReadUInt(); | 395 uint32_t ReadUInt(); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 Fragment BuildForInStatement(bool async); | 621 Fragment BuildForInStatement(bool async); |
612 Fragment BuildSwitchStatement(); | 622 Fragment BuildSwitchStatement(); |
613 Fragment BuildContinueSwitchStatement(); | 623 Fragment BuildContinueSwitchStatement(); |
614 Fragment BuildIfStatement(); | 624 Fragment BuildIfStatement(); |
615 Fragment BuildReturnStatement(); | 625 Fragment BuildReturnStatement(); |
616 Fragment BuildTryCatch(); | 626 Fragment BuildTryCatch(); |
617 Fragment BuildTryFinally(); | 627 Fragment BuildTryFinally(); |
618 Fragment BuildYieldStatement(); | 628 Fragment BuildYieldStatement(); |
619 Fragment BuildVariableDeclaration(); | 629 Fragment BuildVariableDeclaration(); |
620 Fragment BuildFunctionDeclaration(); | 630 Fragment BuildFunctionDeclaration(); |
621 Fragment BuildFunctionNode(intptr_t parent_kernel_offset, | 631 Fragment BuildFunctionNode(TokenPosition parent_position, |
622 TokenPosition parent_position, | 632 StringIndex name_index); |
623 bool declaration, | |
624 intptr_t variable_offeset); | |
625 void SetupFunctionParameters(const dart::Class& klass, | 633 void SetupFunctionParameters(const dart::Class& klass, |
626 const dart::Function& function, | 634 const dart::Function& function, |
627 bool is_method, | 635 bool is_method, |
628 bool is_closure, | 636 bool is_closure, |
629 FunctionNodeHelper* function_node_helper); | 637 FunctionNodeHelper* function_node_helper); |
630 | 638 |
631 FlowGraphBuilder* flow_graph_builder_; | 639 FlowGraphBuilder* flow_graph_builder_; |
632 TranslationHelper& translation_helper_; | 640 TranslationHelper& translation_helper_; |
633 Zone* zone_; | 641 Zone* zone_; |
634 Reader* reader_; | 642 Reader* reader_; |
635 StreamingConstantEvaluator constant_evaluator_; | 643 StreamingConstantEvaluator constant_evaluator_; |
636 StreamingDartTypeTranslator type_translator_; | 644 StreamingDartTypeTranslator type_translator_; |
645 intptr_t relative_kernel_offset_; | |
637 intptr_t current_script_id_; | 646 intptr_t current_script_id_; |
638 intptr_t record_for_script_id_; | 647 intptr_t record_for_script_id_; |
639 GrowableArray<intptr_t>* record_token_positions_into_; | 648 GrowableArray<intptr_t>* record_token_positions_into_; |
640 GrowableArray<intptr_t>* record_yield_positions_into_; | 649 GrowableArray<intptr_t>* record_yield_positions_into_; |
641 | 650 |
642 friend class StreamingConstantEvaluator; | 651 friend class StreamingConstantEvaluator; |
643 friend class StreamingDartTypeTranslator; | 652 friend class StreamingDartTypeTranslator; |
644 friend class StreamingScopeBuilder; | 653 friend class StreamingScopeBuilder; |
645 friend class FunctionNodeHelper; | 654 friend class FunctionNodeHelper; |
646 friend class VariableDeclarationHelper; | 655 friend class VariableDeclarationHelper; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. | 857 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. |
849 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. | 858 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. |
850 class FieldHelper { | 859 class FieldHelper { |
851 public: | 860 public: |
852 enum Fields { | 861 enum Fields { |
853 kStart, // tag. | 862 kStart, // tag. |
854 kCanonicalName, | 863 kCanonicalName, |
855 kPosition, | 864 kPosition, |
856 kEndPosition, | 865 kEndPosition, |
857 kFlags, | 866 kFlags, |
858 kParentClassBinaryOffset, | |
859 kName, | 867 kName, |
860 kSourceUriIndex, | 868 kSourceUriIndex, |
861 kDocumentationCommentIndex, | 869 kDocumentationCommentIndex, |
862 kAnnotations, | 870 kAnnotations, |
863 kType, | 871 kType, |
864 kInitializer, | 872 kInitializer, |
865 kEnd | 873 kEnd |
866 }; | 874 }; |
867 | 875 |
868 explicit FieldHelper(StreamingFlowGraphBuilder* builder) | 876 explicit FieldHelper(StreamingFlowGraphBuilder* builder) |
(...skipping 29 matching lines...) Expand all Loading... | |
898 if (++next_read_ == field) return; | 906 if (++next_read_ == field) return; |
899 case kPosition: | 907 case kPosition: |
900 position_ = builder_->ReadPosition(false); // read position. | 908 position_ = builder_->ReadPosition(false); // read position. |
901 if (++next_read_ == field) return; | 909 if (++next_read_ == field) return; |
902 case kEndPosition: | 910 case kEndPosition: |
903 end_position_ = builder_->ReadPosition(false); // read end position. | 911 end_position_ = builder_->ReadPosition(false); // read end position. |
904 if (++next_read_ == field) return; | 912 if (++next_read_ == field) return; |
905 case kFlags: | 913 case kFlags: |
906 flags_ = builder_->ReadFlags(); // read flags. | 914 flags_ = builder_->ReadFlags(); // read flags. |
907 if (++next_read_ == field) return; | 915 if (++next_read_ == field) return; |
908 case kParentClassBinaryOffset: | |
909 parent_class_binary_offset_ = | |
910 builder_->ReadUInt(); // read parent class binary offset. | |
911 if (++next_read_ == field) return; | |
912 case kName: | 916 case kName: |
913 builder_->SkipName(); // read name. | 917 builder_->SkipName(); // read name. |
914 if (++next_read_ == field) return; | 918 if (++next_read_ == field) return; |
915 case kSourceUriIndex: | 919 case kSourceUriIndex: |
916 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. | 920 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
917 builder_->current_script_id_ = source_uri_index_; | 921 builder_->current_script_id_ = source_uri_index_; |
918 builder_->record_token_position(position_); | 922 builder_->record_token_position(position_); |
919 builder_->record_token_position(end_position_); | 923 builder_->record_token_position(end_position_); |
920 if (++next_read_ == field) return; | 924 if (++next_read_ == field) return; |
921 case kDocumentationCommentIndex: | 925 case kDocumentationCommentIndex: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 *start = function_literal_start_; | 976 *start = function_literal_start_; |
973 *end = function_literal_end_; | 977 *end = function_literal_end_; |
974 } | 978 } |
975 return has_function_literal_initializer_; | 979 return has_function_literal_initializer_; |
976 } | 980 } |
977 | 981 |
978 NameIndex canonical_name_; | 982 NameIndex canonical_name_; |
979 TokenPosition position_; | 983 TokenPosition position_; |
980 TokenPosition end_position_; | 984 TokenPosition end_position_; |
981 word flags_; | 985 word flags_; |
982 intptr_t parent_class_binary_offset_; | |
983 intptr_t source_uri_index_; | 986 intptr_t source_uri_index_; |
984 intptr_t annotation_count_; | 987 intptr_t annotation_count_; |
985 | 988 |
986 private: | 989 private: |
987 StreamingFlowGraphBuilder* builder_; | 990 StreamingFlowGraphBuilder* builder_; |
988 intptr_t next_read_; | 991 intptr_t next_read_; |
989 | 992 |
990 bool has_function_literal_initializer_; | 993 bool has_function_literal_initializer_; |
991 TokenPosition function_literal_start_; | 994 TokenPosition function_literal_start_; |
992 TokenPosition function_literal_end_; | 995 TokenPosition function_literal_end_; |
993 }; | 996 }; |
994 | 997 |
995 // Helper class that reads a kernel Procedure from binary. | 998 // Helper class that reads a kernel Procedure from binary. |
996 // | 999 // |
997 // Use ReadUntilExcluding to read up to but not including a field. | 1000 // Use ReadUntilExcluding to read up to but not including a field. |
998 // One can then for instance read the field from the call-site (and remember to | 1001 // One can then for instance read the field from the call-site (and remember to |
999 // call SetAt to inform this helper class), and then use this to read more. | 1002 // call SetAt to inform this helper class), and then use this to read more. |
1000 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. | 1003 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. |
1001 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. | 1004 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. |
1002 class ProcedureHelper { | 1005 class ProcedureHelper { |
1003 public: | 1006 public: |
1004 enum Fields { | 1007 enum Fields { |
1005 kStart, // tag. | 1008 kStart, // tag. |
1006 kCanonicalName, | 1009 kCanonicalName, |
1007 kPosition, | 1010 kPosition, |
1008 kEndPosition, | 1011 kEndPosition, |
1009 kKind, | 1012 kKind, |
1010 kFlags, | 1013 kFlags, |
1011 kParentClassBinaryOffset, | |
1012 kName, | 1014 kName, |
1013 kSourceUriIndex, | 1015 kSourceUriIndex, |
1014 kDocumentationCommentIndex, | 1016 kDocumentationCommentIndex, |
1015 kAnnotations, | 1017 kAnnotations, |
1016 kFunction, | 1018 kFunction, |
1017 kEnd | 1019 kEnd |
1018 }; | 1020 }; |
1019 | 1021 |
1020 explicit ProcedureHelper(StreamingFlowGraphBuilder* builder) { | 1022 explicit ProcedureHelper(StreamingFlowGraphBuilder* builder) { |
1021 builder_ = builder; | 1023 builder_ = builder; |
(...skipping 24 matching lines...) Expand all Loading... | |
1046 case kEndPosition: | 1048 case kEndPosition: |
1047 end_position_ = builder_->ReadPosition(false); // read end position. | 1049 end_position_ = builder_->ReadPosition(false); // read end position. |
1048 if (++next_read_ == field) return; | 1050 if (++next_read_ == field) return; |
1049 case kKind: | 1051 case kKind: |
1050 kind_ = static_cast<Procedure::ProcedureKind>( | 1052 kind_ = static_cast<Procedure::ProcedureKind>( |
1051 builder_->ReadByte()); // read kind. | 1053 builder_->ReadByte()); // read kind. |
1052 if (++next_read_ == field) return; | 1054 if (++next_read_ == field) return; |
1053 case kFlags: | 1055 case kFlags: |
1054 flags_ = builder_->ReadFlags(); // read flags. | 1056 flags_ = builder_->ReadFlags(); // read flags. |
1055 if (++next_read_ == field) return; | 1057 if (++next_read_ == field) return; |
1056 case kParentClassBinaryOffset: | |
1057 parent_class_binary_offset_ = | |
1058 builder_->ReadUInt(); // read parent class binary offset. | |
1059 if (++next_read_ == field) return; | |
1060 case kName: | 1058 case kName: |
1061 builder_->SkipName(); // read name. | 1059 builder_->SkipName(); // read name. |
1062 if (++next_read_ == field) return; | 1060 if (++next_read_ == field) return; |
1063 case kSourceUriIndex: | 1061 case kSourceUriIndex: |
1064 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. | 1062 source_uri_index_ = builder_->ReadUInt(); // read source_uri_index. |
1065 builder_->current_script_id_ = source_uri_index_; | 1063 builder_->current_script_id_ = source_uri_index_; |
1066 builder_->record_token_position(position_); | 1064 builder_->record_token_position(position_); |
1067 builder_->record_token_position(end_position_); | 1065 builder_->record_token_position(end_position_); |
1068 if (++next_read_ == field) return; | 1066 if (++next_read_ == field) return; |
1069 case kDocumentationCommentIndex: | 1067 case kDocumentationCommentIndex: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1102 } | 1100 } |
1103 bool IsConst() { | 1101 bool IsConst() { |
1104 return (flags_ & Procedure::kFlagConst) == Procedure::kFlagConst; | 1102 return (flags_ & Procedure::kFlagConst) == Procedure::kFlagConst; |
1105 } | 1103 } |
1106 | 1104 |
1107 NameIndex canonical_name_; | 1105 NameIndex canonical_name_; |
1108 TokenPosition position_; | 1106 TokenPosition position_; |
1109 TokenPosition end_position_; | 1107 TokenPosition end_position_; |
1110 Procedure::ProcedureKind kind_; | 1108 Procedure::ProcedureKind kind_; |
1111 word flags_; | 1109 word flags_; |
1112 intptr_t parent_class_binary_offset_; | |
1113 intptr_t source_uri_index_; | 1110 intptr_t source_uri_index_; |
1114 intptr_t annotation_count_; | 1111 intptr_t annotation_count_; |
1115 | 1112 |
1116 private: | 1113 private: |
1117 StreamingFlowGraphBuilder* builder_; | 1114 StreamingFlowGraphBuilder* builder_; |
1118 intptr_t next_read_; | 1115 intptr_t next_read_; |
1119 }; | 1116 }; |
1120 | 1117 |
1121 // Helper class that reads a kernel Constructor from binary. | 1118 // Helper class that reads a kernel Constructor from binary. |
1122 // | 1119 // |
1123 // Use ReadUntilExcluding to read up to but not including a field. | 1120 // Use ReadUntilExcluding to read up to but not including a field. |
1124 // One can then for instance read the field from the call-site (and remember to | 1121 // One can then for instance read the field from the call-site (and remember to |
1125 // call SetAt to inform this helper class), and then use this to read more. | 1122 // call SetAt to inform this helper class), and then use this to read more. |
1126 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. | 1123 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. |
1127 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. | 1124 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. |
1128 class ConstructorHelper { | 1125 class ConstructorHelper { |
1129 public: | 1126 public: |
1130 enum Fields { | 1127 enum Fields { |
1131 kStart, // tag. | 1128 kStart, // tag. |
1132 kCanonicalName, | 1129 kCanonicalName, |
1133 kPosition, | 1130 kPosition, |
1134 kEndPosition, | 1131 kEndPosition, |
1135 kFlags, | 1132 kFlags, |
1136 kParentClassBinaryOffset, | |
1137 kName, | 1133 kName, |
1138 kDocumentationCommentIndex, | 1134 kDocumentationCommentIndex, |
1139 kAnnotations, | 1135 kAnnotations, |
1140 kFunction, | 1136 kFunction, |
1141 kInitializers, | 1137 kInitializers, |
1142 kEnd | 1138 kEnd |
1143 }; | 1139 }; |
1144 | 1140 |
1145 explicit ConstructorHelper(StreamingFlowGraphBuilder* builder) { | 1141 explicit ConstructorHelper(StreamingFlowGraphBuilder* builder) { |
1146 builder_ = builder; | 1142 builder_ = builder; |
(...skipping 20 matching lines...) Expand all Loading... | |
1167 if (++next_read_ == field) return; | 1163 if (++next_read_ == field) return; |
1168 case kPosition: | 1164 case kPosition: |
1169 position_ = builder_->ReadPosition(); // read position. | 1165 position_ = builder_->ReadPosition(); // read position. |
1170 if (++next_read_ == field) return; | 1166 if (++next_read_ == field) return; |
1171 case kEndPosition: | 1167 case kEndPosition: |
1172 end_position_ = builder_->ReadPosition(); // read end position. | 1168 end_position_ = builder_->ReadPosition(); // read end position. |
1173 if (++next_read_ == field) return; | 1169 if (++next_read_ == field) return; |
1174 case kFlags: | 1170 case kFlags: |
1175 flags_ = builder_->ReadFlags(); // read flags. | 1171 flags_ = builder_->ReadFlags(); // read flags. |
1176 if (++next_read_ == field) return; | 1172 if (++next_read_ == field) return; |
1177 case kParentClassBinaryOffset: | |
1178 parent_class_binary_offset_ = | |
1179 builder_->ReadUInt(); // read parent class binary offset. | |
1180 if (++next_read_ == field) return; | |
1181 case kName: | 1173 case kName: |
1182 builder_->SkipName(); // read name. | 1174 builder_->SkipName(); // read name. |
1183 if (++next_read_ == field) return; | 1175 if (++next_read_ == field) return; |
1184 case kDocumentationCommentIndex: | 1176 case kDocumentationCommentIndex: |
1185 builder_->ReadStringReference(); | 1177 builder_->ReadStringReference(); |
1186 if (++next_read_ == field) return; | 1178 if (++next_read_ == field) return; |
1187 case kAnnotations: { | 1179 case kAnnotations: { |
1188 annotation_count_ = builder_->ReadListLength(); // read list length. | 1180 annotation_count_ = builder_->ReadListLength(); // read list length. |
1189 for (intptr_t i = 0; i < annotation_count_; ++i) { | 1181 for (intptr_t i = 0; i < annotation_count_; ++i) { |
1190 builder_->SkipExpression(); // read ith expression. | 1182 builder_->SkipExpression(); // read ith expression. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 return (flags_ & Constructor::kFlagExternal) == Constructor::kFlagExternal; | 1231 return (flags_ & Constructor::kFlagExternal) == Constructor::kFlagExternal; |
1240 } | 1232 } |
1241 bool IsConst() { | 1233 bool IsConst() { |
1242 return (flags_ & Constructor::kFlagConst) == Constructor::kFlagConst; | 1234 return (flags_ & Constructor::kFlagConst) == Constructor::kFlagConst; |
1243 } | 1235 } |
1244 | 1236 |
1245 NameIndex canonical_name_; | 1237 NameIndex canonical_name_; |
1246 TokenPosition position_; | 1238 TokenPosition position_; |
1247 TokenPosition end_position_; | 1239 TokenPosition end_position_; |
1248 word flags_; | 1240 word flags_; |
1249 intptr_t parent_class_binary_offset_; | |
1250 intptr_t annotation_count_; | 1241 intptr_t annotation_count_; |
1251 | 1242 |
1252 private: | 1243 private: |
1253 StreamingFlowGraphBuilder* builder_; | 1244 StreamingFlowGraphBuilder* builder_; |
1254 intptr_t next_read_; | 1245 intptr_t next_read_; |
1255 }; | 1246 }; |
1256 | 1247 |
1257 // Helper class that reads a kernel Class from binary. | 1248 // Helper class that reads a kernel Class from binary. |
1258 // | 1249 // |
1259 // Use ReadUntilExcluding to read up to but not including a field. | 1250 // Use ReadUntilExcluding to read up to but not including a field. |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 private: | 1511 private: |
1521 StreamingFlowGraphBuilder* builder_; | 1512 StreamingFlowGraphBuilder* builder_; |
1522 intptr_t next_read_; | 1513 intptr_t next_read_; |
1523 }; | 1514 }; |
1524 | 1515 |
1525 // A helper class that saves the current reader position, goes to another reader | 1516 // A helper class that saves the current reader position, goes to another reader |
1526 // position, and upon destruction, resets to the original reader position. | 1517 // position, and upon destruction, resets to the original reader position. |
1527 class AlternativeReadingScope { | 1518 class AlternativeReadingScope { |
1528 public: | 1519 public: |
1529 AlternativeReadingScope(Reader* reader, intptr_t new_position) | 1520 AlternativeReadingScope(Reader* reader, intptr_t new_position) |
1530 : reader_(reader), saved_offset_(reader_->offset()) { | 1521 : reader_(reader), |
1522 saved_size_(reader_->size()), | |
1523 saved_raw_buffer_(reader_->raw_buffer()), | |
1524 saved_typed_data_(reader_->typed_data()), | |
1525 saved_offset_(reader_->offset()) { | |
1526 reader_->set_offset(new_position); | |
1527 } | |
1528 | |
1529 AlternativeReadingScope(Reader* reader, | |
1530 const TypedData* new_typed_data, | |
1531 intptr_t new_position) | |
1532 : reader_(reader), | |
1533 saved_size_(reader_->size()), | |
1534 saved_raw_buffer_(reader_->raw_buffer()), | |
1535 saved_typed_data_(reader_->typed_data()), | |
1536 saved_offset_(reader_->offset()) { | |
1537 reader_->set_raw_buffer(NULL); | |
1538 reader_->set_typed_data(new_typed_data); | |
1539 reader_->set_size(new_typed_data->Length()); | |
1531 reader_->set_offset(new_position); | 1540 reader_->set_offset(new_position); |
1532 } | 1541 } |
1533 | 1542 |
1534 explicit AlternativeReadingScope(Reader* reader) | 1543 explicit AlternativeReadingScope(Reader* reader) |
1535 : reader_(reader), saved_offset_(reader_->offset()) {} | 1544 : reader_(reader), |
1545 saved_size_(reader_->size()), | |
1546 saved_raw_buffer_(reader_->raw_buffer()), | |
1547 saved_typed_data_(reader_->typed_data()), | |
1548 saved_offset_(reader_->offset()) {} | |
1536 | 1549 |
1537 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); } | 1550 ~AlternativeReadingScope() { |
1551 reader_->set_raw_buffer(saved_raw_buffer_); | |
1552 reader_->set_typed_data(saved_typed_data_); | |
1553 reader_->set_size(saved_size_); | |
1554 reader_->set_offset(saved_offset_); | |
1555 } | |
1538 | 1556 |
1539 intptr_t saved_offset() { return saved_offset_; } | 1557 intptr_t saved_offset() { return saved_offset_; } |
1540 | 1558 |
1541 private: | 1559 private: |
1542 Reader* reader_; | 1560 Reader* reader_; |
1561 intptr_t saved_size_; | |
1562 const uint8_t* saved_raw_buffer_; | |
1563 const TypedData* saved_typed_data_; | |
1543 intptr_t saved_offset_; | 1564 intptr_t saved_offset_; |
1544 }; | 1565 }; |
1545 | 1566 |
1546 } // namespace kernel | 1567 } // namespace kernel |
1547 } // namespace dart | 1568 } // namespace dart |
1548 | 1569 |
1549 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1570 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1550 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 1571 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
OLD | NEW |