Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 44741aa

Browse files
committed
Fixes #378
Handles fields on "extension" types See patch #1 for the test without the fix. [email protected] Review URL: https://codereview.chromium.org/1492523004 .
1 parent 14a5da5 commit 44741aa

File tree

7 files changed

+351
-8
lines changed

7 files changed

+351
-8
lines changed

lib/src/codegen/js_codegen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
776776
}
777777

778778
// Emit the signature on the class recording the runtime type information
779+
var extensions = _extensionsToImplement(classElem);
779780
{
780781
var tStatics = <JS.Property>[];
781782
var tMethods = <JS.Property>[];
@@ -827,7 +828,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
827828
sigFields.add(build('statics', tStatics));
828829
sigFields.add(aNames);
829830
}
830-
if (!sigFields.isEmpty) {
831+
if (!sigFields.isEmpty || extensions.isNotEmpty) {
831832
var sig = new JS.ObjectInitializer(sigFields);
832833
var classExpr = new JS.Identifier(name);
833834
body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig]));
@@ -836,7 +837,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
836837

837838
// If a concrete class implements one of our extensions, we might need to
838839
// add forwarders.
839-
var extensions = _extensionsToImplement(classElem);
840840
if (extensions.isNotEmpty) {
841841
var methodNames = <JS.Expression>[];
842842
for (var e in extensions) {
@@ -3388,7 +3388,7 @@ class JSGenerator extends CodeGenerator {
33883388
// Clone the AST first, so we can mutate it.
33893389
unit = unit.clone();
33903390
var library = unit.library.element.library;
3391-
var fields = findFieldsNeedingStorage(unit);
3391+
var fields = findFieldsNeedingStorage(unit, _extensionTypes);
33923392
var codegen =
33933393
new JSCodegenVisitor(compiler, rules, library, _extensionTypes, fields);
33943394
var module = codegen.emitLibrary(unit);

lib/src/codegen/js_field_storage.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import '../info.dart' show LibraryUnit;
1212

1313
/// We use a storage slot for fields that override or can be overridden by
1414
/// getter/setter pairs.
15-
HashSet<FieldElement> findFieldsNeedingStorage(LibraryUnit library) {
15+
HashSet<FieldElement> findFieldsNeedingStorage(
16+
LibraryUnit library, HashSet<ClassElement> extensionTypes) {
1617
var overrides = new HashSet<FieldElement>();
1718
for (var unit in library.partsThenLibrary) {
1819
for (var cls in unit.element.types) {
1920
var superclasses = getSuperclasses(cls);
2021
for (var field in cls.fields) {
2122
if (!field.isSynthetic && !overrides.contains(field)) {
22-
checkForPropertyOverride(field, superclasses, overrides);
23+
checkForPropertyOverride(
24+
field, superclasses, overrides, extensionTypes);
2325
}
2426
}
2527
}
@@ -28,8 +30,11 @@ HashSet<FieldElement> findFieldsNeedingStorage(LibraryUnit library) {
2830
return overrides;
2931
}
3032

31-
void checkForPropertyOverride(FieldElement field,
32-
List<ClassElement> superclasses, HashSet<FieldElement> overrides) {
33+
void checkForPropertyOverride(
34+
FieldElement field,
35+
List<ClassElement> superclasses,
36+
HashSet<FieldElement> overrides,
37+
HashSet<ClassElement> extensionTypes) {
3338
assert(!field.isSynthetic);
3439

3540
var library = field.library;
@@ -41,7 +46,8 @@ void checkForPropertyOverride(FieldElement field,
4146
// If we find an abstract getter/setter pair, stop the search.
4247
var getter = superprop.getter;
4348
var setter = superprop.setter;
44-
if ((getter == null || getter.isAbstract) &&
49+
if (!extensionTypes.contains(superclass) &&
50+
(getter == null || getter.isAbstract) &&
4551
(setter == null || setter.isAbstract)) {
4652
break;
4753
}
Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
dart_library.library('collection/src/comparators', null, /* Imports */[
2+
"dart/_runtime",
3+
'dart/core'
4+
], /* Lazy imports */[
5+
], function(exports, dart, core) {
6+
'use strict';
7+
let dartx = dart.dartx;
8+
const _zero = 48;
9+
const _upperCaseA = 65;
10+
const _upperCaseZ = 90;
11+
const _lowerCaseA = 97;
12+
const _lowerCaseZ = 122;
13+
const _asciiCaseBit = 32;
14+
function equalsIgnoreAsciiCase(a, b) {
15+
if (a[dartx.length] != b[dartx.length])
16+
return false;
17+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
18+
let aChar = a[dartx.codeUnitAt](i);
19+
let bChar = b[dartx.codeUnitAt](i);
20+
if (aChar == bChar)
21+
continue;
22+
if ((dart.notNull(aChar) ^ dart.notNull(bChar)) != _asciiCaseBit)
23+
return false;
24+
let aCharUpperCase = dart.notNull(aChar) | dart.notNull(_asciiCaseBit);
25+
if (dart.notNull(_upperCaseA) <= dart.notNull(aCharUpperCase) && dart.notNull(aCharUpperCase) <= dart.notNull(_upperCaseZ)) {
26+
continue;
27+
}
28+
return false;
29+
}
30+
return true;
31+
}
32+
dart.fn(equalsIgnoreAsciiCase, core.bool, [core.String, core.String]);
33+
function hashIgnoreAsciiCase(string) {
34+
let hash = 0;
35+
for (let i = 0; dart.notNull(i) < dart.notNull(string[dartx.length]); i = dart.notNull(i) + 1) {
36+
let char = string[dartx.codeUnitAt](i);
37+
if (dart.notNull(_lowerCaseA) <= dart.notNull(char) && dart.notNull(char) <= dart.notNull(_lowerCaseZ)) {
38+
char = dart.notNull(char) - dart.notNull(_asciiCaseBit);
39+
}
40+
hash = 536870911 & dart.notNull(hash) + dart.notNull(char);
41+
hash = 536870911 & dart.notNull(hash) + ((524287 & dart.notNull(hash)) << 10);
42+
hash = dart.notNull(hash) >> 6;
43+
}
44+
hash = 536870911 & dart.notNull(hash) + ((67108863 & dart.notNull(hash)) << 3);
45+
hash = dart.notNull(hash) >> 11;
46+
return 536870911 & dart.notNull(hash) + ((16383 & dart.notNull(hash)) << 15);
47+
}
48+
dart.fn(hashIgnoreAsciiCase, core.int, [core.String]);
49+
function compareAsciiUpperCase(a, b) {
50+
let defaultResult = 0;
51+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
52+
if (dart.notNull(i) >= dart.notNull(b[dartx.length]))
53+
return 1;
54+
let aChar = a[dartx.codeUnitAt](i);
55+
let bChar = b[dartx.codeUnitAt](i);
56+
if (aChar == bChar)
57+
continue;
58+
let aUpperCase = aChar;
59+
let bUpperCase = bChar;
60+
if (dart.notNull(_lowerCaseA) <= dart.notNull(aChar) && dart.notNull(aChar) <= dart.notNull(_lowerCaseZ)) {
61+
aUpperCase = dart.notNull(aUpperCase) - dart.notNull(_asciiCaseBit);
62+
}
63+
if (dart.notNull(_lowerCaseA) <= dart.notNull(bChar) && dart.notNull(bChar) <= dart.notNull(_lowerCaseZ)) {
64+
bUpperCase = dart.notNull(bUpperCase) - dart.notNull(_asciiCaseBit);
65+
}
66+
if (aUpperCase != bUpperCase)
67+
return (dart.notNull(aUpperCase) - dart.notNull(bUpperCase))[dartx.sign];
68+
if (defaultResult == 0)
69+
defaultResult = dart.notNull(aChar) - dart.notNull(bChar);
70+
}
71+
if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length]))
72+
return -1;
73+
return defaultResult[dartx.sign];
74+
}
75+
dart.fn(compareAsciiUpperCase, core.int, [core.String, core.String]);
76+
function compareAsciiLowerCase(a, b) {
77+
let defaultResult = 0;
78+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
79+
if (dart.notNull(i) >= dart.notNull(b[dartx.length]))
80+
return 1;
81+
let aChar = a[dartx.codeUnitAt](i);
82+
let bChar = b[dartx.codeUnitAt](i);
83+
if (aChar == bChar)
84+
continue;
85+
let aLowerCase = aChar;
86+
let bLowerCase = bChar;
87+
if (dart.notNull(_upperCaseA) <= dart.notNull(bChar) && dart.notNull(bChar) <= dart.notNull(_upperCaseZ)) {
88+
bLowerCase = dart.notNull(bLowerCase) + dart.notNull(_asciiCaseBit);
89+
}
90+
if (dart.notNull(_upperCaseA) <= dart.notNull(aChar) && dart.notNull(aChar) <= dart.notNull(_upperCaseZ)) {
91+
aLowerCase = dart.notNull(aLowerCase) + dart.notNull(_asciiCaseBit);
92+
}
93+
if (aLowerCase != bLowerCase)
94+
return (dart.notNull(aLowerCase) - dart.notNull(bLowerCase))[dartx.sign];
95+
if (defaultResult == 0)
96+
defaultResult = dart.notNull(aChar) - dart.notNull(bChar);
97+
}
98+
if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length]))
99+
return -1;
100+
return defaultResult[dartx.sign];
101+
}
102+
dart.fn(compareAsciiLowerCase, core.int, [core.String, core.String]);
103+
function compareNatural(a, b) {
104+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
105+
if (dart.notNull(i) >= dart.notNull(b[dartx.length]))
106+
return 1;
107+
let aChar = a[dartx.codeUnitAt](i);
108+
let bChar = b[dartx.codeUnitAt](i);
109+
if (aChar != bChar) {
110+
return _compareNaturally(a, b, i, aChar, bChar);
111+
}
112+
}
113+
if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length]))
114+
return -1;
115+
return 0;
116+
}
117+
dart.fn(compareNatural, core.int, [core.String, core.String]);
118+
function compareAsciiLowerCaseNatural(a, b) {
119+
let defaultResult = 0;
120+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
121+
if (dart.notNull(i) >= dart.notNull(b[dartx.length]))
122+
return 1;
123+
let aChar = a[dartx.codeUnitAt](i);
124+
let bChar = b[dartx.codeUnitAt](i);
125+
if (aChar == bChar)
126+
continue;
127+
let aLowerCase = aChar;
128+
let bLowerCase = bChar;
129+
if (dart.notNull(_upperCaseA) <= dart.notNull(aChar) && dart.notNull(aChar) <= dart.notNull(_upperCaseZ)) {
130+
aLowerCase = dart.notNull(aLowerCase) + dart.notNull(_asciiCaseBit);
131+
}
132+
if (dart.notNull(_upperCaseA) <= dart.notNull(bChar) && dart.notNull(bChar) <= dart.notNull(_upperCaseZ)) {
133+
bLowerCase = dart.notNull(bLowerCase) + dart.notNull(_asciiCaseBit);
134+
}
135+
if (aLowerCase != bLowerCase) {
136+
return _compareNaturally(a, b, i, aLowerCase, bLowerCase);
137+
}
138+
if (defaultResult == 0)
139+
defaultResult = dart.notNull(aChar) - dart.notNull(bChar);
140+
}
141+
if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length]))
142+
return -1;
143+
return defaultResult[dartx.sign];
144+
}
145+
dart.fn(compareAsciiLowerCaseNatural, core.int, [core.String, core.String]);
146+
function compareAsciiUpperCaseNatural(a, b) {
147+
let defaultResult = 0;
148+
for (let i = 0; dart.notNull(i) < dart.notNull(a[dartx.length]); i = dart.notNull(i) + 1) {
149+
if (dart.notNull(i) >= dart.notNull(b[dartx.length]))
150+
return 1;
151+
let aChar = a[dartx.codeUnitAt](i);
152+
let bChar = b[dartx.codeUnitAt](i);
153+
if (aChar == bChar)
154+
continue;
155+
let aUpperCase = aChar;
156+
let bUpperCase = bChar;
157+
if (dart.notNull(_lowerCaseA) <= dart.notNull(aChar) && dart.notNull(aChar) <= dart.notNull(_lowerCaseZ)) {
158+
aUpperCase = dart.notNull(aUpperCase) - dart.notNull(_asciiCaseBit);
159+
}
160+
if (dart.notNull(_lowerCaseA) <= dart.notNull(bChar) && dart.notNull(bChar) <= dart.notNull(_lowerCaseZ)) {
161+
bUpperCase = dart.notNull(bUpperCase) - dart.notNull(_asciiCaseBit);
162+
}
163+
if (aUpperCase != bUpperCase) {
164+
return _compareNaturally(a, b, i, aUpperCase, bUpperCase);
165+
}
166+
if (defaultResult == 0)
167+
defaultResult = dart.notNull(aChar) - dart.notNull(bChar);
168+
}
169+
if (dart.notNull(b[dartx.length]) > dart.notNull(a[dartx.length]))
170+
return -1;
171+
return defaultResult[dartx.sign];
172+
}
173+
dart.fn(compareAsciiUpperCaseNatural, core.int, [core.String, core.String]);
174+
function _compareNaturally(a, b, index, aChar, bChar) {
175+
dart.assert(aChar != bChar);
176+
let aIsDigit = _isDigit(aChar);
177+
let bIsDigit = _isDigit(bChar);
178+
if (dart.notNull(aIsDigit)) {
179+
if (dart.notNull(bIsDigit)) {
180+
return _compareNumerically(a, b, aChar, bChar, index);
181+
} else if (dart.notNull(index) > 0 && dart.notNull(_isDigit(a[dartx.codeUnitAt](dart.notNull(index) - 1)))) {
182+
return 1;
183+
}
184+
} else if (dart.notNull(bIsDigit) && dart.notNull(index) > 0 && dart.notNull(_isDigit(b[dartx.codeUnitAt](dart.notNull(index) - 1)))) {
185+
return -1;
186+
}
187+
return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign];
188+
}
189+
dart.fn(_compareNaturally, core.int, [core.String, core.String, core.int, core.int, core.int]);
190+
function _compareNumerically(a, b, aChar, bChar, index) {
191+
if (dart.notNull(_isNonZeroNumberSuffix(a, index))) {
192+
let result = _compareDigitCount(a, b, index, index);
193+
if (result != 0)
194+
return result;
195+
return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign];
196+
}
197+
let aIndex = index;
198+
let bIndex = index;
199+
if (aChar == _zero) {
200+
do {
201+
aIndex = dart.notNull(aIndex) + 1;
202+
if (aIndex == a[dartx.length])
203+
return -1;
204+
aChar = a[dartx.codeUnitAt](aIndex);
205+
} while (aChar == _zero);
206+
if (!dart.notNull(_isDigit(aChar)))
207+
return -1;
208+
} else if (bChar == _zero) {
209+
do {
210+
bIndex = dart.notNull(bIndex) + 1;
211+
if (bIndex == b[dartx.length])
212+
return 1;
213+
bChar = b[dartx.codeUnitAt](bIndex);
214+
} while (bChar == _zero);
215+
if (!dart.notNull(_isDigit(bChar)))
216+
return 1;
217+
}
218+
if (aChar != bChar) {
219+
let result = _compareDigitCount(a, b, aIndex, bIndex);
220+
if (result != 0)
221+
return result;
222+
return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign];
223+
}
224+
while (true) {
225+
let aIsDigit = false;
226+
let bIsDigit = false;
227+
aChar = 0;
228+
bChar = 0;
229+
if ((aIndex = dart.notNull(aIndex) + 1) < dart.notNull(a[dartx.length])) {
230+
aChar = a[dartx.codeUnitAt](aIndex);
231+
aIsDigit = _isDigit(aChar);
232+
}
233+
if ((bIndex = dart.notNull(bIndex) + 1) < dart.notNull(b[dartx.length])) {
234+
bChar = b[dartx.codeUnitAt](bIndex);
235+
bIsDigit = _isDigit(bChar);
236+
}
237+
if (dart.notNull(aIsDigit)) {
238+
if (dart.notNull(bIsDigit)) {
239+
if (aChar == bChar)
240+
continue;
241+
break;
242+
}
243+
return 1;
244+
} else if (dart.notNull(bIsDigit)) {
245+
return -1;
246+
} else {
247+
return (dart.notNull(aIndex) - dart.notNull(bIndex))[dartx.sign];
248+
}
249+
}
250+
let result = _compareDigitCount(a, b, aIndex, bIndex);
251+
if (result != 0)
252+
return result;
253+
return (dart.notNull(aChar) - dart.notNull(bChar))[dartx.sign];
254+
}
255+
dart.fn(_compareNumerically, core.int, [core.String, core.String, core.int, core.int, core.int]);
256+
function _compareDigitCount(a, b, i, j) {
257+
while ((i = dart.notNull(i) + 1) < dart.notNull(a[dartx.length])) {
258+
let aIsDigit = _isDigit(a[dartx.codeUnitAt](i));
259+
if ((j = dart.notNull(j) + 1) == b[dartx.length])
260+
return dart.notNull(aIsDigit) ? 1 : 0;
261+
let bIsDigit = _isDigit(b[dartx.codeUnitAt](j));
262+
if (dart.notNull(aIsDigit)) {
263+
if (dart.notNull(bIsDigit))
264+
continue;
265+
return 1;
266+
} else if (dart.notNull(bIsDigit)) {
267+
return -1;
268+
} else {
269+
return 0;
270+
}
271+
}
272+
if ((j = dart.notNull(j) + 1) < dart.notNull(b[dartx.length]) && dart.notNull(_isDigit(b[dartx.codeUnitAt](j)))) {
273+
return -1;
274+
}
275+
return 0;
276+
}
277+
dart.fn(_compareDigitCount, core.int, [core.String, core.String, core.int, core.int]);
278+
function _isDigit(charCode) {
279+
return (dart.notNull(charCode) ^ dart.notNull(_zero)) <= 9;
280+
}
281+
dart.fn(_isDigit, core.bool, [core.int]);
282+
function _isNonZeroNumberSuffix(string, index) {
283+
while ((index = dart.notNull(index) - 1) >= 0) {
284+
let char = string[dartx.codeUnitAt](index);
285+
if (char != _zero)
286+
return _isDigit(char);
287+
}
288+
return false;
289+
}
290+
dart.fn(_isNonZeroNumberSuffix, core.bool, [core.String, core.int]);
291+
// Exports:
292+
exports.equalsIgnoreAsciiCase = equalsIgnoreAsciiCase;
293+
exports.hashIgnoreAsciiCase = hashIgnoreAsciiCase;
294+
exports.compareAsciiUpperCase = compareAsciiUpperCase;
295+
exports.compareAsciiLowerCase = compareAsciiLowerCase;
296+
exports.compareNatural = compareNatural;
297+
exports.compareAsciiLowerCaseNatural = compareAsciiLowerCaseNatural;
298+
exports.compareAsciiUpperCaseNatural = compareAsciiUpperCaseNatural;
299+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Messages from compiling comparators.dart

0 commit comments

Comments
 (0)