Package: SeqApplyObligation

SeqApplyObligation

nameinstructionbranchcomplexitylinemethod
SeqApplyObligation(PExp, PExp, IPOContextStack, IPogAssistantFactory)
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
SeqApplyObligation(PStateDesignator, PExp, IPOContextStack, IPogAssistantFactory)
M: 74 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.pog.obligation;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.expressions.AAndBooleanBinaryExp;
28: import org.overture.ast.expressions.AGreaterNumericBinaryExp;
29: import org.overture.ast.expressions.AInSetBinaryExp;
30: import org.overture.ast.expressions.AIndicesUnaryExp;
31: import org.overture.ast.expressions.AIntLiteralExp;
32: import org.overture.ast.expressions.ALenUnaryExp;
33: import org.overture.ast.expressions.ALessEqualNumericBinaryExp;
34: import org.overture.ast.expressions.APlusNumericBinaryExp;
35: import org.overture.ast.expressions.PExp;
36: import org.overture.ast.factory.AstExpressionFactory;
37: import org.overture.ast.lex.LexIntegerToken;
38: import org.overture.ast.statements.PStateDesignator;
39: import org.overture.pog.pub.IPOContextStack;
40: import org.overture.pog.pub.IPogAssistantFactory;
41: import org.overture.pog.pub.POType;
42: import org.overture.pog.visitors.StateDesignatorToExpVisitor;
43:
44: public class SeqApplyObligation extends ProofObligation
45: {
46:
47:         private static final long serialVersionUID = -4022111928534078511L;
48:
49:         public SeqApplyObligation(PExp root, PExp arg, IPOContextStack ctxt,
50:                         IPogAssistantFactory af) throws AnalysisException
51:         {
52:                 super(root, POType.SEQ_APPLY, ctxt, root.getLocation(), af);
53:
54:                 AIndicesUnaryExp indsExp = new AIndicesUnaryExp();
55:                 indsExp.setExp(root.clone());
56:
57:                 AInSetBinaryExp inSetExp = AstExpressionFactory.newAInSetBinaryExp(arg.clone(), indsExp);
58:                 stitch = inSetExp;
59:                 valuetree.setPredicate(ctxt.getPredWithContext(stitch));
60:         }
61:
62:         public SeqApplyObligation(PStateDesignator root, PExp arg,
63:                         IPOContextStack ctxt, IPogAssistantFactory af)
64:                         throws AnalysisException
65:         {
66:                 super(root, POType.SEQ_APPLY, ctxt, root.getLocation(), af);
67:                 // arg >0
68:                 AIntLiteralExp zeroExp = new AIntLiteralExp();
69:                 zeroExp.setValue(new LexIntegerToken(0, null));
70:                 AGreaterNumericBinaryExp grExp = AstExpressionFactory.newAGreaterNumericBinaryExp(arg.clone(), zeroExp);
71:
72:                 // len(root)
73:                 ALenUnaryExp lenExp = new ALenUnaryExp();
74:                 PExp stateExp = root.apply(new StateDesignatorToExpVisitor());
75:                 lenExp.setExp(stateExp.clone());
76:
77:                 // len(root)+1
78:                 AIntLiteralExp oneExp = new AIntLiteralExp();
79:                 oneExp.setValue(new LexIntegerToken(1, null));
80:                 APlusNumericBinaryExp plusExp = AstExpressionFactory.newAPlusNumericBinaryExp(lenExp, oneExp);
81:
82:                 // arg <= len(root) +1
83:                 ALessEqualNumericBinaryExp lteExp = AstExpressionFactory.newALessEqualNumericBinaryExp(arg.clone(), plusExp);
84:
85:                 // arg > 0 and arg <= len(root)+1
86:                 AAndBooleanBinaryExp andExp = AstExpressionFactory.newAAndBooleanBinaryExp(grExp, lteExp);
87:
88:                 stitch = andExp;
89:                 valuetree.setPredicate(ctxt.getPredWithContext(stitch));
90:         }
91: }