01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.strategy.feature;
12:
13: import de.uka.ilkd.key.logic.PIOPathIterator;
14: import de.uka.ilkd.key.logic.PosInOccurrence;
15: import de.uka.ilkd.key.logic.op.Op;
16: import de.uka.ilkd.key.logic.op.Operator;
17: import de.uka.ilkd.key.logic.op.Quantifier;
18: import de.uka.ilkd.key.proof.Goal;
19: import de.uka.ilkd.key.rule.RuleApp;
20: import de.uka.ilkd.key.util.Debug;
21:
22: /**
23: * Feature that returns zero iff the application focus of a rule is a potential
24: * cut position (taclet cut_direct). For positions that are below quantifiers,
25: * the feature generally returns zero.
26: */
27: public class AllowedCutPositionFeature extends BinaryFeature {
28:
29: public static final Feature INSTANCE = new AllowedCutPositionFeature();
30:
31: private AllowedCutPositionFeature() {
32: }
33:
34: public boolean filter(RuleApp app, PosInOccurrence pos, Goal goal) {
35: Debug.assertFalse(pos == null,
36: "Feature is only applicable to rules with find");
37:
38: return onlyBelowRightJunctors(pos);
39: }
40:
41: private boolean onlyBelowRightJunctors(PosInOccurrence pos) {
42: boolean negated = pos.isInAntec();
43: final PIOPathIterator it = pos.iterator();
44:
45: while (it.next() != -1) {
46: final int child = it.getChild();
47: final Operator op = it.getSubTerm().op();
48:
49: if (op == Op.NOT) {
50: negated = !negated;
51: } else if (op == (negated ? Op.OR : Op.AND)) {
52: /* nothing */
53: } else if (negated && op == Op.IMP) {
54: if (child == 0)
55: negated = !negated;
56: } else if (op instanceof Quantifier) {
57: return true;
58: } else {
59: return false;
60: }
61: }
62:
63: return true;
64: }
65:
66: }
|