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:
Zalim Bashorov
2014-10-10 16:50:13 +04:00
parent 8bd6acec5d
commit f20ee6df4b
2 changed files with 63 additions and 20 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.Map;
@@ -95,8 +96,16 @@ public final class StandardClasses {
private static void declareKotlinStandardClasses(@NotNull StandardClasses standardClasses) {
standardClasses.declare().forFQ("kotlin.Iterator").kotlinClass("Iterator").methods("next").properties("hasNext");
standardClasses.declare().forFQ("kotlin.IntRange").kotlinClass("NumberRange")
.methods("iterator", "contains").properties("start", "end", "increment");
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
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")
.methods("iterator", "contains").properties("start", "end", "increment");
@@ -104,8 +113,6 @@ public final class StandardClasses {
standardClasses.declare().forFQ("kotlin.CharRange").kotlinClass("CharRange")
.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")
.methods("iterator", "contains").properties("start", "end", "increment");
+52 -16
View File
@@ -613,7 +613,14 @@
isEmpty: function () {
return this.start > this.end;
},
hashCode: function() {
return this.isEmpty() ? -1 : (31 * this.start|0 + this.end|0);
},
equals_za3rmp$: isSameNotNullRanges
}, {
object_initializer$: function () {
return { EMPTY : new this(1, 0) };
}
});
Kotlin.NumberProgression = Kotlin.createClassNow(null,
@@ -627,7 +634,11 @@
},
isEmpty: function() {
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,
@@ -665,8 +676,15 @@
isEmpty: function () {
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,
function (start, end, increment) {
@@ -679,8 +697,12 @@
},
isEmpty: function() {
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,
function (start, end, increment) {
@@ -690,40 +712,54 @@
var value = this.i;
this.i = this.i + this.increment;
return String.fromCharCode(value);
},
}
});
Kotlin.CharRange = Kotlin.createClassNow(null,
function (start, end) {
this.start = start.charCodeAt(0);
this.end = end.charCodeAt(0);
this.start = start;
this.startCode = start.charCodeAt(0);
this.end = end;
this.endCode = end.charCodeAt(0);
this.increment = 1;
}, {
contains: function (char) {
var code = char.charCodeAt(0)
return this.start <= code && code <= this.end;
return this.start <= char && char <= this.end;
},
iterator: function () {
return new Kotlin.CharRangeIterator(this.start, this.end, this.increment);
return new Kotlin.CharRangeIterator(this.startCode, this.endCode, this.increment);
},
isEmpty: function () {
return this.start > this.end;
},
hashCode: function() {
return this.isEmpty() ? -1 : (31 * this.startCode|0 + this.endCode|0);
},
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) {
this.start = start.charCodeAt(0);
this.end = end.charCodeAt(0);
this.start = start;
this.startCode = start.charCodeAt(0);
this.end = end;
this.endCode = end.charCodeAt(0);
this.increment = increment;
}, {
iterator: function () {
return new Kotlin.CharRangeIterator(this.start, this.end, this.increment);
return new Kotlin.CharRangeIterator(this.startCode, this.endCode, this.increment);
},
isEmpty: function() {
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
});
/**