Chromium Code Reviews| Index: runtime/vm/kernel_to_il.h |
| diff --git a/runtime/vm/kernel_to_il.h b/runtime/vm/kernel_to_il.h |
| index 45003704ab6427b22d7f467688544a930916f23c..7bd6b0f9656b3473231d442a459d00ec36d6a7be 100644 |
| --- a/runtime/vm/kernel_to_il.h |
| +++ b/runtime/vm/kernel_to_il.h |
| @@ -81,6 +81,54 @@ class Map : public DirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { |
| } |
| }; |
| + |
| +template <typename V> |
| +class IntKeyRawPointerValueTrait { |
| + public: |
| + typedef int64_t Key; |
| + typedef V Value; |
| + |
| + struct Pair { |
| + Key key; |
| + Value value; |
| + Pair() : key(NULL), value() {} |
| + Pair(const Key key, const Value& value) : key(key), value(value) {} |
| + Pair(const Pair& other) : key(other.key), value(other.value) {} |
| + }; |
| + |
| + static Key KeyOf(Pair kv) { return kv.key; } |
| + static Value ValueOf(Pair kv) { return kv.value; } |
| + static intptr_t Hashcode(Key key) { return reinterpret_cast<intptr_t>(key); } |
| + static bool IsKeyEqual(Pair kv, Key key) { return kv.key == key; } |
| +}; |
| + |
| +template <typename V> |
| +class IntMap : public DirectChainedHashMap<IntKeyRawPointerValueTrait<V> > { |
| + public: |
| + typedef typename IntKeyRawPointerValueTrait<V>::Key Key; |
| + typedef typename IntKeyRawPointerValueTrait<V>::Value Value; |
| + typedef typename IntKeyRawPointerValueTrait<V>::Pair Pair; |
| + |
| + inline void Insert(const Key& key, const Value& value) { |
| + Pair pair(key, value); |
| + DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Insert(pair); |
| + } |
| + |
| + inline V Lookup(const Key& key) { |
| + Pair* pair = |
| + DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); |
| + if (pair == NULL) { |
| + return V(); |
| + } else { |
| + return pair->value; |
| + } |
| + } |
| + |
| + inline Pair* LookupPair(const Key& key) { |
| + return DirectChainedHashMap<IntKeyRawPointerValueTrait<V> >::Lookup(key); |
| + } |
| +}; |
| + |
| template <typename K, typename V> |
| class MallocMap |
| : public MallocDirectChainedHashMap<RawPointerKeyValueTrait<K, V> > { |
| @@ -502,7 +550,7 @@ class ConstantEvaluator : public ExpressionVisitor { |
| struct FunctionScope { |
| - FunctionNode* function; |
| + int64_t kernelFileOffset; |
|
Kevin Millikin (Google)
2017/03/28 06:42:23
This should be named kernel_file_offset to fit the
jensj
2017/03/28 08:56:28
Done.
|
| LocalScope* scope; |
| }; |
| @@ -518,8 +566,8 @@ class ScopeBuildingResult : public ZoneAllocated { |
| yield_jump_variable(NULL), |
| yield_context_variable(NULL) {} |
| - Map<VariableDeclaration, LocalVariable*> locals; |
| - Map<TreeNode, LocalScope*> scopes; |
| + IntMap<LocalVariable*> locals; |
| + IntMap<LocalScope*> scopes; |
| GrowableArray<FunctionScope> function_scopes; |
| // Only non-NULL for instance functions. |
| @@ -606,7 +654,8 @@ class ScopeBuilder : public RecursiveVisitor { |
| virtual void VisitConstructor(Constructor* node); |
| private: |
| - void EnterScope(TreeNode* node, TokenPosition start_position); |
| + template <typename NewScopeType> |
| + void EnterScope(NewScopeType* node, TokenPosition start_position); |
| void ExitScope(TokenPosition end_position); |
| const Type& TranslateVariableType(VariableDeclaration* variable); |
| @@ -633,7 +682,8 @@ class ScopeBuilder : public RecursiveVisitor { |
| const dart::String& GenerateName(const char* prefix, intptr_t suffix); |
| - void HandleLocalFunction(TreeNode* parent, FunctionNode* function); |
| + template <typename FunctionType> |
| + void HandleLocalFunction(FunctionType* parent, FunctionNode* function); |
| void HandleSpecialLoad(LocalVariable** variable, const dart::String& symbol); |
| void LookupCapturedVariableByName(LocalVariable** variable, |
| const dart::String& name); |
| @@ -781,8 +831,8 @@ class FlowGraphBuilder : public ExpressionVisitor, public StatementVisitor { |
| Fragment TranslateFunctionNode(FunctionNode* node, TreeNode* parent); |
| - Fragment EnterScope(TreeNode* node, bool* new_context = NULL); |
| - Fragment ExitScope(TreeNode* node); |
| + Fragment EnterScope(int64_t kernel_offset, bool* new_context = NULL); |
| + Fragment ExitScope(int64_t kernel_offset); |
| Fragment LoadContextAt(int depth); |
| Fragment AdjustContextTo(int depth); |