public class FlatPredList extends FlatPred
Here is a typical use of FlatPredList:
// Stage 1: Setup. predlist = new FlatPredList(zlive_instance); // now add decls, predicates, expressions etc. ZName resultName = predlist.addExpr(expr); Envir env0 = new Envir(); // empty environment // Stage 2: Optimisation. predlist.inferBounds(new Bounds()); // does some static analysis // Ask the FlatPredList to optimise itself for efficient // evaluation, given the inputs in env0 (none in this case). Mode m = predlist.chooseMode(env0); if (m == null) throw new EvalException("Cannot find mode to evaluate " + expr); predlist.setMode(m); // Stage 3: Evaluation. predlist.startEvaluation(); while (predlist.nextEvaluation()) // lookup the result and do something with it. System.out.println(predlist.getEnvir().lookup(resultName));
Modifier and Type | Field and Description |
---|---|
protected Set<net.sourceforge.czt.z.ast.ZName> |
boundVars_
Records the bound variables in this list
(Ignoring the tmp vars produced by Flatten).
|
static boolean |
optimize_
Evaluation is left-to-right if this is false,
or smallest-mode-first if it is true.
|
protected List<FlatPred> |
predlist_
This stores the list of FlatPreds used in the current evaluation.
|
Constructor and Description |
---|
FlatPredList(ZLive newZLive)
Creates an empty FlatPred list.
|
Modifier and Type | Method and Description |
---|---|
void |
add(FlatPred flat)
Add one FlatPred to the FlatPred list.
|
void |
addDecl(net.sourceforge.czt.z.ast.Decl decl)
Adds one declaration to the FlatPred list predList_.
|
void |
addExistsPred(net.sourceforge.czt.z.ast.Pred pred)
This is similar to addPred, but it flattens out any existential
quantifiers within pred.
|
void |
addExistsSchText(net.sourceforge.czt.z.ast.ZSchText stext)
Same as addSchText, but uses addExistsPred to add the predicate part.
|
net.sourceforge.czt.z.ast.ZName |
addExpr(net.sourceforge.czt.z.ast.Expr expr)
Adds one expression to the FlatPred list.
|
void |
addPred(net.sourceforge.czt.z.ast.Pred pred)
Adds one predicate to the FlatPred list.
|
void |
addSchText(net.sourceforge.czt.z.ast.ZSchText stext)
Adds a whole schema text to the FlatPred list.
|
Set<net.sourceforge.czt.z.ast.ZName> |
boundVars()
Returns the bound variables of this FlatPredList,
ignoring any temporary variables.
|
ModeList |
chooseMode(Envir env0)
Optimises the list and chooses a mode.
|
Set<net.sourceforge.czt.z.ast.ZName> |
freeVars()
Returns the free variables of all the FlatPreds.
|
List<net.sourceforge.czt.z.ast.ZName> |
getArgs()
Get the list of variables that this predicate directly
depends upon.
|
protected net.sourceforge.czt.z.util.Factory |
getFactory() |
Envir |
getOutputEnvir()
The output environment of this FlatPred list.
|
boolean |
inferBounds(Bounds bnds)
Infer bounds for any integer variables.
|
boolean |
inferBoundsFixPoint(Bounds bnds)
Equivalent to inferBoundsFixPoint(bnds, 5).
|
boolean |
inferBoundsFixPoint(Bounds bnds,
int maxPasses)
Infer bounds for any integer variables.
|
Iterator<FlatPred> |
iterator()
An iterator over the FlatPreds in this list.
|
void |
makeBound(net.sourceforge.czt.z.ast.ZName name)
Clients can use this to mark some names as
being local to (bound by) this FlatPred list.
|
void |
makeFree(net.sourceforge.czt.z.ast.ZName name)
Clients can use this to say that the given
variable is actually a free variable of this FlatPredList.
|
boolean |
nextEvaluation()
Returns the next solution from this list of FlatPreds.
|
void |
setMode(Mode mode)
Set the mode that will be used to evaluate this list.
|
int |
size()
Returns the number of FlatPreds in this list.
|
void |
startEvaluation()
Starts a fresh evaluation.
|
String |
toString()
This prints each FlatPred on a separate line.
|
accept, getEnvir, getLastArg, getMode, indent, modeAllDefined, modeCollection, modeFunction, modeOneOutput, printArg, printBinOp, printLastArg, printName, printQuant
public static final boolean optimize_
protected List<FlatPred> predlist_
protected Set<net.sourceforge.czt.z.ast.ZName> boundVars_
public FlatPredList(ZLive newZLive)
public int size()
public Iterator<FlatPred> iterator()
public Set<net.sourceforge.czt.z.ast.ZName> boundVars()
public Set<net.sourceforge.czt.z.ast.ZName> freeVars()
public List<net.sourceforge.czt.z.ast.ZName> getArgs()
FlatPred
public void add(FlatPred flat)
flat
- the FlatPred to add.public void makeBound(net.sourceforge.czt.z.ast.ZName name)
name
- public void makeFree(net.sourceforge.czt.z.ast.ZName name)
public void addSchText(net.sourceforge.czt.z.ast.ZSchText stext)
stext
- public void addExistsSchText(net.sourceforge.czt.z.ast.ZSchText stext)
stext
- public void addDecl(net.sourceforge.czt.z.ast.Decl decl)
decl
- May declare several variables.public void addPred(net.sourceforge.czt.z.ast.Pred pred)
pred
- The Pred to flatten and add.public void addExistsPred(net.sourceforge.czt.z.ast.Pred pred)
Note that this method would not be sound for a predicate like
(exists x:0..20 @ x < 10) and (exists x:0..20 @ x > 10),because the flattened result would unify the two x's, and the resulting predicate would be false, rather than true. However, such inputs should never occur, since CZT ASTs always use a different ID for each variable with a different scope, even for sibling scopes.
pred
- public net.sourceforge.czt.z.ast.ZName addExpr(net.sourceforge.czt.z.ast.Expr expr)
The result name is not necessarily free or bound -- this depends upon how the name was declared. So it is the caller's responsibility to make it free if this is desired.
expr
- The Expr to flatten and add.public boolean inferBounds(Bounds bnds)
This does upto inferPasses_ passes over all the predicates in the list (it stops if a fixed point is found earlier).
inferBounds
in class FlatPred
bnds
- The database of lower and upper bounds for integer variables.public boolean inferBoundsFixPoint(Bounds bnds)
public boolean inferBoundsFixPoint(Bounds bnds, int maxPasses)
This does upto maxPasses passes over all the predicates in the list. TODO: stop earlier than maxPasses if a fixed point is reached. That is, if the bounds are not getting any tighter after a pass.
bnds
- The database of lower and upper bounds for integer variables.maxPasses
- The maximum number of iterations done. Must be > 0.public ModeList chooseMode(Envir env0)
chooseMode
in class FlatPred
public void setMode(Mode mode)
public void startEvaluation()
startEvaluation
in class FlatPred
public Envir getOutputEnvir()
public boolean nextEvaluation()
nextEvaluation
in class FlatPred
protected net.sourceforge.czt.z.util.Factory getFactory()
Copyright © 2003–2016 Community Z Tools Project. All rights reserved.