Mercurial > hg > Members > kono > jpf-core
comparison src/main/gov/nasa/jpf/vm/ChoiceGenerator.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children | f6886b2bda4a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
1 /* | |
2 * Copyright (C) 2014, United States Government, as represented by the | |
3 * Administrator of the National Aeronautics and Space Administration. | |
4 * All rights reserved. | |
5 * | |
6 * The Java Pathfinder core (jpf-core) platform is licensed under the | |
7 * Apache License, Version 2.0 (the "License"); you may not use this file except | |
8 * in compliance with the License. You may obtain a copy of the License at | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0. | |
11 * | |
12 * Unless required by applicable law or agreed to in writing, software | |
13 * distributed under the License is distributed on an "AS IS" BASIS, | |
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 * See the License for the specific language governing permissions and | |
16 * limitations under the License. | |
17 */ | |
18 package gov.nasa.jpf.vm; | |
19 | |
20 import gov.nasa.jpf.util.ObjectList; | |
21 | |
22 import java.util.Comparator; | |
23 | |
24 /** | |
25 * generic interface for configurable choice generators | |
26 */ | |
27 public interface ChoiceGenerator<T> extends Cloneable { | |
28 | |
29 //--- the basic ChoiceGenerator interface, mostly used by SystemState | |
30 | |
31 T getNextChoice(); | |
32 | |
33 Class<T> getChoiceType(); | |
34 | |
35 boolean hasMoreChoices(); | |
36 | |
37 /** | |
38 * advance to the next choice. This is the only method that really | |
39 * advances our enumeration | |
40 */ | |
41 void advance(); | |
42 | |
43 void advance(int nChoices); | |
44 | |
45 void select(int nChoice); | |
46 | |
47 boolean isDone(); | |
48 | |
49 void setDone(); | |
50 | |
51 boolean isProcessed(); | |
52 | |
53 /** | |
54 * this has to reset the CG to its initial state, which includes resetting | |
55 * 'isDone' | |
56 */ | |
57 void reset(); | |
58 | |
59 int getTotalNumberOfChoices(); | |
60 | |
61 int getProcessedNumberOfChoices(); | |
62 | |
63 ChoiceGenerator<?> getPreviousChoiceGenerator(); | |
64 | |
65 int getNumberOfParents(); | |
66 | |
67 /** | |
68 * turn the order of choices random (if it isn't already). Only | |
69 * drawback of this generic method (which might be a decorator | |
70 * factory) is that our type layer (e.g. IntChoiceGenerator) | |
71 * has to guarantee type safety. But hey - this is the first case where | |
72 * we can use covariant return types! | |
73 * | |
74 * NOTES: | |
75 * - this method may alter this ChoiceGenerator and return that or return | |
76 * a new "decorated" version. | |
77 * - random data can be read from the "Random random" field in this class. | |
78 */ | |
79 ChoiceGenerator<T> randomize(); | |
80 | |
81 ChoiceGenerator<?> clone() throws CloneNotSupportedException; | |
82 | |
83 ChoiceGenerator<?> deepClone() throws CloneNotSupportedException; | |
84 | |
85 String getId(); | |
86 | |
87 int getIdRef(); | |
88 | |
89 void setIdRef(int idRef); | |
90 | |
91 void setId(String id); | |
92 | |
93 boolean isSchedulingPoint(); | |
94 | |
95 //--- the getters and setters for the CG creation info | |
96 void setThreadInfo(ThreadInfo ti); | |
97 | |
98 ThreadInfo getThreadInfo(); | |
99 | |
100 void setInsn(Instruction insn); | |
101 | |
102 Instruction getInsn(); | |
103 | |
104 void setContext(ThreadInfo tiCreator); | |
105 | |
106 String getSourceLocation(); | |
107 | |
108 boolean supportsReordering(); | |
109 | |
110 /** | |
111 * reorder according to a user provided comparator | |
112 * @returns instance to reordered CG of same choice type, | |
113 * null if not supported by particular CG subclass | |
114 * | |
115 * Note: this should only be called before the first advance, since it | |
116 * can reset the CG enumeration status | |
117 */ | |
118 ChoiceGenerator<T> reorder (Comparator<T> comparator); | |
119 | |
120 void setPreviousChoiceGenerator(ChoiceGenerator<?> cg); | |
121 | |
122 | |
123 void setCascaded(); | |
124 | |
125 boolean isCascaded(); | |
126 | |
127 <T extends ChoiceGenerator<?>> T getPreviousChoiceGeneratorOfType(Class<T> cls); | |
128 | |
129 /** | |
130 * returns the prev CG if it was registered for the same insn | |
131 */ | |
132 ChoiceGenerator<?> getCascadedParent(); | |
133 | |
134 /** | |
135 * return array with all cascaded parents and this CG, in registration order | |
136 */ | |
137 ChoiceGenerator<?>[] getCascade(); | |
138 | |
139 /** | |
140 * return array with all parents and this CG, in registration order | |
141 */ | |
142 ChoiceGenerator<?>[] getAll(); | |
143 | |
144 /** | |
145 * return array with all CGs (including this one) of given 'cgType', in registration order | |
146 */ | |
147 <C extends ChoiceGenerator<?>> C[] getAllOfType(Class<C> cgType); | |
148 | |
149 | |
150 //--- the generic attribute API | |
151 boolean hasAttr(); | |
152 | |
153 boolean hasAttr(Class<?> attrType); | |
154 | |
155 /** | |
156 * this returns all of them - use either if you know there will be only | |
157 * one attribute at a time, or check/process result with ObjectList | |
158 */ | |
159 Object getAttr(); | |
160 | |
161 /** | |
162 * this replaces all of them - use only if you know | |
163 * - there will be only one attribute at a time | |
164 * - you obtained the value you set by a previous getXAttr() | |
165 * - you constructed a multi value list with ObjectList.createList() | |
166 */ | |
167 void setAttr(Object a); | |
168 | |
169 void addAttr(Object a); | |
170 | |
171 void removeAttr(Object a); | |
172 | |
173 void replaceAttr(Object oldAttr, Object newAttr); | |
174 | |
175 /** | |
176 * this only returns the first attr of this type, there can be more | |
177 * if you don't use client private types or the provided type is too general | |
178 */ | |
179 <A> A getAttr(Class<A> attrType); | |
180 | |
181 <A> A getNextAttr(Class<A> attrType, Object prev); | |
182 | |
183 ObjectList.Iterator attrIterator(); | |
184 | |
185 <A> ObjectList.TypedIterator<A> attrIterator(Class<A> attrType); | |
186 | |
187 } |