Package: RepeatTraceNode$1

RepeatTraceNode$1

nameinstructionbranchcomplexitylinemethod
execute()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 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.codegen.runtime.traces;
25:
26: import java.util.HashMap;
27: import java.util.Map;
28:
29: import org.overture.codegen.runtime.Utils;
30:
31: public class RepeatTraceNode extends TraceNode implements IIterableTraceNode
32: {
33:         public final int from;
34:         public final int to;
35:
36:         private Map<Integer, Pair<Integer, Integer>> indics;
37:         private final TraceNode repeat;
38:
39:         public RepeatTraceNode(TraceNode repeat, long from, long to)
40:         {
41:                 this.repeat = repeat;
42:                 this.from = (int) from;
43:                 this.to = (int) to;
44:         }
45:
46:         /*
47:          * (non-Javadoc)
48:          * @see org.overture.interpreter.traces.IIterableTraceNode#get(int)
49:          */
50:         @Override
51:         public CallSequence get(int index)
52:         {
53:                 if (indics == null)
54:                 {
55:                         size();
56:                 }
57:                 Pair<Integer, Integer> v = indics.get(index);
58:
59:                 int r = v.getFirst();
60:
61:                 if (r == 0)
62:                 {
63:                         CallSequence seq = getVars();
64:                         CallStatement skip = new CallStatement()
65:                         {
66:                                 public Object execute()
67:                                 {
68:                                         return Utils.VOID_VALUE;
69:                                 }
70:
71:                                 @Override
72:                                 public String toString()
73:                                 {
74:                                         return "skip";
75:                                 }
76:                         };
77:
78:                         seq.add(skip);
79:                         return seq;
80:
81:                 } else
82:                 {
83:
84:                         TestSequence rtests = repeat.getTests();
85:                         int count = rtests.size();
86:                         int[] c = new int[r];
87:
88:                         for (int i = 0; i < r; i++)
89:                         {
90:                                 c[i] = count;
91:                         }
92:
93:                         Permutor p = new Permutor(c);
94:                         int[] select = null;
95:                         for (int i = 0; i < v.getSecond(); i++)
96:                         {
97:                                 select = p.next();
98:                         }
99:
100:                         CallSequence seq = getVars();
101:
102:                         for (int i = 0; i < r; i++)
103:                         {
104:                                 seq.addAll(rtests.get(select[i]));
105:                         }
106:                         return seq;
107:                 }
108:
109:         }
110:
111:         @Override
112:         public TestSequence getTests()
113:         {
114:                 return new LazyTestSequence(this);
115:         }
116:
117:         /*
118:          * (non-Javadoc)
119:          * @see org.overture.interpreter.traces.IIterableTraceNode#size()
120:          */
121:         @Override
122:         public int size()
123:         {
124:                 if (indics != null)
125:                 {
126:                         return indics.size();
127:                 }
128:
129:                 indics = new HashMap<Integer, Pair<Integer, Integer>>();
130:
131:                 int size = 0;
132:                 TestSequence rtests = repeat.getTests();
133:                 int count = rtests.size();
134:                 for (int r = from; r <= to; r++)
135:                 {
136:                         if (r == 0)
137:                         {
138:
139:                                 indics.put(size, new Pair<Integer, Integer>(r, 0));
140:                                 size++;
141:                                 continue;
142:                         }
143:
144:                         int[] c = new int[r];
145:
146:                         for (int i = 0; i < r; i++)
147:                         {
148:                                 c[i] = count;
149:                         }
150:
151:                         Permutor p = new Permutor(c);
152:
153:                         int j = 0;
154:                         while (p.hasNext())
155:                         {
156:                                 j++;
157:                                 p.next();
158:                                 indics.put(size, new Pair<Integer, Integer>(r, j));
159:                                 size++;
160:                         }
161:                 }
162:                 return size;
163:         }
164:
165:         @Override
166:         public String toString()
167:         {
168:                 return repeat.toString() + (from == 1 && to == 1 ? ""
169:                                 : from == to ? "{" + from + "}" : "{" + from + ", " + to + "}");
170:         }
171: }