JS backend: fixes in ranges:
* map all number ranges and progressions; * add missed hashCode and static EMPTY to Range implementations; * add missed hashCode and equals to Progression implementations; * fix type of start and end in CharRange and CharProgression.
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -95,8 +96,16 @@ public final class StandardClasses {
|
|||||||
private static void declareKotlinStandardClasses(@NotNull StandardClasses standardClasses) {
|
private static void declareKotlinStandardClasses(@NotNull StandardClasses standardClasses) {
|
||||||
standardClasses.declare().forFQ("kotlin.Iterator").kotlinClass("Iterator").methods("next").properties("hasNext");
|
standardClasses.declare().forFQ("kotlin.Iterator").kotlinClass("Iterator").methods("next").properties("hasNext");
|
||||||
|
|
||||||
standardClasses.declare().forFQ("kotlin.IntRange").kotlinClass("NumberRange")
|
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
|
||||||
.methods("iterator", "contains").properties("start", "end", "increment");
|
if (type == PrimitiveType.CHAR || type == PrimitiveType.LONG) continue;
|
||||||
|
|
||||||
|
String typeName = type.getTypeName().asString();
|
||||||
|
standardClasses.declare().forFQ("kotlin." + typeName + "Range").kotlinClass("NumberRange")
|
||||||
|
.methods("iterator", "contains").properties("start", "end", "increment");
|
||||||
|
|
||||||
|
standardClasses.declare().forFQ("kotlin." + typeName + "Progression").kotlinClass("NumberProgression")
|
||||||
|
.methods("iterator", "contains").properties("start", "end", "increment");
|
||||||
|
}
|
||||||
|
|
||||||
standardClasses.declare().forFQ("kotlin.LongRange").kotlinClass("LongRange")
|
standardClasses.declare().forFQ("kotlin.LongRange").kotlinClass("LongRange")
|
||||||
.methods("iterator", "contains").properties("start", "end", "increment");
|
.methods("iterator", "contains").properties("start", "end", "increment");
|
||||||
@@ -104,8 +113,6 @@ public final class StandardClasses {
|
|||||||
standardClasses.declare().forFQ("kotlin.CharRange").kotlinClass("CharRange")
|
standardClasses.declare().forFQ("kotlin.CharRange").kotlinClass("CharRange")
|
||||||
.methods("iterator", "contains").properties("start", "end", "increment");
|
.methods("iterator", "contains").properties("start", "end", "increment");
|
||||||
|
|
||||||
standardClasses.declare().forFQ("kotlin.IntProgression").kotlinClass("NumberProgression")
|
|
||||||
.methods("iterator", "contains").properties("start", "end", "increment");
|
|
||||||
|
|
||||||
standardClasses.declare().forFQ("kotlin.LongProgression").kotlinClass("LongProgression")
|
standardClasses.declare().forFQ("kotlin.LongProgression").kotlinClass("LongProgression")
|
||||||
.methods("iterator", "contains").properties("start", "end", "increment");
|
.methods("iterator", "contains").properties("start", "end", "increment");
|
||||||
|
|||||||
@@ -613,7 +613,14 @@
|
|||||||
isEmpty: function () {
|
isEmpty: function () {
|
||||||
return this.start > this.end;
|
return this.start > this.end;
|
||||||
},
|
},
|
||||||
|
hashCode: function() {
|
||||||
|
return this.isEmpty() ? -1 : (31 * this.start|0 + this.end|0);
|
||||||
|
},
|
||||||
equals_za3rmp$: isSameNotNullRanges
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
|
}, {
|
||||||
|
object_initializer$: function () {
|
||||||
|
return { EMPTY : new this(1, 0) };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.NumberProgression = Kotlin.createClassNow(null,
|
Kotlin.NumberProgression = Kotlin.createClassNow(null,
|
||||||
@@ -627,7 +634,11 @@
|
|||||||
},
|
},
|
||||||
isEmpty: function() {
|
isEmpty: function() {
|
||||||
return this.increment > 0 ? this.start > this.end : this.start < this.end;
|
return this.increment > 0 ? this.start > this.end : this.start < this.end;
|
||||||
}
|
},
|
||||||
|
hashCode: function() {
|
||||||
|
return this.isEmpty() ? -1 : (31 * (31 * this.start|0 + this.end|0) + this.increment|0);
|
||||||
|
},
|
||||||
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.LongRangeIterator = Kotlin.createClassNow(Kotlin.Iterator,
|
Kotlin.LongRangeIterator = Kotlin.createClassNow(Kotlin.Iterator,
|
||||||
@@ -665,8 +676,15 @@
|
|||||||
isEmpty: function () {
|
isEmpty: function () {
|
||||||
return this.start.compare(this.end) > 0;
|
return this.start.compare(this.end) > 0;
|
||||||
},
|
},
|
||||||
equals_za3rmp$: isSameNotNullRanges
|
hashCode: function() {
|
||||||
});
|
return this.isEmpty() ? -1 : (31 * this.start.toInt() + this.end.toInt());
|
||||||
|
},
|
||||||
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
|
}, {
|
||||||
|
object_initializer$: function () {
|
||||||
|
return { EMPTY : new this(Kotlin.Long.ONE, Kotlin.Long.ZERO) };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Kotlin.LongProgression = Kotlin.createClassNow(null,
|
Kotlin.LongProgression = Kotlin.createClassNow(null,
|
||||||
function (start, end, increment) {
|
function (start, end, increment) {
|
||||||
@@ -679,8 +697,12 @@
|
|||||||
},
|
},
|
||||||
isEmpty: function() {
|
isEmpty: function() {
|
||||||
return this.increment.isNegative() ? this.start.compare(this.end) < 0 : this.start.compare(this.end) > 0;
|
return this.increment.isNegative() ? this.start.compare(this.end) < 0 : this.start.compare(this.end) > 0;
|
||||||
}
|
},
|
||||||
});
|
hashCode: function() {
|
||||||
|
return this.isEmpty() ? -1 : (31 * (31 * this.start.toInt() + this.end.toInt()) + this.increment.toInt());
|
||||||
|
},
|
||||||
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
|
});
|
||||||
|
|
||||||
Kotlin.CharRangeIterator = Kotlin.createClassNow(Kotlin.RangeIterator,
|
Kotlin.CharRangeIterator = Kotlin.createClassNow(Kotlin.RangeIterator,
|
||||||
function (start, end, increment) {
|
function (start, end, increment) {
|
||||||
@@ -690,40 +712,54 @@
|
|||||||
var value = this.i;
|
var value = this.i;
|
||||||
this.i = this.i + this.increment;
|
this.i = this.i + this.increment;
|
||||||
return String.fromCharCode(value);
|
return String.fromCharCode(value);
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.CharRange = Kotlin.createClassNow(null,
|
Kotlin.CharRange = Kotlin.createClassNow(null,
|
||||||
function (start, end) {
|
function (start, end) {
|
||||||
this.start = start.charCodeAt(0);
|
this.start = start;
|
||||||
this.end = end.charCodeAt(0);
|
this.startCode = start.charCodeAt(0);
|
||||||
|
this.end = end;
|
||||||
|
this.endCode = end.charCodeAt(0);
|
||||||
this.increment = 1;
|
this.increment = 1;
|
||||||
}, {
|
}, {
|
||||||
contains: function (char) {
|
contains: function (char) {
|
||||||
var code = char.charCodeAt(0)
|
return this.start <= char && char <= this.end;
|
||||||
return this.start <= code && code <= this.end;
|
|
||||||
},
|
},
|
||||||
iterator: function () {
|
iterator: function () {
|
||||||
return new Kotlin.CharRangeIterator(this.start, this.end, this.increment);
|
return new Kotlin.CharRangeIterator(this.startCode, this.endCode, this.increment);
|
||||||
},
|
},
|
||||||
isEmpty: function () {
|
isEmpty: function () {
|
||||||
return this.start > this.end;
|
return this.start > this.end;
|
||||||
},
|
},
|
||||||
|
hashCode: function() {
|
||||||
|
return this.isEmpty() ? -1 : (31 * this.startCode|0 + this.endCode|0);
|
||||||
|
},
|
||||||
equals_za3rmp$: isSameNotNullRanges
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
|
}, {
|
||||||
|
object_initializer$: function () {
|
||||||
|
return { EMPTY : new this(Kotlin.toChar(1), Kotlin.toChar(0)) };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.CharNumberProgression = Kotlin.createClassNow(null,
|
Kotlin.CharProgression = Kotlin.createClassNow(null,
|
||||||
function (start, end, increment) {
|
function (start, end, increment) {
|
||||||
this.start = start.charCodeAt(0);
|
this.start = start;
|
||||||
this.end = end.charCodeAt(0);
|
this.startCode = start.charCodeAt(0);
|
||||||
|
this.end = end;
|
||||||
|
this.endCode = end.charCodeAt(0);
|
||||||
this.increment = increment;
|
this.increment = increment;
|
||||||
}, {
|
}, {
|
||||||
iterator: function () {
|
iterator: function () {
|
||||||
return new Kotlin.CharRangeIterator(this.start, this.end, this.increment);
|
return new Kotlin.CharRangeIterator(this.startCode, this.endCode, this.increment);
|
||||||
},
|
},
|
||||||
isEmpty: function() {
|
isEmpty: function() {
|
||||||
return this.increment > 0 ? this.start > this.end : this.start < this.end;
|
return this.increment > 0 ? this.start > this.end : this.start < this.end;
|
||||||
}
|
},
|
||||||
|
hashCode: function() {
|
||||||
|
return this.isEmpty() ? -1 : (31 * (31 * this.startCode|0 + this.endCode|0) + this.increment|0);
|
||||||
|
},
|
||||||
|
equals_za3rmp$: isSameNotNullRanges
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user