| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /** Weak set of AST nodes. */ | |
| 6 // TODO(sigmund): delete this. This is a temporary workaround to keep 'frog' | |
| 7 // as independent as possible of the await experimental feature. Ideally we | |
| 8 // should either make [Node] hashable or store information collected by analyses | |
| 9 // in the nodes themselves. | |
| 10 class NodeSet { | |
| 11 Map<String, List<Node>> _hashset; | |
| 12 NodeSet() : _hashset = {}; | |
| 13 | |
| 14 bool add(Node n) { | |
| 15 if (contains(n)) return false; | |
| 16 String key = n.span.locationText; | |
| 17 List<Node> nodes = _hashset[key]; | |
| 18 if (nodes == null) { | |
| 19 _hashset[key] = [n]; | |
| 20 } else { | |
| 21 nodes.add(n); | |
| 22 } | |
| 23 return true; | |
| 24 } | |
| 25 | |
| 26 bool contains(Node n) { | |
| 27 String key = n.span.locationText; | |
| 28 List<Node> nodes = _hashset[key]; | |
| 29 if (nodes == null) { | |
| 30 return false; | |
| 31 } | |
| 32 for (Node member in nodes) { | |
| 33 if (n === member) return true; | |
| 34 } | |
| 35 return false; | |
| 36 } | |
| 37 } | |
| OLD | NEW |