Class OperatorMap

java.lang.Object
org.ek9lang.compiler.common.OperatorMap

public class OperatorMap extends Object
Enhanced mapping of EK9 operators to their metadata and method names. Provides bidirectional mapping with comprehensive operator details including purity, argument requirements, return value information, and side effect classification.

Side effect types:
- RETURN_MUTATION: Operations that return non-Void values
- THIS_MUTATION: Operations that mutate the object itself (assignment/mutator operators)
- POSSIBLE_MUTATION: Non-pure operations that may have indirect effects or mutations
- NO_MUTATION: Implied when no mutation side effects are present (empty set)

  • Constructor Details

    • OperatorMap

      public OperatorMap()
  • Method Details

    • getOperatorDetails

      public OperatorDetails getOperatorDetails(String ek9Operator)
      Get operator details by EK9 operator symbol.
    • getOperatorDetailsByMethod

      public OperatorDetails getOperatorDetailsByMethod(String methodName)
      Get operator details by method name.
    • hasOperator

      public boolean hasOperator(String ek9Operator)
      Check if an EK9 operator exists.
    • hasMethod

      public boolean hasMethod(String methodName)
      Check if a method name maps to an operator.
    • getForward

      public String getForward(String ek9Operator)
      Get method name for EK9 operator (backward compatibility).
    • getForward

      public String getForward(String ek9Operator, int argumentCount)
      THE single source of truth for the arity-aware operator glyph -> method name mapping.

      "-" is the ONLY operator glyph overloaded by arity: the ARG-LESS unary - (negate) maps to _negate, while the ARG-BEARING binary - (subtract) maps to _sub. This mirrors the runtime (e.g. Integer._negate() vs Integer._sub(arg)) and the arity split enforced by ValidOperatorOrError.minusOperatorOrError: _negate is ALWAYS zero-arg, _sub ALWAYS takes an argument. Every DEFINITION-side name derivation (the IR OperationInstr stamp, both backends, trait vtable slot naming, constrained-type delegation) MUST use this — never the arity-blind getForward(String), which unconditionally yields _sub for "-" and so defines an arg-less operator - as _sub() while its call resolves to _negate() (native eager-link failure / JVM latent NoSuchMethodError).

      Parameters:
      ek9Operator - the EK9 operator glyph
      argumentCount - the number of parameters the operator method takes (excludes the receiver)
      Returns:
      the arity-correct runtime method name
    • resolvedMethodName

      public String resolvedMethodName(MethodSymbol methodSymbol)
      THE canonical resolver from an operator MethodSymbol to its backend method name, arity-aware (splits "-" into _negate/_sub by the symbol's own parameter count — see getForward(String, int)). Returns the plain name for non-operators or operators not in the map. Use this at every definition/layout site that derives a name from an operator symbol rather than an OperationInstr.
      Parameters:
      methodSymbol - the operator (or plain) method symbol
      Returns:
      the resolved runtime method name
    • getBackward

      public String getBackward(String methodName)
      Get EK9 operator for method name (backward compatibility).
    • checkForward

      public boolean checkForward(String ek9Operator)
      Check if EK9 operator exists (backward compatibility).
    • checkBackward

      public boolean checkBackward(String methodName)
      Check if method name maps to operator (backward compatibility).
    • expectsParameter

      public boolean expectsParameter(String ek9Operator)
      For operators that require a single parameter. Updated to use OperatorDetails metadata.
    • expectsZeroParameters

      public boolean expectsZeroParameters(String ek9Operator)
      Used on a class/record not expecting any parameters at all. Updated to use OperatorDetails metadata.
    • getSideEffects

      public Set<String> getSideEffects(String ek9Operator)
      Get the side effects for an EK9 operator. Centralizes all side effect determination logic based on operator characteristics.
    • getSideEffectsByMethod

      public Set<String> getSideEffectsByMethod(String methodName)
      Get the side effects for a method name (backward lookup). Convenience method for when you have the method name instead of the EK9 operator.
    • getForwardKeys

      public Iterable<String> getForwardKeys()
      Get all EK9 operator symbols (for testing).
    • getBackwardKeys

      public Iterable<String> getBackwardKeys()
      Get all method names (for testing).