Record Class ReferenceAssignment

java.lang.Object
java.lang.Record
org.ek9lang.compiler.support.ReferenceAssignment
Record Components:
target - the variable now holding the reference.
source - the expression whose object it refers to.

public record ReferenceAssignment(ISymbol target, EK9Parser.ExpressionContext source) extends Record
THE reading of a statement that makes a local variable (never a property) refer to the SAME object an expression evaluates to - a reference copy (an alias), never a value copy. Use this wherever a check must follow an object through a local name, rather than re-deriving which operators alias.

Two statement shapes alias:

  • A declaration by <-, :=, = or : (:~: merges into a new object and does not).
  • An assignment to a bare identifier by a pointer assignment, as OperationIsAssignment defines it (:=, =, :, :=?). The in-place operators (+=, :=:, :~:, ...) mutate the object the target already refers to and create no new reference.

Used by the constructor this-escape check (E08250, phase 3) and the shared-state mutation check (E08251, phase 5): both were defeated by other <- this / counter <- shared.total followed by use of the local.

  • Constructor Details

    • ReferenceAssignment

      public ReferenceAssignment(ISymbol target, EK9Parser.ExpressionContext source)
      Creates an instance of a ReferenceAssignment record class.
      Parameters:
      target - the value for the target record component
      source - the value for the source record component
  • Method Details

    • of

      The reference a variable declaration creates, if it creates one.
    • of

      The reference an assignment statement creates, if it creates one.
    • mutatesInPlace

      public static boolean mutatesInPlace(EK9Parser.AssignmentStatementContext ctx)
      True when the assignment statement mutates, in place, the object its target refers to (+=, :=:, :~:, ...), rather than re-pointing the target.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
    • target

      public ISymbol target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • source

      public EK9Parser.ExpressionContext source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component