Skip to content

Commit c0a5054

Browse files
olafurpgjulienrf
authored andcommitted
WIP
1 parent 2466d82 commit c0a5054

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

output/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package fix
22

33
import strawman.collection.{ arrayToArrayOps, stringToStringOps }
4-
import strawman.collection.immutable.{ #::, ::, HashMap, LazyList, List, Map, Nil, Vector }
4+
import strawman.collection.immutable.{ #::, ::, HashMap, LazyList, List, Map, Nil, Range, Vector }
55
import strawman.collection.mutable.ArrayBuffer
66
object Collectionstrawman_v0_List {
77
List(1, 2, 3)
@@ -46,6 +46,6 @@ object Collectionstrawman_v0_ArrayAndString {
4646
}
4747

4848
object Collectionstrawman_v0_Range {
49-
Range.inclusive(1, 10).map(_ + 1)
50-
Range(1, 10).map(_ + 1)
49+
Range.inclusive(1, 10).map(_ + 2)
50+
Range(0, 10).map(_ + 3)
5151
}

rewrites/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,25 @@ case class Collectionstrawman_v0(mirror: SemanticCtx)
2121
toImport.asPatch
2222
}
2323

24+
val rangeImport = Symbol("_root_.strawman.collection.immutable.Range.")
25+
val inclusiveRange = Symbol(
26+
"_root_.scala.runtime.RichInt#to(I)Lscala/collection/immutable/Range/Inclusive;.")
27+
val rangeSymbol = Symbol(
28+
"_root_.scala.runtime.RichInt#until(I)Lscala/collection/immutable/Range;.")
29+
def range(ctx: RewriteCtx): Patch = {
30+
ctx.tree.collect {
31+
case tree @ Term.ApplyInfix(lhs, op, targs, arg :: Nil)
32+
if op.symbol.contains(inclusiveRange) =>
33+
ctx.replaceTree(tree, q"Range.inclusive($lhs, $arg)".syntax) +
34+
ctx.addGlobalImport(rangeImport)
35+
case tree @ Term.ApplyInfix(lhs, op, targs, arg :: Nil)
36+
if op.symbol.contains(rangeSymbol) =>
37+
ctx.replaceTree(tree, q"Range($lhs, $arg)".syntax) +
38+
ctx.addGlobalImport(rangeImport)
39+
}
40+
}.asPatch
41+
2442
def rewrite(ctx: RewriteCtx): Patch = {
25-
ctx.debugMirror()
2643
def p(name: String) =
2744
s"scala.Predef.$name" -> s"strawman.collection.immutable.$name"
2845
def s(name: String, rename: Option[String] = None) =
@@ -32,28 +49,28 @@ case class Collectionstrawman_v0(mirror: SemanticCtx)
3249
s"strawman.collection.immutable.${rename.getOrElse(name)}"
3350
def m(name: String) =
3451
s"scala.collection.mutable.$name" -> s"strawman.collection.mutable.$name"
35-
ifSymbolFound(ctx) +
36-
ctx.replaceSymbols(
37-
i("HashMap"),
38-
i("Map"),
39-
p("Map"),
40-
s("List"),
41-
i("List"),
42-
s("Nil"),
43-
i("Nil"),
44-
s("`::`"),
45-
i("`::`"),
46-
s("`+:`"),
47-
i("`+:`"),
48-
s("`:+`"),
49-
i("`:+`"),
50-
i("Stream", Some("LazyList")),
51-
s("Stream", Some("LazyList")),
52-
s("`#::`"),
53-
s("`#::`"),
54-
s("Vector"),
55-
i("Vector"),
56-
m("ArrayBuffer")
57-
)
52+
ctx.replaceSymbols(
53+
i("HashMap"),
54+
i("Map"),
55+
p("Map"),
56+
s("List"),
57+
i("List"),
58+
s("Nil"),
59+
i("Nil"),
60+
s("`::`"),
61+
i("`::`"),
62+
s("`+:`"),
63+
i("`+:`"),
64+
s("`:+`"),
65+
i("`:+`"),
66+
i("Stream", Some("LazyList")),
67+
s("Stream", Some("LazyList")),
68+
s("`#::`"),
69+
s("Vector"),
70+
i("Vector"),
71+
m("ArrayBuffer")
72+
) +
73+
ifSymbolFound(ctx) +
74+
range(ctx)
5875
}
5976
}

0 commit comments

Comments
 (0)