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> |
11 | 11 |
12 #include "vm/kernel.h" | 12 #include "vm/kernel.h" |
13 #include "vm/kernel_binary.h" | 13 #include "vm/kernel_binary.h" |
14 #include "vm/kernel_to_il.h" | 14 #include "vm/kernel_to_il.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 namespace kernel { | 18 namespace kernel { |
19 | 19 |
20 class StreamingDartTypeTranslator { | 20 class StreamingDartTypeTranslator { |
21 public: | 21 public: |
22 StreamingDartTypeTranslator(StreamingFlowGraphBuilder* builder, | 22 StreamingDartTypeTranslator(StreamingFlowGraphBuilder* builder, |
23 bool finalize = false); | 23 bool finalize = false); |
24 | 24 |
25 // Can return a malformed type. | 25 // Can return a malformed type. |
26 AbstractType& BuildType(); | 26 AbstractType& BuildType(); |
27 // Can return a malformed type. | |
28 AbstractType& BuildTypeWithoutFinalization(); | |
29 // Is guaranteed to be not malformed. | 27 // Is guaranteed to be not malformed. |
30 AbstractType& BuildVariableType(); | 28 AbstractType& BuildVariableType(); |
31 | 29 |
32 // Will return `TypeArguments::null()` in case any of the arguments are | 30 // Will return `TypeArguments::null()` in case any of the arguments are |
33 // malformed. | 31 // malformed. |
34 const TypeArguments& BuildTypeArguments(intptr_t length); | 32 const TypeArguments& BuildTypeArguments(intptr_t length); |
35 | 33 |
36 // Will return `TypeArguments::null()` in case any of the arguments are | 34 // Will return `TypeArguments::null()` in case any of the arguments are |
37 // malformed. | 35 // malformed. |
38 const TypeArguments& BuildInstantiatedTypeArguments( | 36 const TypeArguments& BuildInstantiatedTypeArguments( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 intptr_t kernel_offset, | 94 intptr_t kernel_offset, |
97 const uint8_t* buffer, | 95 const uint8_t* buffer, |
98 intptr_t buffer_length); | 96 intptr_t buffer_length); |
99 | 97 |
100 virtual ~StreamingScopeBuilder(); | 98 virtual ~StreamingScopeBuilder(); |
101 | 99 |
102 ScopeBuildingResult* BuildScopes(); | 100 ScopeBuildingResult* BuildScopes(); |
103 | 101 |
104 private: | 102 private: |
105 void VisitField(); | 103 void VisitField(); |
| 104 void ReadFieldUntilAnnotation(TokenPosition* position, |
| 105 TokenPosition* end_position, |
| 106 word* flags, |
| 107 intptr_t* parent_offset); |
106 | 108 |
| 109 /** |
| 110 * Will read until the function node; as this is optional, will return the tag |
| 111 * (i.e. either kSomething or kNothing). |
| 112 */ |
| 113 Tag ReadProcedureUntilFunctionNode(word* kind, intptr_t* parent_offset); |
| 114 void GetTypeParameterInfoForPossibleProcedure( |
| 115 intptr_t outermost_kernel_offset, |
| 116 bool* member_is_procedure, |
| 117 bool* is_factory_procedure, |
| 118 intptr_t* member_type_parameters, |
| 119 intptr_t* member_type_parameters_offset_start); |
107 void VisitProcedure(); | 120 void VisitProcedure(); |
108 | 121 |
| 122 /** |
| 123 * Will return binary offset of parent class. |
| 124 */ |
| 125 intptr_t ReadConstructorUntilFunctionNode(); |
109 void VisitConstructor(); | 126 void VisitConstructor(); |
110 | 127 |
| 128 void ReadClassUntilTypeParameters(); |
| 129 void ReadClassUntilFields(); |
| 130 |
| 131 void ReadFunctionNodeUntilTypeParameters(word* async_marker, |
| 132 word* dart_async_marker); |
111 void VisitFunctionNode(); | 133 void VisitFunctionNode(); |
| 134 |
| 135 void DiscoverEnclosingElements(Zone* zone, |
| 136 const Function& function, |
| 137 Function* outermost_function, |
| 138 intptr_t* outermost_kernel_offset, |
| 139 intptr_t* parent_class_offset); |
| 140 intptr_t GetParentOffset(intptr_t offset); |
| 141 void GetTypeParameterInfoForClass(intptr_t class_offset, |
| 142 intptr_t* type_paremeter_counts, |
| 143 intptr_t* type_paremeter_offset); |
112 void VisitNode(); | 144 void VisitNode(); |
113 void VisitInitializer(); | 145 void VisitInitializer(); |
114 void VisitExpression(); | 146 void VisitExpression(); |
115 void VisitStatement(); | 147 void VisitStatement(); |
116 void VisitArguments(); | 148 void VisitArguments(); |
117 void VisitVariableDeclaration(); | 149 void VisitVariableDeclaration(); |
118 void VisitDartType(); | 150 void VisitDartType(); |
119 void VisitInterfaceType(bool simple); | 151 void VisitInterfaceType(bool simple); |
120 void VisitFunctionType(bool simple); | 152 void VisitFunctionType(bool simple); |
121 void VisitTypeParameterType(); | 153 void VisitTypeParameterType(); |
(...skipping 20 matching lines...) Expand all Loading... |
142 | 174 |
143 void AddExceptionVariable(GrowableArray<LocalVariable*>* variables, | 175 void AddExceptionVariable(GrowableArray<LocalVariable*>* variables, |
144 const char* prefix, | 176 const char* prefix, |
145 intptr_t nesting_depth); | 177 intptr_t nesting_depth); |
146 | 178 |
147 void AddTryVariables(); | 179 void AddTryVariables(); |
148 void AddCatchVariables(); | 180 void AddCatchVariables(); |
149 void AddIteratorVariable(); | 181 void AddIteratorVariable(); |
150 void AddSwitchVariable(); | 182 void AddSwitchVariable(); |
151 | 183 |
| 184 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset); |
| 185 |
152 // Record an assignment or reference to a variable. If the occurrence is | 186 // Record an assignment or reference to a variable. If the occurrence is |
153 // in a nested function, ensure that the variable is handled properly as a | 187 // in a nested function, ensure that the variable is handled properly as a |
154 // captured variable. | 188 // captured variable. |
155 void LookupVariable(intptr_t declaration_binary_offest); | 189 void LookupVariable(intptr_t declaration_binary_offest); |
156 | 190 |
157 const dart::String& GenerateName(const char* prefix, intptr_t suffix); | 191 const dart::String& GenerateName(const char* prefix, intptr_t suffix); |
158 | 192 |
159 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); | 193 void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); |
160 void LookupCapturedVariableByName(LocalVariable** variable, | 194 void LookupCapturedVariableByName(LocalVariable** variable, |
161 const dart::String& name); | 195 const dart::String& name); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 229 |
196 bool needs_expr_temp_; | 230 bool needs_expr_temp_; |
197 TokenPosition first_body_token_position_; | 231 TokenPosition first_body_token_position_; |
198 | 232 |
199 StreamingFlowGraphBuilder* builder_; | 233 StreamingFlowGraphBuilder* builder_; |
200 StreamingDartTypeTranslator type_translator_; | 234 StreamingDartTypeTranslator type_translator_; |
201 | 235 |
202 word unused_word; | 236 word unused_word; |
203 intptr_t unused_intptr; | 237 intptr_t unused_intptr; |
204 TokenPosition unused_tokenposition; | 238 TokenPosition unused_tokenposition; |
205 NameIndex unused_nameindex; | |
206 }; | 239 }; |
207 | 240 |
208 | 241 |
209 // There are several cases when we are compiling constant expressions: | |
210 // | |
211 // * constant field initializers: | |
212 // const FieldName = <expr>; | |
213 // | |
214 // * constant expressions: | |
215 // const [<expr>, ...] | |
216 // const {<expr> : <expr>, ...} | |
217 // const Constructor(<expr>, ...) | |
218 // | |
219 // * constant default parameters: | |
220 // f(a, [b = <expr>]) | |
221 // f(a, {b: <expr>}) | |
222 // | |
223 // * constant values to compare in a [SwitchCase] | |
224 // case <expr>: | |
225 // | |
226 // In all cases `<expr>` must be recursively evaluated and canonicalized at | |
227 // compile-time. | |
228 class StreamingConstantEvaluator { | 242 class StreamingConstantEvaluator { |
229 public: | 243 public: |
230 explicit StreamingConstantEvaluator(StreamingFlowGraphBuilder* builder); | 244 explicit StreamingConstantEvaluator(StreamingFlowGraphBuilder* builder); |
231 | 245 |
232 virtual ~StreamingConstantEvaluator() {} | 246 virtual ~StreamingConstantEvaluator() {} |
233 | 247 |
234 Instance& EvaluateExpression(intptr_t offset, bool reset_position = true); | 248 Instance& EvaluateExpression(intptr_t offset, bool reset_position = true); |
235 Instance& EvaluateListLiteral(intptr_t offset, bool reset_position = true); | 249 Instance& EvaluateListLiteral(intptr_t offset, bool reset_position = true); |
236 Instance& EvaluateMapLiteral(intptr_t offset, bool reset_position = true); | 250 Instance& EvaluateMapLiteral(intptr_t offset, bool reset_position = true); |
237 Instance& EvaluateConstructorInvocation(intptr_t offset, | 251 Instance& EvaluateConstructorInvocation(intptr_t offset, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, | 321 StreamingFlowGraphBuilder(FlowGraphBuilder* flow_graph_builder, |
308 const uint8_t* buffer, | 322 const uint8_t* buffer, |
309 intptr_t buffer_length) | 323 intptr_t buffer_length) |
310 : flow_graph_builder_(flow_graph_builder), | 324 : flow_graph_builder_(flow_graph_builder), |
311 translation_helper_(flow_graph_builder->translation_helper_), | 325 translation_helper_(flow_graph_builder->translation_helper_), |
312 zone_(flow_graph_builder->zone_), | 326 zone_(flow_graph_builder->zone_), |
313 reader_(new Reader(buffer, buffer_length)), | 327 reader_(new Reader(buffer, buffer_length)), |
314 constant_evaluator_(this), | 328 constant_evaluator_(this), |
315 type_translator_(this, /* finalize= */ true) {} | 329 type_translator_(this, /* finalize= */ true) {} |
316 | 330 |
| 331 ~StreamingFlowGraphBuilder() { delete reader_; } |
| 332 |
| 333 Fragment BuildExpressionAt(intptr_t kernel_offset); |
| 334 Fragment BuildStatementAt(intptr_t kernel_offset); |
| 335 |
| 336 private: |
317 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, | 337 StreamingFlowGraphBuilder(TranslationHelper* translation_helper, |
318 Zone* zone, | 338 Zone* zone, |
319 const uint8_t* buffer, | 339 const uint8_t* buffer, |
320 intptr_t buffer_length) | 340 intptr_t buffer_length) |
321 : flow_graph_builder_(NULL), | 341 : flow_graph_builder_(NULL), |
322 translation_helper_(*translation_helper), | 342 translation_helper_(*translation_helper), |
323 zone_(zone), | 343 zone_(zone), |
324 reader_(new Reader(buffer, buffer_length)), | 344 reader_(new Reader(buffer, buffer_length)), |
325 constant_evaluator_(this), | 345 constant_evaluator_(this), |
326 type_translator_(this, /* finalize= */ true) {} | 346 type_translator_(this, /* finalize= */ true) {} |
327 | 347 |
328 ~StreamingFlowGraphBuilder() { delete reader_; } | |
329 | |
330 FlowGraph* BuildGraph(intptr_t kernel_offset); | |
331 | |
332 Fragment BuildStatementAt(intptr_t kernel_offset); | |
333 RawObject* BuildParameterDescriptor(intptr_t kernel_offset); | |
334 RawObject* EvaluateMetadata(intptr_t kernel_offset); | |
335 | |
336 private: | |
337 void DiscoverEnclosingElements(Zone* zone, | |
338 const Function& function, | |
339 Function* outermost_function, | |
340 intptr_t* outermost_kernel_offset, | |
341 intptr_t* parent_class_offset); | |
342 intptr_t GetParentOffset(intptr_t offset); | |
343 void GetTypeParameterInfoForClass(intptr_t class_offset, | |
344 intptr_t* type_paremeter_counts, | |
345 intptr_t* type_paremeter_offset); | |
346 void ReadClassUntilFields(); | |
347 void ReadClassUntilTypeParameters(); | |
348 /** | |
349 * Will return binary offset of parent class. | |
350 */ | |
351 intptr_t ReadConstructorUntilFunctionNode(); | |
352 /** | |
353 * Will read until the function node; as this is optional, will return the tag | |
354 * (i.e. either kSomething or kNothing). | |
355 */ | |
356 Tag ReadProcedureUntilFunctionNode(word* kind, intptr_t* parent_offset); | |
357 | |
358 void ReadFieldUntilAnnotation(NameIndex* canonical_name, | |
359 TokenPosition* position, | |
360 TokenPosition* end_position, | |
361 word* flags, | |
362 intptr_t* parent_offset); | |
363 void GetTypeParameterInfoForPossibleProcedure( | |
364 intptr_t outermost_kernel_offset, | |
365 bool* member_is_procedure, | |
366 bool* is_factory_procedure, | |
367 intptr_t* member_type_parameters, | |
368 intptr_t* member_type_parameters_offset_start); | |
369 void ReadFunctionNodeUntilTypeParameters(TokenPosition* position, | |
370 TokenPosition* end_position, | |
371 word* async_marker, | |
372 word* dart_async_marker); | |
373 /** | |
374 * Will return kernel offset for parent class if reading a constructor. | |
375 * Will otherwise return -1. | |
376 */ | |
377 intptr_t ReadUntilFunctionNode(); | |
378 StringIndex GetNameFromVariableDeclaration(intptr_t kernel_offset); | |
379 | |
380 FlowGraph* BuildGraphOfStaticFieldInitializer(); | |
381 FlowGraph* BuildGraphOfFieldAccessor(LocalVariable* setter_value); | |
382 void SetupDefaultParameterValues(); | |
383 Fragment BuildFieldInitializer(NameIndex canonical_name); | |
384 Fragment BuildInitializers(intptr_t constructor_class_parent_offset); | |
385 FlowGraph* BuildGraphOfImplicitClosureFunction(const Function& function); | |
386 FlowGraph* BuildGraphOfFunction( | |
387 bool is_in_builtin_library_toplevel, | |
388 intptr_t constructor_class_parent_offset = -1); | |
389 Fragment BuildGetMainClosure(); | |
390 | |
391 Fragment BuildExpression(TokenPosition* position = NULL); | 348 Fragment BuildExpression(TokenPosition* position = NULL); |
392 Fragment BuildStatement(); | 349 Fragment BuildStatement(); |
393 | 350 |
394 intptr_t ReaderOffset(); | 351 intptr_t ReaderOffset(); |
395 void SetOffset(intptr_t offset); | 352 void SetOffset(intptr_t offset); |
396 void SkipBytes(intptr_t skip); | 353 void SkipBytes(intptr_t skip); |
397 bool ReadBool(); | 354 bool ReadBool(); |
398 uint8_t ReadByte(); | 355 uint8_t ReadByte(); |
399 uint32_t ReadUInt(); | 356 uint32_t ReadUInt(); |
400 uint32_t PeekUInt(); | 357 uint32_t PeekUInt(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 void catch_depth_dec(); | 392 void catch_depth_dec(); |
436 void try_depth_inc(); | 393 void try_depth_inc(); |
437 void try_depth_dec(); | 394 void try_depth_dec(); |
438 intptr_t CurrentTryIndex(); | 395 intptr_t CurrentTryIndex(); |
439 intptr_t AllocateTryIndex(); | 396 intptr_t AllocateTryIndex(); |
440 LocalVariable* CurrentException(); | 397 LocalVariable* CurrentException(); |
441 LocalVariable* CurrentStackTrace(); | 398 LocalVariable* CurrentStackTrace(); |
442 CatchBlock* catch_block(); | 399 CatchBlock* catch_block(); |
443 ActiveClass* active_class(); | 400 ActiveClass* active_class(); |
444 ScopeBuildingResult* scopes(); | 401 ScopeBuildingResult* scopes(); |
445 void set_scopes(ScopeBuildingResult* scope); | |
446 ParsedFunction* parsed_function(); | 402 ParsedFunction* parsed_function(); |
447 TryFinallyBlock* try_finally_block(); | 403 TryFinallyBlock* try_finally_block(); |
448 SwitchBlock* switch_block(); | 404 SwitchBlock* switch_block(); |
449 BreakableBlock* breakable_block(); | 405 BreakableBlock* breakable_block(); |
450 GrowableArray<YieldContinuation>& yield_continuations(); | 406 GrowableArray<YieldContinuation>& yield_continuations(); |
451 Value* stack(); | 407 Value* stack(); |
452 Value* Pop(); | 408 Value* Pop(); |
453 | 409 |
454 Tag PeekArgumentsFirstPositionalTag(); | 410 Tag PeekArgumentsFirstPositionalTag(); |
455 const TypeArguments& PeekArgumentsInstantiatedType(const dart::Class& klass); | 411 const TypeArguments& PeekArgumentsInstantiatedType(const dart::Class& klass); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 Fragment BuildStringConcatenation(TokenPosition* position); | 530 Fragment BuildStringConcatenation(TokenPosition* position); |
575 Fragment BuildIsExpression(TokenPosition* position); | 531 Fragment BuildIsExpression(TokenPosition* position); |
576 Fragment BuildAsExpression(TokenPosition* position); | 532 Fragment BuildAsExpression(TokenPosition* position); |
577 Fragment BuildSymbolLiteral(TokenPosition* position); | 533 Fragment BuildSymbolLiteral(TokenPosition* position); |
578 Fragment BuildTypeLiteral(TokenPosition* position); | 534 Fragment BuildTypeLiteral(TokenPosition* position); |
579 Fragment BuildThisExpression(TokenPosition* position); | 535 Fragment BuildThisExpression(TokenPosition* position); |
580 Fragment BuildRethrow(TokenPosition* position); | 536 Fragment BuildRethrow(TokenPosition* position); |
581 Fragment BuildThrow(TokenPosition* position); | 537 Fragment BuildThrow(TokenPosition* position); |
582 Fragment BuildListLiteral(bool is_const, TokenPosition* position); | 538 Fragment BuildListLiteral(bool is_const, TokenPosition* position); |
583 Fragment BuildMapLiteral(bool is_const, TokenPosition* position); | 539 Fragment BuildMapLiteral(bool is_const, TokenPosition* position); |
584 Fragment BuildFunctionExpression(); | |
585 Fragment BuildLet(TokenPosition* position); | 540 Fragment BuildLet(TokenPosition* position); |
586 Fragment BuildBigIntLiteral(TokenPosition* position); | 541 Fragment BuildBigIntLiteral(TokenPosition* position); |
587 Fragment BuildStringLiteral(TokenPosition* position); | 542 Fragment BuildStringLiteral(TokenPosition* position); |
588 Fragment BuildIntLiteral(uint8_t payload, TokenPosition* position); | 543 Fragment BuildIntLiteral(uint8_t payload, TokenPosition* position); |
589 Fragment BuildIntLiteral(bool is_negative, TokenPosition* position); | 544 Fragment BuildIntLiteral(bool is_negative, TokenPosition* position); |
590 Fragment BuildDoubleLiteral(TokenPosition* position); | 545 Fragment BuildDoubleLiteral(TokenPosition* position); |
591 Fragment BuildBoolLiteral(bool value, TokenPosition* position); | 546 Fragment BuildBoolLiteral(bool value, TokenPosition* position); |
592 Fragment BuildNullLiteral(TokenPosition* position); | 547 Fragment BuildNullLiteral(TokenPosition* position); |
593 | 548 |
594 Fragment BuildInvalidStatement(); | 549 Fragment BuildInvalidStatement(); |
595 Fragment BuildExpressionStatement(); | 550 Fragment BuildExpressionStatement(); |
596 Fragment BuildBlock(); | 551 Fragment BuildBlock(); |
597 Fragment BuildEmptyStatement(); | 552 Fragment BuildEmptyStatement(); |
598 Fragment BuildAssertStatement(); | 553 Fragment BuildAssertStatement(); |
599 Fragment BuildLabeledStatement(); | 554 Fragment BuildLabeledStatement(); |
600 Fragment BuildBreakStatement(); | 555 Fragment BuildBreakStatement(); |
601 Fragment BuildWhileStatement(); | 556 Fragment BuildWhileStatement(); |
602 Fragment BuildDoStatement(); | 557 Fragment BuildDoStatement(); |
603 Fragment BuildForStatement(); | 558 Fragment BuildForStatement(); |
604 Fragment BuildForInStatement(bool async); | 559 Fragment BuildForInStatement(bool async); |
605 Fragment BuildSwitchStatement(); | 560 Fragment BuildSwitchStatement(); |
606 Fragment BuildContinueSwitchStatement(); | 561 Fragment BuildContinueSwitchStatement(); |
607 Fragment BuildIfStatement(); | 562 Fragment BuildIfStatement(); |
608 Fragment BuildReturnStatement(); | 563 Fragment BuildReturnStatement(); |
609 Fragment BuildTryCatch(); | 564 Fragment BuildTryCatch(); |
610 Fragment BuildTryFinally(); | 565 Fragment BuildTryFinally(); |
611 Fragment BuildYieldStatement(); | 566 Fragment BuildYieldStatement(); |
612 Fragment BuildVariableDeclaration(); | 567 Fragment BuildVariableDeclaration(); |
613 Fragment BuildFunctionDeclaration(); | |
614 Fragment BuildFunctionNode(intptr_t parent_kernel_offset, | |
615 TokenPosition parent_position, | |
616 bool declaration, | |
617 intptr_t variable_offeset); | |
618 void SetupFunctionParameters(const dart::Class& klass, | |
619 const dart::Function& function, | |
620 bool is_method, | |
621 bool is_closure); | |
622 | 568 |
623 FlowGraphBuilder* flow_graph_builder_; | 569 FlowGraphBuilder* flow_graph_builder_; |
624 TranslationHelper& translation_helper_; | 570 TranslationHelper& translation_helper_; |
625 Zone* zone_; | 571 Zone* zone_; |
626 Reader* reader_; | 572 Reader* reader_; |
627 StreamingConstantEvaluator constant_evaluator_; | 573 StreamingConstantEvaluator constant_evaluator_; |
628 StreamingDartTypeTranslator type_translator_; | 574 StreamingDartTypeTranslator type_translator_; |
629 | 575 |
630 word unused_word; | |
631 intptr_t unused_intptr; | |
632 TokenPosition unused_tokenposition; | |
633 NameIndex unused_nameindex; | |
634 | |
635 friend class StreamingConstantEvaluator; | 576 friend class StreamingConstantEvaluator; |
636 friend class StreamingDartTypeTranslator; | 577 friend class StreamingDartTypeTranslator; |
637 friend class StreamingScopeBuilder; | 578 friend class StreamingScopeBuilder; |
638 }; | 579 }; |
639 | 580 |
640 // A helper class that saves the current reader position, goes to another reader | 581 // A helper class that saves the current reader position, goes to another reader |
641 // position, and upon destruction, resets to the original reader position. | 582 // position, and upon destruction, resets to the original reader position. |
642 class AlternativeReadingScope { | 583 class AlternativeReadingScope { |
643 public: | 584 public: |
644 AlternativeReadingScope(Reader* reader, intptr_t new_position) | 585 AlternativeReadingScope(Reader* reader, intptr_t new_position) |
645 : reader_(reader), saved_offset_(reader_->offset()) { | 586 : reader_(reader), saved_offset_(reader_->offset()) { |
646 reader_->set_offset(new_position); | 587 reader_->set_offset(new_position); |
647 } | 588 } |
648 | 589 |
649 explicit AlternativeReadingScope(Reader* reader) | 590 explicit AlternativeReadingScope(Reader* reader) |
650 : reader_(reader), saved_offset_(reader_->offset()) {} | 591 : reader_(reader), saved_offset_(reader_->offset()) {} |
651 | 592 |
652 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); } | 593 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); } |
653 | 594 |
654 private: | 595 private: |
655 Reader* reader_; | 596 Reader* reader_; |
656 intptr_t saved_offset_; | 597 intptr_t saved_offset_; |
657 }; | 598 }; |
658 | 599 |
659 } // namespace kernel | 600 } // namespace kernel |
660 } // namespace dart | 601 } // namespace dart |
661 | 602 |
662 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 603 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
663 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ | 604 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ |
OLD | NEW |