Class Transformer


  • public final class Transformer
    extends java.lang.Object
    The Transformer class contains static methods for common expression transformations.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Node standardize​(Node expression)
      Replace operations in expression with standard counterparts.
      static Node substitute​(Node expression, java.lang.String name, Node term)
      Substitute given term for variables with specified name in expression.
      static Node substitute​(Node expression, NodeProvider nodeProvider)
      Performs substitutions are described in the NodeProvider at the specified node.
      static Node substitute​(Node expression, VariableProvider variableProvider)
      Performs substitutions are described in the VariableProvider at the specified node.
      static Node substituteAllBindings​(Node expression)
      Substitute all bindings in given expression.
      static Node substituteBinding​(NodeBinding binding)
      Apply given binding substitutions to underlying expression.
      static Node transform​(Node tree, java.lang.Enum<?> indicator, TransformerRule rule)
      Transforms an expression using the given rule.
      static Node transform​(Node tree, NodeTransformer transformer)
      Transforms an expression using the given transformer.
      static java.util.List<Node> transformAll​(java.util.Collection<? extends Node> forest, java.lang.Enum<?> indicator, TransformerRule rule)
      Transforms a collection of expressions using the given rule.
      static java.util.List<Node> transformAll​(java.util.Collection<? extends Node> forest, NodeTransformer transformer)
      Transforms a collection of expressions using the given rule.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • substitute

        public static Node substitute​(Node expression,
                                      java.lang.String name,
                                      Node term)
        Substitute given term for variables with specified name in expression. Substitution considers variable names ignoring types.

        Provided term instance is referenced in resulting expression w/o copying.

        Parameters:
        expression - Expression in which substitution takes place.
        name - Name of variables to be substituted.
        term - Term to replace variables.
        Returns:
        An expression where all variables with given name are replaced with term specified.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • substitute

        public static Node substitute​(Node expression,
                                      VariableProvider variableProvider)
        Performs substitutions are described in the VariableProvider at the specified node.
        Parameters:
        expression - The node to be processed.
        variableProvider - The substitutions storage.
        Returns:
        The node upon that all the described substitutions are already performed.
      • substitute

        public static Node substitute​(Node expression,
                                      NodeProvider nodeProvider)
        Performs substitutions are described in the NodeProvider at the specified node.
        Parameters:
        expression - The node to be processed.
        nodeProvider - The substitutions storage.
        Returns:
        The node upon that all the described substitutions are already performed.
      • substituteBinding

        public static Node substituteBinding​(NodeBinding binding)
        Apply given binding substitutions to underlying expression. Substitution applies to single binding provided, ignoring additional bindings in expression. However, nested binding scope is correctly resolved, i.e. substitution applies to free variables in underlying expression and in bound values of nested bindings.
        Parameters:
        binding - Binding node to be substituted.
        Returns:
        An underlying expression with all bindings specified being substituted.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • substituteAllBindings

        public static Node substituteAllBindings​(Node expression)
        Substitute all bindings in given expression. Substitution applies with respect to nested binding scope.

        Substitution applies non-recursively, i.e. any bindings found in bound values are not substituted.

        Parameters:
        expression - Expression to be substituted.
        Returns:
        An expression resulting from substitution of all bindings found in initial expression.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • standardize

        public static Node standardize​(Node expression)
        Replace operations in expression with standard counterparts. Transforms composite math predicates such as NEQ, GEQ etc. into formula using NOT, EQ, LE, GE and boolean functions. Supports general and bitvector operations.

        Transformation considers only standard predicates.

        Parameters:
        expression - Expression to be transformed.
        Returns:
        Expression with non-standard operations being replaced.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • transform

        public static Node transform​(Node tree,
                                     java.lang.Enum<?> indicator,
                                     TransformerRule rule)
        Transforms an expression using the given rule.
        Parameters:
        tree - Expression to be transformed.
        indicator - Node kind or operation id of nodes rule is to be applied to.
        rule - Transformation rule.
        Returns:
        Transformed expression.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • transform

        public static Node transform​(Node tree,
                                     NodeTransformer transformer)
        Transforms an expression using the given transformer.
        Parameters:
        tree - Expression to be transformed.
        transformer - Transformer for be used.
        Returns:
        Transformed expression.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • transformAll

        public static java.util.List<Node> transformAll​(java.util.Collection<? extends Node> forest,
                                                        java.lang.Enum<?> indicator,
                                                        TransformerRule rule)
        Transforms a collection of expressions using the given rule.
        Parameters:
        forest - Collection of expressions to be transformed.
        indicator - Node kind or operation id of nodes rule is to be applied to.
        rule - Transformation rule.
        Returns:
        List of transformed expressions in order of base collection iteration.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • transformAll

        public static java.util.List<Node> transformAll​(java.util.Collection<? extends Node> forest,
                                                        NodeTransformer transformer)
        Transforms a collection of expressions using the given rule.
        Parameters:
        forest - Collection of expressions to be transformed.
        transformer - Transformer for be used.
        Returns:
        List of transformed expressions in order of base collection iteration.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.