Skip to content

Commit

Permalink
SubTermFinder: add option "only outermost", i.e., if set this means i…
Browse files Browse the repository at this point in the history
…f a subterm is reported, do not report its subterms
  • Loading branch information
alexandernutz committed May 25, 2018
1 parent fb73d0c commit 48c7898
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ public class SubTermFinder extends NonRecursive {


private final Predicate<Term> mPredicate;
private final boolean mOnlyOutermost;

private HashSet<Term> mResult;
private HashSet<Term> mVisitedSubterms;

public SubTermFinder(final Predicate<Term> predicate) {
this(predicate, false);
}

public SubTermFinder(final Predicate<Term> predicate, final boolean onlyOutermost) {
mPredicate = predicate;
mOnlyOutermost = onlyOutermost;
}

public Set<Term> findMatchingSubterms(final Term term) {
Expand Down Expand Up @@ -83,6 +89,10 @@ public void walk(final NonRecursive walker, final ConstantTerm term) {
public void walk(final NonRecursive walker, final AnnotatedTerm term) {
if (mPredicate.test(term)) {
mResult.add(term);
if (mOnlyOutermost) {
// ignore subterms
return;
}
}
walker.enqueueWalker(new FindWalker(term.getSubterm()));
}
Expand All @@ -97,6 +107,10 @@ public void walk(final NonRecursive walker, final ApplicationTerm term) {

if (mPredicate.test(term)) {
mResult.add(term);
if (mOnlyOutermost) {
// ignore subterms
return;
}
}

for (final Term t : term.getParameters()) {
Expand All @@ -113,6 +127,10 @@ public void walk(final NonRecursive walker, final LetTerm term) {
public void walk(final NonRecursive walker, final QuantifiedFormula term) {
if (mPredicate.test(term)) {
mResult.add(term);
if (mOnlyOutermost) {
// ignore subterms
return;
}
}

walker.enqueueWalker(new FindWalker(term.getSubformula()));
Expand Down

0 comments on commit 48c7898

Please sign in to comment.