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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/kernel_binary_flowgraph.h
diff --git a/runtime/vm/kernel_binary_flowgraph.h b/runtime/vm/kernel_binary_flowgraph.h
index daf12245225fbe6557dff61427841f0bb4142a09..a9120ad8f7d3f570d65864d5bcf0e4f84461f7a4 100644
--- a/runtime/vm/kernel_binary_flowgraph.h
+++ b/runtime/vm/kernel_binary_flowgraph.h
@@ -656,6 +656,27 @@ class StreamingFlowGraphBuilder {
friend class KernelReader;
};
+// A helper class that saves the current reader position, goes to another reader
+// position, and upon destruction, resets to the original reader position.
+class AlternativeReadingScope {
+ public:
+ AlternativeReadingScope(Reader* reader, intptr_t new_position)
+ : reader_(reader), saved_offset_(reader_->offset()) {
+ reader_->set_offset(new_position);
+ }
+
+ explicit AlternativeReadingScope(Reader* reader)
+ : reader_(reader), saved_offset_(reader_->offset()) {}
+
+ ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); }
+
+ intptr_t saved_offset() { return saved_offset_; }
+
+ private:
+ Reader* reader_;
+ intptr_t saved_offset_;
+};
+
// Helper class that reads a kernel FunctionNode from binary.
//
// Use ReadUntilExcluding to read up to but not including a field.
@@ -938,16 +959,16 @@ class FieldHelper {
if (builder_->ReadTag() == kSomething) {
if (detect_function_literal_initializer &&
builder_->PeekTag() == kFunctionExpression) {
- has_function_literal_initializer_ = true;
- intptr_t expr_offset = builder_->ReaderOffset();
+ AlternativeReadingScope alt(builder_->reader_);
Tag tag = builder_->ReadTag();
ASSERT(tag == kFunctionExpression);
- tag = builder_->ReadTag();
- ASSERT(tag == kFunctionNode);
- function_literal_start_ = builder_->ReadPosition();
- function_literal_end_ = builder_->ReadPosition();
- builder_->SetOffset(expr_offset);
+ FunctionNodeHelper helper(builder_);
+ helper.ReadUntilIncluding(FunctionNodeHelper::kEndPosition);
+
+ has_function_literal_initializer_ = true;
+ function_literal_start_ = helper.position_;
+ function_literal_end_ = helper.end_position_;
}
builder_->SkipExpression(); // read initializer.
}
@@ -1525,27 +1546,6 @@ class LibraryHelper {
intptr_t next_read_;
};
-// A helper class that saves the current reader position, goes to another reader
-// position, and upon destruction, resets to the original reader position.
-class AlternativeReadingScope {
- public:
- AlternativeReadingScope(Reader* reader, intptr_t new_position)
- : reader_(reader), saved_offset_(reader_->offset()) {
- reader_->set_offset(new_position);
- }
-
- explicit AlternativeReadingScope(Reader* reader)
- : reader_(reader), saved_offset_(reader_->offset()) {}
-
- ~AlternativeReadingScope() { reader_->set_offset(saved_offset_); }
-
- intptr_t saved_offset() { return saved_offset_; }
-
- private:
- Reader* reader_;
- intptr_t saved_offset_;
-};
-
} // namespace kernel
} // namespace dart
« 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