OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 library dart2js.util; | 5 library dart2js.util; |
6 | 6 |
7 import 'util_implementation.dart'; | 7 import 'util_implementation.dart'; |
8 import 'characters.dart'; | 8 import 'characters.dart'; |
9 | 9 |
10 export 'setlet.dart'; | 10 export 'setlet.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 static int mapHash(Map map, [int existing = 0]) { | 56 static int mapHash(Map map, [int existing = 0]) { |
57 int h = existing; | 57 int h = existing; |
58 for (var key in map.keys) { | 58 for (var key in map.keys) { |
59 h = mixHashCodeBits(h, key.hashCode); | 59 h = mixHashCodeBits(h, key.hashCode); |
60 h = mixHashCodeBits(h, map[key].hashCode); | 60 h = mixHashCodeBits(h, map[key].hashCode); |
61 } | 61 } |
62 return h; | 62 return h; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 /** | |
67 * Tagging interface for classes from which source spans can be generated. | |
68 */ | |
69 // TODO(johnniwinther): Find a better name. | |
70 // TODO(ahe): How about "Bolt"? | |
71 abstract class Spannable {} | |
72 | |
73 class _SpannableSentinel implements Spannable { | |
74 final String name; | |
75 | |
76 const _SpannableSentinel(this.name); | |
77 | |
78 String toString() => name; | |
79 } | |
80 | |
81 /// Sentinel spannable used to mark that diagnostics should point to the | |
82 /// current element. Note that the diagnostic reporting will fail if the current | |
83 /// element is `null`. | |
84 const Spannable CURRENT_ELEMENT_SPANNABLE = | |
85 const _SpannableSentinel("Current element"); | |
86 | |
87 /// Sentinel spannable used to mark that there might be no location for the | |
88 /// diagnostic. Use this only when it is not an error not to have a current | |
89 /// element. | |
90 const Spannable NO_LOCATION_SPANNABLE = | |
91 const _SpannableSentinel("No location"); | |
92 | |
93 class SpannableAssertionFailure { | |
94 final Spannable node; | |
95 final String message; | |
96 SpannableAssertionFailure(this.node, this.message); | |
97 | |
98 String toString() => 'Assertion failure' | |
99 '${message != null ? ': $message' : ''}'; | |
100 } | |
101 | |
102 bool equalElements(List a, List b) { | 66 bool equalElements(List a, List b) { |
103 if (a.length != b.length) return false; | 67 if (a.length != b.length) return false; |
104 for (int index = 0; index < a.length; index++) { | 68 for (int index = 0; index < a.length; index++) { |
105 if (a[index] != b[index]) { | 69 if (a[index] != b[index]) { |
106 return false; | 70 return false; |
107 } | 71 } |
108 } | 72 } |
109 return true; | 73 return true; |
110 } | 74 } |
111 | 75 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 if (usedNames.contains(suggestedName)) { | 217 if (usedNames.contains(suggestedName)) { |
254 int counter = 0; | 218 int counter = 0; |
255 while (usedNames.contains(result)) { | 219 while (usedNames.contains(result)) { |
256 counter++; | 220 counter++; |
257 result = "$suggestedName$counter"; | 221 result = "$suggestedName$counter"; |
258 } | 222 } |
259 } | 223 } |
260 usedNames.add(result); | 224 usedNames.add(result); |
261 return result; | 225 return result; |
262 } | 226 } |
OLD | NEW |