Record Class CallContext

java.lang.Object
java.lang.Record
org.ek9lang.compiler.phase7.calls.CallContext

public record CallContext(ISymbol targetType, String targetVariable, String methodName, List<ISymbol> argumentTypes, List<String> argumentVariables, String scopeId, ISymbol returnType, org.antlr.v4.runtime.ParserRuleContext parseContext, boolean explicitSuperReceiver) extends Record
Context information needed for resolving method calls and constructing CallDetails. Contains all the information needed to perform cost-based method resolution and parameter-by-parameter promotion checking.
  • Constructor Details

    • CallContext

      public CallContext(ISymbol targetType, String targetVariable, String methodName, List<ISymbol> argumentTypes, List<String> argumentVariables, String scopeId, ISymbol returnType, org.antlr.v4.runtime.ParserRuleContext parseContext)
      Every call site that is not an explicit super receiver - which is all of them but one.

      Kept so the shape fact can be added without touching call sites that cannot express it.

    • CallContext

      public CallContext(ISymbol targetType, String targetVariable, String methodName, List<ISymbol> argumentTypes, List<String> argumentVariables, String scopeId, ISymbol returnType, org.antlr.v4.runtime.ParserRuleContext parseContext, boolean explicitSuperReceiver)
      Creates an instance of a CallContext record class.
      Parameters:
      targetType - the value for the targetType record component
      targetVariable - the value for the targetVariable record component
      methodName - the value for the methodName record component
      argumentTypes - the value for the argumentTypes record component
      argumentVariables - the value for the argumentVariables record component
      scopeId - the value for the scopeId record component
      returnType - the value for the returnType record component
      parseContext - the value for the parseContext record component
      explicitSuperReceiver - the value for the explicitSuperReceiver record component
  • Method Details

    • forPrimaryReferenceOperation

      public static CallContext forPrimaryReferenceOperation(ISymbol leftType, ISymbol rightType, ISymbol returnType, String methodName, String leftVariable, String rightVariable, String scopeId, boolean isSuperReceiver)
      Create context for a method-based operator applied to an explicit this or super primary reference - super :=: source, super :~: source, and friends.

      The receiver is emitted as a temp (the IR reads _temp1 = LOAD super), so by the time CallDetails is built the super-ness is no longer visible in the receiver name. It has to travel with the context instead: super.m() names the PARENT's body specifically and MUST be a direct call. Deriving dispatch from the target's openness alone makes it virtual - a super class has to be as open to be extended at all - which on the LLVM back-end vtable-dispatches straight back into the override that issued the call, and recurses until the stack dies.

      Parameters:
      isSuperReceiver - true when the primary reference is super, false for this
    • forBinaryOperation

      public static CallContext forBinaryOperation(ISymbol leftType, ISymbol rightType, ISymbol returnType, String methodName, String leftVariable, String rightVariable, String scopeId)
      Create context for binary operation: left.method(right)
    • forBinaryOperationWithContext

      public static CallContext forBinaryOperationWithContext(ISymbol leftType, ISymbol rightType, ISymbol returnType, String methodName, String leftVariable, String rightVariable, String scopeId, org.antlr.v4.runtime.ParserRuleContext parseContext)
      Create context for binary operation with parseContext: left.method(right) Used when Phase 3 has already resolved the method (e.g., switch case comparisons)
    • forUnaryOperation

      public static CallContext forUnaryOperation(ISymbol targetType, String methodName, String targetVariable, ISymbol returnType, String scopeId)
      Create context for unary operation: target.method()
    • forUnaryOperation

      public static CallContext forUnaryOperation(ISymbol targetType, String methodName, String targetVariable, ISymbol returnType, String scopeId, boolean isSuperReceiver)
      Context for a unary operator applied to an explicit super primary reference - $super, #?super, $$super. Like forPrimaryReferenceOperation(ISymbol, ISymbol, ISymbol, String, String, String, String, boolean), the super-ness has to travel with the context (isSuperReceiver) rather than the receiver name: it names the PARENT's operator specifically and MUST be a non-virtual (direct) call, otherwise virtual dispatch re-enters the override on the receiver's runtime type and recurses forever.
    • forFunctionCall

      public static CallContext forFunctionCall(ISymbol targetType, List<ISymbol> argumentTypes, String methodName, String targetVariable, List<String> argumentVariables, String scopeId, EK9Parser.CallContext parseContext)
      Create context for function call: function(args...)
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      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.
    • targetType

      public ISymbol targetType()
      Returns the value of the targetType record component.
      Returns:
      the value of the targetType record component
    • targetVariable

      public String targetVariable()
      Returns the value of the targetVariable record component.
      Returns:
      the value of the targetVariable record component
    • methodName

      public String methodName()
      Returns the value of the methodName record component.
      Returns:
      the value of the methodName record component
    • argumentTypes

      public List<ISymbol> argumentTypes()
      Returns the value of the argumentTypes record component.
      Returns:
      the value of the argumentTypes record component
    • argumentVariables

      public List<String> argumentVariables()
      Returns the value of the argumentVariables record component.
      Returns:
      the value of the argumentVariables record component
    • scopeId

      public String scopeId()
      Returns the value of the scopeId record component.
      Returns:
      the value of the scopeId record component
    • returnType

      public ISymbol returnType()
      Returns the value of the returnType record component.
      Returns:
      the value of the returnType record component
    • parseContext

      public org.antlr.v4.runtime.ParserRuleContext parseContext()
      Returns the value of the parseContext record component.
      Returns:
      the value of the parseContext record component
    • explicitSuperReceiver

      public boolean explicitSuperReceiver()
      Returns the value of the explicitSuperReceiver record component.
      Returns:
      the value of the explicitSuperReceiver record component