OLD | NEW |
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_TO_IL_H_ | 5 #ifndef RUNTIME_VM_KERNEL_TO_IL_H_ |
6 #define RUNTIME_VM_KERNEL_TO_IL_H_ | 6 #define RUNTIME_VM_KERNEL_TO_IL_H_ |
7 | 7 |
8 #if !defined(DART_PRECOMPILED_RUNTIME) | 8 #if !defined(DART_PRECOMPILED_RUNTIME) |
9 | 9 |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } else { | 74 } else { |
75 return pair->value; | 75 return pair->value; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 inline Pair* LookupPair(const Key& key) { | 79 inline Pair* LookupPair(const Key& key) { |
80 return DirectChainedHashMap<RawPointerKeyValueTrait<K, V> >::Lookup(key); | 80 return DirectChainedHashMap<RawPointerKeyValueTrait<K, V> >::Lookup(key); |
81 } | 81 } |
82 }; | 82 }; |
83 | 83 |
84 | |
85 template <typename V> | |
86 class IntKeyRawPointerValueTrait { | |
87 public: | |
88 typedef intptr_t Key; | |
89 typedef V Value; | |
90 | |
91 struct Pair { | |
92 Key key; | |
93 Value value; | |
94 Pair() : key(NULL), value() {} | |
95 Pair(const Key key, const Value& value) : key(key), value(value) {} | |
96 Pair(const Pair& other) : key(other.key), value(other.value) {} | |
97 }; | |
98 | |
99 static Key KeyOf(Pair kv) { return kv.key; } | |
100 static Value ValueOf(Pair kv) { return kv.value; } | |
101 static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); } | |
102 static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; } | |
103 }; | |
104 | |
105 template <typename V> | |
106 class IntMap : public DirectChainedHashMap<IntKeyRawPointerValueTrait<V> > { | |
107 public: | |
108 typedef typename IntKeyRawPointerValueTrait<V>::Key Key; | |
109 typedef typename IntKeyRawPointerValueTrait<V>::Value Value; | |
110 typedef typename IntKeyRawPointerValueTrait<V>::Pair Pair; | |
111 | |
112 inline void Insert(const Key& key, const Value& value) { | |
113 Pair pair(key, value); | |
114 DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Insert(pair); | |
115 } | |
116 | |
117 inline V Lookup(const Key& key) { | |
118 Pair* pair = | |
119 DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); | |
120 if (pair == NULL) { | |
121 return V(); | |
122 } else { | |
123 return pair->value; | |
124 } | |
125 } | |
126 | |
127 inline Pair* LookupPair(const Key& key) { | |
128 return DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); | |
129 } | |
130 }; | |
131 | |
132 template <typename K, typename V> | 84 template <typename K, typename V> |
133 class MallocMap | 85 class MallocMap |
134 : public MallocDirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { | 86 : public MallocDirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { |
135 public: | 87 public: |
136 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; | 88 typedef typename RawPointerKeyValueTrait<K, V>::Key Key; |
137 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; | 89 typedef typename RawPointerKeyValueTrait<K, V>::Value Value; |
138 typedef typename RawPointerKeyValueTrait<K, V>::Pair Pair; | 90 typedef typename RawPointerKeyValueTrait<K, V>::Pair Pair; |
139 | 91 |
140 inline void Insert(const Key& key, const Value& value) { | 92 inline void Insert(const Key& key, const Value& value) { |
141 Pair pair(key, value); | 93 Pair pair(key, value); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 Zone* zone_; | 495 Zone* zone_; |
544 TranslationHelper& translation_helper_; | 496 TranslationHelper& translation_helper_; |
545 DartTypeTranslator& type_translator_; | 497 DartTypeTranslator& type_translator_; |
546 | 498 |
547 Script& script_; | 499 Script& script_; |
548 Instance& result_; | 500 Instance& result_; |
549 }; | 501 }; |
550 | 502 |
551 | 503 |
552 struct FunctionScope { | 504 struct FunctionScope { |
553 intptr_t kernel_offset; | 505 FunctionNode* function; |
554 LocalScope* scope; | 506 LocalScope* scope; |
555 }; | 507 }; |
556 | 508 |
557 | 509 |
558 class ScopeBuildingResult : public ZoneAllocated { | 510 class ScopeBuildingResult : public ZoneAllocated { |
559 public: | 511 public: |
560 ScopeBuildingResult() | 512 ScopeBuildingResult() |
561 : this_variable(NULL), | 513 : this_variable(NULL), |
562 type_arguments_variable(NULL), | 514 type_arguments_variable(NULL), |
563 switch_variable(NULL), | 515 switch_variable(NULL), |
564 finally_return_variable(NULL), | 516 finally_return_variable(NULL), |
565 setter_value(NULL), | 517 setter_value(NULL), |
566 yield_jump_variable(NULL), | 518 yield_jump_variable(NULL), |
567 yield_context_variable(NULL) {} | 519 yield_context_variable(NULL) {} |
568 | 520 |
569 IntMap<LocalVariable*> locals; | 521 Map<VariableDeclaration, LocalVariable*> locals; |
570 IntMap<LocalScope*> scopes; | 522 Map<TreeNode, LocalScope*> scopes; |
571 GrowableArray<FunctionScope> function_scopes; | 523 GrowableArray<FunctionScope> function_scopes; |
572 | 524 |
573 // Only non-NULL for instance functions. | 525 // Only non-NULL for instance functions. |
574 LocalVariable* this_variable; | 526 LocalVariable* this_variable; |
575 | 527 |
576 // Only non-NULL for factory constructor functions. | 528 // Only non-NULL for factory constructor functions. |
577 LocalVariable* type_arguments_variable; | 529 LocalVariable* type_arguments_variable; |
578 | 530 |
579 // Non-NULL when the function contains a switch statement. | 531 // Non-NULL when the function contains a switch statement. |
580 LocalVariable* switch_variable; | 532 LocalVariable* switch_variable; |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 namespace kernel { | 1029 namespace kernel { |
1078 | 1030 |
1079 RawObject* EvaluateMetadata(TreeNode* const kernel_node); | 1031 RawObject* EvaluateMetadata(TreeNode* const kernel_node); |
1080 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); | 1032 RawObject* BuildParameterDescriptor(TreeNode* const kernel_node); |
1081 | 1033 |
1082 } // namespace kernel | 1034 } // namespace kernel |
1083 } // namespace dart | 1035 } // namespace dart |
1084 | 1036 |
1085 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 1037 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
1086 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ | 1038 #endif // RUNTIME_VM_KERNEL_TO_IL_H_ |
OLD | NEW |