Class SimValueBuilder


  • public final class SimValueBuilder
    extends Object
    Builder API for constructing simulated values with field initialization.
    • Method Detail

      • forType

        public static SimValueBuilder forType​(IRType type)
        Starts a builder for an IR type.
        Parameters:
        type - the value type
        Returns:
        the new builder
      • forClass

        public static SimValueBuilder forClass​(String className)
        Starts a builder for an object type, accepting dotted or slashed names.
        Parameters:
        className - the class name
        Returns:
        the new builder
      • forArray

        public static SimValueBuilder forArray​(IRType elementType)
        Starts a builder for a one-dimensional array.
        Parameters:
        elementType - the element type
        Returns:
        the new builder
      • withIntValue

        public SimValueBuilder withIntValue​(int value)
        Sets the constant this value carries.
        Parameters:
        value - the int constant
        Returns:
        this builder
      • withLongValue

        public SimValueBuilder withLongValue​(long value)
        Sets the constant this value carries.
        Parameters:
        value - the long constant
        Returns:
        this builder
      • withFloatValue

        public SimValueBuilder withFloatValue​(float value)
        Sets the constant this value carries.
        Parameters:
        value - the float constant
        Returns:
        this builder
      • withDoubleValue

        public SimValueBuilder withDoubleValue​(double value)
        Sets the constant this value carries.
        Parameters:
        value - the double constant
        Returns:
        this builder
      • withBooleanValue

        public SimValueBuilder withBooleanValue​(boolean value)
        Sets the constant this value carries, stored as the int 0 or 1.
        Parameters:
        value - the boolean constant
        Returns:
        this builder
      • withStringValue

        public SimValueBuilder withStringValue​(String value)
        Sets the constant this value carries.
        Parameters:
        value - the string constant
        Returns:
        this builder
      • withAllocationSite

        public SimValueBuilder withAllocationSite​(AllocationSite site)
        Pins the value to an allocation site, which also makes it non-null.
        Parameters:
        site - the allocation site
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         SimValue value)
        Sets a field to an already built value.
        Parameters:
        fieldName - the field name
        value - the field value
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         SimValueBuilder nested)
        Sets a field to a nested builder, built against the same heap at build time.
        Parameters:
        fieldName - the field name
        nested - the builder for the field value
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         int value)
        Sets a field to an int constant.
        Parameters:
        fieldName - the field name
        value - the constant
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         long value)
        Sets a field to a long constant.
        Parameters:
        fieldName - the field name
        value - the constant
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         boolean value)
        Sets a field to a boolean constant.
        Parameters:
        fieldName - the field name
        value - the constant
        Returns:
        this builder
      • withField

        public SimValueBuilder withField​(String fieldName,
                                         String value)
        Sets a field to a java.lang.String constant.
        Parameters:
        fieldName - the field name
        value - the constant
        Returns:
        this builder
      • asArray

        public SimValueBuilder asArray​(SimValue... elements)
        Replaces the array contents and sets the length to match.
        Parameters:
        elements - the array elements in index order
        Returns:
        this builder
      • withArrayLength

        public SimValueBuilder withArrayLength​(int length)
        Sets the array length independently of the elements supplied.
        Parameters:
        length - the array length
        Returns:
        this builder
      • withArrayElement

        public SimValueBuilder withArrayElement​(SimValue element)
        Appends one element at the next index.
        Parameters:
        element - the element value
        Returns:
        this builder
      • nullable

        public SimValueBuilder nullable()
        Marks the value as possibly null, the default state.
        Returns:
        this builder
      • definitelyNull

        public SimValueBuilder definitelyNull()
        Marks the value as null, dropping any allocation site.
        Returns:
        this builder
      • definitelyNotNull

        public SimValueBuilder definitelyNotNull()
        Marks the value as non-null.
        Returns:
        this builder
      • getType

        public IRType getType()
        Returns:
        the type
      • build

        public SimValue build​(SimHeap heap)
        Materializes the value, allocating on the heap and recursively building nested field builders.
        Parameters:
        heap - the heap that receives allocations, field stores and array stores
        Returns:
        the built value