Class UndefinedSingleValue

java.lang.Object
io.matita08.value.Value
io.matita08.value.UndefinedSingleValue
All Implemented Interfaces:
Cloneable

public class UndefinedSingleValue extends Value implements Cloneable
Concrete implementation of Value representing an undefined single-word value. This class simulates uninitialized memory or register contents by returning random values for all operations, helping to identify programming errors where uninitialized values are used.

UndefinedSingleValue implements the Cloneable interface but returns the same instance when cloned, as all undefined values exhibit the same random behavior.

All arithmetic operations with undefined values result in undefined values, and comparison operations always return false to prevent undefined behavior from appearing as valid comparisons.

Since:
1.0
  • Method Details

    • getSigned

      public int getSigned()
      Gets the value interpreted as a signed integer. The sign interpretation depends on the value type and configuration.

      For UndefinedSingleValue, returns a random value in the signed range by subtracting ValueMax from the random value to center it around zero.

      Specified by:
      getSigned in class Value
      Returns:
      the value as a signed integer
    • getUnsigned

      public int getUnsigned()
      Gets the value interpreted as an unsigned integer. All negative representations are treated as positive values.

      For UndefinedSingleValue, returns a random value in the unsigned range by taking the modulo with ValueMax.

      Specified by:
      getUnsigned in class Value
      Returns:
      the value as an unsigned integer
    • clone

      public UndefinedSingleValue clone()
      Returns the same UndefinedSingleValue instance. Since all undefined values exhibit the same behavior, cloning returns the same instance for efficiency.
      Overrides:
      clone in class Object
      Returns:
      this instance
    • set

      public Value set(int n)
      Sets this value to the specified numeric value. The behavior depends on the concrete value type - some types may return a new instance while others modify the current instance.

      For UndefinedSingleValue, setting a concrete value creates a new SingleValue with that value, effectively "defining" the undefined value.

      Specified by:
      set in class Value
      Parameters:
      n - the new numeric value
      Returns:
      the value instance (may be this instance or a new one)
    • isUndefined

      public boolean isUndefined()
      Checks if this value is in an undefined state. Undefined values represent uninitialized memory or registers.

      For UndefinedSingleValue, always returns true since the value is not defined.

      Overrides:
      isUndefined in class Value
      Returns:
      true if this value is undefined, false for concrete values
    • add

      public Value add(Value v2)
      Performs addition with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or overflow based on the value types involved.

      For UndefinedSingleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      add in class Value
      Parameters:
      v2 - the value to add to this value
      Returns:
      a new value containing the sum
    • sub

      public Value sub(Value v2)
      Performs subtraction with another value. The operation is performed using the appropriate numeric representation and may handle sign extension or underflow based on the value types involved.

      For UndefinedSingleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      sub in class Value
      Parameters:
      v2 - the value to subtract from this value
      Returns:
      a new value containing the difference
    • mul

      public Value mul(Value v2)
      Performs multiplication with another value. The operation is performed using the appropriate numeric representation and may handle overflow based on the value types involved.

      For UndefinedSingleValue, any arithmetic operation results in an undefined value, so returns this instance.

      Specified by:
      mul in class Value
      Parameters:
      v2 - the value to multiply with this value
      Returns:
      a new value containing the product
    • toString

      public String toString()
      Returns a string representation of this value. The representation uses the radix specified by Constants.getRadix() and may show special indicators for undefined values.

      For UndefinedSingleValue, returns "?" to visually indicate the undefined state.

      Overrides:
      toString in class Value
      Returns:
      a string representation of this value
    • equals

      public boolean equals(int n)
      Checks if this value equals the specified numeric value. The comparison is performed against both signed and unsigned interpretations to handle cases where the same bit pattern can represent different values.

      For UndefinedSingleValue, always returns false since equality with an undefined value is undefined and should not be relied upon.

      Overrides:
      equals in class Value
      Parameters:
      n - the numeric value to compare against
      Returns:
      true if either the signed or unsigned interpretation matches the specified value