Record Class ReturnVariableDetails

java.lang.Object
java.lang.Record
org.ek9lang.compiler.ir.data.ReturnVariableDetails

public record ReturnVariableDetails(String returnVariable, String returnVariableType, List<IRInstr> returnVariableDeclaration, List<IRInstr> returnVariableInitialisation) extends Record
Record containing return variable management information for CONTROL_FLOW_CHAIN constructs.

Return variables are used in expression forms of control flow constructs where the result of the construct is assigned to a declared variable: - switch expressions: "result <- switch someVar" - if expressions: "result <- if condition then value1 else value2"

For statement forms (if statements, switch statements), return variables are not used since the construct doesn't produce a result value.

  • Constructor Details

    • ReturnVariableDetails

      public ReturnVariableDetails(String returnVariable, String returnVariableType, List<IRInstr> returnVariableSetup)
      Return variable details whose setup is not split (the whole setup is the initialisation) - the record's shape before FLOW-14a, kept so a construction written against it still compiles; prefer withSetup(String, String, List).
    • ReturnVariableDetails

      public ReturnVariableDetails(String returnVariable, String returnVariableType, List<IRInstr> returnVariableDeclaration, List<IRInstr> returnVariableInitialisation)
      Creates an instance of a ReturnVariableDetails record class.
      Parameters:
      returnVariable - the value for the returnVariable record component
      returnVariableType - the value for the returnVariableType record component
      returnVariableDeclaration - the value for the returnVariableDeclaration record component
      returnVariableInitialisation - the value for the returnVariableInitialisation record component
  • Method Details

    • none

      public static ReturnVariableDetails none()
      Create empty return variable details (no return variable).
    • withSetup

      public static ReturnVariableDetails withSetup(String returnVariable, String returnVariableType, List<IRInstr> returnVariableSetup)
      Create return variable details with setup instructions that are not split into declaration and initialisation (the whole setup is the initialisation).
    • withParts

      public static ReturnVariableDetails withParts(String returnVariable, String returnVariableType, List<IRInstr> returnVariableDeclaration, List<IRInstr> returnVariableInitialisation)
      Create return variable details whose setup is known as its two halves - THE structured split a try expression relocates by (FLOW-14a): never re-derive it by scanning the setup's opcodes.
    • returnVariableSetup

      public List<IRInstr> returnVariableSetup()
      Instructions to set up the return variable: the declaration, then the initialisation. Empty list if no setup is needed.
    • hasReturnVariable

      public boolean hasReturnVariable()
      Check if this has a return variable.
    • isEmpty

      public boolean isEmpty()
      Check if this return details object is empty (no return variable).
    • toString

      @Nonnull public String toString()
      IR-optimized toString following EK9's bracket-only, no-indentation format. Returns empty string if no return variable to prevent rightward drift.
      Specified by:
      toString in class Record
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • returnVariable

      public String returnVariable()
      Returns the value of the returnVariable record component.
      Returns:
      the value of the returnVariable record component
    • returnVariableType

      public String returnVariableType()
      Returns the value of the returnVariableType record component.
      Returns:
      the value of the returnVariableType record component
    • returnVariableDeclaration

      public List<IRInstr> returnVariableDeclaration()
      Returns the value of the returnVariableDeclaration record component.
      Returns:
      the value of the returnVariableDeclaration record component
    • returnVariableInitialisation

      public List<IRInstr> returnVariableInitialisation()
      Returns the value of the returnVariableInitialisation record component.
      Returns:
      the value of the returnVariableInitialisation record component