Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naive implementation of subst (#233)
- Loading branch information
Showing
2 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
base/src/main/java/org/arend/term/concrete/ConcreteSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.arend.term.concrete; | ||
|
||
import org.arend.naming.reference.Referable; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ConcreteSubstitution extends BaseConcreteExpressionVisitor<Void> { | ||
private final Map<Referable, Concrete.Expression> mySubstitution; | ||
|
||
public ConcreteSubstitution(@NotNull Map<Referable, Concrete.Expression> substitution) { | ||
mySubstitution = substitution; | ||
} | ||
|
||
public ConcreteSubstitution() { | ||
this(new HashMap<>()); | ||
} | ||
|
||
public void bind(@NotNull Referable referable, @Nullable Concrete.Expression expression) { | ||
mySubstitution.put(referable, expression); | ||
} | ||
|
||
public void unbind(@NotNull Referable referable) { | ||
mySubstitution.remove(referable); | ||
} | ||
|
||
public int size() { | ||
return mySubstitution.size(); | ||
} | ||
|
||
@Override | ||
public Concrete.Expression visitReference(Concrete.ReferenceExpression expr, Void params) { | ||
var subst = mySubstitution.get(expr.getReferent()); | ||
return subst != null ? subst : super.visitReference(expr, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters