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 MetaEqual extends AbstractMetaOperator {
28:
29: public MetaEqual() {
30: super (new Name("#eq"), 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 MetaEqual
45: && term.arity() == arity();
46: }
47:
48: /** calculates the resulting term. */
49: public Term calculate(Term term, SVInstantiations svInst,
50: Services services) {
51: Term arg1 = term.sub(0);
52: Term arg2 = term.sub(1);
53: BigInteger bigIntArg1 = null;
54: BigInteger bigIntArg2 = null;
55:
56: bigIntArg1 = new BigInteger(convertToDecimalString(arg1,
57: services));
58: bigIntArg2 = new BigInteger(convertToDecimalString(arg2,
59: services));
60:
61: boolean result = bigIntArg1.compareTo(bigIntArg2) == 0;
62:
63: if (result)
64: return termFactory.createJunctorTerm(Op.TRUE);
65: else
66: return termFactory.createJunctorTerm(Op.FALSE);
67:
68: }
69:
70: }
|