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
  • Constructor Details

  • Method Details

    • pushTerms

      protected final void pushTerms​(Term[] terms)
      Push all terms in the array on the todo stack as CONVERT work item.
      Parameters:
      terms - the array of terms.
    • pushTerm

      protected final void pushTerm​(Term term)
      Push a term on the todo stack as CONVERT work item.
      Parameters:
      term - the term to convert.
    • setResult

      protected final void setResult​(Term term)
      Set the conversion result to term.
      Parameters:
      term - the converted term.
    • beginScope

      protected void beginScope​(TermVariable[] vars)
    • endScope

      protected void endScope()
    • convert

      protected void convert​(Term term)
      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

      public void convertApplicationTerm​(ApplicationTerm appTerm, Term[] newArgs)
    • preConvertLet

      public void preConvertLet​(LetTerm oldLet, Term[] newValues)
    • postConvertLet

      public void postConvertLet​(LetTerm oldLet, Term[] newValues, Term newBody)
    • postConvertLambda

      public void postConvertLambda​(LambdaTerm old, Term newBody)
    • postConvertQuantifier

      public void postConvertQuantifier​(QuantifiedFormula old, Term newBody)
    • postConvertAnnotation

      public void postConvertAnnotation​(AnnotatedTerm old, Annotation[] newAnnots, Term newBody)
    • preConvertMatchCase

      public void preConvertMatchCase​(MatchTerm oldMatch, int caseNr)
    • postConvertMatch

      public void postConvertMatch​(MatchTerm oldMatch, Term newDataTerm, Term[] newCases)
    • transform

      public final Term transform​(Term term)
      Transform a term.
      Parameters:
      term - the term to transform.
      Returns:
      the resulting transformed term.
    • getConverted

      protected final 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

      protected final Term[] getConverted​(Term[] oldArgs)
      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: NonRecursive
      Manually 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:
      reset in class NonRecursive