Skip to content

Commit bcf5437

Browse files
Extract SymbolTransformerComposition to not be local (#220)
1 parent 75edeec commit bcf5437

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

src/main/scala/inox/transformers/SymbolTransformer.scala

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,7 @@ trait SymbolTransformer { self =>
1313
def compose(that: SymbolTransformer { val t: self.s.type }): SymbolTransformer {
1414
val s: that.s.type
1515
val t: self.t.type
16-
} = {
17-
/** Enables equality checks between symbol transformer compositions */
18-
class SymbolTransformerComposition(protected val lhs: self.type,
19-
protected val rhs: that.type)
20-
(override val s: rhs.s.type,
21-
override val t: self.t.type)
22-
extends SymbolTransformer {
23-
24-
override def transform(syms: s.Symbols): t.Symbols = lhs.transform(rhs.transform(syms))
25-
26-
override def equals(that: Any): Boolean = that match {
27-
// NOTE: there is a spurious warning saying:
28-
// "the type test for SymbolTransformerComposition cannot be checked at runtime because it's a local class"
29-
// but the type test actually works as expected
30-
case c: SymbolTransformerComposition => rhs == c.rhs && lhs == c.lhs
31-
case _ => false
32-
}
33-
34-
override def hashCode: Int = 31 * rhs.hashCode + lhs.hashCode
35-
}
36-
37-
new SymbolTransformerComposition(self, that)(that.s, self.t)
38-
}
16+
} = SymbolTransformerComposition(self, that)
3917

4018
def andThen(that: SymbolTransformer {
4119
val s: self.t.type
@@ -59,6 +37,36 @@ trait SimpleSymbolTransformer extends SymbolTransformer { self =>
5937
.withFunctions(syms.functions.values.toSeq.map(transformFunction))
6038
.withSorts(syms.sorts.values.toSeq.map(transformSort))
6139
}
40+
41+
/** Enables equality checks between symbol transformer compositions */
42+
class SymbolTransformerComposition(protected val left: SymbolTransformer,
43+
protected val right: SymbolTransformer { val t: left.s.type })
44+
(override val s: right.s.type,
45+
override val t: left.t.type)
46+
extends SymbolTransformer {
47+
48+
49+
override def transform(syms: s.Symbols): t.Symbols = left.transform(right.transform(syms))
50+
51+
override def equals(that: Any): Boolean = that match {
52+
// NOTE: there is a spurious warning saying:
53+
// "the type test for SymbolTransformerComposition cannot be checked at runtime because it's a local class"
54+
// but the type test actually works as expected
55+
case c: SymbolTransformerComposition => right == c.right && left == c.left
56+
case _ => false
57+
}
58+
59+
override def hashCode: Int = 31 * right.hashCode + left.hashCode
60+
}
61+
62+
object SymbolTransformerComposition {
63+
def apply(left: SymbolTransformer, right: SymbolTransformer {val t: left.s.type}): SymbolTransformer {
64+
val s: right.s.type
65+
val t: left.t.type
66+
} =
67+
class LocalComposition(lhs: left.type, rhs: right.type, s: right.s.type, t: left.t.type) extends SymbolTransformerComposition(left, right)(s, t)
68+
new LocalComposition(left, right, right.s, left.t)
69+
}
6270

6371
object SymbolTransformer {
6472
def apply(trans: DefinitionTransformer): SymbolTransformer {

0 commit comments

Comments
 (0)