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

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

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/bootstrap_nocore.cc ('k') | runtime/vm/kernel.cc » ('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 4
5 #ifndef RUNTIME_VM_KERNEL_H_ 5 #ifndef RUNTIME_VM_KERNEL_H_
6 #define RUNTIME_VM_KERNEL_H_ 6 #define RUNTIME_VM_KERNEL_H_
7 7
8 #if !defined(DART_PRECOMPILED_RUNTIME) 8 #if !defined(DART_PRECOMPILED_RUNTIME)
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
11 #include "vm/globals.h" 11 #include "vm/globals.h"
12 #include "vm/growable_array.h" 12 #include "vm/growable_array.h"
13 #include "vm/token_position.h" 13 #include "vm/token_position.h"
14 14
15 15
16 #define KERNEL_NODES_DO(M) \
17 M(Name) \
18 M(DartType) \
19 M(InvalidType) \
20 M(DynamicType) \
21 M(VoidType) \
22 M(BottomType) \
23 M(InterfaceType) \
24 M(FunctionType) \
25 M(TypeParameterType) \
26 M(VectorType) \
27 M(TypedefType)
28
29 #define KERNEL_TREE_NODES_DO(M) \
30 M(Library) \
31 M(Typedef) \
32 M(Class) \
33 M(NormalClass) \
34 M(MixinClass) \
35 M(Member) \
36 M(Field) \
37 M(Constructor) \
38 M(Procedure) \
39 M(Initializer) \
40 M(InvalidInitializer) \
41 M(FieldInitializer) \
42 M(SuperInitializer) \
43 M(RedirectingInitializer) \
44 M(LocalInitializer) \
45 M(FunctionNode) \
46 M(Expression) \
47 M(InvalidExpression) \
48 M(VariableGet) \
49 M(VariableSet) \
50 M(PropertyGet) \
51 M(PropertySet) \
52 M(DirectPropertyGet) \
53 M(DirectPropertySet) \
54 M(StaticGet) \
55 M(StaticSet) \
56 M(Arguments) \
57 M(NamedExpression) \
58 M(MethodInvocation) \
59 M(DirectMethodInvocation) \
60 M(StaticInvocation) \
61 M(ConstructorInvocation) \
62 M(Not) \
63 M(LogicalExpression) \
64 M(ConditionalExpression) \
65 M(StringConcatenation) \
66 M(IsExpression) \
67 M(AsExpression) \
68 M(BasicLiteral) \
69 M(StringLiteral) \
70 M(BigintLiteral) \
71 M(IntLiteral) \
72 M(DoubleLiteral) \
73 M(BoolLiteral) \
74 M(NullLiteral) \
75 M(SymbolLiteral) \
76 M(TypeLiteral) \
77 M(ThisExpression) \
78 M(Rethrow) \
79 M(Throw) \
80 M(ListLiteral) \
81 M(MapLiteral) \
82 M(MapEntry) \
83 M(AwaitExpression) \
84 M(FunctionExpression) \
85 M(Let) \
86 M(VectorCreation) \
87 M(VectorGet) \
88 M(VectorSet) \
89 M(VectorCopy) \
90 M(ClosureCreation) \
91 M(Statement) \
92 M(InvalidStatement) \
93 M(ExpressionStatement) \
94 M(Block) \
95 M(EmptyStatement) \
96 M(AssertStatement) \
97 M(LabeledStatement) \
98 M(BreakStatement) \
99 M(WhileStatement) \
100 M(DoStatement) \
101 M(ForStatement) \
102 M(ForInStatement) \
103 M(SwitchStatement) \
104 M(SwitchCase) \
105 M(ContinueSwitchStatement) \
106 M(IfStatement) \
107 M(ReturnStatement) \
108 M(TryCatch) \
109 M(Catch) \
110 M(TryFinally) \
111 M(YieldStatement) \
112 M(VariableDeclaration) \
113 M(FunctionDeclaration) \
114 M(TypeParameter) \
115 M(Program)
116
117 #define KERNEL_ALL_NODES_DO(M) \
118 M(Node) \
119 KERNEL_NODES_DO(M) \
120 M(TreeNode) \
121 KERNEL_TREE_NODES_DO(M)
122
123 namespace dart { 16 namespace dart {
124 17
125 class Field; 18 class Field;
126 class ParsedFunction; 19 class ParsedFunction;
127 class Zone; 20 class Zone;
128 21
129 namespace kernel { 22 namespace kernel {
130 23
131 24
132 class Reader; 25 class Reader;
133 class TreeNode;
134 class TypeParameter;
135
136 // Boxes a value of type `T*` and `delete`s it on destruction.
137 template <typename T>
138 class Child {
139 public:
140 Child() : pointer_(NULL) {}
141 explicit Child(T* value) : pointer_(value) {}
142
143 ~Child() { delete pointer_; }
144
145 // Support `Child<T> box = T* obj`.
146 T*& operator=(T* value) {
147 ASSERT(pointer_ == NULL);
148 return pointer_ = value;
149 }
150
151 // Implicitly convert `Child<T>` to `T*`.
152 operator T*&() { return pointer_; }
153
154 T* operator->() { return pointer_; }
155
156 private:
157 T* pointer_;
158 };
159
160 // Boxes a value of type `T*` (only used to mark a member as a weak reference).
161 template <typename T>
162 class Ref {
163 public:
164 Ref() : pointer_(NULL) {}
165 explicit Ref(T* value) : pointer_(value) {}
166
167 // Support `Ref<T> box = T* obj`.
168 T*& operator=(T* value) {
169 ASSERT(pointer_ == NULL);
170 return pointer_ = value;
171 }
172
173 // Implicitly convert `Ref<T>` to `T*`.
174 operator T*&() { return pointer_; }
175
176 T* operator->() { return pointer_; }
177
178 private:
179 T* pointer_;
180 };
181
182
183 // A list of pointers that are each deleted when the list is destroyed.
184 template <typename T>
185 class List {
186 public:
187 List() : array_(NULL), length_(0) {}
188 ~List();
189
190 template <typename IT>
191 void ReadFrom(Reader* reader);
192
193 template <typename IT>
194 void ReadFrom(Reader* reader, TreeNode* parent);
195
196 template <typename IT>
197 void ReadFromStatic(Reader* reader);
198
199 // Extends the array to at least be able to hold [length] elements.
200 //
201 // Free places will be filled with `NULL` values.
202 void EnsureInitialized(int length);
203
204 // Returns element at [index].
205 //
206 // If the array is not big enough, it will be grown via `EnsureInitialized`.
207 // If the element doesn't exist, it will be created via `new IT()`.
208 template <typename IT>
209 IT* GetOrCreate(int index);
210
211 template <typename IT, typename PT>
212 IT* GetOrCreate(int index, PT* parent);
213
214 // Returns element at [index].
215 T*& operator[](int index) {
216 ASSERT(index < length_);
217 return array_[index];
218 }
219
220 int length() { return length_; }
221
222 T** raw_array() { return array_; }
223
224 bool CanStream() {
225 for (intptr_t i = 0; i < length_; ++i) {
226 if (!array_[i]->can_stream()) return false;
227 }
228 return true;
229 }
230
231 private:
232 T** array_;
233 int length_;
234
235 DISALLOW_COPY_AND_ASSIGN(List);
236 };
237
238
239 // A list that cannot be resized and which, unlike List<T>, does not enforce
240 // its members to be pointers and does not `delete` its members on destruction.
241 template <typename T>
242 class RawList {
243 public:
244 RawList() : pointer_(NULL) {}
245
246 ~RawList() {
247 if (pointer_ != NULL) {
248 delete[] pointer_;
249 }
250 }
251
252 void Initialize(int length) {
253 ASSERT(pointer_ == NULL);
254 pointer_ = new T[length];
255 length_ = length;
256 }
257
258 T& operator[](int index) { return pointer_[index]; }
259
260 int length() { return length_; }
261
262 private:
263 int length_;
264 T* pointer_;
265
266 DISALLOW_COPY_AND_ASSIGN(RawList);
267 };
268
269
270 class TypeParameterList : public List<TypeParameter> {
271 public:
272 void ReadFrom(Reader* reader);
273 TypeParameterList() : first_offset(-1) {}
274 intptr_t first_offset;
275 };
276
277
278 class Source {
279 public:
280 ~Source();
281
282 private:
283 uint8_t* uri_; // UTF-8 encoded.
284 intptr_t uri_size_; // In bytes.
285 uint8_t* source_code_; // UTF-8 encoded.
286 intptr_t source_code_size_; // In bytes.
287 intptr_t* line_starts_;
288 intptr_t line_count_;
289
290 friend class SourceTable;
291 };
292
293
294 class SourceTable {
295 public:
296 ~SourceTable();
297
298 void ReadFrom(Reader* reader);
299
300 intptr_t size() { return size_; }
301
302 uint8_t* UriFor(intptr_t i) { return sources_[i].uri_; }
303 intptr_t UriSizeFor(intptr_t i) { return sources_[i].uri_size_; }
304
305 uint8_t* SourceCodeFor(intptr_t i) { return sources_[i].source_code_; }
306 intptr_t SourceCodeSizeFor(intptr_t i) {
307 return sources_[i].source_code_size_;
308 }
309
310 intptr_t* LineStartsFor(intptr_t i) { return sources_[i].line_starts_; }
311 intptr_t LineCountFor(intptr_t i) { return sources_[i].line_count_; }
312
313 private:
314 SourceTable() : size_(0), sources_(NULL) {}
315
316 friend class Program;
317
318 // The number of entries in the table.
319 intptr_t size_;
320
321 // An array of sources.
322 Source* sources_;
323
324 DISALLOW_COPY_AND_ASSIGN(SourceTable);
325 };
326 26
327 27
328 class StringIndex { 28 class StringIndex {
329 public: 29 public:
330 StringIndex() : value_(-1) {} 30 StringIndex() : value_(-1) {}
331 explicit StringIndex(int value) : value_(value) {} 31 explicit StringIndex(int value) : value_(value) {}
332 32
333 operator int() const { return value_; } 33 operator int() const { return value_; }
334 34
335 private: 35 private:
336 int value_; 36 int value_;
337 }; 37 };
338 38
339 39
340 class NameIndex { 40 class NameIndex {
341 public: 41 public:
342 NameIndex() : value_(-1) {} 42 NameIndex() : value_(-1) {}
343 explicit NameIndex(int value) : value_(value) {} 43 explicit NameIndex(int value) : value_(value) {}
344 44
345 operator int() const { return value_; } 45 operator int() const { return value_; }
346 46
347 private: 47 private:
348 int value_; 48 int value_;
349 }; 49 };
350 50
351 51
352 // Forward declare all classes. 52 class Field {
353 #define DO(name) class name;
354 KERNEL_ALL_NODES_DO(DO)
355 #undef DO
356
357
358 #define DEFINE_CASTING_OPERATIONS(klass) \
359 virtual bool Is##klass() { return true; } \
360 \
361 static klass* Cast(Node* node) { \
362 ASSERT(node == NULL || node->Is##klass()); \
363 return static_cast<klass*>(node); \
364 } \
365 \
366 virtual Node::NodeType Type() { return Node::kType##klass; }
367
368 #define DEFINE_IS_OPERATION(klass) \
369 virtual bool Is##klass() { return false; }
370
371 #define DEFINE_ALL_IS_OPERATIONS() \
372 KERNEL_NODES_DO(DEFINE_IS_OPERATION) \
373 DEFINE_IS_OPERATION(TreeNode) \
374 KERNEL_TREE_NODES_DO(DEFINE_IS_OPERATION)
375
376 class Typedef;
377 class Class;
378 class Constructor;
379 class Field;
380 class Library;
381 class LibraryDependency;
382 class Combinator;
383 class LinkedNode;
384 class Member;
385 class Procedure;
386
387 class Node {
388 public:
389 virtual ~Node();
390
391 enum NodeType {
392 #define DO(name) kType##name,
393 KERNEL_ALL_NODES_DO(DO)
394 #undef DO
395
396 kNumTypes
397 };
398
399 DEFINE_ALL_IS_OPERATIONS();
400 DEFINE_CASTING_OPERATIONS(Node);
401
402 protected:
403 Node() {}
404
405 private:
406 DISALLOW_COPY_AND_ASSIGN(Node);
407 };
408
409
410 class TreeNode : public Node {
411 public:
412 virtual ~TreeNode();
413
414 DEFINE_CASTING_OPERATIONS(TreeNode);
415
416 intptr_t kernel_offset() const {
417 ASSERT(kernel_offset_ > 0);
418 return kernel_offset_;
419 }
420
421 protected:
422 TreeNode() : kernel_offset_(-1) {}
423
424 // Offset for this node in the kernel-binary. If this node has a tag the
425 // offset includes the tag. Can be -1 to indicate "unknown" or invalid offset.
426 intptr_t kernel_offset_;
427
428 private:
429 DISALLOW_COPY_AND_ASSIGN(TreeNode);
430 };
431
432
433 class LinkedNode : public TreeNode {
434 public:
435 virtual ~LinkedNode();
436
437 NameIndex canonical_name() { return canonical_name_; }
438
439 protected:
440 LinkedNode() {}
441
442 NameIndex canonical_name_;
443
444 private:
445 DISALLOW_COPY_AND_ASSIGN(LinkedNode);
446 };
447
448
449 class Library : public LinkedNode {
450 public:
451 Library* ReadFrom(Reader* reader);
452
453 virtual ~Library();
454
455 DEFINE_CASTING_OPERATIONS(Library);
456
457 StringIndex import_uri() { return import_uri_index_; }
458 intptr_t source_uri_index() { return source_uri_index_; }
459 StringIndex name() { return name_index_; }
460 List<Expression>& annotations() { return annotations_; }
461 List<LibraryDependency>& dependencies() { return dependency_; }
462 List<Typedef>& typedefs() { return typedefs_; }
463 List<Class>& classes() { return classes_; }
464 List<Field>& fields() { return fields_; }
465 List<Procedure>& procedures() { return procedures_; }
466
467 const uint8_t* kernel_data() { return kernel_data_; }
468 intptr_t kernel_data_size() { return kernel_data_size_; }
469
470 private:
471 Library() : kernel_data_(NULL), kernel_data_size_(-1) {}
472
473 template <typename T>
474 friend class List;
475
476 StringIndex name_index_;
477 StringIndex import_uri_index_;
478 intptr_t source_uri_index_;
479 List<Expression> annotations_;
480 List<LibraryDependency> dependency_;
481 List<Typedef> typedefs_;
482 List<Class> classes_;
483 List<Field> fields_;
484 List<Procedure> procedures_;
485 const uint8_t* kernel_data_;
486 intptr_t kernel_data_size_;
487
488 DISALLOW_COPY_AND_ASSIGN(Library);
489 };
490
491
492 class LibraryDependency {
493 public:
494 enum Flags {
495 kFlagExport = 1 << 0,
496 kFlagDeferred = 1 << 1,
497 };
498
499 static LibraryDependency* ReadFrom(Reader* reader);
500
501 virtual ~LibraryDependency();
502
503 bool is_export() { return (flags_ & kFlagExport) != 0; }
504 bool is_import() { return (flags_ & kFlagExport) == 0; }
505 bool is_deferred() { return (flags_ & kFlagDeferred) != 0; }
506 List<Expression>& annotations() { return annotations_; }
507 NameIndex target() { return target_reference_; }
508 StringIndex name() { return name_index_; }
509
510 private:
511 LibraryDependency() {}
512
513 word flags_;
514 List<Expression> annotations_;
515 NameIndex target_reference_;
516 StringIndex name_index_;
517 List<Combinator> combinators_;
518
519 DISALLOW_COPY_AND_ASSIGN(LibraryDependency);
520 };
521
522
523 class Combinator {
524 public:
525 static Combinator* ReadFrom(Reader* reader);
526
527 virtual ~Combinator();
528
529 bool is_show() { return is_show_; }
530 RawList<intptr_t>& names() { return name_indices_; }
531
532 private:
533 Combinator() {}
534
535 bool is_show_;
536 RawList<intptr_t> name_indices_;
537
538 DISALLOW_COPY_AND_ASSIGN(Combinator);
539 };
540
541
542 class Typedef : public LinkedNode {
543 public:
544 Typedef* ReadFrom(Reader* reader);
545
546 virtual ~Typedef();
547
548 DEFINE_CASTING_OPERATIONS(Typedef);
549
550 Library* parent() { return parent_; }
551 StringIndex name() { return name_index_; }
552 intptr_t source_uri_index() { return source_uri_index_; }
553 TokenPosition position() { return position_; }
554 TypeParameterList& type_parameters() { return type_parameters_; }
555 DartType* type() { return type_; }
556
557 protected:
558 Typedef() : position_(TokenPosition::kNoSource) {}
559
560 private:
561 template <typename T>
562 friend class List;
563
564 StringIndex name_index_;
565 Ref<Library> parent_;
566 intptr_t source_uri_index_;
567 TokenPosition position_;
568 TypeParameterList type_parameters_;
569 Child<DartType> type_;
570 };
571
572
573 class Class : public LinkedNode {
574 public:
575 Class* ReadFrom(Reader* reader);
576
577 virtual ~Class();
578
579 DEFINE_CASTING_OPERATIONS(Class);
580
581 Library* parent() { return parent_; }
582 StringIndex name() { return name_index_; }
583 intptr_t source_uri_index() { return source_uri_index_; }
584 bool is_abstract() { return is_abstract_; }
585 List<Expression>& annotations() { return annotations_; }
586 TokenPosition position() { return position_; }
587
588 virtual List<TypeParameter>& type_parameters() = 0;
589 virtual List<InterfaceType>& implemented_classes() = 0;
590 virtual List<Field>& fields() = 0;
591 virtual List<Constructor>& constructors() = 0;
592 virtual List<Procedure>& procedures() = 0;
593
594 protected:
595 Class() : is_abstract_(false), position_(TokenPosition::kNoSource) {}
596
597 private:
598 template <typename T>
599 friend class List;
600
601 StringIndex name_index_;
602 Ref<Library> parent_;
603 intptr_t source_uri_index_;
604 bool is_abstract_;
605 List<Expression> annotations_;
606 TokenPosition position_;
607
608 DISALLOW_COPY_AND_ASSIGN(Class);
609 };
610
611
612 class NormalClass : public Class {
613 public:
614 NormalClass* ReadFrom(Reader* reader);
615
616 virtual ~NormalClass();
617
618 DEFINE_CASTING_OPERATIONS(NormalClass);
619
620 virtual TypeParameterList& type_parameters() { return type_parameters_; }
621 InterfaceType* super_class() { return super_class_; }
622 virtual List<InterfaceType>& implemented_classes() {
623 return implemented_classes_;
624 }
625 virtual List<Constructor>& constructors() { return constructors_; }
626 virtual List<Procedure>& procedures() { return procedures_; }
627 virtual List<Field>& fields() { return fields_; }
628
629 private:
630 NormalClass() {}
631
632 template <typename T>
633 friend class List;
634
635 TypeParameterList type_parameters_;
636 Child<InterfaceType> super_class_;
637 List<InterfaceType> implemented_classes_;
638 List<Constructor> constructors_;
639 List<Procedure> procedures_;
640 List<Field> fields_;
641
642 DISALLOW_COPY_AND_ASSIGN(NormalClass);
643 };
644
645
646 class Member : public LinkedNode {
647 public:
648 virtual ~Member();
649
650 DEFINE_CASTING_OPERATIONS(Member);
651
652 TreeNode* parent() { return parent_; }
653 Name* name() { return name_; }
654 List<Expression>& annotations() { return annotations_; }
655 TokenPosition position() { return position_; }
656 TokenPosition end_position() { return end_position_; }
657
658 protected:
659 Member()
660 : position_(TokenPosition::kNoSource),
661 end_position_(TokenPosition::kNoSource) {}
662
663 template <typename T>
664 friend class List;
665
666 Ref<TreeNode> parent_;
667 Child<Name> name_;
668 List<Expression> annotations_;
669 TokenPosition position_;
670 TokenPosition end_position_;
671
672 private:
673 DISALLOW_COPY_AND_ASSIGN(Member);
674 };
675
676
677 class Field : public Member {
678 public: 53 public:
679 enum Flags { 54 enum Flags {
680 kFlagFinal = 1 << 0, 55 kFlagFinal = 1 << 0,
681 kFlagConst = 1 << 1, 56 kFlagConst = 1 << 1,
682 kFlagStatic = 1 << 2, 57 kFlagStatic = 1 << 2,
683 }; 58 };
684
685 Field* ReadFrom(Reader* reader);
686
687 virtual ~Field();
688
689 DEFINE_CASTING_OPERATIONS(Field);
690
691 bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
692 bool IsFinal() { return (flags_ & kFlagFinal) == kFlagFinal; }
693 bool IsStatic() { return (flags_ & kFlagStatic) == kFlagStatic; }
694 intptr_t source_uri_index() { return source_uri_index_; }
695
696 DartType* type() { return type_; }
697 Expression* initializer() { return initializer_; }
698
699 private:
700 Field() {}
701
702 template <typename T>
703 friend class List;
704
705 word flags_;
706 intptr_t source_uri_index_;
707 Child<DartType> type_;
708 Child<Expression> initializer_;
709
710 DISALLOW_COPY_AND_ASSIGN(Field);
711 }; 59 };
712 60
713 61
714 class Constructor : public Member { 62 class Constructor {
715 public: 63 public:
716 enum Flags { 64 enum Flags {
717 kFlagConst = 1 << 0, 65 kFlagConst = 1 << 0,
718 kFlagExternal = 1 << 1, 66 kFlagExternal = 1 << 1,
719 }; 67 };
720
721 Constructor* ReadFrom(Reader* reader);
722
723 virtual ~Constructor();
724
725 DEFINE_CASTING_OPERATIONS(Constructor);
726
727 bool IsExternal() { return (flags_ & kFlagExternal) == kFlagExternal; }
728 bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
729
730 FunctionNode* function() { return function_; }
731 List<Initializer>& initializers() { return initializers_; }
732
733 private:
734 template <typename T>
735 friend class List;
736
737 Constructor() {}
738
739 uint8_t flags_;
740 Child<FunctionNode> function_;
741 List<Initializer> initializers_;
742
743 DISALLOW_COPY_AND_ASSIGN(Constructor);
744 }; 68 };
745 69
746 70
747 class Procedure : public Member { 71 class Procedure {
748 public: 72 public:
749 enum Flags { 73 enum Flags {
750 kFlagStatic = 1 << 0, 74 kFlagStatic = 1 << 0,
751 kFlagAbstract = 1 << 1, 75 kFlagAbstract = 1 << 1,
752 kFlagExternal = 1 << 2, 76 kFlagExternal = 1 << 2,
753 kFlagConst = 1 << 3, // Only for external const factories. 77 kFlagConst = 1 << 3, // Only for external const factories.
754 }; 78 };
755 79
756 // Keep in sync with package:dynamo/lib/ast.dart:ProcedureKind 80 // Keep in sync with package:dynamo/lib/ast.dart:ProcedureKind
757 enum ProcedureKind { 81 enum ProcedureKind {
758 kMethod, 82 kMethod,
759 kGetter, 83 kGetter,
760 kSetter, 84 kSetter,
761 kOperator, 85 kOperator,
762 kFactory, 86 kFactory,
763 87
764 kIncompleteProcedure = 255 88 kIncompleteProcedure = 255
765 }; 89 };
766
767 Procedure* ReadFrom(Reader* reader);
768
769 virtual ~Procedure();
770
771 DEFINE_CASTING_OPERATIONS(Procedure);
772
773 ProcedureKind kind() { return kind_; }
774 FunctionNode* function() { return function_; }
775
776 bool IsStatic() { return (flags_ & kFlagStatic) == kFlagStatic; }
777 bool IsAbstract() { return (flags_ & kFlagAbstract) == kFlagAbstract; }
778 bool IsExternal() { return (flags_ & kFlagExternal) == kFlagExternal; }
779 bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
780 intptr_t source_uri_index() { return source_uri_index_; }
781
782 private:
783 Procedure() : kind_(kIncompleteProcedure), flags_(0), function_(NULL) {}
784
785 template <typename T>
786 friend class List;
787
788 ProcedureKind kind_;
789 word flags_;
790 intptr_t source_uri_index_;
791 Child<FunctionNode> function_;
792
793 DISALLOW_COPY_AND_ASSIGN(Procedure);
794 }; 90 };
795 91
796 92
797 class Initializer : public TreeNode { 93 class FunctionNode {
798 public:
799 static Initializer* ReadFrom(Reader* reader);
800
801 virtual ~Initializer();
802
803 DEFINE_CASTING_OPERATIONS(Initializer);
804
805 protected:
806 Initializer() {}
807
808 private:
809 DISALLOW_COPY_AND_ASSIGN(Initializer);
810 };
811
812
813 class InvalidInitializer : public Initializer {
814 public:
815 static InvalidInitializer* ReadFromImpl(Reader* reader);
816
817 virtual ~InvalidInitializer();
818
819 DEFINE_CASTING_OPERATIONS(InvalidInitializer);
820
821 private:
822 InvalidInitializer() {}
823
824 DISALLOW_COPY_AND_ASSIGN(InvalidInitializer);
825 };
826
827
828 class FieldInitializer : public Initializer {
829 public:
830 static FieldInitializer* ReadFromImpl(Reader* reader);
831
832 virtual ~FieldInitializer();
833
834 DEFINE_CASTING_OPERATIONS(FieldInitializer);
835
836 NameIndex field() { return field_reference_; }
837 Expression* value() { return value_; }
838
839 private:
840 FieldInitializer() {}
841
842 NameIndex field_reference_; // Field canonical name.
843 Child<Expression> value_;
844
845 DISALLOW_COPY_AND_ASSIGN(FieldInitializer);
846 };
847
848
849 class SuperInitializer : public Initializer {
850 public:
851 static SuperInitializer* ReadFromImpl(Reader* reader);
852
853 virtual ~SuperInitializer();
854
855 DEFINE_CASTING_OPERATIONS(SuperInitializer);
856
857 NameIndex target() { return target_reference_; }
858 Arguments* arguments() { return arguments_; }
859
860 private:
861 SuperInitializer() {}
862
863 NameIndex target_reference_; // Constructor canonical name.
864 Child<Arguments> arguments_;
865
866 DISALLOW_COPY_AND_ASSIGN(SuperInitializer);
867 };
868
869
870 class RedirectingInitializer : public Initializer {
871 public:
872 static RedirectingInitializer* ReadFromImpl(Reader* reader);
873
874 virtual ~RedirectingInitializer();
875
876 DEFINE_CASTING_OPERATIONS(RedirectingInitializer);
877
878 NameIndex target() { return target_reference_; }
879 Arguments* arguments() { return arguments_; }
880
881 private:
882 RedirectingInitializer() {}
883
884 NameIndex target_reference_; // Constructor canonical name.
885 Child<Arguments> arguments_;
886
887 DISALLOW_COPY_AND_ASSIGN(RedirectingInitializer);
888 };
889
890
891 class LocalInitializer : public Initializer {
892 public:
893 static LocalInitializer* ReadFromImpl(Reader* reader);
894
895 virtual ~LocalInitializer();
896
897 DEFINE_CASTING_OPERATIONS(LocalInitializer);
898
899 VariableDeclaration* variable() { return variable_; }
900
901 private:
902 LocalInitializer() {}
903
904 Child<VariableDeclaration> variable_;
905
906 DISALLOW_COPY_AND_ASSIGN(LocalInitializer);
907 };
908
909
910 class FunctionNode : public TreeNode {
911 public: 94 public:
912 enum AsyncMarker { 95 enum AsyncMarker {
913 kSync = 0, 96 kSync = 0,
914 kSyncStar = 1, 97 kSyncStar = 1,
915 kAsync = 2, 98 kAsync = 2,
916 kAsyncStar = 3, 99 kAsyncStar = 3,
917 kSyncYielding = 4, 100 kSyncYielding = 4,
918 }; 101 };
919
920 static FunctionNode* ReadFrom(Reader* reader);
921
922 virtual ~FunctionNode();
923
924 DEFINE_CASTING_OPERATIONS(FunctionNode);
925
926 AsyncMarker async_marker() { return async_marker_; }
927 AsyncMarker dart_async_marker() { return dart_async_marker_; }
928 TypeParameterList& type_parameters() { return type_parameters_; }
929 int required_parameter_count() { return required_parameter_count_; }
930 List<VariableDeclaration>& positional_parameters() {
931 return positional_parameters_;
932 }
933 List<VariableDeclaration>& named_parameters() { return named_parameters_; }
934 DartType* return_type() { return return_type_; }
935
936 Statement* body() { return body_; }
937 void ReplaceBody(Statement* body);
938
939 TokenPosition position() { return position_; }
940 TokenPosition end_position() { return end_position_; }
941
942 private:
943 FunctionNode()
944 : position_(TokenPosition::kNoSource),
945 end_position_(TokenPosition::kNoSource) {}
946
947 AsyncMarker async_marker_;
948 AsyncMarker dart_async_marker_;
949 TypeParameterList type_parameters_;
950 int required_parameter_count_;
951 List<VariableDeclaration> positional_parameters_;
952 List<VariableDeclaration> named_parameters_;
953 Child<DartType> return_type_;
954 Child<Statement> body_;
955 TokenPosition position_;
956 TokenPosition end_position_;
957
958 DISALLOW_COPY_AND_ASSIGN(FunctionNode);
959 }; 102 };
960 103
961 104 class VariableDeclaration {
962 class Expression : public TreeNode {
963 public: 105 public:
964 static Expression* ReadFrom(Reader* reader); 106 enum Flags {
965 107 kFlagFinal = 1 << 0,
966 virtual ~Expression(); 108 kFlagConst = 1 << 1,
967 109 };
968 DEFINE_CASTING_OPERATIONS(Expression);
969
970 TokenPosition position() { return position_; }
971 void set_position(TokenPosition position) { position_ = position; }
972
973 protected:
974 Expression() : position_(TokenPosition::kNoSource) {}
975 TokenPosition position_;
976
977 private:
978 DISALLOW_COPY_AND_ASSIGN(Expression);
979 }; 110 };
980 111
981 112 class YieldStatement {
982 class InvalidExpression : public Expression {
983 public:
984 static InvalidExpression* ReadFrom(Reader* reader);
985
986 virtual ~InvalidExpression();
987
988 DEFINE_CASTING_OPERATIONS(InvalidExpression);
989
990 private:
991 InvalidExpression() {}
992
993 DISALLOW_COPY_AND_ASSIGN(InvalidExpression);
994 };
995
996
997 class VariableGet : public Expression {
998 public:
999 static VariableGet* ReadFrom(Reader* reader);
1000 static VariableGet* ReadFrom(Reader* reader, uint8_t payload);
1001
1002 virtual ~VariableGet();
1003
1004 DEFINE_CASTING_OPERATIONS(VariableGet);
1005
1006 VariableDeclaration* variable() { return variable_; }
1007
1008 private:
1009 VariableGet() {}
1010
1011 Ref<VariableDeclaration> variable_;
1012 intptr_t variable_kernel_offset_;
1013
1014 DISALLOW_COPY_AND_ASSIGN(VariableGet);
1015 };
1016
1017
1018 class VariableSet : public Expression {
1019 public:
1020 static VariableSet* ReadFrom(Reader* reader);
1021 static VariableSet* ReadFrom(Reader* reader, uint8_t payload);
1022
1023 virtual ~VariableSet();
1024
1025 DEFINE_CASTING_OPERATIONS(VariableSet);
1026
1027 VariableDeclaration* variable() { return variable_; }
1028 Expression* expression() { return expression_; }
1029
1030 private:
1031 VariableSet() {}
1032
1033 Ref<VariableDeclaration> variable_;
1034 intptr_t variable_kernel_offset_;
1035 Child<Expression> expression_;
1036
1037 DISALLOW_COPY_AND_ASSIGN(VariableSet);
1038 };
1039
1040
1041 class PropertyGet : public Expression {
1042 public:
1043 static PropertyGet* ReadFrom(Reader* reader);
1044
1045 virtual ~PropertyGet();
1046
1047 DEFINE_CASTING_OPERATIONS(PropertyGet);
1048
1049 Expression* receiver() { return receiver_; }
1050 Name* name() { return name_; }
1051
1052 private:
1053 PropertyGet() {}
1054
1055 NameIndex interface_target_reference_;
1056 Child<Expression> receiver_;
1057 Child<Name> name_;
1058
1059 DISALLOW_COPY_AND_ASSIGN(PropertyGet);
1060 };
1061
1062
1063 class PropertySet : public Expression {
1064 public:
1065 static PropertySet* ReadFrom(Reader* reader);
1066
1067 virtual ~PropertySet();
1068
1069 DEFINE_CASTING_OPERATIONS(PropertySet);
1070
1071 Expression* receiver() { return receiver_; }
1072 Name* name() { return name_; }
1073 Expression* value() { return value_; }
1074
1075 private:
1076 PropertySet() {}
1077
1078 NameIndex interface_target_reference_;
1079 Child<Expression> receiver_;
1080 Child<Name> name_;
1081 Child<Expression> value_;
1082
1083 DISALLOW_COPY_AND_ASSIGN(PropertySet);
1084 };
1085
1086
1087 class DirectPropertyGet : public Expression {
1088 public:
1089 static DirectPropertyGet* ReadFrom(Reader* reader);
1090
1091 virtual ~DirectPropertyGet();
1092
1093 DEFINE_CASTING_OPERATIONS(DirectPropertyGet);
1094
1095 Expression* receiver() { return receiver_; }
1096 NameIndex target() { return target_reference_; }
1097
1098 private:
1099 DirectPropertyGet() {}
1100
1101 NameIndex target_reference_; // Member canonical name.
1102 Child<Expression> receiver_;
1103
1104 DISALLOW_COPY_AND_ASSIGN(DirectPropertyGet);
1105 };
1106
1107
1108 class DirectPropertySet : public Expression {
1109 public:
1110 static DirectPropertySet* ReadFrom(Reader* reader);
1111
1112 virtual ~DirectPropertySet();
1113
1114 DEFINE_CASTING_OPERATIONS(DirectPropertySet);
1115
1116 NameIndex target() { return target_reference_; }
1117 Expression* receiver() { return receiver_; }
1118 Expression* value() { return value_; }
1119
1120 private:
1121 DirectPropertySet() {}
1122
1123 NameIndex target_reference_; // Member canonical name.
1124 Child<Expression> receiver_;
1125 Child<Expression> value_;
1126
1127 DISALLOW_COPY_AND_ASSIGN(DirectPropertySet);
1128 };
1129
1130
1131 class StaticGet : public Expression {
1132 public:
1133 static StaticGet* ReadFrom(Reader* reader);
1134
1135 virtual ~StaticGet();
1136
1137 DEFINE_CASTING_OPERATIONS(StaticGet);
1138
1139 NameIndex target() { return target_reference_; }
1140
1141 private:
1142 StaticGet() {}
1143
1144 NameIndex target_reference_; // Member canonical name.
1145
1146 DISALLOW_COPY_AND_ASSIGN(StaticGet);
1147 };
1148
1149
1150 class StaticSet : public Expression {
1151 public:
1152 static StaticSet* ReadFrom(Reader* reader);
1153
1154 virtual ~StaticSet();
1155
1156 DEFINE_CASTING_OPERATIONS(StaticSet);
1157
1158 NameIndex target() { return target_reference_; }
1159 Expression* expression() { return expression_; }
1160
1161 private:
1162 StaticSet() {}
1163
1164 NameIndex target_reference_; // Member canonical name.
1165 Child<Expression> expression_;
1166
1167 DISALLOW_COPY_AND_ASSIGN(StaticSet);
1168 };
1169
1170
1171 class Arguments : public TreeNode {
1172 public:
1173 static Arguments* ReadFrom(Reader* reader);
1174
1175 virtual ~Arguments();
1176
1177 DEFINE_CASTING_OPERATIONS(Arguments);
1178
1179
1180 // TODO(regis): Support type arguments of generic functions.
1181 List<DartType>& types() { return types_; }
1182 List<Expression>& positional() { return positional_; }
1183 List<NamedExpression>& named() { return named_; }
1184
1185 int count() { return positional_.length() + named_.length(); }
1186
1187 private:
1188 Arguments() {}
1189
1190 List<DartType> types_;
1191 List<Expression> positional_;
1192 List<NamedExpression> named_;
1193
1194 DISALLOW_COPY_AND_ASSIGN(Arguments);
1195 };
1196
1197
1198 class NamedExpression : public TreeNode {
1199 public:
1200 static NamedExpression* ReadFrom(Reader* reader);
1201
1202 NamedExpression(StringIndex name_index, Expression* expr)
1203 : name_index_(name_index), expression_(expr) {}
1204 virtual ~NamedExpression();
1205
1206 DEFINE_CASTING_OPERATIONS(NamedExpression);
1207
1208 StringIndex name() { return name_index_; }
1209 Expression* expression() { return expression_; }
1210
1211 private:
1212 NamedExpression() {}
1213
1214 StringIndex name_index_;
1215 Child<Expression> expression_;
1216
1217 DISALLOW_COPY_AND_ASSIGN(NamedExpression);
1218 };
1219
1220
1221 class MethodInvocation : public Expression {
1222 public:
1223 static MethodInvocation* ReadFrom(Reader* reader);
1224
1225 virtual ~MethodInvocation();
1226
1227 DEFINE_CASTING_OPERATIONS(MethodInvocation);
1228
1229 Expression* receiver() { return receiver_; }
1230 Name* name() { return name_; }
1231 Arguments* arguments() { return arguments_; }
1232
1233 private:
1234 MethodInvocation() {}
1235
1236 NameIndex interface_target_reference_;
1237 Child<Expression> receiver_;
1238 Child<Name> name_;
1239 Child<Arguments> arguments_;
1240
1241 DISALLOW_COPY_AND_ASSIGN(MethodInvocation);
1242 };
1243
1244
1245 class DirectMethodInvocation : public Expression {
1246 public:
1247 static DirectMethodInvocation* ReadFrom(Reader* reader);
1248
1249 virtual ~DirectMethodInvocation();
1250
1251 DEFINE_CASTING_OPERATIONS(DirectMethodInvocation);
1252
1253 Expression* receiver() { return receiver_; }
1254 NameIndex target() { return target_reference_; }
1255 Arguments* arguments() { return arguments_; }
1256
1257 private:
1258 DirectMethodInvocation() {}
1259
1260 NameIndex target_reference_; // Procedure canonical name.
1261 Child<Expression> receiver_;
1262 Child<Arguments> arguments_;
1263
1264 DISALLOW_COPY_AND_ASSIGN(DirectMethodInvocation);
1265 };
1266
1267
1268 class StaticInvocation : public Expression {
1269 public:
1270 static StaticInvocation* ReadFrom(Reader* reader, bool is_const);
1271 ~StaticInvocation();
1272
1273 DEFINE_CASTING_OPERATIONS(StaticInvocation);
1274
1275 NameIndex procedure() { return procedure_reference_; }
1276 Arguments* arguments() { return arguments_; }
1277 bool is_const() { return is_const_; }
1278
1279 private:
1280 StaticInvocation() {}
1281
1282 NameIndex procedure_reference_; // Procedure canonical name.
1283 bool is_const_;
1284 Child<Arguments> arguments_;
1285
1286 DISALLOW_COPY_AND_ASSIGN(StaticInvocation);
1287 };
1288
1289
1290 class ConstructorInvocation : public Expression {
1291 public:
1292 static ConstructorInvocation* ReadFrom(Reader* reader, bool is_const);
1293
1294 virtual ~ConstructorInvocation();
1295
1296 DEFINE_CASTING_OPERATIONS(ConstructorInvocation);
1297
1298 bool is_const() { return is_const_; }
1299 NameIndex target() { return target_reference_; }
1300 Arguments* arguments() { return arguments_; }
1301
1302 private:
1303 ConstructorInvocation() {}
1304
1305 bool is_const_;
1306 NameIndex target_reference_; // Constructor canonical name.
1307 Child<Arguments> arguments_;
1308
1309 DISALLOW_COPY_AND_ASSIGN(ConstructorInvocation);
1310 };
1311
1312
1313 class Not : public Expression {
1314 public:
1315 static Not* ReadFrom(Reader* reader);
1316
1317 virtual ~Not();
1318
1319 DEFINE_CASTING_OPERATIONS(Not);
1320
1321 Expression* expression() { return expression_; }
1322
1323 private:
1324 Not() {}
1325
1326 Child<Expression> expression_;
1327
1328 DISALLOW_COPY_AND_ASSIGN(Not);
1329 };
1330
1331
1332 class LogicalExpression : public Expression {
1333 public:
1334 enum Operator { kAnd, kOr };
1335
1336 static LogicalExpression* ReadFrom(Reader* reader);
1337
1338 virtual ~LogicalExpression();
1339
1340 DEFINE_CASTING_OPERATIONS(LogicalExpression);
1341
1342 Expression* left() { return left_; }
1343 Operator op() { return operator_; }
1344 Expression* right() { return right_; }
1345
1346 private:
1347 LogicalExpression() {}
1348
1349 Child<Expression> left_;
1350 Operator operator_;
1351 Child<Expression> right_;
1352
1353 DISALLOW_COPY_AND_ASSIGN(LogicalExpression);
1354 };
1355
1356
1357 class ConditionalExpression : public Expression {
1358 public:
1359 static ConditionalExpression* ReadFrom(Reader* reader);
1360
1361 virtual ~ConditionalExpression();
1362
1363 DEFINE_CASTING_OPERATIONS(ConditionalExpression);
1364
1365 Expression* condition() { return condition_; }
1366 Expression* then() { return then_; }
1367 Expression* otherwise() { return otherwise_; }
1368
1369 private:
1370 ConditionalExpression() {}
1371
1372 Child<Expression> condition_;
1373 Child<Expression> then_;
1374 Child<Expression> otherwise_;
1375
1376 DISALLOW_COPY_AND_ASSIGN(ConditionalExpression);
1377 };
1378
1379
1380 class StringConcatenation : public Expression {
1381 public:
1382 static StringConcatenation* ReadFrom(Reader* reader);
1383
1384 virtual ~StringConcatenation();
1385
1386 DEFINE_CASTING_OPERATIONS(StringConcatenation);
1387
1388 List<Expression>& expressions() { return expressions_; }
1389
1390 private:
1391 StringConcatenation() {}
1392
1393 List<Expression> expressions_;
1394
1395 DISALLOW_COPY_AND_ASSIGN(StringConcatenation);
1396 };
1397
1398
1399 class IsExpression : public Expression {
1400 public:
1401 static IsExpression* ReadFrom(Reader* reader);
1402
1403 virtual ~IsExpression();
1404
1405 DEFINE_CASTING_OPERATIONS(IsExpression);
1406
1407 Expression* operand() { return operand_; }
1408 DartType* type() { return type_; }
1409
1410 private:
1411 IsExpression() {}
1412
1413 Child<Expression> operand_;
1414 Child<DartType> type_;
1415
1416 DISALLOW_COPY_AND_ASSIGN(IsExpression);
1417 };
1418
1419
1420 class AsExpression : public Expression {
1421 public:
1422 static AsExpression* ReadFrom(Reader* reader);
1423
1424 virtual ~AsExpression();
1425
1426 DEFINE_CASTING_OPERATIONS(AsExpression);
1427
1428 Expression* operand() { return operand_; }
1429 DartType* type() { return type_; }
1430
1431 private:
1432 AsExpression() {}
1433
1434 Child<Expression> operand_;
1435 Child<DartType> type_;
1436
1437 DISALLOW_COPY_AND_ASSIGN(AsExpression);
1438 };
1439
1440
1441 class BasicLiteral : public Expression {
1442 public:
1443 virtual ~BasicLiteral();
1444
1445 DEFINE_CASTING_OPERATIONS(BasicLiteral);
1446 };
1447
1448
1449 class StringLiteral : public BasicLiteral {
1450 public:
1451 static StringLiteral* ReadFrom(Reader* reader);
1452
1453 explicit StringLiteral(StringIndex string_index)
1454 : value_index_(string_index) {}
1455 virtual ~StringLiteral();
1456
1457 DEFINE_CASTING_OPERATIONS(StringLiteral);
1458
1459 StringIndex value() { return value_index_; }
1460
1461 protected:
1462 StringLiteral() {}
1463
1464 StringIndex value_index_;
1465
1466 private:
1467 DISALLOW_COPY_AND_ASSIGN(StringLiteral);
1468 };
1469
1470
1471 class BigintLiteral : public StringLiteral {
1472 public:
1473 static BigintLiteral* ReadFrom(Reader* reader);
1474
1475 explicit BigintLiteral(StringIndex string_index)
1476 : StringLiteral(string_index) {}
1477 virtual ~BigintLiteral();
1478
1479 DEFINE_CASTING_OPERATIONS(BigintLiteral);
1480
1481 private:
1482 BigintLiteral() {}
1483
1484 DISALLOW_COPY_AND_ASSIGN(BigintLiteral);
1485 };
1486
1487
1488 class IntLiteral : public BasicLiteral {
1489 public:
1490 static IntLiteral* ReadFrom(Reader* reader, bool is_negative);
1491 static IntLiteral* ReadFrom(Reader* reader, uint8_t payload);
1492
1493 virtual ~IntLiteral();
1494
1495 DEFINE_CASTING_OPERATIONS(IntLiteral);
1496
1497 int64_t value() { return value_; }
1498
1499 private:
1500 IntLiteral() {}
1501
1502 int64_t value_;
1503
1504 DISALLOW_COPY_AND_ASSIGN(IntLiteral);
1505 };
1506
1507
1508 class DoubleLiteral : public BasicLiteral {
1509 public:
1510 static DoubleLiteral* ReadFrom(Reader* reader);
1511
1512 virtual ~DoubleLiteral();
1513
1514 DEFINE_CASTING_OPERATIONS(DoubleLiteral);
1515
1516 StringIndex value() { return value_index_; }
1517
1518 private:
1519 DoubleLiteral() {}
1520
1521 StringIndex value_index_;
1522
1523 DISALLOW_COPY_AND_ASSIGN(DoubleLiteral);
1524 };
1525
1526
1527 class BoolLiteral : public BasicLiteral {
1528 public:
1529 static BoolLiteral* ReadFrom(Reader* reader, bool value);
1530
1531 virtual ~BoolLiteral();
1532
1533 DEFINE_CASTING_OPERATIONS(BoolLiteral);
1534
1535 bool value() { return value_; }
1536
1537 private:
1538 BoolLiteral() {}
1539
1540 bool value_;
1541
1542 DISALLOW_COPY_AND_ASSIGN(BoolLiteral);
1543 };
1544
1545
1546 class NullLiteral : public BasicLiteral {
1547 public:
1548 static NullLiteral* ReadFrom(Reader* reader);
1549
1550 virtual ~NullLiteral();
1551
1552 DEFINE_CASTING_OPERATIONS(NullLiteral);
1553
1554 private:
1555 NullLiteral() {}
1556
1557 DISALLOW_COPY_AND_ASSIGN(NullLiteral);
1558 };
1559
1560
1561 class SymbolLiteral : public Expression {
1562 public:
1563 static SymbolLiteral* ReadFrom(Reader* reader);
1564
1565 virtual ~SymbolLiteral();
1566
1567 DEFINE_CASTING_OPERATIONS(SymbolLiteral);
1568
1569 StringIndex value() { return value_index_; }
1570
1571 private:
1572 SymbolLiteral() {}
1573
1574 StringIndex value_index_;
1575
1576 DISALLOW_COPY_AND_ASSIGN(SymbolLiteral);
1577 };
1578
1579
1580 class TypeLiteral : public Expression {
1581 public:
1582 static TypeLiteral* ReadFrom(Reader* reader);
1583
1584 virtual ~TypeLiteral();
1585
1586 DEFINE_CASTING_OPERATIONS(TypeLiteral);
1587
1588 DartType* type() { return type_; }
1589
1590 private:
1591 TypeLiteral() {}
1592
1593 Child<DartType> type_;
1594
1595 DISALLOW_COPY_AND_ASSIGN(TypeLiteral);
1596 };
1597
1598
1599 class ThisExpression : public Expression {
1600 public:
1601 static ThisExpression* ReadFrom(Reader* reader);
1602
1603 virtual ~ThisExpression();
1604
1605 DEFINE_CASTING_OPERATIONS(ThisExpression);
1606
1607 private:
1608 ThisExpression() {}
1609
1610 DISALLOW_COPY_AND_ASSIGN(ThisExpression);
1611 };
1612
1613
1614 class Rethrow : public Expression {
1615 public:
1616 static Rethrow* ReadFrom(Reader* reader);
1617
1618 virtual ~Rethrow();
1619
1620 DEFINE_CASTING_OPERATIONS(Rethrow);
1621
1622 private:
1623 Rethrow() {}
1624
1625 DISALLOW_COPY_AND_ASSIGN(Rethrow);
1626 };
1627
1628
1629 class Throw : public Expression {
1630 public:
1631 static Throw* ReadFrom(Reader* reader);
1632
1633 virtual ~Throw();
1634
1635 DEFINE_CASTING_OPERATIONS(Throw);
1636
1637 Expression* expression() { return expression_; }
1638
1639 private:
1640 Throw() {}
1641
1642 Child<Expression> expression_;
1643
1644 DISALLOW_COPY_AND_ASSIGN(Throw);
1645 };
1646
1647
1648 class ListLiteral : public Expression {
1649 public:
1650 static ListLiteral* ReadFrom(Reader* reader, bool is_const);
1651
1652 virtual ~ListLiteral();
1653
1654 DEFINE_CASTING_OPERATIONS(ListLiteral);
1655
1656 bool is_const() { return is_const_; }
1657 DartType* type() { return type_; }
1658 List<Expression>& expressions() { return expressions_; }
1659
1660 private:
1661 ListLiteral() {}
1662
1663 bool is_const_;
1664 Child<DartType> type_;
1665 List<Expression> expressions_;
1666
1667 DISALLOW_COPY_AND_ASSIGN(ListLiteral);
1668 };
1669
1670
1671 class MapLiteral : public Expression {
1672 public:
1673 static MapLiteral* ReadFrom(Reader* reader, bool is_const);
1674
1675 virtual ~MapLiteral();
1676
1677 DEFINE_CASTING_OPERATIONS(MapLiteral);
1678
1679 bool is_const() { return is_const_; }
1680 DartType* key_type() { return key_type_; }
1681 DartType* value_type() { return value_type_; }
1682 List<MapEntry>& entries() { return entries_; }
1683
1684 private:
1685 MapLiteral() {}
1686
1687 bool is_const_;
1688 Child<DartType> key_type_;
1689 Child<DartType> value_type_;
1690 List<MapEntry> entries_;
1691
1692 DISALLOW_COPY_AND_ASSIGN(MapLiteral);
1693 };
1694
1695
1696 class MapEntry : public TreeNode {
1697 public:
1698 static MapEntry* ReadFrom(Reader* reader);
1699
1700 virtual ~MapEntry();
1701
1702 DEFINE_CASTING_OPERATIONS(MapEntry);
1703
1704 Expression* key() { return key_; }
1705 Expression* value() { return value_; }
1706
1707 private:
1708 MapEntry() {}
1709
1710 template <typename T>
1711 friend class List;
1712
1713 Child<Expression> key_;
1714 Child<Expression> value_;
1715
1716 DISALLOW_COPY_AND_ASSIGN(MapEntry);
1717 };
1718
1719
1720 class AwaitExpression : public Expression {
1721 public:
1722 static AwaitExpression* ReadFrom(Reader* reader);
1723
1724 virtual ~AwaitExpression();
1725
1726 DEFINE_CASTING_OPERATIONS(AwaitExpression);
1727
1728 Expression* operand() { return operand_; }
1729
1730 private:
1731 AwaitExpression() {}
1732
1733 Child<Expression> operand_;
1734
1735 DISALLOW_COPY_AND_ASSIGN(AwaitExpression);
1736 };
1737
1738
1739 class FunctionExpression : public Expression {
1740 public:
1741 static FunctionExpression* ReadFrom(Reader* reader);
1742
1743 virtual ~FunctionExpression();
1744
1745 DEFINE_CASTING_OPERATIONS(FunctionExpression);
1746
1747 FunctionNode* function() { return function_; }
1748
1749 private:
1750 FunctionExpression() {}
1751
1752 Child<FunctionNode> function_;
1753
1754 DISALLOW_COPY_AND_ASSIGN(FunctionExpression);
1755 };
1756
1757
1758 class Let : public Expression {
1759 public:
1760 static Let* ReadFrom(Reader* reader);
1761
1762 virtual ~Let();
1763
1764 DEFINE_CASTING_OPERATIONS(Let);
1765
1766 VariableDeclaration* variable() { return variable_; }
1767 Expression* body() { return body_; }
1768 TokenPosition position() { return position_; }
1769 TokenPosition end_position() { return end_position_; }
1770
1771 private:
1772 Let()
1773 : position_(TokenPosition::kNoSource),
1774 end_position_(TokenPosition::kNoSource) {}
1775
1776 Child<VariableDeclaration> variable_;
1777 Child<Expression> body_;
1778 TokenPosition position_;
1779 TokenPosition end_position_;
1780
1781 DISALLOW_COPY_AND_ASSIGN(Let);
1782 };
1783
1784
1785 class VectorCreation : public Expression {
1786 public:
1787 static VectorCreation* ReadFrom(Reader* reader);
1788
1789 virtual ~VectorCreation();
1790
1791 DEFINE_CASTING_OPERATIONS(VectorCreation);
1792
1793 intptr_t value() { return value_; }
1794
1795 private:
1796 VectorCreation() {}
1797
1798 intptr_t value_;
1799
1800 DISALLOW_COPY_AND_ASSIGN(VectorCreation);
1801 };
1802
1803
1804 class VectorGet : public Expression {
1805 public:
1806 static VectorGet* ReadFrom(Reader* reader);
1807
1808 virtual ~VectorGet();
1809
1810 DEFINE_CASTING_OPERATIONS(VectorGet);
1811
1812 Expression* vector_expression() { return vector_expression_; }
1813 intptr_t index() { return index_; }
1814
1815 private:
1816 VectorGet() {}
1817
1818 Child<Expression> vector_expression_;
1819 intptr_t index_;
1820
1821 DISALLOW_COPY_AND_ASSIGN(VectorGet);
1822 };
1823
1824
1825 class VectorSet : public Expression {
1826 public:
1827 static VectorSet* ReadFrom(Reader* reader);
1828
1829 virtual ~VectorSet();
1830
1831 DEFINE_CASTING_OPERATIONS(VectorSet);
1832
1833 Expression* vector_expression() { return vector_expression_; }
1834 intptr_t index() { return index_; }
1835 Expression* value() { return value_; }
1836
1837 private:
1838 VectorSet() {}
1839
1840 Child<Expression> vector_expression_;
1841 intptr_t index_;
1842 Child<Expression> value_;
1843
1844 DISALLOW_COPY_AND_ASSIGN(VectorSet);
1845 };
1846
1847
1848 class VectorCopy : public Expression {
1849 public:
1850 static VectorCopy* ReadFrom(Reader* reader);
1851
1852 virtual ~VectorCopy();
1853
1854 DEFINE_CASTING_OPERATIONS(VectorCopy);
1855
1856 Expression* vector_expression() { return vector_expression_; }
1857
1858 private:
1859 VectorCopy() {}
1860
1861 Child<Expression> vector_expression_;
1862
1863 DISALLOW_COPY_AND_ASSIGN(VectorCopy);
1864 };
1865
1866
1867 class ClosureCreation : public Expression {
1868 public:
1869 static ClosureCreation* ReadFrom(Reader* reader);
1870
1871 virtual ~ClosureCreation();
1872
1873 DEFINE_CASTING_OPERATIONS(ClosureCreation);
1874
1875 NameIndex top_level_function() { return top_level_function_reference_; }
1876 Expression* context_vector() { return context_vector_; }
1877 FunctionType* function_type() { return function_type_; }
1878
1879 private:
1880 ClosureCreation() {}
1881
1882 NameIndex top_level_function_reference_; // Procedure canonical name.
1883 Child<Expression> context_vector_;
1884 Child<FunctionType> function_type_;
1885
1886 DISALLOW_COPY_AND_ASSIGN(ClosureCreation);
1887 };
1888
1889
1890 class Statement : public TreeNode {
1891 public:
1892 static Statement* ReadFrom(Reader* reader);
1893
1894 virtual ~Statement();
1895
1896 DEFINE_CASTING_OPERATIONS(Statement);
1897
1898 TokenPosition position() { return position_; }
1899
1900 protected:
1901 Statement() : position_(TokenPosition::kNoSource) {}
1902 TokenPosition position_;
1903
1904 private:
1905 DISALLOW_COPY_AND_ASSIGN(Statement);
1906 };
1907
1908
1909 class InvalidStatement : public Statement {
1910 public:
1911 static InvalidStatement* ReadFrom(Reader* reader);
1912
1913 virtual ~InvalidStatement();
1914
1915 DEFINE_CASTING_OPERATIONS(InvalidStatement);
1916
1917 private:
1918 InvalidStatement() {}
1919
1920 DISALLOW_COPY_AND_ASSIGN(InvalidStatement);
1921 };
1922
1923
1924 class ExpressionStatement : public Statement {
1925 public:
1926 static ExpressionStatement* ReadFrom(Reader* reader);
1927
1928 explicit ExpressionStatement(Expression* exp) : expression_(exp) {}
1929 virtual ~ExpressionStatement();
1930
1931 DEFINE_CASTING_OPERATIONS(ExpressionStatement);
1932
1933 Expression* expression() { return expression_; }
1934
1935 private:
1936 ExpressionStatement() {}
1937
1938 Child<Expression> expression_;
1939
1940 DISALLOW_COPY_AND_ASSIGN(ExpressionStatement);
1941 };
1942
1943
1944 class Block : public Statement {
1945 public:
1946 static Block* ReadFromImpl(Reader* reader);
1947
1948 virtual ~Block();
1949
1950 DEFINE_CASTING_OPERATIONS(Block);
1951
1952 List<Statement>& statements() { return statements_; }
1953 TokenPosition end_position() { return end_position_; }
1954
1955 private:
1956 Block() : end_position_(TokenPosition::kNoSource) {}
1957
1958 List<Statement> statements_;
1959 TokenPosition end_position_;
1960
1961 DISALLOW_COPY_AND_ASSIGN(Block);
1962 };
1963
1964
1965 class EmptyStatement : public Statement {
1966 public:
1967 static EmptyStatement* ReadFrom(Reader* reader);
1968
1969 virtual ~EmptyStatement();
1970
1971 DEFINE_CASTING_OPERATIONS(EmptyStatement);
1972
1973 private:
1974 EmptyStatement() {}
1975
1976 DISALLOW_COPY_AND_ASSIGN(EmptyStatement);
1977 };
1978
1979
1980 class AssertStatement : public Statement {
1981 public:
1982 static AssertStatement* ReadFrom(Reader* reader);
1983
1984 virtual ~AssertStatement();
1985
1986 DEFINE_CASTING_OPERATIONS(AssertStatement);
1987
1988 Expression* condition() { return condition_; }
1989 Expression* message() { return message_; }
1990
1991 private:
1992 AssertStatement() {}
1993
1994 Child<Expression> condition_;
1995 Child<Expression> message_;
1996
1997 DISALLOW_COPY_AND_ASSIGN(AssertStatement);
1998 };
1999
2000
2001 class LabeledStatement : public Statement {
2002 public:
2003 static LabeledStatement* ReadFrom(Reader* reader);
2004
2005 virtual ~LabeledStatement();
2006
2007 DEFINE_CASTING_OPERATIONS(LabeledStatement);
2008
2009 Statement* body() { return body_; }
2010
2011 private:
2012 LabeledStatement() {}
2013
2014 Child<Statement> body_;
2015
2016 DISALLOW_COPY_AND_ASSIGN(LabeledStatement);
2017 };
2018
2019
2020 class BreakStatement : public Statement {
2021 public:
2022 static BreakStatement* ReadFrom(Reader* reader);
2023
2024 virtual ~BreakStatement();
2025
2026 DEFINE_CASTING_OPERATIONS(BreakStatement);
2027
2028 intptr_t target_index() { return target_index_; }
2029
2030 private:
2031 BreakStatement() {}
2032
2033 intptr_t target_index_;
2034
2035 DISALLOW_COPY_AND_ASSIGN(BreakStatement);
2036 };
2037
2038
2039 class WhileStatement : public Statement {
2040 public:
2041 static WhileStatement* ReadFrom(Reader* reader);
2042
2043 virtual ~WhileStatement();
2044
2045 DEFINE_CASTING_OPERATIONS(WhileStatement);
2046
2047 Expression* condition() { return condition_; }
2048 Statement* body() { return body_; }
2049
2050 private:
2051 WhileStatement() {}
2052
2053 Child<Expression> condition_;
2054 Child<Statement> body_;
2055
2056 DISALLOW_COPY_AND_ASSIGN(WhileStatement);
2057 };
2058
2059
2060 class DoStatement : public Statement {
2061 public:
2062 static DoStatement* ReadFrom(Reader* reader);
2063
2064 virtual ~DoStatement();
2065
2066 DEFINE_CASTING_OPERATIONS(DoStatement);
2067
2068 Expression* condition() { return condition_; }
2069 Statement* body() { return body_; }
2070
2071 private:
2072 DoStatement() {}
2073
2074 Child<Expression> condition_;
2075 Child<Statement> body_;
2076
2077 DISALLOW_COPY_AND_ASSIGN(DoStatement);
2078 };
2079
2080
2081 class ForStatement : public Statement {
2082 public:
2083 static ForStatement* ReadFrom(Reader* reader);
2084
2085 virtual ~ForStatement();
2086
2087 DEFINE_CASTING_OPERATIONS(ForStatement);
2088
2089 List<VariableDeclaration>& variables() { return variables_; }
2090 Expression* condition() { return condition_; }
2091 List<Expression>& updates() { return updates_; }
2092 Statement* body() { return body_; }
2093 TokenPosition position() { return position_; }
2094 TokenPosition end_position() { return end_position_; }
2095
2096 private:
2097 ForStatement()
2098 : position_(TokenPosition::kNoSource),
2099 end_position_(TokenPosition::kNoSource) {}
2100
2101 List<VariableDeclaration> variables_;
2102 Child<Expression> condition_;
2103 List<Expression> updates_;
2104 Child<Statement> body_;
2105 TokenPosition position_;
2106 TokenPosition end_position_;
2107
2108 DISALLOW_COPY_AND_ASSIGN(ForStatement);
2109 };
2110
2111
2112 class ForInStatement : public Statement {
2113 public:
2114 static ForInStatement* ReadFrom(Reader* reader, bool is_async);
2115
2116 virtual ~ForInStatement();
2117
2118 DEFINE_CASTING_OPERATIONS(ForInStatement);
2119
2120 VariableDeclaration* variable() { return variable_; }
2121 Expression* iterable() { return iterable_; }
2122 Statement* body() { return body_; }
2123 bool is_async() { return is_async_; }
2124 TokenPosition position() { return position_; }
2125 TokenPosition end_position() { return end_position_; }
2126
2127 private:
2128 ForInStatement()
2129 : position_(TokenPosition::kNoSource),
2130 end_position_(TokenPosition::kNoSource) {}
2131
2132 Child<VariableDeclaration> variable_;
2133 Child<Expression> iterable_;
2134 Child<Statement> body_;
2135 bool is_async_;
2136 TokenPosition position_;
2137 TokenPosition end_position_;
2138
2139 DISALLOW_COPY_AND_ASSIGN(ForInStatement);
2140 };
2141
2142
2143 class SwitchStatement : public Statement {
2144 public:
2145 static SwitchStatement* ReadFrom(Reader* reader);
2146
2147 virtual ~SwitchStatement();
2148
2149 DEFINE_CASTING_OPERATIONS(SwitchStatement);
2150
2151 Expression* condition() { return condition_; }
2152 List<SwitchCase>& cases() { return cases_; }
2153
2154 private:
2155 SwitchStatement() {}
2156
2157 Child<Expression> condition_;
2158 List<SwitchCase> cases_;
2159
2160 DISALLOW_COPY_AND_ASSIGN(SwitchStatement);
2161 };
2162
2163
2164 class SwitchCase : public TreeNode {
2165 public:
2166 SwitchCase* ReadFrom(Reader* reader);
2167
2168 virtual ~SwitchCase();
2169
2170 DEFINE_CASTING_OPERATIONS(SwitchCase);
2171
2172 List<Expression>& expressions() { return expressions_; }
2173 bool is_default() { return is_default_; }
2174 Statement* body() { return body_; }
2175
2176 private:
2177 SwitchCase() {}
2178
2179 template <typename T>
2180 friend class List;
2181
2182 List<Expression> expressions_;
2183 bool is_default_;
2184 Child<Statement> body_;
2185
2186 DISALLOW_COPY_AND_ASSIGN(SwitchCase);
2187 };
2188
2189
2190 class ContinueSwitchStatement : public Statement {
2191 public:
2192 static ContinueSwitchStatement* ReadFrom(Reader* reader);
2193
2194 virtual ~ContinueSwitchStatement();
2195
2196 DEFINE_CASTING_OPERATIONS(ContinueSwitchStatement);
2197
2198 intptr_t target_index() { return target_index_; }
2199
2200 private:
2201 ContinueSwitchStatement() {}
2202
2203 intptr_t target_index_;
2204
2205 DISALLOW_COPY_AND_ASSIGN(ContinueSwitchStatement);
2206 };
2207
2208
2209 class IfStatement : public Statement {
2210 public:
2211 static IfStatement* ReadFrom(Reader* reader);
2212
2213 virtual ~IfStatement();
2214
2215 DEFINE_CASTING_OPERATIONS(IfStatement);
2216
2217 Expression* condition() { return condition_; }
2218 Statement* then() { return then_; }
2219 Statement* otherwise() { return otherwise_; }
2220
2221 private:
2222 IfStatement() {}
2223
2224 Child<Expression> condition_;
2225 Child<Statement> then_;
2226 Child<Statement> otherwise_;
2227
2228 DISALLOW_COPY_AND_ASSIGN(IfStatement);
2229 };
2230
2231
2232 class ReturnStatement : public Statement {
2233 public:
2234 static ReturnStatement* ReadFrom(Reader* reader);
2235
2236 virtual ~ReturnStatement();
2237
2238 DEFINE_CASTING_OPERATIONS(ReturnStatement);
2239
2240 Expression* expression() { return expression_; }
2241
2242 private:
2243 ReturnStatement() {}
2244
2245 Child<Expression> expression_;
2246
2247 DISALLOW_COPY_AND_ASSIGN(ReturnStatement);
2248 };
2249
2250
2251 class TryCatch : public Statement {
2252 public:
2253 static TryCatch* ReadFrom(Reader* reader);
2254
2255 virtual ~TryCatch();
2256
2257 DEFINE_CASTING_OPERATIONS(TryCatch);
2258
2259 Statement* body() { return body_; }
2260 List<Catch>& catches() { return catches_; }
2261
2262 private:
2263 TryCatch() {}
2264
2265 Child<Statement> body_;
2266 List<Catch> catches_;
2267
2268 DISALLOW_COPY_AND_ASSIGN(TryCatch);
2269 };
2270
2271
2272 class Catch : public TreeNode {
2273 public:
2274 static Catch* ReadFrom(Reader* reader);
2275
2276 virtual ~Catch();
2277
2278 DEFINE_CASTING_OPERATIONS(Catch);
2279
2280 DartType* guard() { return guard_; }
2281 VariableDeclaration* exception() { return exception_; }
2282 VariableDeclaration* stack_trace() { return stack_trace_; }
2283 Statement* body() { return body_; }
2284 TokenPosition position() { return position_; }
2285 TokenPosition end_position() { return end_position_; }
2286
2287 private:
2288 Catch()
2289 : position_(TokenPosition::kNoSource),
2290 end_position_(TokenPosition::kNoSource) {}
2291
2292 template <typename T>
2293 friend class List;
2294
2295 Child<DartType> guard_;
2296 Child<VariableDeclaration> exception_;
2297 Child<VariableDeclaration> stack_trace_;
2298 Child<Statement> body_;
2299 TokenPosition position_;
2300 TokenPosition end_position_;
2301
2302 DISALLOW_COPY_AND_ASSIGN(Catch);
2303 };
2304
2305
2306 class TryFinally : public Statement {
2307 public:
2308 static TryFinally* ReadFrom(Reader* reader);
2309
2310 virtual ~TryFinally();
2311
2312 DEFINE_CASTING_OPERATIONS(TryFinally);
2313
2314 Statement* body() { return body_; }
2315 Statement* finalizer() { return finalizer_; }
2316
2317 private:
2318 TryFinally() {}
2319
2320 Child<Statement> body_;
2321 Child<Statement> finalizer_;
2322
2323 DISALLOW_COPY_AND_ASSIGN(TryFinally);
2324 };
2325
2326
2327 class YieldStatement : public Statement {
2328 public: 113 public:
2329 enum { 114 enum {
2330 kFlagYieldStar = 1 << 0, 115 kFlagYieldStar = 1 << 0,
2331 kFlagNative = 1 << 1, 116 kFlagNative = 1 << 1,
2332 }; 117 };
2333 static YieldStatement* ReadFrom(Reader* reader);
2334
2335 virtual ~YieldStatement();
2336
2337 DEFINE_CASTING_OPERATIONS(YieldStatement);
2338
2339 bool is_yield_start() { return (flags_ & kFlagYieldStar) == kFlagYieldStar; }
2340 bool is_native() { return (flags_ & kFlagNative) == kFlagNative; }
2341 Expression* expression() { return expression_; }
2342
2343 private:
2344 YieldStatement() {}
2345
2346 word flags_;
2347 Child<Expression> expression_;
2348
2349 DISALLOW_COPY_AND_ASSIGN(YieldStatement);
2350 }; 118 };
2351 119
2352 120
2353 class VariableDeclaration : public Statement { 121 class LogicalExpression {
2354 public: 122 public:
2355 enum Flags { 123 enum Operator { kAnd, kOr };
2356 kFlagFinal = 1 << 0,
2357 kFlagConst = 1 << 1,
2358 };
2359
2360 static VariableDeclaration* ReadFrom(Reader* reader);
2361 static VariableDeclaration* ReadFromImpl(Reader* reader, bool read_tag);
2362
2363 virtual ~VariableDeclaration();
2364
2365 DEFINE_CASTING_OPERATIONS(VariableDeclaration);
2366
2367 bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
2368 bool IsFinal() { return (flags_ & kFlagFinal) == kFlagFinal; }
2369
2370 StringIndex name() { return name_index_; }
2371 DartType* type() { return type_; }
2372 Expression* initializer() { return initializer_; }
2373 TokenPosition equals_position() { return equals_position_; }
2374 TokenPosition end_position() { return end_position_; }
2375 void set_end_position(TokenPosition position) { end_position_ = position; }
2376 intptr_t kernel_offset_no_tag() const { return kernel_offset_no_tag_; }
2377
2378 private:
2379 VariableDeclaration()
2380 : equals_position_(TokenPosition::kNoSourcePos),
2381 end_position_(TokenPosition::kNoSource),
2382 kernel_offset_no_tag_(-1) {}
2383
2384 template <typename T>
2385 friend class List;
2386
2387 StringIndex name_index_;
2388 word flags_;
2389 Child<DartType> type_;
2390 Child<Expression> initializer_;
2391 TokenPosition equals_position_;
2392 TokenPosition end_position_;
2393
2394 // Offset for this node in the kernel-binary. Always without the tag.
2395 // Can be -1 to indicate "unknown" or invalid offset.
2396 intptr_t kernel_offset_no_tag_;
2397
2398 DISALLOW_COPY_AND_ASSIGN(VariableDeclaration);
2399 }; 124 };
2400 125
2401 126
2402 class FunctionDeclaration : public Statement { 127 class Program {
2403 public:
2404 static FunctionDeclaration* ReadFrom(Reader* reader);
2405
2406 virtual ~FunctionDeclaration();
2407
2408 DEFINE_CASTING_OPERATIONS(FunctionDeclaration);
2409
2410 VariableDeclaration* variable() { return variable_; }
2411 FunctionNode* function() { return function_; }
2412
2413 private:
2414 FunctionDeclaration() {}
2415
2416 Child<VariableDeclaration> variable_;
2417 Child<FunctionNode> function_;
2418
2419 DISALLOW_COPY_AND_ASSIGN(FunctionDeclaration);
2420 };
2421
2422
2423 class Name : public Node {
2424 public:
2425 static Name* ReadFrom(Reader* reader);
2426
2427 virtual ~Name();
2428
2429 DEFINE_CASTING_OPERATIONS(Name);
2430
2431 StringIndex string_index() { return string_index_; }
2432 NameIndex library() { return library_reference_; }
2433
2434 private:
2435 Name(intptr_t string_index, intptr_t library_reference)
2436 : string_index_(string_index),
2437 library_reference_(library_reference) {} // NOLINT
2438
2439 StringIndex string_index_;
2440 NameIndex library_reference_; // Library canonical name.
2441
2442 DISALLOW_COPY_AND_ASSIGN(Name);
2443 };
2444
2445
2446 class DartType : public Node {
2447 public:
2448 static DartType* ReadFrom(Reader* reader);
2449
2450 virtual ~DartType();
2451
2452 DEFINE_CASTING_OPERATIONS(DartType);
2453
2454 protected:
2455 DartType() {}
2456
2457 private:
2458 DISALLOW_COPY_AND_ASSIGN(DartType);
2459 };
2460
2461
2462 class InvalidType : public DartType {
2463 public:
2464 static InvalidType* ReadFrom(Reader* reader);
2465
2466 virtual ~InvalidType();
2467
2468 DEFINE_CASTING_OPERATIONS(InvalidType);
2469
2470 private:
2471 InvalidType() {}
2472
2473 DISALLOW_COPY_AND_ASSIGN(InvalidType);
2474 };
2475
2476
2477 class DynamicType : public DartType {
2478 public:
2479 static DynamicType* ReadFrom(Reader* reader);
2480
2481 virtual ~DynamicType();
2482
2483 DEFINE_CASTING_OPERATIONS(DynamicType);
2484
2485 private:
2486 DynamicType() {}
2487
2488 DISALLOW_COPY_AND_ASSIGN(DynamicType);
2489 };
2490
2491
2492 class VoidType : public DartType {
2493 public:
2494 static VoidType* ReadFrom(Reader* reader);
2495
2496 virtual ~VoidType();
2497
2498 DEFINE_CASTING_OPERATIONS(VoidType);
2499
2500 private:
2501 VoidType() {}
2502
2503 DISALLOW_COPY_AND_ASSIGN(VoidType);
2504 };
2505
2506
2507 class BottomType : public DartType {
2508 public:
2509 static BottomType* ReadFrom(Reader* reader);
2510
2511 virtual ~BottomType();
2512
2513 DEFINE_CASTING_OPERATIONS(BottomType);
2514
2515 private:
2516 BottomType() {}
2517
2518 DISALLOW_COPY_AND_ASSIGN(BottomType);
2519 };
2520
2521
2522 class InterfaceType : public DartType {
2523 public:
2524 static InterfaceType* ReadFrom(Reader* reader);
2525 static InterfaceType* ReadFrom(Reader* reader, bool _without_type_arguments_);
2526
2527 explicit InterfaceType(NameIndex class_reference)
2528 : class_reference_(class_reference) {}
2529 virtual ~InterfaceType();
2530
2531 DEFINE_CASTING_OPERATIONS(InterfaceType);
2532
2533 NameIndex klass() { return class_reference_; }
2534 List<DartType>& type_arguments() { return type_arguments_; }
2535
2536 private:
2537 InterfaceType() {}
2538
2539 NameIndex class_reference_; // Class canonical name.
2540 List<DartType> type_arguments_;
2541
2542 DISALLOW_COPY_AND_ASSIGN(InterfaceType);
2543 };
2544
2545
2546 class TypedefType : public DartType {
2547 public:
2548 static TypedefType* ReadFrom(Reader* reader);
2549
2550 explicit TypedefType(NameIndex class_reference)
2551 : typedef_reference_(class_reference) {}
2552 virtual ~TypedefType();
2553
2554 DEFINE_CASTING_OPERATIONS(TypedefType);
2555
2556 NameIndex typedef_reference() { return typedef_reference_; }
2557 List<DartType>& type_arguments() { return type_arguments_; }
2558
2559 private:
2560 TypedefType() {}
2561
2562 NameIndex typedef_reference_; // Typedef canonical name.
2563 List<DartType> type_arguments_;
2564
2565 DISALLOW_COPY_AND_ASSIGN(TypedefType);
2566 };
2567
2568
2569 class NamedParameter {
2570 public:
2571 static NamedParameter* ReadFrom(Reader* reader);
2572
2573 NamedParameter(StringIndex name_index, DartType* type)
2574 : name_index_(name_index), type_(type) {}
2575
2576 StringIndex name() { return name_index_; }
2577 DartType* type() { return type_; }
2578
2579 private:
2580 NamedParameter() {}
2581
2582 StringIndex name_index_;
2583 Child<DartType> type_;
2584
2585 DISALLOW_COPY_AND_ASSIGN(NamedParameter);
2586 };
2587
2588
2589 class FunctionType : public DartType {
2590 public:
2591 static FunctionType* ReadFrom(Reader* reader);
2592 static FunctionType* ReadFrom(Reader* reader, bool _without_type_arguments_);
2593
2594 virtual ~FunctionType();
2595
2596 DEFINE_CASTING_OPERATIONS(FunctionType);
2597
2598 TypeParameterList& type_parameters() { return type_parameters_; }
2599 int required_parameter_count() { return required_parameter_count_; }
2600 List<DartType>& positional_parameters() { return positional_parameters_; }
2601 List<NamedParameter>& named_parameters() { return named_parameters_; }
2602 DartType* return_type() { return return_type_; }
2603
2604 private:
2605 FunctionType() {}
2606
2607 TypeParameterList type_parameters_;
2608 int required_parameter_count_;
2609 List<DartType> positional_parameters_;
2610 List<NamedParameter> named_parameters_;
2611 Child<DartType> return_type_;
2612
2613 DISALLOW_COPY_AND_ASSIGN(FunctionType);
2614 };
2615
2616
2617 class TypeParameterType : public DartType {
2618 public:
2619 static TypeParameterType* ReadFrom(Reader* reader);
2620
2621 virtual ~TypeParameterType();
2622
2623 DEFINE_CASTING_OPERATIONS(TypeParameterType);
2624
2625 TypeParameter* parameter() { return parameter_; }
2626
2627 private:
2628 TypeParameterType() {}
2629
2630 Ref<TypeParameter> parameter_;
2631
2632 DISALLOW_COPY_AND_ASSIGN(TypeParameterType);
2633 };
2634
2635
2636 class VectorType : public DartType {
2637 public:
2638 static VectorType* ReadFrom(Reader* reader);
2639
2640 virtual ~VectorType();
2641
2642 DEFINE_CASTING_OPERATIONS(VectorType);
2643
2644 private:
2645 VectorType() {}
2646
2647 DISALLOW_COPY_AND_ASSIGN(VectorType);
2648 };
2649
2650
2651 class TypeParameter : public TreeNode {
2652 public:
2653 TypeParameter* ReadFrom(Reader* reader);
2654
2655 virtual ~TypeParameter();
2656
2657 DEFINE_CASTING_OPERATIONS(TypeParameter);
2658
2659 StringIndex name() { return name_index_; }
2660 DartType* bound() { return bound_; }
2661
2662 private:
2663 TypeParameter() {}
2664
2665 template <typename T>
2666 friend class List;
2667 friend class TypeParameterList;
2668
2669 StringIndex name_index_;
2670 Child<DartType> bound_;
2671
2672 DISALLOW_COPY_AND_ASSIGN(TypeParameter);
2673 };
2674
2675
2676 class Program : public TreeNode {
2677 public: 128 public:
2678 static Program* ReadFrom(Reader* reader); 129 static Program* ReadFrom(Reader* reader);
2679 130
2680 virtual ~Program();
2681
2682 DEFINE_CASTING_OPERATIONS(Program);
2683
2684 SourceTable& source_table() { return source_table_; }
2685 List<Library>& libraries() { return libraries_; }
2686 NameIndex main_method() { return main_method_reference_; } 131 NameIndex main_method() { return main_method_reference_; }
2687 MallocGrowableArray<MallocGrowableArray<intptr_t>*> valid_token_positions;
2688 MallocGrowableArray<MallocGrowableArray<intptr_t>*> yield_token_positions;
2689 intptr_t string_table_offset() { return string_table_offset_; } 132 intptr_t string_table_offset() { return string_table_offset_; }
2690 intptr_t name_table_offset() { return name_table_offset_; } 133 intptr_t name_table_offset() { return name_table_offset_; }
134 const uint8_t* kernel_data() { return kernel_data_; }
135 intptr_t kernel_data_size() { return kernel_data_size_; }
136 intptr_t library_count() { return library_count_; }
2691 137
2692 private: 138 private:
2693 Program() {} 139 Program() : kernel_data_(NULL), kernel_data_size_(-1) {}
2694 140
2695 NameIndex main_method_reference_; // Procedure. 141 NameIndex main_method_reference_; // Procedure.
2696 List<Library> libraries_; 142 intptr_t library_count_;
2697 SourceTable source_table_;
2698 143
2699 // The offset from the start of the binary to the start of the string table. 144 // The offset from the start of the binary to the start of the string table.
2700 intptr_t string_table_offset_; 145 intptr_t string_table_offset_;
2701 146
2702 // The offset from the start of the binary to the canonical name table. 147 // The offset from the start of the binary to the canonical name table.
2703 intptr_t name_table_offset_; 148 intptr_t name_table_offset_;
2704 149
150 const uint8_t* kernel_data_;
151 intptr_t kernel_data_size_;
152
2705 DISALLOW_COPY_AND_ASSIGN(Program); 153 DISALLOW_COPY_AND_ASSIGN(Program);
2706 }; 154 };
2707 155
2708 156
2709 class Reference : public AllStatic {
2710 public:
2711 // Read canonical name references.
2712 static NameIndex ReadMemberFrom(Reader* reader, bool allow_null = false);
2713 static NameIndex ReadClassFrom(Reader* reader, bool allow_null = false);
2714 static NameIndex ReadTypedefFrom(Reader* reader);
2715 static NameIndex ReadLibraryFrom(Reader* reader);
2716 };
2717
2718
2719 template <typename T>
2720 List<T>::~List() {
2721 for (int i = 0; i < length_; i++) {
2722 delete array_[i];
2723 }
2724 delete[] array_;
2725 }
2726
2727
2728 template <typename T>
2729 void List<T>::EnsureInitialized(int length) {
2730 if (length < length_) return;
2731
2732 T** old_array = array_;
2733 int old_length = length_;
2734
2735 // TODO(27590) Maybe we should use double-growth instead to avoid running
2736 // into the quadratic case.
2737 length_ = length;
2738 array_ = new T*[length_];
2739
2740 // Move old elements at the start (if necessary).
2741 int offset = 0;
2742 if (old_array != NULL) {
2743 for (; offset < old_length; offset++) {
2744 array_[offset] = old_array[offset];
2745 }
2746 }
2747
2748 // Set the rest to NULL.
2749 for (; offset < length_; offset++) {
2750 array_[offset] = NULL;
2751 }
2752
2753 delete[] old_array;
2754 }
2755
2756
2757 template <typename T>
2758 template <typename IT>
2759 IT* List<T>::GetOrCreate(int index) {
2760 EnsureInitialized(index + 1);
2761
2762 T* member = array_[index];
2763 if (member == NULL) {
2764 member = array_[index] = new IT();
2765 }
2766 return IT::Cast(member);
2767 }
2768
2769
2770 template <typename T>
2771 template <typename IT, typename PT>
2772 IT* List<T>::GetOrCreate(int index, PT* parent) {
2773 EnsureInitialized(index + 1);
2774
2775 T* member = array_[index];
2776 if (member == NULL) {
2777 member = array_[index] = new IT();
2778 member->parent_ = parent;
2779 } else {
2780 ASSERT(member->parent_ == parent);
2781 }
2782 return IT::Cast(member);
2783 }
2784
2785 ParsedFunction* ParseStaticFieldInitializer(Zone* zone, 157 ParsedFunction* ParseStaticFieldInitializer(Zone* zone,
2786 const dart::Field& field); 158 const dart::Field& field);
2787 159
2788 } // namespace kernel 160 } // namespace kernel
2789 161
2790 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer, 162 kernel::Program* ReadPrecompiledKernelFromBuffer(const uint8_t* buffer,
2791 intptr_t buffer_length); 163 intptr_t buffer_length);
2792 164
2793 165
2794 } // namespace dart 166 } // namespace dart
2795 167
2796 #endif // !defined(DART_PRECOMPILED_RUNTIME) 168 #endif // !defined(DART_PRECOMPILED_RUNTIME)
2797 #endif // RUNTIME_VM_KERNEL_H_ 169 #endif // RUNTIME_VM_KERNEL_H_
OLDNEW
« no previous file with comments | « runtime/vm/bootstrap_nocore.cc ('k') | runtime/vm/kernel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698