OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 part of js_backend.namer; | 5 part of js_backend.namer; |
6 | 6 |
7 abstract class _NamerName extends jsAst.Name { | 7 abstract class _NamerName extends jsAst.Name { |
8 int get _kind; | 8 int get _kind; |
9 _NamerName get _target => this; | 9 _NamerName get _target => this; |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 String get key => name; | 27 String get key => name; |
28 | 28 |
29 operator ==(other) { | 29 operator ==(other) { |
30 if (other is _NameReference) other = other._target; | 30 if (other is _NameReference) other = other._target; |
31 if (identical(this, other)) return true; | 31 if (identical(this, other)) return true; |
32 return (other is StringBackedName) && other.name == name; | 32 return (other is StringBackedName) && other.name == name; |
33 } | 33 } |
34 | 34 |
35 int get hashCode => name.hashCode; | 35 int get hashCode => name.hashCode; |
36 | 36 |
37 int compareTo(_NamerName other) { | 37 int compareTo(covariant _NamerName other) { |
38 other = other._target; | 38 other = other._target; |
39 if (other._kind != _kind) return other._kind - _kind; | 39 if (other._kind != _kind) return other._kind - _kind; |
40 return name.compareTo(other.name); | 40 return name.compareTo(other.name); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer { | 44 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer { |
45 final jsAst.Name prefix; | 45 final jsAst.Name prefix; |
46 final jsAst.Name base; | 46 final jsAst.Name base; |
47 int get _kind; | 47 int get _kind; |
48 | 48 |
49 Iterable<jsAst.Node> get containedNodes => [prefix, base]; | 49 Iterable<jsAst.Node> get containedNodes => [prefix, base]; |
50 | 50 |
51 _PrefixedName(this.prefix, this.base); | 51 _PrefixedName(this.prefix, this.base); |
52 | 52 |
53 String get name => prefix.name + base.name; | 53 String get name => prefix.name + base.name; |
54 | 54 |
55 String get key => prefix.key + base.key; | 55 String get key => prefix.key + base.key; |
56 | 56 |
57 bool operator ==(other) { | 57 bool operator ==(other) { |
58 if (other is _NameReference) other = other._target; | 58 if (other is _NameReference) other = other._target; |
59 if (identical(this, other)) return true; | 59 if (identical(this, other)) return true; |
60 if (other is! _PrefixedName) return false; | 60 if (other is! _PrefixedName) return false; |
61 return other.base == base && other.prefix == prefix; | 61 return other.base == base && other.prefix == prefix; |
62 } | 62 } |
63 | 63 |
64 int get hashCode => base.hashCode * 13 + prefix.hashCode; | 64 int get hashCode => base.hashCode * 13 + prefix.hashCode; |
65 | 65 |
66 int compareTo(_NamerName other) { | 66 int compareTo(covariant _NamerName other) { |
67 other = other._target; | 67 other = other._target; |
68 if (other._kind != _kind) return other._kind - _kind; | 68 if (other._kind != _kind) return other._kind - _kind; |
69 _PrefixedName otherSameKind = other; | 69 _PrefixedName otherSameKind = other; |
70 int result = prefix.compareTo(otherSameKind.prefix); | 70 int result = prefix.compareTo(otherSameKind.prefix); |
71 if (result == 0) { | 71 if (result == 0) { |
72 result = prefix.compareTo(otherSameKind.prefix); | 72 result = prefix.compareTo(otherSameKind.prefix); |
73 if (result == 0) { | 73 if (result == 0) { |
74 result = base.compareTo(otherSameKind.base); | 74 result = base.compareTo(otherSameKind.base); |
75 } | 75 } |
76 } | 76 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int get hashCode { | 132 int get hashCode { |
133 if (_cachedHashCode < 0) { | 133 if (_cachedHashCode < 0) { |
134 _cachedHashCode = 0; | 134 _cachedHashCode = 0; |
135 for (jsAst.Name name in _parts) { | 135 for (jsAst.Name name in _parts) { |
136 _cachedHashCode = (_cachedHashCode * 17 + name.hashCode) & 0x7fffffff; | 136 _cachedHashCode = (_cachedHashCode * 17 + name.hashCode) & 0x7fffffff; |
137 } | 137 } |
138 } | 138 } |
139 return _cachedHashCode; | 139 return _cachedHashCode; |
140 } | 140 } |
141 | 141 |
142 int compareTo(_NamerName other) { | 142 int compareTo(covariant _NamerName other) { |
143 other = other._target; | 143 other = other._target; |
144 if (other._kind != _kind) return other._kind - _kind; | 144 if (other._kind != _kind) return other._kind - _kind; |
145 CompoundName otherSameKind = other; | 145 CompoundName otherSameKind = other; |
146 if (otherSameKind._parts.length != _parts.length) { | 146 if (otherSameKind._parts.length != _parts.length) { |
147 return otherSameKind._parts.length - _parts.length; | 147 return otherSameKind._parts.length - _parts.length; |
148 } | 148 } |
149 int result = 0; | 149 int result = 0; |
150 for (int pos = 0; result == 0 && pos < _parts.length; pos++) { | 150 for (int pos = 0; result == 0 && pos < _parts.length; pos++) { |
151 result = _parts[pos].compareTo(otherSameKind._parts[pos]); | 151 result = _parts[pos].compareTo(otherSameKind._parts[pos]); |
152 } | 152 } |
(...skipping 11 matching lines...) Expand all Loading... |
164 TokenName(this._scope, this.key); | 164 TokenName(this._scope, this.key); |
165 | 165 |
166 bool get isFinalized => _name != null; | 166 bool get isFinalized => _name != null; |
167 | 167 |
168 String get name { | 168 String get name { |
169 assert(isFinalized); | 169 assert(isFinalized); |
170 return _name; | 170 return _name; |
171 } | 171 } |
172 | 172 |
173 @override | 173 @override |
174 int compareTo(_NamerName other) { | 174 int compareTo(covariant _NamerName other) { |
175 other = other._target; | 175 other = other._target; |
176 if (other._kind != _kind) return other._kind - _kind; | 176 if (other._kind != _kind) return other._kind - _kind; |
177 TokenName otherToken = other; | 177 TokenName otherToken = other; |
178 return key.compareTo(otherToken.key); | 178 return key.compareTo(otherToken.key); |
179 } | 179 } |
180 | 180 |
181 markSeen(jsAst.TokenCounter counter) => _rc++; | 181 markSeen(jsAst.TokenCounter counter) => _rc++; |
182 | 182 |
183 @override | 183 @override |
184 bool operator ==(other) { | 184 bool operator ==(other) { |
(...skipping 20 matching lines...) Expand all Loading... |
205 int get _kind => _target._kind; | 205 int get _kind => _target._kind; |
206 String get key => _target.key; | 206 String get key => _target.key; |
207 | 207 |
208 Iterable<jsAst.Node> get containedNodes => [_target]; | 208 Iterable<jsAst.Node> get containedNodes => [_target]; |
209 | 209 |
210 _NameReference(this._target); | 210 _NameReference(this._target); |
211 | 211 |
212 String get name => _target.name; | 212 String get name => _target.name; |
213 | 213 |
214 @override | 214 @override |
215 int compareTo(_NamerName other) => _target.compareTo(other); | 215 int compareTo(covariant _NamerName other) => _target.compareTo(other); |
216 | 216 |
217 @override | 217 @override |
218 bool operator ==(other) => _target == other; | 218 bool operator ==(other) => _target == other; |
219 | 219 |
220 @override | 220 @override |
221 int get hashCode => _target.hashCode; | 221 int get hashCode => _target.hashCode; |
222 } | 222 } |
OLD | NEW |