Skip to content

Commit a8ad7ae

Browse files
committed
Add an option to copy positions from old tree when doing substitutions
1 parent a6cbf8e commit a8ad7ae

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/scala/inox/ast/ExprOps.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ trait ExprOps extends GenTreeOps {
3838
lazy val Deconstructor = Operator
3939

4040
/** Replaces bottom-up variables by looking up for them in a map */
41-
def replaceFromSymbols[V <: VariableSymbol](substs: Map[V, Expr], expr: Expr)(implicit ev: VariableConverter[V]): Expr = {
41+
def replaceFromSymbols[V <: VariableSymbol](
42+
substs: Map[V, Expr],
43+
expr: Expr,
44+
copyPositions: Boolean = false
45+
)(implicit ev: VariableConverter[V]): Expr = {
4246
new SelfTreeTransformer {
4347
override def transform(expr: Expr): Expr = expr match {
44-
case v: Variable => substs.getOrElse(v.to[V], super.transform(v))
48+
case v: Variable =>
49+
val res = substs.getOrElse(v.to[V], super.transform(v))
50+
if (copyPositions) res.copiedFrom(v)
51+
else res
4552
case _ => super.transform(expr)
4653
}
4754
}.transform(expr)

0 commit comments

Comments
 (0)