Class Environment<M extends Environment<M,​E,​T,​V>,​E extends SymbolicExpression,​T extends NonRelationalElement<T,​E,​M>,​V extends Lattice<V>>

    • Constructor Detail

      • Environment

        protected Environment​(T domain)
        Builds an empty environment.
        Parameters:
        domain - a singleton instance to be used during semantic operations to retrieve top and bottom values
      • Environment

        protected Environment​(T domain,
                              java.util.Map<Identifier,​T> function)
        Builds an environment containing the given mapping. If function is null, the new environment is the top environment if lattice.isTop() holds, and it is the bottom environment if lattice.isBottom() holds.
        Parameters:
        domain - a singleton instance to be used during semantic operations to retrieve top and bottom values
        function - the function representing the mapping contained in the new environment; can be null
    • Method Detail

      • copy

        protected abstract M copy()
        Copies this environment. The function of the returned environment must be a (shallow) copy of the one of the given environment.
        Returns:
        a copy of the given environment
      • eval

        protected abstract org.apache.commons.lang3.tuple.Pair<T,​V> eval​(E expression,
                                                                               ProgramPoint pp)
                                                                        throws SemanticException
        Yields the evaluation of the given expression, happening at the given program point. The result of the evaluation is in the form of <abstract element, evaluation result>, where evaluation result is the true result of the evaluation, while abstract element is the element derived by the result that is to be stored inside the environment mapped to an identifier.
        Parameters:
        expression - the expression to evaluate
        pp - the program point where the evaluation happens
        Returns:
        the result of the evaluation
        Throws:
        SemanticException - if something goes wrong during the evaluation
      • assignAux

        protected abstract M assignAux​(Identifier id,
                                       E expression,
                                       java.util.Map<Identifier,​T> function,
                                       T value,
                                       V eval,
                                       ProgramPoint pp)
        Auxiliary function of assign(Identifier, SymbolicExpression, ProgramPoint) that is invoked after the evaluation of the expression.
        Parameters:
        id - the identifier that has been assigned
        expression - the expression that has been evaluated and assigned
        function - a copy of the current function, where the id has been assigned to eval
        value - the final value stored for id, after considering applying NonRelationalElement.variable(Identifier, ProgramPoint) and Identifier.isWeak()
        eval - the abstract value that is the result of the evaluation of value
        pp - the program point that where this operation is being evaluated
        Returns:
        a new instance of this environment containing the given function, obtained by assigning id to eval
      • assume

        public final M assume​(E expression,
                              ProgramPoint pp)
                       throws SemanticException
        Description copied from interface: SemanticDomain
        Yields a copy of this domain, modified by assuming that the given expression holds. It is required that the returned domain is in relation with this one. A safe (but imprecise) implementation of this method can always return this.
        Specified by:
        assume in interface SemanticDomain<M extends Environment<M,​E,​T,​V>,​E extends SymbolicExpression,​T extends NonRelationalElement<T,​E,​M>>
        Parameters:
        expression - the expression to assume to hold.
        pp - the program point that where this operation is being evaluated
        Returns:
        the (optionally) modified copy of this domain
        Throws:
        SemanticException - if an error occurs during the computation
      • assumeSatisfied

        protected abstract M assumeSatisfied​(V eval)
        Assumes that an expression, that evaluated to eval, is always satisfied by this environment. This auxiliary method serves as a constructor for the final concrete instance of environment.
        Parameters:
        eval - the result of the evaluation of the expression that is always satisfied
        Returns:
        the (possibly) updated environment
      • glb

        public final M glb​(M other)
                    throws SemanticException
        Performs the greatest lower bound between this environment and other.
        Parameters:
        other - the other environment
        Returns:
        the greatest lower bound between this environment and other
        Throws:
        SemanticException - if something goes wrong during the computation
      • glbAux

        protected abstract M glbAux​(T lattice,
                                    java.util.Map<Identifier,​T> function,
                                    M other)
        Auxiliary glb operation, invoked after the result has been computed to create the concrete instance of environment. Note that any additional information that is instance-specific (i.e. anything but function and lattice singleton) has to be computed by this method.
        Parameters:
        lattice - the lattice that is the result of the glb
        function - the function that is the result of the glb (might be null
        other - the other environment
        Returns:
        the final instance of the glb
      • isTop

        public final boolean isTop()
        Yields true if and only if this object represents the top of the lattice. The default implementation of this method uses reference equality between this and the value returned by Lattice.top(), thus assuming that the top element is a singleton. If this is not the case, override this method accordingly to provide a coherent test.

        An environment is the top environment if the underlying lattice's isTop() holds and its function is null.
        Specified by:
        isTop in interface Lattice<M extends Environment<M,​E,​T,​V>>
        Returns:
        true if this is the top of the lattice
      • isBottom

        public final boolean isBottom()
        Yields true if and only if this object represents the bottom of the lattice. The default implementation of this method uses reference equality between this and the value returned by Lattice.bottom(), thus assuming that the bottom element is a singleton. If this is not the case, override this method accordingly to provide a coherent test.

        An environment is the bottom environment if the underlying lattice's isBottom() holds and its function is null.
        Specified by:
        isBottom in interface Lattice<M extends Environment<M,​E,​T,​V>>
        Returns:
        true if this is the bottom of the lattice
      • popScope

        public M popScope​(ScopeToken scope)
                   throws SemanticException
        Description copied from interface: SemanticDomain
        Pops the scope identified by the given token from the domain. This causes all the visible variables (i.e. that are not mapped to a scope) to be removed from the domain, while the local variables that were associated to the given scope token (and thus hidden) will become visible again.
        Specified by:
        popScope in interface SemanticDomain<M extends Environment<M,​E,​T,​V>,​E extends SymbolicExpression,​T extends NonRelationalElement<T,​E,​M>>
        Parameters:
        scope - the token of the scope to be restored
        Returns:
        a copy of this domain where the local variables have been removed, while the variables mapped to the given scope are visible again
        Throws:
        SemanticException - if an error occurs during the computation