Class TermTransformer
java.lang.Object
de.uni_freiburg.informatik.ultimate.logic.NonRecursive
de.uni_freiburg.informatik.ultimate.logic.TermTransformer
- Direct Known Subclasses:
FormulaUnLet,IRAConstantFormatter
public class TermTransformer extends NonRecursive
This is the base class for transforming formulas. It does nothing by itself
but you can use it to create arbitrary transformations on formulas. The
transform method applies the transformation in a non-recursive manner. To
achieve this it uses a todo stack, which contains terms and a small info how
much of this term was already processed. Additionally it uses a convert stack
that contains the most recent converted terms, which is used to collect the
arguments of function calls and the subterm of other terms.
Subclasses should override the function convert. It takes as argument the
term to convert and should set its result with setResult. If it needs to
build a more complex term with transformed arguments, it can enqueue the
subclasses BuildLetTerm, BuildApplicationTerm, BuildAnnotatedTerm with
enqueueWalker. The arguments should be added to the work queue by
pushTerm/pushTerms.
Of course, you can also add your own Build class that takes the converted
arguments from the conversion stack using getConverted().
- Author:
- Jochen Hoenicke
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classTermTransformer.BuildAnnotationCollect the sub term and annotations of an annotated formula from the converted stack.protected static classTermTransformer.BuildApplicationTermCollect the arguments of an application term from the converted stack and finish the conversion of appTerm.protected static classTermTransformer.BuildLambdaCollect the sub term of a lambda term and build the converted formula.protected static classTermTransformer.BuildLetTermCollect the sub term and the values of a let term from the converted stack and finish the conversion of let term.protected static classTermTransformer.BuildObjectArrayCollect the sub terms and sub arrays of an array (part of an annotated formula).protected static classTermTransformer.BuildQuantifierCollect the sub term of a quantified formula and build the converted formula.protected static classTermTransformer.StartLetTermWalker that is called after the variable values are transformed and before the let body starts.protected static classTermTransformer.WalkMatchTermWalk over each case of a match term, one after another.Nested classes/interfaces inherited from class de.uni_freiburg.informatik.ultimate.logic.NonRecursive
NonRecursive.TermWalker, NonRecursive.Walker -
Constructor Summary
Constructors Constructor Description TermTransformer() -
Method Summary
Modifier and Type Method Description protected voidbeginScope(TermVariable[] vars)protected voidconvert(Term term)The function that does the transformation.voidconvertApplicationTerm(ApplicationTerm appTerm, Term[] newArgs)protected voidendScope()protected TermgetConverted()Get a single converted term from the converted stack.protected Term[]getConverted(Term[] oldArgs)Get the converted terms from the converted stack.protected java.lang.Object[]getConvertedObjectArray()Get a single converted object array from the converted stack.voidpostConvertAnnotation(AnnotatedTerm old, Annotation[] newAnnots, Term newBody)voidpostConvertLambda(LambdaTerm old, Term newBody)voidpostConvertLet(LetTerm oldLet, Term[] newValues, Term newBody)voidpostConvertMatch(MatchTerm oldMatch, Term newDataTerm, Term[] newCases)voidpostConvertQuantifier(QuantifiedFormula old, Term newBody)voidpreConvertLet(LetTerm oldLet, Term[] newValues)voidpreConvertMatchCase(MatchTerm oldMatch, int caseNr)protected voidpushTerm(Term term)Push a term on the todo stack as CONVERT work item.protected voidpushTerms(Term[] terms)Push all terms in the array on the todo stack as CONVERT work item.voidreset()Manually reset this walker.protected voidsetResult(Term term)Set the conversion result to term.Termtransform(Term term)Transform a term.Methods inherited from class de.uni_freiburg.informatik.ultimate.logic.NonRecursive
enqueueWalker, run, run, toString
-
Constructor Details
-
TermTransformer
public TermTransformer()
-
-
Method Details
-
pushTerms
Push all terms in the array on the todo stack as CONVERT work item.- Parameters:
terms- the array of terms.
-
pushTerm
Push a term on the todo stack as CONVERT work item.- Parameters:
term- the term to convert.
-
setResult
Set the conversion result to term.- Parameters:
term- the converted term.
-
beginScope
-
endScope
protected void endScope() -
convert
The function that does the transformation. Override this function if you build your own term transformer. It does not return the result but instead it puts it on the converted stack using setResult(). Instead it can also enqueue some Builders that will in the end put the result on the converted stack. You can always call super.convert() if you do not need to convert the term. It will still convert the sub-terms. If you do not want to convert the sub terms, call setResult(term) instead.- Parameters:
term- The term to convert.
-
convertApplicationTerm
-
preConvertLet
-
postConvertLet
-
postConvertLambda
-
postConvertQuantifier
-
postConvertAnnotation
-
preConvertMatchCase
-
postConvertMatch
-
transform
Transform a term.- Parameters:
term- the term to transform.- Returns:
- the resulting transformed term.
-
getConverted
Get a single converted term from the converted stack. This is the dual of pushTerm() that is called after the term were removed from the todo stack and pushed to the converted stack.- Returns:
- the new converted term.
-
getConvertedObjectArray
protected final java.lang.Object[] getConvertedObjectArray()Get a single converted object array from the converted stack.- Returns:
- the new converted object array.
-
getConverted
Get the converted terms from the converted stack. This is the dual of pushTerms() that is called after the term were removed from the todo stack and pushed to the converted stack. It takes the old terms as argument and checks for changes.- Parameters:
oldArgs- the original arguments.- Returns:
- the new converted arguments. It will return the same array oldArgs if there were no changes.
-
reset
public void reset()Description copied from class:NonRecursiveManually reset this walker. This function can be used to clear the todo stack when an exception is raised by a walker. This exception will terminate the non-recursive walk but will leave some walker in the todo stack.- Overrides:
resetin classNonRecursive
-