Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1985)

Side by Side Diff: pkg/compiler/lib/src/js_backend/namer_names.dart

Issue 1274203003: dart2js: Ensure each use site of a name uses a new ast node. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 5 part of js_backend;
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 10
10 toString() => throw new UnsupportedError("Cannot convert a name to a string"); 11 toString() => throw new UnsupportedError("Cannot convert a name to a string");
11 } 12 }
12 13
13 enum _NamerNameKinds { 14 enum _NamerNameKinds {
14 StringBacked, 15 StringBacked,
15 Getter, 16 Getter,
16 Setter, 17 Setter,
17 Async, 18 Async,
18 Compound, 19 Compound,
19 Token 20 Token
20 } 21 }
21 22
22 class StringBackedName extends _NamerName { 23 class StringBackedName extends _NamerName {
23 final String name; 24 final String name;
24 int get _kind => _NamerNameKinds.StringBacked.index; 25 int get _kind => _NamerNameKinds.StringBacked.index;
25 26
26 StringBackedName(this.name); 27 StringBackedName(this.name);
27 28
28 String get key => name; 29 String get key => name;
29 30
30 operator==(other) { 31 operator==(other) {
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(_NamerName other) { 39 int compareTo(_NamerName other) {
40 other = other._target;
38 if (other._kind != _kind) return other._kind - _kind; 41 if (other._kind != _kind) return other._kind - _kind;
39 return name.compareTo(other.name); 42 return name.compareTo(other.name);
40 } 43 }
41 } 44 }
42 45
43 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer { 46 abstract class _PrefixedName extends _NamerName implements jsAst.AstContainer {
44 final jsAst.Name prefix; 47 final jsAst.Name prefix;
45 final jsAst.Name base; 48 final jsAst.Name base;
46 int get _kind; 49 int get _kind;
47 50
48 Iterable<jsAst.Node> get containedNodes => [prefix, base]; 51 Iterable<jsAst.Node> get containedNodes => [prefix, base];
49 52
50 _PrefixedName(this.prefix, this.base); 53 _PrefixedName(this.prefix, this.base);
51 54
52 String get name => prefix.name + base.name; 55 String get name => prefix.name + base.name;
53 56
54 String get key => prefix.key + base.key; 57 String get key => prefix.key + base.key;
55 58
56 bool operator==(other) { 59 bool operator==(other) {
60 if (other is _NameReference) other = other._target;
57 if (identical(this, other)) return true; 61 if (identical(this, other)) return true;
58 if (other is! _PrefixedName) return false; 62 if (other is! _PrefixedName) return false;
59 return other.base == base && other.prefix == prefix; 63 return other.base == base && other.prefix == prefix;
60 } 64 }
61 65
62 int get hashCode => base.hashCode * 13 + prefix.hashCode; 66 int get hashCode => base.hashCode * 13 + prefix.hashCode;
63 67
64 int compareTo(_NamerName other) { 68 int compareTo(_NamerName other) {
69 other = other._target;
65 if (other._kind != _kind) return other._kind - _kind; 70 if (other._kind != _kind) return other._kind - _kind;
66 _PrefixedName otherSameKind = other; 71 _PrefixedName otherSameKind = other;
67 int result = prefix.compareTo(otherSameKind.prefix); 72 int result = prefix.compareTo(otherSameKind.prefix);
68 if (result == 0) { 73 if (result == 0) {
69 result = prefix.compareTo(otherSameKind.prefix); 74 result = prefix.compareTo(otherSameKind.prefix);
70 if (result == 0) { 75 if (result == 0) {
71 result = base.compareTo(otherSameKind.base); 76 result = base.compareTo(otherSameKind.base);
72 } 77 }
73 } 78 }
74 return result; 79 return result;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 String get name { 114 String get name {
110 if (_cachedName == null) { 115 if (_cachedName == null) {
111 _cachedName = _parts.map((jsAst.Name name) => name.name).join(); 116 _cachedName = _parts.map((jsAst.Name name) => name.name).join();
112 } 117 }
113 return _cachedName; 118 return _cachedName;
114 } 119 }
115 120
116 String get key => _parts.map((_NamerName name) => name.key).join(); 121 String get key => _parts.map((_NamerName name) => name.key).join();
117 122
118 bool operator==(other) { 123 bool operator==(other) {
124 if (other is _NameReference) other = other._target;
119 if (identical(this, other)) return true; 125 if (identical(this, other)) return true;
120 if (other is! CompoundName) return false; 126 if (other is! CompoundName) return false;
121 if (other._parts.length != _parts.length) return false; 127 if (other._parts.length != _parts.length) return false;
122 for (int i = 0; i < _parts.length; ++i) { 128 for (int i = 0; i < _parts.length; ++i) {
123 if (other._parts[i] != _parts[i]) return false; 129 if (other._parts[i] != _parts[i]) return false;
124 } 130 }
125 return true; 131 return true;
126 } 132 }
127 133
128 int get hashCode { 134 int get hashCode {
129 if (_cachedHashCode < 0) { 135 if (_cachedHashCode < 0) {
130 _cachedHashCode = 0; 136 _cachedHashCode = 0;
131 for (jsAst.Name name in _parts) { 137 for (jsAst.Name name in _parts) {
132 _cachedHashCode = (_cachedHashCode * 17 + name.hashCode) & 0x7fffffff; 138 _cachedHashCode = (_cachedHashCode * 17 + name.hashCode) & 0x7fffffff;
133 } 139 }
134 } 140 }
135 return _cachedHashCode; 141 return _cachedHashCode;
136 } 142 }
137 143
138 int compareTo(_NamerName other) { 144 int compareTo(_NamerName other) {
145 other = other._target;
139 if (other._kind != _kind) return other._kind - _kind; 146 if (other._kind != _kind) return other._kind - _kind;
140 CompoundName otherSameKind = other; 147 CompoundName otherSameKind = other;
141 if (otherSameKind._parts.length != _parts.length) { 148 if (otherSameKind._parts.length != _parts.length) {
142 return otherSameKind._parts.length - _parts.length; 149 return otherSameKind._parts.length - _parts.length;
143 } 150 }
144 int result = 0; 151 int result = 0;
145 for (int pos = 0; result == 0 && pos < _parts.length; pos++) { 152 for (int pos = 0; result == 0 && pos < _parts.length; pos++) {
146 result = _parts[pos].compareTo(otherSameKind._parts[pos]); 153 result = _parts[pos].compareTo(otherSameKind._parts[pos]);
147 } 154 }
148 return result; 155 return result;
(...skipping 11 matching lines...) Expand all
160 167
161 bool get isFinalized => _name != null; 168 bool get isFinalized => _name != null;
162 169
163 String get name { 170 String get name {
164 assert(isFinalized); 171 assert(isFinalized);
165 return _name; 172 return _name;
166 } 173 }
167 174
168 @override 175 @override
169 int compareTo(_NamerName other) { 176 int compareTo(_NamerName other) {
177 other = other._target;
170 if (other._kind != _kind) return other._kind - _kind; 178 if (other._kind != _kind) return other._kind - _kind;
171 TokenName otherToken = other; 179 TokenName otherToken = other;
172 return key.compareTo(otherToken.key); 180 return key.compareTo(otherToken.key);
173 } 181 }
174 182
175 markSeen(jsAst.TokenCounter counter) => _rc++; 183 markSeen(jsAst.TokenCounter counter) => _rc++;
176 184
185 @override
186 bool operator==(other) {
187 if (other is _NameReference) other = other._target;
188 if (identical(this, other)) return true;
189 return false;
190 }
191
192 @override
193 int get hashCode => super.hashCode;
194
177 finalize() { 195 finalize() {
178 assert(!isFinalized); 196 assert(!isFinalized);
179 _name = _scope.getNextName(); 197 _name = _scope.getNextName();
180 } 198 }
199 }
200
201 class _NameReference extends _NamerName implements jsAst.AstContainer {
202 _NamerName _target;
203
204 int get _kind => _target._kind;
205 String get key => _target.key;
206
207 Iterable<jsAst.Node> get containedNodes => [_target];
208
209 _NameReference(this._target);
210
211 String get name => _target.name;
212
213 @override
214 int compareTo(_NamerName other) => _target.compareTo(other);
215
216 @override
217 bool operator==(other) => _target == other;
218
219 @override
220 int get hashCode => _target.hashCode;
181 } 221 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698