Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: runtime/vm/kernel_binary_flowgraph.h

Issue 2991233002: [kernel] Use helper functions to minimize assumptions about dill layout. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 friend class VariableDeclarationHelper; 649 friend class VariableDeclarationHelper;
650 friend class FieldHelper; 650 friend class FieldHelper;
651 friend class ProcedureHelper; 651 friend class ProcedureHelper;
652 friend class ClassHelper; 652 friend class ClassHelper;
653 friend class LibraryHelper; 653 friend class LibraryHelper;
654 friend class ConstructorHelper; 654 friend class ConstructorHelper;
655 friend class SimpleExpressionConverter; 655 friend class SimpleExpressionConverter;
656 friend class KernelReader; 656 friend class KernelReader;
657 }; 657 };
658 658
659 // A helper class that saves the current reader position, goes to another reader
660 // position, and upon destruction, resets to the original reader position.
661 class AlternativeReadingScope {
662 public:
663 AlternativeReadingScope(Reader* reader, intptr_t new_position)
664 : reader_(reader), saved_offset_(reader_->offset()) {
665 reader_->set_offset(new_position);
666 }
667
668 explicit AlternativeReadingScope(Reader* reader)
669 : reader_(reader), saved_offset_(reader_->offset()) {}
670
671 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); }
672
673 intptr_t saved_offset() { return saved_offset_; }
674
675 private:
676 Reader* reader_;
677 intptr_t saved_offset_;
678 };
679
659 // Helper class that reads a kernel FunctionNode from binary. 680 // Helper class that reads a kernel FunctionNode from binary.
660 // 681 //
661 // Use ReadUntilExcluding to read up to but not including a field. 682 // Use ReadUntilExcluding to read up to but not including a field.
662 // One can then for instance read the field from the call-site (and remember to 683 // One can then for instance read the field from the call-site (and remember to
663 // call SetAt to inform this helper class), and then use this to read more. 684 // call SetAt to inform this helper class), and then use this to read more.
664 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class. 685 // "Dumb" fields are stored (e.g. integers) and can be fetched from this class.
665 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped. 686 // If asked to read a "non-dumb" field (e.g. an expression) it will be skipped.
666 class FunctionNodeHelper { 687 class FunctionNodeHelper {
667 public: 688 public:
668 enum Fields { 689 enum Fields {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 } 952 }
932 if (++next_read_ == field) return; 953 if (++next_read_ == field) return;
933 } 954 }
934 case kType: 955 case kType:
935 builder_->SkipDartType(); // read type. 956 builder_->SkipDartType(); // read type.
936 if (++next_read_ == field) return; 957 if (++next_read_ == field) return;
937 case kInitializer: 958 case kInitializer:
938 if (builder_->ReadTag() == kSomething) { 959 if (builder_->ReadTag() == kSomething) {
939 if (detect_function_literal_initializer && 960 if (detect_function_literal_initializer &&
940 builder_->PeekTag() == kFunctionExpression) { 961 builder_->PeekTag() == kFunctionExpression) {
941 has_function_literal_initializer_ = true; 962 AlternativeReadingScope alt(builder_->reader_);
942 intptr_t expr_offset = builder_->ReaderOffset();
943 Tag tag = builder_->ReadTag(); 963 Tag tag = builder_->ReadTag();
944 ASSERT(tag == kFunctionExpression); 964 ASSERT(tag == kFunctionExpression);
945 tag = builder_->ReadTag();
946 ASSERT(tag == kFunctionNode);
947 function_literal_start_ = builder_->ReadPosition();
948 function_literal_end_ = builder_->ReadPosition();
949 965
950 builder_->SetOffset(expr_offset); 966 FunctionNodeHelper helper(builder_);
967 helper.ReadUntilIncluding(FunctionNodeHelper::kEndPosition);
968
969 has_function_literal_initializer_ = true;
970 function_literal_start_ = helper.position_;
971 function_literal_end_ = helper.end_position_;
951 } 972 }
952 builder_->SkipExpression(); // read initializer. 973 builder_->SkipExpression(); // read initializer.
953 } 974 }
954 if (++next_read_ == field) return; 975 if (++next_read_ == field) return;
955 case kEnd: 976 case kEnd:
956 return; 977 return;
957 } 978 }
958 } 979 }
959 980
960 void SetNext(Fields field) { next_read_ = field; } 981 void SetNext(Fields field) { next_read_ = field; }
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1539
1519 NameIndex canonical_name_; 1540 NameIndex canonical_name_;
1520 StringIndex name_index_; 1541 StringIndex name_index_;
1521 intptr_t source_uri_index_; 1542 intptr_t source_uri_index_;
1522 1543
1523 private: 1544 private:
1524 StreamingFlowGraphBuilder* builder_; 1545 StreamingFlowGraphBuilder* builder_;
1525 intptr_t next_read_; 1546 intptr_t next_read_;
1526 }; 1547 };
1527 1548
1528 // A helper class that saves the current reader position, goes to another reader
1529 // position, and upon destruction, resets to the original reader position.
1530 class AlternativeReadingScope {
1531 public:
1532 AlternativeReadingScope(Reader* reader, intptr_t new_position)
1533 : reader_(reader), saved_offset_(reader_->offset()) {
1534 reader_->set_offset(new_position);
1535 }
1536
1537 explicit AlternativeReadingScope(Reader* reader)
1538 : reader_(reader), saved_offset_(reader_->offset()) {}
1539
1540 ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); }
1541
1542 intptr_t saved_offset() { return saved_offset_; }
1543
1544 private:
1545 Reader* reader_;
1546 intptr_t saved_offset_;
1547 };
1548
1549 } // namespace kernel 1549 } // namespace kernel
1550 } // namespace dart 1550 } // namespace dart
1551 1551
1552 #endif // !defined(DART_PRECOMPILED_RUNTIME) 1552 #endif // !defined(DART_PRECOMPILED_RUNTIME)
1553 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_ 1553 #endif // RUNTIME_VM_KERNEL_BINARY_FLOWGRAPH_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698