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: package de.uka.ilkd.key.rule.metaconstruct.arith;
11:
12: import java.math.BigInteger;
13:
14: import de.uka.ilkd.key.java.Services;
15: import de.uka.ilkd.key.logic.Name;
16: import de.uka.ilkd.key.logic.Term;
17: import de.uka.ilkd.key.logic.op.AbstractMetaOperator;
18: import de.uka.ilkd.key.logic.op.Op;
19: import de.uka.ilkd.key.rule.inst.SVInstantiations;
20:
21: /** this class implements the interface for
22: * MetaAdderators. MetaAdderators are used to do complex term
23: * transformation when applying a taclet. Often these transformation
24: * caanot be described with the taclet scheme (or trying to do so would
25: * result in a huge number of rules)
26: */
27: public class MetaLeq extends AbstractMetaOperator {
28:
29: public MetaLeq() {
30: super (new Name("#leq"), 2);
31: }
32:
33: /**
34: * checks whether the top level structure of the given @link Term
35: * is syntactically valid, given the assumption that the top level
36: * operator of the term is the same as this Operator. The
37: * assumption that the top level operator and the term are equal
38: * is NOT checked.
39: * @return true iff the top level structure of
40: * the @link Term is valid.
41: */
42: public boolean validTopLevel(Term term) {
43: // a meta operator accepts almost everything
44: return term.op() instanceof MetaLeq && term.arity() == arity();
45: }
46:
47: /** calculates the resulting term. */
48: public Term calculate(Term term, SVInstantiations svInst,
49: Services services) {
50: Term arg1 = term.sub(0);
51: Term arg2 = term.sub(1);
52: BigInteger bigIntArg1 = null;
53: BigInteger bigIntArg2 = null;
54:
55: bigIntArg1 = new BigInteger(convertToDecimalString(arg1,
56: services));
57: bigIntArg2 = new BigInteger(convertToDecimalString(arg2,
58: services));
59: boolean result = bigIntArg1.compareTo(bigIntArg2) <= 0;
60:
61: if (result)
62: return termFactory.createJunctorTerm(Op.TRUE);
63: else
64: return termFactory.createJunctorTerm(Op.FALSE);
65:
66: }
67:
68: }
|