public abstract class FlatPred extends Object
Design Rationale: The natural representation of the data inside each kind of FlatPred is quite different to the normal CZT AST classes, which means that the standard CZT visitors and utilities would not automatically work on FlatPred classes. However, for backwards compatibility, the FlatPred classes implement the Pred interface, and generate the appropriate children on the fly, so that they seem to be standard Z AST objects. For example, this allows the usual print visitors to display the FlatPred objects.
The mode selection uses a stateless interface, where the chosen mode information is returned in a separate object rather than changing the internal state of the FlatPred. This enables different input environments to be tried and the corresponding modes stored and compared, which gives more flexibility in the searching algorithms that use modes.
Modifier and Type | Field and Description |
---|---|
protected ArrayList<net.sourceforge.czt.z.ast.ZName> |
args_
The list of arguments to this FlatPred.
|
protected Mode |
evalMode_
The mode that will be used during evaluation.
|
protected Set<net.sourceforge.czt.z.ast.ZName> |
freeVars_
Records the free variables used within this predicate.
|
protected static String |
INDENT |
protected static Logger |
LOG |
protected static net.sourceforge.czt.z.util.PrintVisitor |
printer_
A non-unicode print visitor used for debug and toString messages.
|
protected int |
solutionsReturned_
The number of solutions that have been returned by nextEvaluation().
|
Modifier | Constructor and Description |
---|---|
protected |
FlatPred()
Default constructor for subclasses to call.
|
Modifier and Type | Method and Description |
---|---|
<R> R |
accept(net.sourceforge.czt.util.Visitor<R> visitor)
Calls visitor.visitPred (preferably) or visitor.visitTerm.
|
abstract Mode |
chooseMode(Envir env)
Choose the mode that this predicate could use in this environment.
|
Set<net.sourceforge.czt.z.ast.ZName> |
freeVars()
Returns the free variables that appear in the predicate.
|
List<net.sourceforge.czt.z.ast.ZName> |
getArgs()
Get the list of variables that this predicate directly
depends upon.
|
Envir |
getEnvir()
Get the output environment of the evaluation.
|
net.sourceforge.czt.z.ast.ZName |
getLastArg()
Get the variable at the end of getArgs().
|
Mode |
getMode()
Get the mode that has been set for evaluation purposes.
|
String |
indent(String str)
Indents a multi-line string by replacing all newlines
by a newline followed by two spaces.
|
boolean |
inferBounds(Bounds bnds)
Infer bounds for any integer variables.
|
protected Mode |
modeAllDefined(Envir env)
A default implementation of chooseMode.
|
Mode |
modeCollection(Envir env)
A default implementation of chooseMode.
|
protected Mode |
modeFunction(Envir env)
A default implementation of chooseMode.
|
protected Mode |
modeOneOutput(Envir env)
A default implementation of chooseMode.
|
abstract boolean |
nextEvaluation()
Generates the next solution that satisfies this predicate.
|
protected String |
printArg(int argNum)
Pretty-prints the name of the i'th argument, via nameString.
|
protected String |
printBinOp(String op)
A toString method for binary operators.
|
protected String |
printLastArg()
Pretty-prints getLastArg()
|
static String |
printName(net.sourceforge.czt.z.ast.ZName name)
Convenience method to convert a ZName into a string.
|
protected String |
printQuant(String quant,
String stext,
String body,
String endQuant) |
void |
setMode(Mode mode)
Set the mode that will be used to evaluate this predicate.
|
void |
startEvaluation() |
String |
toString()
A default implementation of toString.
|
protected static final String INDENT
protected static final Logger LOG
protected Set<net.sourceforge.czt.z.ast.ZName> freeVars_
protected Mode evalMode_
protected ArrayList<net.sourceforge.czt.z.ast.ZName> args_
protected int solutionsReturned_
protected static net.sourceforge.czt.z.util.PrintVisitor printer_
public List<net.sourceforge.czt.z.ast.ZName> getArgs()
public net.sourceforge.czt.z.ast.ZName getLastArg()
public Mode getMode()
public Envir getEnvir()
public Set<net.sourceforge.czt.z.ast.ZName> freeVars()
public boolean inferBounds(Bounds bnds)
bnds
- The database of lower and upper bounds for integer variables.The default implementation infers nothing and returns false.
public abstract Mode chooseMode(Envir env)
protected Mode modeAllDefined(Envir env)
protected Mode modeFunction(Envir env)
protected Mode modeOneOutput(Envir env)
public Mode modeCollection(Envir env)
public void setMode(Mode mode)
mode
- Must be one of the modes returned previously by chooseMode.public void startEvaluation()
public abstract boolean nextEvaluation()
public static String printName(net.sourceforge.czt.z.ast.ZName name)
protected String printArg(int argNum)
protected String printLastArg()
public String toString()
protected String printBinOp(String op)
public String indent(String str)
str
- the (possibly multi-line) string to indentpublic <R> R accept(net.sourceforge.czt.util.Visitor<R> visitor)
Copyright © 2003–2016 Community Z Tools Project. All rights reserved.