| 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 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 7 abstract class _NamerName extends jsAst.Name { | 8 abstract class _NamerName extends jsAst.Name { |
| 8 int get _kind; | 9 int get _kind; |
| 9 _NamerName get _target => this; | 10 _NamerName get _target => this; |
| 10 | 11 |
| 11 String toString() { | 12 String toString() { |
| 12 if (DEBUG_MODE) { | 13 if (DEBUG_MODE) { |
| 13 return 'Name($key)'; | 14 return 'Name($key)'; |
| 14 } | 15 } |
| 15 throw new UnsupportedError("Cannot convert a name to a string"); | 16 throw new UnsupportedError("Cannot convert a name to a string"); |
| 16 } | 17 } |
| 17 } | 18 } |
| 18 | 19 |
| 19 enum _NamerNameKinds { StringBacked, Getter, Setter, Async, Compound, Token } | 20 enum _NamerNameKinds { StringBacked, Getter, Setter, Async, Compound, Token } |
| 20 | 21 |
| 22 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 21 class StringBackedName extends _NamerName { | 23 class StringBackedName extends _NamerName { |
| 22 final String name; | 24 final String name; |
| 23 int get _kind => _NamerNameKinds.StringBacked.index; | 25 int get _kind => _NamerNameKinds.StringBacked.index; |
| 24 | 26 |
| 25 StringBackedName(this.name); | 27 StringBackedName(this.name); |
| 26 | 28 |
| 27 String get key => name; | 29 String get key => name; |
| 28 | 30 |
| 29 operator ==(other) { | 31 operator ==(other) { |
| 30 if (other is _NameReference) other = other._target; | 32 if (other is _NameReference) other = other._target; |
| 31 if (identical(this, other)) return true; | 33 if (identical(this, other)) return true; |
| 32 return (other is StringBackedName) && other.name == name; | 34 return (other is StringBackedName) && other.name == name; |
| 33 } | 35 } |
| 34 | 36 |
| 35 int get hashCode => name.hashCode; | 37 int get hashCode => name.hashCode; |
| 36 | 38 |
| 37 int compareTo(covariant _NamerName other) { | 39 int compareTo(covariant _NamerName other) { |
| 38 other = other._target; | 40 other = other._target; |
| 39 if (other._kind != _kind) return other._kind - _kind; | 41 if (other._kind != _kind) return other._kind - _kind; |
| 40 return name.compareTo(other.name); | 42 return name.compareTo(other.name); |
| 41 } | 43 } |
| 42 } | 44 } |
| 43 | 45 |
| 46 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 44 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer { | 47 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer { |
| 45 final jsAst.Name prefix; | 48 final jsAst.Name prefix; |
| 46 final jsAst.Name base; | 49 final jsAst.Name base; |
| 47 int get _kind; | 50 int get _kind; |
| 48 | 51 |
| 49 Iterable<jsAst.Node> get containedNodes => [prefix, base]; | 52 Iterable<jsAst.Node> get containedNodes => [prefix, base]; |
| 50 | 53 |
| 51 _PrefixedName(this.prefix, this.base); | 54 _PrefixedName(this.prefix, this.base); |
| 52 | 55 |
| 53 String get name => prefix.name + base.name; | 56 String get name => prefix.name + base.name; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 if (result == 0) { | 74 if (result == 0) { |
| 72 result = prefix.compareTo(otherSameKind.prefix); | 75 result = prefix.compareTo(otherSameKind.prefix); |
| 73 if (result == 0) { | 76 if (result == 0) { |
| 74 result = base.compareTo(otherSameKind.base); | 77 result = base.compareTo(otherSameKind.base); |
| 75 } | 78 } |
| 76 } | 79 } |
| 77 return result; | 80 return result; |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 84 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 81 class GetterName extends _PrefixedName { | 85 class GetterName extends _PrefixedName { |
| 82 int get _kind => _NamerNameKinds.Getter.index; | 86 int get _kind => _NamerNameKinds.Getter.index; |
| 83 | 87 |
| 84 GetterName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); | 88 GetterName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); |
| 85 } | 89 } |
| 86 | 90 |
| 91 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 87 class SetterName extends _PrefixedName { | 92 class SetterName extends _PrefixedName { |
| 88 int get _kind => _NamerNameKinds.Setter.index; | 93 int get _kind => _NamerNameKinds.Setter.index; |
| 89 | 94 |
| 90 SetterName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); | 95 SetterName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); |
| 91 } | 96 } |
| 92 | 97 |
| 98 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 93 class _AsyncName extends _PrefixedName { | 99 class _AsyncName extends _PrefixedName { |
| 94 int get _kind => _NamerNameKinds.Async.index; | 100 int get _kind => _NamerNameKinds.Async.index; |
| 95 | 101 |
| 96 _AsyncName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); | 102 _AsyncName(jsAst.Name prefix, jsAst.Name base) : super(prefix, base); |
| 97 | 103 |
| 98 @override | 104 @override |
| 99 bool get allowRename => true; | 105 bool get allowRename => true; |
| 100 } | 106 } |
| 101 | 107 |
| 108 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 102 class CompoundName extends _NamerName implements jsAst.AstContainer { | 109 class CompoundName extends _NamerName implements jsAst.AstContainer { |
| 103 final List<_NamerName> _parts; | 110 final List<_NamerName> _parts; |
| 104 int get _kind => _NamerNameKinds.Compound.index; | 111 int get _kind => _NamerNameKinds.Compound.index; |
| 105 String _cachedName; | 112 String _cachedName; |
| 106 int _cachedHashCode = -1; | 113 int _cachedHashCode = -1; |
| 107 | 114 |
| 108 Iterable<jsAst.Node> get containedNodes => _parts; | 115 Iterable<jsAst.Node> get containedNodes => _parts; |
| 109 | 116 |
| 110 CompoundName(this._parts); | 117 CompoundName(this._parts); |
| 111 | 118 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 return otherSameKind._parts.length - _parts.length; | 154 return otherSameKind._parts.length - _parts.length; |
| 148 } | 155 } |
| 149 int result = 0; | 156 int result = 0; |
| 150 for (int pos = 0; result == 0 && pos < _parts.length; pos++) { | 157 for (int pos = 0; result == 0 && pos < _parts.length; pos++) { |
| 151 result = _parts[pos].compareTo(otherSameKind._parts[pos]); | 158 result = _parts[pos].compareTo(otherSameKind._parts[pos]); |
| 152 } | 159 } |
| 153 return result; | 160 return result; |
| 154 } | 161 } |
| 155 } | 162 } |
| 156 | 163 |
| 164 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 157 class TokenName extends _NamerName implements jsAst.ReferenceCountedAstNode { | 165 class TokenName extends _NamerName implements jsAst.ReferenceCountedAstNode { |
| 158 int get _kind => _NamerNameKinds.Token.index; | 166 int get _kind => _NamerNameKinds.Token.index; |
| 159 String _name; | 167 String _name; |
| 160 final String key; | 168 final String key; |
| 161 final TokenScope _scope; | 169 final TokenScope _scope; |
| 162 int _rc = 0; | 170 int _rc = 0; |
| 163 | 171 |
| 164 TokenName(this._scope, this.key); | 172 TokenName(this._scope, this.key); |
| 165 | 173 |
| 166 bool get isFinalized => _name != null; | 174 bool get isFinalized => _name != null; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 192 | 200 |
| 193 finalize() { | 201 finalize() { |
| 194 assert( | 202 assert( |
| 195 !isFinalized, | 203 !isFinalized, |
| 196 failedAt(NO_LOCATION_SPANNABLE, | 204 failedAt(NO_LOCATION_SPANNABLE, |
| 197 "TokenName($key)=$_name has already been finalized.")); | 205 "TokenName($key)=$_name has already been finalized.")); |
| 198 _name = _scope.getNextName(); | 206 _name = _scope.getNextName(); |
| 199 } | 207 } |
| 200 } | 208 } |
| 201 | 209 |
| 210 // ignore: STRONG_MODE_INVALID_METHOD_OVERRIDE_FROM_BASE |
| 202 class _NameReference extends _NamerName implements jsAst.AstContainer { | 211 class _NameReference extends _NamerName implements jsAst.AstContainer { |
| 203 _NamerName _target; | 212 _NamerName _target; |
| 204 | 213 |
| 205 int get _kind => _target._kind; | 214 int get _kind => _target._kind; |
| 206 String get key => _target.key; | 215 String get key => _target.key; |
| 207 | 216 |
| 208 Iterable<jsAst.Node> get containedNodes => [_target]; | 217 Iterable<jsAst.Node> get containedNodes => [_target]; |
| 209 | 218 |
| 210 _NameReference(this._target); | 219 _NameReference(this._target); |
| 211 | 220 |
| 212 String get name => _target.name; | 221 String get name => _target.name; |
| 213 | 222 |
| 214 @override | 223 @override |
| 215 int compareTo(covariant _NamerName other) => _target.compareTo(other); | 224 int compareTo(covariant _NamerName other) => _target.compareTo(other); |
| 216 | 225 |
| 217 @override | 226 @override |
| 218 bool operator ==(other) => _target == other; | 227 bool operator ==(other) => _target == other; |
| 219 | 228 |
| 220 @override | 229 @override |
| 221 int get hashCode => _target.hashCode; | 230 int get hashCode => _target.hashCode; |
| 222 } | 231 } |
| OLD | NEW |