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

Side by Side Diff: runtime/vm/kernel_binary.cc

Issue 2931773005: [kernel] Delete most of the AST (Closed)
Patch Set: Review Created 3 years, 5 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 | « runtime/vm/kernel_binary.h ('k') | runtime/vm/kernel_binary_flowgraph.h » ('j') | 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #if !defined(DART_PRECOMPILED_RUNTIME) 4 #if !defined(DART_PRECOMPILED_RUNTIME)
5 5
6 #include "vm/kernel_binary.h" 6 #include "vm/kernel_binary.h"
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/growable_array.h" 9 #include "vm/growable_array.h"
10 #include "vm/kernel.h" 10 #include "vm/kernel.h"
11 #include "vm/kernel_to_il.h" 11 #include "vm/kernel_to_il.h"
12 #include "vm/os.h" 12 #include "vm/os.h"
13 13
14 #if defined(DEBUG)
15 #define TRACE_READ_OFFSET() \
16 do { \
17 if (FLAG_trace_kernel_binary) reader->DumpOffset(DART_PRETTY_FUNCTION); \
18 } while (0)
19 #else
20 #define TRACE_READ_OFFSET()
21 #endif
22 14
23 namespace dart { 15 namespace dart {
24 16
25 17
26 namespace kernel { 18 namespace kernel {
27 19
28
29 Reader::~Reader() {
30 delete[] string_offsets_;
31 delete[] canonical_name_parents_;
32 delete[] canonical_name_strings_;
33 }
34
35
36 template <typename T>
37 template <typename IT>
38 void List<T>::ReadFrom(Reader* reader, TreeNode* parent) {
39 TRACE_READ_OFFSET();
40 ASSERT(parent != NULL);
41 int length = reader->ReadListLength();
42 EnsureInitialized(length);
43
44 for (intptr_t i = 0; i < length_; i++) {
45 IT* object = GetOrCreate<IT>(i, parent);
46 object->ReadFrom(reader);
47 }
48 }
49
50
51 template <typename T>
52 template <typename IT>
53 void List<T>::ReadFrom(Reader* reader) {
54 TRACE_READ_OFFSET();
55 int length = reader->ReadListLength();
56 EnsureInitialized(length);
57
58 for (intptr_t i = 0; i < length_; i++) {
59 GetOrCreate<IT>(i)->ReadFrom(reader);
60 }
61 }
62
63
64 template <typename T>
65 template <typename IT>
66 void List<T>::ReadFromStatic(Reader* reader) {
67 TRACE_READ_OFFSET();
68 int length = reader->ReadListLength();
69 EnsureInitialized(length);
70
71 for (intptr_t i = 0; i < length_; i++) {
72 ASSERT(array_[i] == NULL);
73 array_[i] = IT::ReadFrom(reader);
74 }
75 }
76
77
78 void TypeParameterList::ReadFrom(Reader* reader) {
79 // It is possible for the bound of the first type parameter to refer to
80 // the second type parameter. This means we need to create [TypeParameter]
81 // objects before reading the bounds.
82 int length = reader->ReadListLength();
83 EnsureInitialized(length);
84
85 // Make all [TypeParameter]s available in scope.
86 for (intptr_t i = 0; i < length; i++) {
87 TypeParameter* parameter = (*this)[i] = new TypeParameter();
88 reader->helper()->type_parameters().Push(parameter);
89 }
90
91 if (length > 0) {
92 // Read all [TypeParameter]s and their bounds.
93 for (intptr_t i = 0; i < length; i++) {
94 (*this)[i]->ReadFrom(reader);
95 }
96 first_offset = (*this)[0]->kernel_offset_;
97 }
98 }
99
100
101 NamedParameter* NamedParameter::ReadFrom(Reader* reader) {
102 TRACE_READ_OFFSET();
103 StringIndex name_index(reader->ReadUInt());
104 DartType* type = DartType::ReadFrom(reader);
105 return new NamedParameter(name_index, type);
106 }
107
108
109 template <typename B, typename S>
110 class DowncastReader {
111 public:
112 static S* ReadFrom(Reader* reader) {
113 TRACE_READ_OFFSET();
114 return S::Cast(B::ReadFrom(reader));
115 }
116 };
117
118
119 class VariableDeclarationImpl {
120 public:
121 static VariableDeclaration* ReadFrom(Reader* reader) {
122 TRACE_READ_OFFSET();
123 return VariableDeclaration::ReadFromImpl(reader, false);
124 }
125 };
126
127
128 void SourceTable::ReadFrom(Reader* reader) {
129 size_ = reader->ReadUInt();
130 sources_ = new Source[size_];
131
132 // Build a table of the URI offsets.
133 intptr_t* end_offsets = new intptr_t[size_];
134 for (intptr_t i = 0; i < size_; ++i) {
135 end_offsets[i] = reader->ReadUInt();
136 }
137
138 // Read the URI strings.
139 intptr_t start_offset = 0;
140 for (intptr_t i = 0; i < size_; ++i) {
141 intptr_t length = end_offsets[i] - start_offset;
142 uint8_t* buffer = new uint8_t[length];
143 memmove(buffer, reader->buffer() + reader->offset(), length);
144 reader->Consume(length);
145
146 sources_[i].uri_ = buffer;
147 sources_[i].uri_size_ = length;
148
149 start_offset = end_offsets[i];
150 }
151
152 // Read the source code strings and line starts.
153 for (intptr_t i = 0; i < size_; ++i) {
154 intptr_t length = reader->ReadUInt();
155 uint8_t* string_buffer = new uint8_t[length];
156 memmove(string_buffer, reader->buffer() + reader->offset(), length);
157 reader->Consume(length);
158 intptr_t line_count = reader->ReadUInt();
159 intptr_t* line_starts = new intptr_t[line_count];
160 intptr_t previous_line_start = 0;
161 for (intptr_t j = 0; j < line_count; ++j) {
162 intptr_t line_start = reader->ReadUInt() + previous_line_start;
163 line_starts[j] = line_start;
164 previous_line_start = line_start;
165 }
166
167 sources_[i].source_code_ = string_buffer;
168 sources_[i].source_code_size_ = length;
169 sources_[i].line_starts_ = line_starts;
170 sources_[i].line_count_ = line_count;
171 }
172 }
173
174
175 Library* Library::ReadFrom(Reader* reader) {
176 TRACE_READ_OFFSET();
177 kernel_offset_ = reader->offset(); // no tag.
178 int flags = reader->ReadFlags();
179 ASSERT(flags == 0); // external libraries not supported
180 kernel_data_ = reader->buffer();
181 kernel_data_size_ = reader->size();
182
183 canonical_name_ = reader->ReadCanonicalNameReference();
184 name_index_ = StringIndex(reader->ReadUInt());
185 import_uri_index_ = reader->CanonicalNameString(canonical_name_);
186 source_uri_index_ = reader->ReadUInt();
187 reader->set_current_script_id(source_uri_index_);
188
189 annotations_.ReadFromStatic<Expression>(reader);
190 dependencies().ReadFromStatic<LibraryDependency>(reader);
191 int num_typedefs = reader->ReadUInt();
192 typedefs().EnsureInitialized(num_typedefs);
193 for (intptr_t i = 0; i < num_typedefs; i++) {
194 typedefs().GetOrCreate<Typedef>(i, this)->ReadFrom(reader);
195 }
196 int num_classes = reader->ReadUInt();
197 classes().EnsureInitialized(num_classes);
198 for (intptr_t i = 0; i < num_classes; i++) {
199 Tag tag = reader->ReadTag();
200 ASSERT(tag == kClass);
201 NormalClass* klass = classes().GetOrCreate<NormalClass>(i, this);
202 klass->ReadFrom(reader);
203 }
204
205 fields().ReadFrom<Field>(reader, this);
206 procedures().ReadFrom<Procedure>(reader, this);
207
208 return this;
209 }
210
211
212 LibraryDependency* LibraryDependency::ReadFrom(Reader* reader) {
213 TRACE_READ_OFFSET();
214
215 LibraryDependency* node = new LibraryDependency();
216 node->flags_ = reader->ReadFlags();
217 node->annotations_.ReadFromStatic<Expression>(reader);
218 node->target_reference_ = Reference::ReadLibraryFrom(reader);
219 node->name_index_ = StringIndex(reader->ReadUInt());
220 node->combinators_.ReadFromStatic<Combinator>(reader);
221
222 return node;
223 }
224
225
226 Combinator* Combinator::ReadFrom(Reader* reader) {
227 TRACE_READ_OFFSET();
228
229 Combinator* node = new Combinator();
230 node->is_show_ = (reader->ReadByte() == 1);
231 int num_names = reader->ReadUInt();
232 node->name_indices_.Initialize(num_names);
233 for (intptr_t i = 0; i < num_names; ++i) {
234 node->name_indices_[i] = reader->ReadUInt();
235 }
236
237 return node;
238 }
239
240
241 Typedef* Typedef::ReadFrom(Reader* reader) {
242 TRACE_READ_OFFSET();
243
244 canonical_name_ = reader->ReadCanonicalNameReference();
245 position_ = reader->ReadPosition(false);
246 name_index_ = StringIndex(reader->ReadUInt());
247 source_uri_index_ = reader->ReadUInt();
248 type_parameters_.ReadFrom(reader);
249 type_ = DartType::ReadFrom(reader);
250
251 return this;
252 }
253
254
255 Class* Class::ReadFrom(Reader* reader) {
256 TRACE_READ_OFFSET();
257
258 kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
259 canonical_name_ = reader->ReadCanonicalNameReference();
260 position_ = reader->ReadPosition(false);
261 is_abstract_ = reader->ReadBool();
262 name_index_ = StringIndex(reader->ReadUInt());
263 source_uri_index_ = reader->ReadUInt();
264 reader->set_current_script_id(source_uri_index_);
265 reader->record_token_position(position_);
266 annotations_.ReadFromStatic<Expression>(reader);
267
268 return this;
269 }
270
271
272 NormalClass* NormalClass::ReadFrom(Reader* reader) {
273 TRACE_READ_OFFSET();
274 Class::ReadFrom(reader);
275 TypeParameterScope<ReaderHelper> scope(reader->helper());
276
277 type_parameters_.ReadFrom(reader);
278 DartType* type = reader->ReadOptional<DartType>();
279
280 super_class_ = InterfaceType::Cast(type);
281 reader->ReadOptional<DartType>(); // Mixed-in type is unused.
282 implemented_classes_.ReadFromStatic<DowncastReader<DartType, InterfaceType> >(
283 reader);
284 fields_.ReadFrom<Field>(reader, this);
285 constructors_.ReadFrom<Constructor>(reader, this);
286 procedures_.ReadFrom<Procedure>(reader, this);
287
288 return this;
289 }
290
291
292 NameIndex Reference::ReadMemberFrom(Reader* reader, bool allow_null) {
293 TRACE_READ_OFFSET();
294 NameIndex canonical_name = reader->ReadCanonicalNameReference();
295 if ((canonical_name == -1) && !allow_null) {
296 FATAL("Expected a valid member reference, but got `null`");
297 }
298 return canonical_name;
299 }
300
301
302 NameIndex Reference::ReadClassFrom(Reader* reader, bool allow_null) {
303 TRACE_READ_OFFSET();
304 NameIndex canonical_name = reader->ReadCanonicalNameReference();
305 if ((canonical_name == -1) && !allow_null) {
306 FATAL("Expected a valid class reference, but got `null`");
307 }
308 return canonical_name;
309 }
310
311
312 NameIndex Reference::ReadTypedefFrom(Reader* reader) {
313 TRACE_READ_OFFSET();
314 NameIndex canonical_name = reader->ReadCanonicalNameReference();
315 if (canonical_name == -1) {
316 FATAL("Expected a valid typedef reference, but got `null`");
317 }
318 return canonical_name;
319 }
320
321
322 NameIndex Reference::ReadLibraryFrom(Reader* reader) {
323 TRACE_READ_OFFSET();
324 NameIndex canonical_name = reader->ReadCanonicalNameReference();
325 if (canonical_name == -1) {
326 FATAL("Expected a valid typedef reference, but got `null`");
327 }
328 return canonical_name;
329 }
330
331
332 Field* Field::ReadFrom(Reader* reader) {
333 TRACE_READ_OFFSET();
334 kernel_offset_ = reader->offset(); // Notice the ReadTag() below.
335 Tag tag = reader->ReadTag();
336 ASSERT(tag == kField);
337
338 canonical_name_ = reader->ReadCanonicalNameReference();
339 position_ = reader->ReadPosition(false);
340 end_position_ = reader->ReadPosition(false);
341 flags_ = reader->ReadFlags();
342 reader->ReadUInt(); // parent class binary offset (or 0).
343 name_ = Name::ReadFrom(reader);
344 source_uri_index_ = reader->ReadUInt();
345 reader->set_current_script_id(source_uri_index_);
346 reader->record_token_position(position_);
347 reader->record_token_position(end_position_);
348 annotations_.ReadFromStatic<Expression>(reader);
349 type_ = DartType::ReadFrom(reader);
350 initializer_ = reader->ReadOptional<Expression>();
351
352 return this;
353 }
354
355
356 Constructor* Constructor::ReadFrom(Reader* reader) {
357 TRACE_READ_OFFSET();
358 kernel_offset_ = reader->offset(); // Notice the ReadTag() below.
359 Tag tag = reader->ReadTag();
360 ASSERT(tag == kConstructor);
361
362 canonical_name_ = reader->ReadCanonicalNameReference();
363 VariableScope<ReaderHelper> parameters(reader->helper());
364 position_ = reader->ReadPosition();
365 end_position_ = reader->ReadPosition();
366 flags_ = reader->ReadFlags();
367 reader->ReadUInt(); // parent class binary offset.
368 name_ = Name::ReadFrom(reader);
369 annotations_.ReadFromStatic<Expression>(reader);
370 function_ = FunctionNode::ReadFrom(reader);
371 initializers_.ReadFromStatic<Initializer>(reader);
372
373 return this;
374 }
375
376
377 Procedure* Procedure::ReadFrom(Reader* reader) {
378 TRACE_READ_OFFSET();
379 kernel_offset_ = reader->offset(); // Notice the ReadTag() below.
380 Tag tag = reader->ReadTag();
381 ASSERT(tag == kProcedure);
382
383 canonical_name_ = reader->ReadCanonicalNameReference();
384 VariableScope<ReaderHelper> parameters(reader->helper());
385 position_ = reader->ReadPosition(false);
386 end_position_ = reader->ReadPosition(false);
387 kind_ = static_cast<ProcedureKind>(reader->ReadByte());
388 flags_ = reader->ReadFlags();
389 reader->ReadUInt(); // parent class binary offset (or 0).
390 name_ = Name::ReadFrom(reader);
391 source_uri_index_ = reader->ReadUInt();
392 reader->set_current_script_id(source_uri_index_);
393 reader->record_token_position(position_);
394 reader->record_token_position(end_position_);
395 annotations_.ReadFromStatic<Expression>(reader);
396 function_ = reader->ReadOptional<FunctionNode>();
397
398 return this;
399 }
400
401
402 Initializer* Initializer::ReadFrom(Reader* reader) {
403 TRACE_READ_OFFSET();
404 Tag tag = reader->ReadTag();
405 switch (tag) {
406 case kInvalidInitializer:
407 return InvalidInitializer::ReadFromImpl(reader);
408 case kFieldInitializer:
409 return FieldInitializer::ReadFromImpl(reader);
410 case kSuperInitializer:
411 return SuperInitializer::ReadFromImpl(reader);
412 case kRedirectingInitializer:
413 return RedirectingInitializer::ReadFromImpl(reader);
414 case kLocalInitializer:
415 return LocalInitializer::ReadFromImpl(reader);
416 default:
417 UNREACHABLE();
418 }
419 return NULL;
420 }
421
422
423 InvalidInitializer* InvalidInitializer::ReadFromImpl(Reader* reader) {
424 TRACE_READ_OFFSET();
425 return new InvalidInitializer();
426 }
427
428
429 FieldInitializer* FieldInitializer::ReadFromImpl(Reader* reader) {
430 TRACE_READ_OFFSET();
431 FieldInitializer* initializer = new FieldInitializer();
432 initializer->field_reference_ = Reference::ReadMemberFrom(reader);
433 initializer->value_ = Expression::ReadFrom(reader);
434
435 return initializer;
436 }
437
438
439 SuperInitializer* SuperInitializer::ReadFromImpl(Reader* reader) {
440 TRACE_READ_OFFSET();
441 SuperInitializer* init = new SuperInitializer();
442 init->target_reference_ = Reference::ReadMemberFrom(reader);
443 init->arguments_ = Arguments::ReadFrom(reader);
444
445 return init;
446 }
447
448
449 RedirectingInitializer* RedirectingInitializer::ReadFromImpl(Reader* reader) {
450 TRACE_READ_OFFSET();
451 RedirectingInitializer* init = new RedirectingInitializer();
452 init->target_reference_ = Reference::ReadMemberFrom(reader);
453 init->arguments_ = Arguments::ReadFrom(reader);
454
455 return init;
456 }
457
458
459 LocalInitializer* LocalInitializer::ReadFromImpl(Reader* reader) {
460 TRACE_READ_OFFSET();
461 LocalInitializer* init = new LocalInitializer();
462 init->variable_ = VariableDeclaration::ReadFromImpl(reader, false);
463
464 return init;
465 }
466
467
468 Expression* Expression::ReadFrom(Reader* reader) {
469 TRACE_READ_OFFSET();
470 uint8_t payload = 0;
471 Tag tag = reader->ReadTag(&payload);
472 switch (tag) {
473 case kInvalidExpression:
474 return InvalidExpression::ReadFrom(reader);
475 case kVariableGet:
476 return VariableGet::ReadFrom(reader);
477 case kSpecializedVariableGet:
478 return VariableGet::ReadFrom(reader, payload);
479 case kVariableSet:
480 return VariableSet::ReadFrom(reader);
481 case kSpecializedVariableSet:
482 return VariableSet::ReadFrom(reader, payload);
483 case kPropertyGet:
484 return PropertyGet::ReadFrom(reader);
485 case kPropertySet:
486 return PropertySet::ReadFrom(reader);
487 case kDirectPropertyGet:
488 return DirectPropertyGet::ReadFrom(reader);
489 case kDirectPropertySet:
490 return DirectPropertySet::ReadFrom(reader);
491 case kStaticGet:
492 return StaticGet::ReadFrom(reader);
493 case kStaticSet:
494 return StaticSet::ReadFrom(reader);
495 case kMethodInvocation:
496 return MethodInvocation::ReadFrom(reader);
497 case kDirectMethodInvocation:
498 return DirectMethodInvocation::ReadFrom(reader);
499 case kStaticInvocation:
500 return StaticInvocation::ReadFrom(reader, false);
501 case kConstStaticInvocation:
502 return StaticInvocation::ReadFrom(reader, true);
503 case kConstructorInvocation:
504 return ConstructorInvocation::ReadFrom(reader, false);
505 case kConstConstructorInvocation:
506 return ConstructorInvocation::ReadFrom(reader, true);
507 case kNot:
508 return Not::ReadFrom(reader);
509 case kLogicalExpression:
510 return LogicalExpression::ReadFrom(reader);
511 case kConditionalExpression:
512 return ConditionalExpression::ReadFrom(reader);
513 case kStringConcatenation:
514 return StringConcatenation::ReadFrom(reader);
515 case kIsExpression:
516 return IsExpression::ReadFrom(reader);
517 case kAsExpression:
518 return AsExpression::ReadFrom(reader);
519 case kSymbolLiteral:
520 return SymbolLiteral::ReadFrom(reader);
521 case kTypeLiteral:
522 return TypeLiteral::ReadFrom(reader);
523 case kThisExpression:
524 return ThisExpression::ReadFrom(reader);
525 case kRethrow:
526 return Rethrow::ReadFrom(reader);
527 case kThrow:
528 return Throw::ReadFrom(reader);
529 case kListLiteral:
530 return ListLiteral::ReadFrom(reader, false);
531 case kConstListLiteral:
532 return ListLiteral::ReadFrom(reader, true);
533 case kMapLiteral:
534 return MapLiteral::ReadFrom(reader, false);
535 case kConstMapLiteral:
536 return MapLiteral::ReadFrom(reader, true);
537 case kAwaitExpression:
538 return AwaitExpression::ReadFrom(reader);
539 case kFunctionExpression:
540 return FunctionExpression::ReadFrom(reader);
541 case kLet:
542 return Let::ReadFrom(reader);
543 case kVectorCreation:
544 return VectorCreation::ReadFrom(reader);
545 case kVectorGet:
546 return VectorGet::ReadFrom(reader);
547 case kVectorSet:
548 return VectorSet::ReadFrom(reader);
549 case kVectorCopy:
550 return VectorCopy::ReadFrom(reader);
551 case kClosureCreation:
552 return ClosureCreation::ReadFrom(reader);
553 case kBigIntLiteral:
554 return BigintLiteral::ReadFrom(reader);
555 case kStringLiteral:
556 return StringLiteral::ReadFrom(reader);
557 case kSpecialIntLiteral:
558 return IntLiteral::ReadFrom(reader, payload);
559 case kNegativeIntLiteral:
560 return IntLiteral::ReadFrom(reader, true);
561 case kPositiveIntLiteral:
562 return IntLiteral::ReadFrom(reader, false);
563 case kDoubleLiteral:
564 return DoubleLiteral::ReadFrom(reader);
565 case kTrueLiteral:
566 return BoolLiteral::ReadFrom(reader, true);
567 case kFalseLiteral:
568 return BoolLiteral::ReadFrom(reader, false);
569 case kNullLiteral:
570 return NullLiteral::ReadFrom(reader);
571 default:
572 UNREACHABLE();
573 }
574 return NULL;
575 }
576
577
578 InvalidExpression* InvalidExpression::ReadFrom(Reader* reader) {
579 TRACE_READ_OFFSET();
580 InvalidExpression* invalid_expression = new InvalidExpression();
581 invalid_expression->kernel_offset_ =
582 reader->offset() - 1; // -1 to include tag byte.
583 return invalid_expression;
584 }
585
586
587 VariableGet* VariableGet::ReadFrom(Reader* reader) {
588 TRACE_READ_OFFSET();
589 VariableGet* get = new VariableGet();
590 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
591 get->position_ = reader->ReadPosition();
592 get->variable_kernel_offset_ = reader->ReadUInt();
593 get->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt());
594 ASSERT(get->variable_->kernel_offset_no_tag() ==
595 get->variable_kernel_offset_);
596 reader->ReadOptional<DartType>(); // Unused promoted type.
597 return get;
598 }
599
600
601 VariableGet* VariableGet::ReadFrom(Reader* reader, uint8_t payload) {
602 TRACE_READ_OFFSET();
603 VariableGet* get = new VariableGet();
604 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
605 get->position_ = reader->ReadPosition();
606 get->variable_kernel_offset_ = reader->ReadUInt();
607 get->variable_ = reader->helper()->variables().Lookup(payload);
608 ASSERT(get->variable_->kernel_offset_no_tag() ==
609 get->variable_kernel_offset_);
610 return get;
611 }
612
613
614 VariableSet* VariableSet::ReadFrom(Reader* reader) {
615 TRACE_READ_OFFSET();
616 VariableSet* set = new VariableSet();
617 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
618 set->position_ = reader->ReadPosition();
619 set->variable_kernel_offset_ = reader->ReadUInt();
620 set->variable_ = reader->helper()->variables().Lookup(reader->ReadUInt());
621 ASSERT(set->variable_->kernel_offset_no_tag() ==
622 set->variable_kernel_offset_);
623 set->expression_ = Expression::ReadFrom(reader);
624
625 return set;
626 }
627
628
629 VariableSet* VariableSet::ReadFrom(Reader* reader, uint8_t payload) {
630 TRACE_READ_OFFSET();
631 VariableSet* set = new VariableSet();
632 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
633 set->variable_ = reader->helper()->variables().Lookup(payload);
634 set->position_ = reader->ReadPosition();
635 set->variable_kernel_offset_ = reader->ReadUInt();
636 ASSERT(set->variable_->kernel_offset_no_tag() ==
637 set->variable_kernel_offset_);
638 set->expression_ = Expression::ReadFrom(reader);
639
640 return set;
641 }
642
643
644 PropertyGet* PropertyGet::ReadFrom(Reader* reader) {
645 TRACE_READ_OFFSET();
646 PropertyGet* get = new PropertyGet();
647 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
648 get->position_ = reader->ReadPosition();
649 get->receiver_ = Expression::ReadFrom(reader);
650 get->name_ = Name::ReadFrom(reader);
651 get->interface_target_reference_ = Reference::ReadMemberFrom(reader, true);
652
653 return get;
654 }
655
656
657 PropertySet* PropertySet::ReadFrom(Reader* reader) {
658 TRACE_READ_OFFSET();
659 PropertySet* set = new PropertySet();
660 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
661 set->position_ = reader->ReadPosition();
662 set->receiver_ = Expression::ReadFrom(reader);
663 set->name_ = Name::ReadFrom(reader);
664 set->value_ = Expression::ReadFrom(reader);
665 set->interface_target_reference_ = Reference::ReadMemberFrom(reader, true);
666
667 return set;
668 }
669
670
671 DirectPropertyGet* DirectPropertyGet::ReadFrom(Reader* reader) {
672 TRACE_READ_OFFSET();
673 DirectPropertyGet* get = new DirectPropertyGet();
674 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
675 get->position_ = reader->ReadPosition();
676 get->receiver_ = Expression::ReadFrom(reader);
677 get->target_reference_ = Reference::ReadMemberFrom(reader);
678
679 return get;
680 }
681
682
683 DirectPropertySet* DirectPropertySet::ReadFrom(Reader* reader) {
684 TRACE_READ_OFFSET();
685 DirectPropertySet* set = new DirectPropertySet();
686 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
687 set->position_ = reader->ReadPosition();
688 set->receiver_ = Expression::ReadFrom(reader);
689 set->target_reference_ = Reference::ReadMemberFrom(reader);
690 set->value_ = Expression::ReadFrom(reader);
691
692 return set;
693 }
694
695
696 StaticGet* StaticGet::ReadFrom(Reader* reader) {
697 TRACE_READ_OFFSET();
698 StaticGet* get = new StaticGet();
699 get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
700 get->position_ = reader->ReadPosition();
701 get->target_reference_ = Reference::ReadMemberFrom(reader);
702 return get;
703 }
704
705
706 StaticSet* StaticSet::ReadFrom(Reader* reader) {
707 TRACE_READ_OFFSET();
708 StaticSet* set = new StaticSet();
709 set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
710 set->position_ = reader->ReadPosition();
711 set->target_reference_ = Reference::ReadMemberFrom(reader);
712 set->expression_ = Expression::ReadFrom(reader);
713
714 return set;
715 }
716
717
718 Arguments* Arguments::ReadFrom(Reader* reader) {
719 TRACE_READ_OFFSET();
720 Arguments* arguments = new Arguments();
721 intptr_t num_arguments = reader->ReadUInt();
722 arguments->types().ReadFromStatic<DartType>(reader);
723 arguments->positional().ReadFromStatic<Expression>(reader);
724 arguments->named().ReadFromStatic<NamedExpression>(reader);
725 ASSERT(arguments->count() == num_arguments);
726
727 return arguments;
728 }
729
730
731 NamedExpression* NamedExpression::ReadFrom(Reader* reader) {
732 TRACE_READ_OFFSET();
733 StringIndex name_index(reader->ReadUInt());
734 Expression* expression = Expression::ReadFrom(reader);
735 NamedExpression* named = new NamedExpression(name_index, expression);
736
737 return named;
738 }
739
740
741 MethodInvocation* MethodInvocation::ReadFrom(Reader* reader) {
742 TRACE_READ_OFFSET();
743 MethodInvocation* invocation = new MethodInvocation();
744 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
745 invocation->position_ = reader->ReadPosition();
746 invocation->receiver_ = Expression::ReadFrom(reader);
747 invocation->name_ = Name::ReadFrom(reader);
748 invocation->arguments_ = Arguments::ReadFrom(reader);
749 invocation->interface_target_reference_ =
750 Reference::ReadMemberFrom(reader, true);
751
752 return invocation;
753 }
754
755
756 DirectMethodInvocation* DirectMethodInvocation::ReadFrom(Reader* reader) {
757 TRACE_READ_OFFSET();
758 DirectMethodInvocation* invocation = new DirectMethodInvocation();
759 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
760 invocation->receiver_ = Expression::ReadFrom(reader);
761 invocation->target_reference_ = Reference::ReadMemberFrom(reader);
762 invocation->arguments_ = Arguments::ReadFrom(reader);
763
764 return invocation;
765 }
766
767
768 StaticInvocation* StaticInvocation::ReadFrom(Reader* reader, bool is_const) {
769 TRACE_READ_OFFSET();
770 StaticInvocation* invocation = new StaticInvocation();
771 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
772 invocation->is_const_ = is_const;
773 invocation->position_ = reader->ReadPosition();
774 invocation->procedure_reference_ = Reference::ReadMemberFrom(reader);
775 invocation->arguments_ = Arguments::ReadFrom(reader);
776
777 return invocation;
778 }
779
780
781 ConstructorInvocation* ConstructorInvocation::ReadFrom(Reader* reader,
782 bool is_const) {
783 TRACE_READ_OFFSET();
784 ConstructorInvocation* invocation = new ConstructorInvocation();
785 invocation->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
786 invocation->is_const_ = is_const;
787 invocation->position_ = reader->ReadPosition();
788 invocation->target_reference_ = Reference::ReadMemberFrom(reader);
789 invocation->arguments_ = Arguments::ReadFrom(reader);
790
791 return invocation;
792 }
793
794
795 Not* Not::ReadFrom(Reader* reader) {
796 TRACE_READ_OFFSET();
797 Not* n = new Not();
798 n->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
799 n->expression_ = Expression::ReadFrom(reader);
800
801 return n;
802 }
803
804
805 LogicalExpression* LogicalExpression::ReadFrom(Reader* reader) {
806 TRACE_READ_OFFSET();
807 LogicalExpression* expr = new LogicalExpression();
808 expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
809 expr->left_ = Expression::ReadFrom(reader);
810 expr->operator_ = static_cast<Operator>(reader->ReadByte());
811 expr->right_ = Expression::ReadFrom(reader);
812
813 return expr;
814 }
815
816
817 ConditionalExpression* ConditionalExpression::ReadFrom(Reader* reader) {
818 TRACE_READ_OFFSET();
819 ConditionalExpression* expr = new ConditionalExpression();
820 expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
821 expr->condition_ = Expression::ReadFrom(reader);
822 expr->then_ = Expression::ReadFrom(reader);
823 expr->otherwise_ = Expression::ReadFrom(reader);
824 reader->ReadOptional<DartType>(); // Unused static type.
825
826 return expr;
827 }
828
829
830 StringConcatenation* StringConcatenation::ReadFrom(Reader* reader) {
831 TRACE_READ_OFFSET();
832 StringConcatenation* concat = new StringConcatenation();
833 concat->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
834 concat->position_ = reader->ReadPosition();
835 concat->expressions_.ReadFromStatic<Expression>(reader);
836
837 return concat;
838 }
839
840
841 IsExpression* IsExpression::ReadFrom(Reader* reader) {
842 TRACE_READ_OFFSET();
843 IsExpression* expr = new IsExpression();
844 expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
845 expr->position_ = reader->ReadPosition();
846 expr->operand_ = Expression::ReadFrom(reader);
847 expr->type_ = DartType::ReadFrom(reader);
848
849 return expr;
850 }
851
852
853 AsExpression* AsExpression::ReadFrom(Reader* reader) {
854 TRACE_READ_OFFSET();
855 AsExpression* expr = new AsExpression();
856 expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
857 expr->position_ = reader->ReadPosition();
858 expr->operand_ = Expression::ReadFrom(reader);
859 expr->type_ = DartType::ReadFrom(reader);
860
861 return expr;
862 }
863
864
865 StringLiteral* StringLiteral::ReadFrom(Reader* reader) {
866 TRACE_READ_OFFSET();
867 intptr_t offset = reader->offset() - 1; // -1 to include tag byte.
868 StringLiteral* lit = new StringLiteral(StringIndex(reader->ReadUInt()));
869 lit->kernel_offset_ = offset;
870 return lit;
871 }
872
873
874 BigintLiteral* BigintLiteral::ReadFrom(Reader* reader) {
875 TRACE_READ_OFFSET();
876 intptr_t offset = reader->offset() - 1; // -1 to include tag byte.
877 BigintLiteral* lit = new BigintLiteral(StringIndex(reader->ReadUInt()));
878 lit->kernel_offset_ = offset;
879 return lit;
880 }
881
882
883 IntLiteral* IntLiteral::ReadFrom(Reader* reader, bool is_negative) {
884 TRACE_READ_OFFSET();
885 IntLiteral* literal = new IntLiteral();
886 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
887 literal->value_ = is_negative ? -static_cast<int64_t>(reader->ReadUInt())
888 : reader->ReadUInt();
889 return literal;
890 }
891
892
893 IntLiteral* IntLiteral::ReadFrom(Reader* reader, uint8_t payload) {
894 TRACE_READ_OFFSET();
895 IntLiteral* literal = new IntLiteral();
896 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
897 literal->value_ = static_cast<int32_t>(payload) - SpecializedIntLiteralBias;
898 return literal;
899 }
900
901
902 DoubleLiteral* DoubleLiteral::ReadFrom(Reader* reader) {
903 TRACE_READ_OFFSET();
904 DoubleLiteral* literal = new DoubleLiteral();
905 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
906 literal->value_index_ = StringIndex(reader->ReadUInt());
907 return literal;
908 }
909
910
911 BoolLiteral* BoolLiteral::ReadFrom(Reader* reader, bool value) {
912 TRACE_READ_OFFSET();
913 BoolLiteral* lit = new BoolLiteral();
914 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
915 lit->value_ = value;
916 return lit;
917 }
918
919
920 NullLiteral* NullLiteral::ReadFrom(Reader* reader) {
921 TRACE_READ_OFFSET();
922 NullLiteral* lit = new NullLiteral();
923 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
924 return lit;
925 }
926
927
928 SymbolLiteral* SymbolLiteral::ReadFrom(Reader* reader) {
929 TRACE_READ_OFFSET();
930 SymbolLiteral* lit = new SymbolLiteral();
931 lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
932 lit->value_index_ = StringIndex(reader->ReadUInt());
933 return lit;
934 }
935
936
937 TypeLiteral* TypeLiteral::ReadFrom(Reader* reader) {
938 TRACE_READ_OFFSET();
939 TypeLiteral* literal = new TypeLiteral();
940 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
941 literal->type_ = DartType::ReadFrom(reader);
942 return literal;
943 }
944
945
946 ThisExpression* ThisExpression::ReadFrom(Reader* reader) {
947 TRACE_READ_OFFSET();
948 ThisExpression* this_expr = new ThisExpression();
949 this_expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
950 return this_expr;
951 }
952
953
954 Rethrow* Rethrow::ReadFrom(Reader* reader) {
955 TRACE_READ_OFFSET();
956 Rethrow* rethrow = new Rethrow();
957 rethrow->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
958 rethrow->position_ = reader->ReadPosition();
959 return rethrow;
960 }
961
962
963 Throw* Throw::ReadFrom(Reader* reader) {
964 TRACE_READ_OFFSET();
965 Throw* t = new Throw();
966 t->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
967 t->position_ = reader->ReadPosition();
968 t->expression_ = Expression::ReadFrom(reader);
969
970 return t;
971 }
972
973
974 ListLiteral* ListLiteral::ReadFrom(Reader* reader, bool is_const) {
975 TRACE_READ_OFFSET();
976 ListLiteral* literal = new ListLiteral();
977 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
978 literal->is_const_ = is_const;
979 literal->position_ = reader->ReadPosition();
980 literal->type_ = DartType::ReadFrom(reader);
981 literal->expressions_.ReadFromStatic<Expression>(reader);
982
983 return literal;
984 }
985
986
987 MapLiteral* MapLiteral::ReadFrom(Reader* reader, bool is_const) {
988 TRACE_READ_OFFSET();
989 MapLiteral* literal = new MapLiteral();
990 literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
991 literal->is_const_ = is_const;
992 literal->position_ = reader->ReadPosition();
993 literal->key_type_ = DartType::ReadFrom(reader);
994 literal->value_type_ = DartType::ReadFrom(reader);
995 literal->entries_.ReadFromStatic<MapEntry>(reader);
996
997 return literal;
998 }
999
1000
1001 MapEntry* MapEntry::ReadFrom(Reader* reader) {
1002 MapEntry* entry = new MapEntry();
1003 entry->key_ = Expression::ReadFrom(reader);
1004 entry->value_ = Expression::ReadFrom(reader);
1005
1006 return entry;
1007 }
1008
1009
1010 AwaitExpression* AwaitExpression::ReadFrom(Reader* reader) {
1011 TRACE_READ_OFFSET();
1012 AwaitExpression* await = new AwaitExpression();
1013 await->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1014 await->operand_ = Expression::ReadFrom(reader);
1015
1016 return await;
1017 }
1018
1019
1020 FunctionExpression* FunctionExpression::ReadFrom(Reader* reader) {
1021 TRACE_READ_OFFSET();
1022 VariableScope<ReaderHelper> parameters(reader->helper());
1023 FunctionExpression* expr = new FunctionExpression();
1024 expr->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1025 expr->function_ = FunctionNode::ReadFrom(reader);
1026
1027 return expr;
1028 }
1029
1030
1031 Let* Let::ReadFrom(Reader* reader) {
1032 TRACE_READ_OFFSET();
1033 VariableScope<ReaderHelper> vars(reader->helper());
1034 PositionScope scope(reader);
1035
1036 Let* let = new Let();
1037 let->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1038 let->variable_ = VariableDeclaration::ReadFromImpl(reader, false);
1039 let->body_ = Expression::ReadFrom(reader);
1040 let->position_ = reader->min_position();
1041 let->end_position_ = reader->max_position();
1042
1043 return let;
1044 }
1045
1046
1047 VectorCreation* VectorCreation::ReadFrom(Reader* reader) {
1048 TRACE_READ_OFFSET();
1049
1050 VectorCreation* vector_creation = new VectorCreation();
1051 vector_creation->kernel_offset_ =
1052 reader->offset() - 1; // -1 to include tag byte.
1053 vector_creation->value_ = reader->ReadUInt();
1054
1055 return vector_creation;
1056 }
1057
1058
1059 VectorGet* VectorGet::ReadFrom(Reader* reader) {
1060 TRACE_READ_OFFSET();
1061
1062 VectorGet* vector_get = new VectorGet();
1063 vector_get->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1064 vector_get->vector_expression_ = Expression::ReadFrom(reader);
1065 vector_get->index_ = reader->ReadUInt();
1066
1067 return vector_get;
1068 }
1069
1070
1071 VectorSet* VectorSet::ReadFrom(Reader* reader) {
1072 TRACE_READ_OFFSET();
1073
1074 VectorSet* vector_set = new VectorSet();
1075 vector_set->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1076 vector_set->vector_expression_ = Expression::ReadFrom(reader);
1077 vector_set->index_ = reader->ReadUInt();
1078 vector_set->value_ = Expression::ReadFrom(reader);
1079
1080 return vector_set;
1081 }
1082
1083
1084 VectorCopy* VectorCopy::ReadFrom(Reader* reader) {
1085 TRACE_READ_OFFSET();
1086
1087 VectorCopy* vector_copy = new VectorCopy();
1088 vector_copy->kernel_offset_ =
1089 reader->offset() - 1; // -1 to include tag byte.
1090 vector_copy->vector_expression_ = Expression::ReadFrom(reader);
1091
1092 return vector_copy;
1093 }
1094
1095
1096 ClosureCreation* ClosureCreation::ReadFrom(Reader* reader) {
1097 TRACE_READ_OFFSET();
1098
1099 ClosureCreation* closure_creation = new ClosureCreation();
1100 closure_creation->kernel_offset_ =
1101 reader->offset() - 1; // to include tag byte.
1102 closure_creation->top_level_function_reference_ =
1103 Reference::ReadMemberFrom(reader);
1104 closure_creation->context_vector_ = Expression::ReadFrom(reader);
1105 closure_creation->function_type_ =
1106 FunctionType::Cast(DartType::ReadFrom(reader));
1107
1108 return closure_creation;
1109 }
1110
1111
1112 Statement* Statement::ReadFrom(Reader* reader) {
1113 TRACE_READ_OFFSET();
1114 Tag tag = reader->ReadTag();
1115 switch (tag) {
1116 case kInvalidStatement:
1117 return InvalidStatement::ReadFrom(reader);
1118 case kExpressionStatement:
1119 return ExpressionStatement::ReadFrom(reader);
1120 case kBlock:
1121 return Block::ReadFromImpl(reader);
1122 case kEmptyStatement:
1123 return EmptyStatement::ReadFrom(reader);
1124 case kAssertStatement:
1125 return AssertStatement::ReadFrom(reader);
1126 case kLabeledStatement:
1127 return LabeledStatement::ReadFrom(reader);
1128 case kBreakStatement:
1129 return BreakStatement::ReadFrom(reader);
1130 case kWhileStatement:
1131 return WhileStatement::ReadFrom(reader);
1132 case kDoStatement:
1133 return DoStatement::ReadFrom(reader);
1134 case kForStatement:
1135 return ForStatement::ReadFrom(reader);
1136 case kForInStatement:
1137 return ForInStatement::ReadFrom(reader, false);
1138 case kAsyncForInStatement:
1139 return ForInStatement::ReadFrom(reader, true);
1140 case kSwitchStatement:
1141 return SwitchStatement::ReadFrom(reader);
1142 case kContinueSwitchStatement:
1143 return ContinueSwitchStatement::ReadFrom(reader);
1144 case kIfStatement:
1145 return IfStatement::ReadFrom(reader);
1146 case kReturnStatement:
1147 return ReturnStatement::ReadFrom(reader);
1148 case kTryCatch:
1149 return TryCatch::ReadFrom(reader);
1150 case kTryFinally:
1151 return TryFinally::ReadFrom(reader);
1152 case kYieldStatement:
1153 return YieldStatement::ReadFrom(reader);
1154 case kVariableDeclaration:
1155 return VariableDeclaration::ReadFromImpl(reader, true);
1156 case kFunctionDeclaration:
1157 return FunctionDeclaration::ReadFrom(reader);
1158 default:
1159 UNREACHABLE();
1160 }
1161 return NULL;
1162 }
1163
1164
1165 InvalidStatement* InvalidStatement::ReadFrom(Reader* reader) {
1166 TRACE_READ_OFFSET();
1167 InvalidStatement* stmt = new InvalidStatement();
1168 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1169 return stmt;
1170 }
1171
1172
1173 ExpressionStatement* ExpressionStatement::ReadFrom(Reader* reader) {
1174 TRACE_READ_OFFSET();
1175 intptr_t offset = reader->offset() - 1; // -1 to include tag byte.
1176 ExpressionStatement* stmt =
1177 new ExpressionStatement(Expression::ReadFrom(reader));
1178 stmt->kernel_offset_ = offset;
1179
1180 return stmt;
1181 }
1182
1183
1184 Block* Block::ReadFromImpl(Reader* reader) {
1185 TRACE_READ_OFFSET();
1186 PositionScope scope(reader);
1187
1188 VariableScope<ReaderHelper> vars(reader->helper());
1189 Block* block = new Block();
1190 block->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1191 block->statements().ReadFromStatic<Statement>(reader);
1192 block->position_ = reader->min_position();
1193 block->end_position_ = reader->max_position();
1194
1195 return block;
1196 }
1197
1198
1199 EmptyStatement* EmptyStatement::ReadFrom(Reader* reader) {
1200 TRACE_READ_OFFSET();
1201 EmptyStatement* stmt = new EmptyStatement();
1202 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1203 return stmt;
1204 }
1205
1206
1207 AssertStatement* AssertStatement::ReadFrom(Reader* reader) {
1208 TRACE_READ_OFFSET();
1209 AssertStatement* stmt = new AssertStatement();
1210 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1211 stmt->condition_ = Expression::ReadFrom(reader);
1212 reader->ReadPosition(); // condition start offset.
1213 reader->ReadPosition(); // condition end offset.
1214 stmt->message_ = reader->ReadOptional<Expression>();
1215
1216 return stmt;
1217 }
1218
1219
1220 LabeledStatement* LabeledStatement::ReadFrom(Reader* reader) {
1221 TRACE_READ_OFFSET();
1222 LabeledStatement* stmt = new LabeledStatement();
1223 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1224
1225 reader->helper()->labels()->Push(stmt);
1226 stmt->body_ = Statement::ReadFrom(reader);
1227 reader->helper()->labels()->Pop(stmt);
1228
1229 return stmt;
1230 }
1231
1232
1233 BreakStatement* BreakStatement::ReadFrom(Reader* reader) {
1234 TRACE_READ_OFFSET();
1235 BreakStatement* stmt = new BreakStatement();
1236 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1237 stmt->position_ = reader->ReadPosition();
1238 stmt->target_index_ = reader->ReadUInt();
1239 return stmt;
1240 }
1241
1242
1243 WhileStatement* WhileStatement::ReadFrom(Reader* reader) {
1244 TRACE_READ_OFFSET();
1245 WhileStatement* stmt = new WhileStatement();
1246 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1247 stmt->condition_ = Expression::ReadFrom(reader);
1248 stmt->body_ = Statement::ReadFrom(reader);
1249
1250 return stmt;
1251 }
1252
1253
1254 DoStatement* DoStatement::ReadFrom(Reader* reader) {
1255 TRACE_READ_OFFSET();
1256 DoStatement* dostmt = new DoStatement();
1257 dostmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1258 dostmt->body_ = Statement::ReadFrom(reader);
1259 dostmt->condition_ = Expression::ReadFrom(reader);
1260
1261 return dostmt;
1262 }
1263
1264
1265 ForStatement* ForStatement::ReadFrom(Reader* reader) {
1266 TRACE_READ_OFFSET();
1267 VariableScope<ReaderHelper> vars(reader->helper());
1268 PositionScope scope(reader);
1269
1270 ForStatement* forstmt = new ForStatement();
1271 forstmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1272 forstmt->variables_.ReadFromStatic<VariableDeclarationImpl>(reader);
1273 forstmt->condition_ = reader->ReadOptional<Expression>();
1274 forstmt->updates_.ReadFromStatic<Expression>(reader);
1275 forstmt->body_ = Statement::ReadFrom(reader);
1276 forstmt->end_position_ = reader->max_position();
1277 forstmt->position_ = reader->min_position();
1278
1279 return forstmt;
1280 }
1281
1282
1283 ForInStatement* ForInStatement::ReadFrom(Reader* reader, bool is_async) {
1284 TRACE_READ_OFFSET();
1285 VariableScope<ReaderHelper> vars(reader->helper());
1286 PositionScope scope(reader);
1287
1288 ForInStatement* forinstmt = new ForInStatement();
1289 forinstmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1290 forinstmt->is_async_ = is_async;
1291 forinstmt->position_ = reader->ReadPosition();
1292 forinstmt->variable_ = VariableDeclaration::ReadFromImpl(reader, false);
1293 forinstmt->iterable_ = Expression::ReadFrom(reader);
1294 forinstmt->body_ = Statement::ReadFrom(reader);
1295 forinstmt->end_position_ = reader->max_position();
1296 if (!forinstmt->position_.IsReal()) {
1297 forinstmt->position_ = reader->min_position();
1298 }
1299 forinstmt->variable_->set_end_position(forinstmt->position_);
1300
1301 return forinstmt;
1302 }
1303
1304
1305 SwitchStatement* SwitchStatement::ReadFrom(Reader* reader) {
1306 TRACE_READ_OFFSET();
1307 SwitchStatement* stmt = new SwitchStatement();
1308 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1309 stmt->condition_ = Expression::ReadFrom(reader);
1310 int count = reader->ReadUInt();
1311 stmt->cases_.EnsureInitialized(count);
1312 for (intptr_t i = 0; i < count; i++) {
1313 SwitchCase* sc = stmt->cases_.GetOrCreate<SwitchCase>(i);
1314 sc->ReadFrom(reader);
1315 }
1316
1317 return stmt;
1318 }
1319
1320
1321 SwitchCase* SwitchCase::ReadFrom(Reader* reader) {
1322 TRACE_READ_OFFSET();
1323 int length = reader->ReadListLength();
1324 expressions_.EnsureInitialized(length);
1325
1326 for (intptr_t i = 0; i < length; i++) {
1327 ASSERT(expressions_[i] == NULL);
1328 TokenPosition position = reader->ReadPosition();
1329 expressions_[i] = Expression::ReadFrom(reader);
1330 expressions_[i]->set_position(position);
1331 }
1332 is_default_ = reader->ReadBool();
1333 body_ = Statement::ReadFrom(reader);
1334
1335 return this;
1336 }
1337
1338
1339 ContinueSwitchStatement* ContinueSwitchStatement::ReadFrom(Reader* reader) {
1340 TRACE_READ_OFFSET();
1341 ContinueSwitchStatement* stmt = new ContinueSwitchStatement();
1342 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1343 stmt->target_index_ = reader->ReadUInt();
1344
1345 return stmt;
1346 }
1347
1348
1349 IfStatement* IfStatement::ReadFrom(Reader* reader) {
1350 TRACE_READ_OFFSET();
1351 IfStatement* ifstmt = new IfStatement();
1352 ifstmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1353 ifstmt->condition_ = Expression::ReadFrom(reader);
1354 ifstmt->then_ = Statement::ReadFrom(reader);
1355 ifstmt->otherwise_ = Statement::ReadFrom(reader);
1356
1357 return ifstmt;
1358 }
1359
1360
1361 ReturnStatement* ReturnStatement::ReadFrom(Reader* reader) {
1362 TRACE_READ_OFFSET();
1363 ReturnStatement* ret = new ReturnStatement();
1364 ret->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1365 ret->position_ = reader->ReadPosition();
1366 ret->expression_ = reader->ReadOptional<Expression>();
1367
1368 return ret;
1369 }
1370
1371
1372 TryCatch* TryCatch::ReadFrom(Reader* reader) {
1373 TRACE_READ_OFFSET();
1374 PositionScope scope(reader);
1375
1376 TryCatch* tc = new TryCatch();
1377 tc->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1378 tc->body_ = Statement::ReadFrom(reader);
1379 reader->ReadBool(); // whether any catch needs a stacktrace.
1380 tc->catches_.ReadFromStatic<Catch>(reader);
1381 tc->position_ = reader->min_position();
1382
1383 return tc;
1384 }
1385
1386
1387 Catch* Catch::ReadFrom(Reader* reader) {
1388 TRACE_READ_OFFSET();
1389 VariableScope<ReaderHelper> vars(reader->helper());
1390 PositionScope scope(reader);
1391
1392 Catch* c = new Catch();
1393 c->kernel_offset_ = reader->offset(); // Catch has no tag.
1394 c->guard_ = DartType::ReadFrom(reader);
1395 c->exception_ =
1396 reader->ReadOptional<VariableDeclaration, VariableDeclarationImpl>();
1397 c->stack_trace_ =
1398 reader->ReadOptional<VariableDeclaration, VariableDeclarationImpl>();
1399 c->body_ = Statement::ReadFrom(reader);
1400 c->end_position_ = reader->max_position();
1401 c->position_ = reader->min_position();
1402
1403 return c;
1404 }
1405
1406
1407 TryFinally* TryFinally::ReadFrom(Reader* reader) {
1408 TRACE_READ_OFFSET();
1409 TryFinally* tf = new TryFinally();
1410 tf->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1411 tf->body_ = Statement::ReadFrom(reader);
1412 tf->finalizer_ = Statement::ReadFrom(reader);
1413
1414 return tf;
1415 }
1416
1417
1418 YieldStatement* YieldStatement::ReadFrom(Reader* reader) {
1419 TRACE_READ_OFFSET();
1420 YieldStatement* stmt = new YieldStatement();
1421 stmt->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1422 stmt->position_ = reader->ReadPosition();
1423 reader->record_yield_token_position(stmt->position_);
1424 stmt->flags_ = reader->ReadByte();
1425 stmt->expression_ = Expression::ReadFrom(reader);
1426
1427 return stmt;
1428 }
1429
1430
1431 VariableDeclaration* VariableDeclaration::ReadFrom(Reader* reader) {
1432 TRACE_READ_OFFSET();
1433 Tag tag = reader->ReadTag();
1434 ASSERT(tag == kVariableDeclaration);
1435 return VariableDeclaration::ReadFromImpl(reader, true);
1436 }
1437
1438
1439 VariableDeclaration* VariableDeclaration::ReadFromImpl(Reader* reader,
1440 bool read_tag) {
1441 TRACE_READ_OFFSET();
1442 PositionScope scope(reader);
1443
1444 VariableDeclaration* decl = new VariableDeclaration();
1445 // -1 or -0 depending on whether there's a tag or not.
1446 decl->kernel_offset_ = reader->offset() - (read_tag ? 1 : 0);
1447 decl->kernel_offset_no_tag_ = reader->offset();
1448 decl->position_ = reader->ReadPosition();
1449 decl->equals_position_ = reader->ReadPosition();
1450 decl->flags_ = reader->ReadFlags();
1451 decl->name_index_ = StringIndex(reader->ReadUInt());
1452 decl->type_ = DartType::ReadFrom(reader);
1453 decl->initializer_ = reader->ReadOptional<Expression>();
1454
1455 // Go to next token position so it ends *after* the last potentially
1456 // debuggable position in the initializer.
1457 TokenPosition position = reader->max_position();
1458 if (position.IsReal()) position.Next();
1459 decl->end_position_ = position;
1460 reader->helper()->variables().Push(decl);
1461
1462 return decl;
1463 }
1464
1465
1466 FunctionDeclaration* FunctionDeclaration::ReadFrom(Reader* reader) {
1467 TRACE_READ_OFFSET();
1468 FunctionDeclaration* decl = new FunctionDeclaration();
1469 decl->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
1470 decl->position_ = reader->ReadPosition();
1471 decl->variable_ = VariableDeclaration::ReadFromImpl(reader, false);
1472 VariableScope<ReaderHelper> parameters(reader->helper());
1473 decl->function_ = FunctionNode::ReadFrom(reader);
1474
1475 return decl;
1476 }
1477
1478
1479 Name* Name::ReadFrom(Reader* reader) {
1480 StringIndex name_index(reader->ReadUInt());
1481 if ((reader->StringLength(name_index) >= 1) &&
1482 (reader->CharacterAt(name_index, 0) == '_')) {
1483 intptr_t library_reference = reader->ReadCanonicalNameReference();
1484 return new Name(name_index, library_reference);
1485 } else {
1486 return new Name(name_index, NULL);
1487 }
1488 }
1489
1490
1491 DartType* DartType::ReadFrom(Reader* reader) {
1492 TRACE_READ_OFFSET();
1493 Tag tag = reader->ReadTag();
1494 switch (tag) {
1495 case kInvalidType:
1496 return InvalidType::ReadFrom(reader);
1497 case kDynamicType:
1498 return DynamicType::ReadFrom(reader);
1499 case kVoidType:
1500 return VoidType::ReadFrom(reader);
1501 case kBottomType:
1502 return BottomType::ReadFrom(reader);
1503 case kInterfaceType:
1504 return InterfaceType::ReadFrom(reader);
1505 case kSimpleInterfaceType:
1506 return InterfaceType::ReadFrom(reader, true);
1507 case kFunctionType:
1508 return FunctionType::ReadFrom(reader);
1509 case kSimpleFunctionType:
1510 return FunctionType::ReadFrom(reader, true);
1511 case kTypeParameterType:
1512 return TypeParameterType::ReadFrom(reader);
1513 case kVectorType:
1514 return VectorType::ReadFrom(reader);
1515 case kTypedefType:
1516 return TypedefType::ReadFrom(reader);
1517 default:
1518 UNREACHABLE();
1519 }
1520 UNREACHABLE();
1521 return NULL;
1522 }
1523
1524
1525 InvalidType* InvalidType::ReadFrom(Reader* reader) {
1526 TRACE_READ_OFFSET();
1527 return new InvalidType();
1528 }
1529
1530
1531 DynamicType* DynamicType::ReadFrom(Reader* reader) {
1532 TRACE_READ_OFFSET();
1533 return new DynamicType();
1534 }
1535
1536
1537 VoidType* VoidType::ReadFrom(Reader* reader) {
1538 TRACE_READ_OFFSET();
1539 return new VoidType();
1540 }
1541
1542
1543 BottomType* BottomType::ReadFrom(Reader* reader) {
1544 TRACE_READ_OFFSET();
1545 return new BottomType();
1546 }
1547
1548
1549 InterfaceType* InterfaceType::ReadFrom(Reader* reader) {
1550 TRACE_READ_OFFSET();
1551 NameIndex klass_name = Reference::ReadClassFrom(reader);
1552 InterfaceType* type = new InterfaceType(klass_name);
1553 type->type_arguments().ReadFromStatic<DartType>(reader);
1554 return type;
1555 }
1556
1557
1558 InterfaceType* InterfaceType::ReadFrom(Reader* reader,
1559 bool _without_type_arguments_) {
1560 TRACE_READ_OFFSET();
1561 NameIndex klass_name = Reference::ReadClassFrom(reader);
1562 InterfaceType* type = new InterfaceType(klass_name);
1563 ASSERT(_without_type_arguments_);
1564 return type;
1565 }
1566
1567
1568 TypedefType* TypedefType::ReadFrom(Reader* reader) {
1569 TRACE_READ_OFFSET();
1570 NameIndex typedef_name = Reference::ReadTypedefFrom(reader);
1571 TypedefType* type = new TypedefType(typedef_name);
1572 type->type_arguments().ReadFromStatic<DartType>(reader);
1573 return type;
1574 }
1575
1576
1577 FunctionType* FunctionType::ReadFrom(Reader* reader) {
1578 TRACE_READ_OFFSET();
1579 FunctionType* type = new FunctionType();
1580 TypeParameterScope<ReaderHelper> scope(reader->helper());
1581 type->type_parameters().ReadFrom(reader);
1582 type->required_parameter_count_ = reader->ReadUInt();
1583 intptr_t total_parameter_count = reader->ReadUInt();
1584 type->positional_parameters().ReadFromStatic<DartType>(reader);
1585 type->named_parameters().ReadFromStatic<NamedParameter>(reader);
1586 ASSERT(type->positional_parameters().length() +
1587 type->named_parameters().length() ==
1588 total_parameter_count);
1589 type->return_type_ = DartType::ReadFrom(reader);
1590 return type;
1591 }
1592
1593
1594 FunctionType* FunctionType::ReadFrom(Reader* reader, bool _is_simple_) {
1595 TRACE_READ_OFFSET();
1596 FunctionType* type = new FunctionType();
1597 ASSERT(_is_simple_);
1598 type->positional_parameters().ReadFromStatic<DartType>(reader);
1599 type->required_parameter_count_ = type->positional_parameters().length();
1600 type->return_type_ = DartType::ReadFrom(reader);
1601 return type;
1602 }
1603
1604
1605 TypeParameterType* TypeParameterType::ReadFrom(Reader* reader) {
1606 TRACE_READ_OFFSET();
1607 TypeParameterType* type = new TypeParameterType();
1608 type->parameter_ =
1609 reader->helper()->type_parameters().Lookup(reader->ReadUInt());
1610 reader->ReadUInt(); // binary offset of parameter list
1611 reader->ReadUInt(); // index of parameter
1612 // There is an optional promoted bound, currently ignored.
1613 delete reader->ReadOptional<DartType>();
1614 return type;
1615 }
1616
1617
1618 VectorType* VectorType::ReadFrom(Reader* reader) {
1619 TRACE_READ_OFFSET();
1620 VectorType* type = new VectorType();
1621 return type;
1622 }
1623
1624
1625 Program* Program::ReadFrom(Reader* reader) { 20 Program* Program::ReadFrom(Reader* reader) {
1626 TRACE_READ_OFFSET();
1627 uint32_t magic = reader->ReadUInt32(); 21 uint32_t magic = reader->ReadUInt32();
1628 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier"); 22 if (magic != kMagicProgramFile) FATAL("Invalid magic identifier");
1629 23
1630 Program* program = new Program(); 24 Program* program = new Program();
1631 reader->helper()->set_program(program); 25 program->kernel_data_ = reader->buffer();
26 program->kernel_data_size_ = reader->size();
1632 27
1633 // Deserialize the string offset table to give fast access to the string data
1634 // during deserialization.
1635 program->string_table_offset_ = reader->offset(); 28 program->string_table_offset_ = reader->offset();
1636 intptr_t string_count = reader->ReadUInt();
1637 reader->string_offsets_ = new intptr_t[string_count + 1];
1638 intptr_t offset = 0;
1639 for (intptr_t i = 0; i < string_count; ++i) {
1640 reader->string_offsets_[i] = offset;
1641 offset = reader->ReadUInt();
1642 }
1643 reader->string_offsets_[string_count] = offset;
1644 // Skip the UTF-8 encoded strings.
1645 reader->MarkStringDataOffset();
1646 reader->Consume(offset);
1647 29
1648 program->source_table_.ReadFrom(reader); 30 // Read backwards at the end.
1649 31 reader->set_offset(reader->size() - 4);
1650 // Deserialize the canonical name table to give fast access to canonical names 32 program->library_count_ = reader->ReadUInt32();
1651 // during deserialization. 33 reader->set_offset(reader->size() - 4 - 4 * program->library_count_ - 2 * 4);
1652 program->name_table_offset_ = reader->offset(); 34 program->name_table_offset_ = reader->ReadUInt32();
1653 intptr_t name_count = reader->ReadUInt(); 35 program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1);
1654 reader->canonical_name_parents_ = new NameIndex[name_count];
1655 reader->canonical_name_strings_ = new StringIndex[name_count];
1656 for (int i = 0; i < name_count; ++i) {
1657 // The parent name index is biased: 0 is the root name and otherwise N+1 is
1658 // the Nth name.
1659 reader->canonical_name_parents_[i] = reader->ReadCanonicalNameReference();
1660 reader->canonical_name_strings_[i] = StringIndex(reader->ReadUInt());
1661 }
1662
1663 int libraries = reader->ReadUInt();
1664 program->libraries().EnsureInitialized(libraries);
1665 for (intptr_t i = 0; i < libraries; i++) {
1666 program->libraries().GetOrCreate<Library>(i)->ReadFrom(reader);
1667 }
1668
1669 program->main_method_reference_ =
1670 Reference::ReadMemberFrom(reader, /*allow_null=*/true);
1671 36
1672 return program; 37 return program;
1673 } 38 }
1674 39
1675 40
1676 FunctionNode* FunctionNode::ReadFrom(Reader* reader) {
1677 TRACE_READ_OFFSET();
1678 TypeParameterScope<ReaderHelper> scope(reader->helper());
1679
1680 FunctionNode* function = new FunctionNode();
1681 // FunctionNode tag not read yet.
1682 function->kernel_offset_ = reader->offset();
1683 Tag tag = reader->ReadTag();
1684 ASSERT(tag == kFunctionNode);
1685 function->position_ = reader->ReadPosition();
1686 function->end_position_ = reader->ReadPosition();
1687 function->async_marker_ =
1688 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte());
1689 function->dart_async_marker_ =
1690 static_cast<FunctionNode::AsyncMarker>(reader->ReadByte());
1691 function->type_parameters().ReadFrom(reader);
1692 reader->ReadUInt(); // total parameter count.
1693 function->required_parameter_count_ = reader->ReadUInt();
1694 function->positional_parameters().ReadFromStatic<VariableDeclarationImpl>(
1695 reader);
1696 function->named_parameters().ReadFromStatic<VariableDeclarationImpl>(reader);
1697 function->return_type_ = DartType::ReadFrom(reader);
1698
1699 LabelScope<ReaderHelper, BlockStack<LabeledStatement> > labels(
1700 reader->helper());
1701 VariableScope<ReaderHelper> vars(reader->helper());
1702 function->body_ = reader->ReadOptional<Statement>();
1703
1704 return function;
1705 }
1706
1707
1708 TypeParameter* TypeParameter::ReadFrom(Reader* reader) {
1709 TRACE_READ_OFFSET();
1710 kernel_offset_ = reader->offset();
1711 name_index_ = StringIndex(reader->ReadUInt());
1712 bound_ = DartType::ReadFrom(reader);
1713 return this;
1714 }
1715
1716
1717 } // namespace kernel 41 } // namespace kernel
1718 42
1719 43
1720 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 44 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
1721 intptr_t buffer_length) { 45 intptr_t buffer_length) {
1722 kernel::Reader reader(buffer, buffer_length); 46 kernel::Reader reader(buffer, buffer_length);
1723 return kernel::Program::ReadFrom(&reader); 47 return kernel::Program::ReadFrom(&reader);
1724 } 48 }
1725 49
1726 50
1727 } // namespace dart 51 } // namespace dart
1728 #endif // !defined(DART_PRECOMPILED_RUNTIME) 52 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_binary.h ('k') | runtime/vm/kernel_binary_flowgraph.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698