Class CycleGuardOwner

java.lang.Object
org.ek9lang.compiler.phase7.support.CycleGuardOwner

public final class CycleGuardOwner extends Object
THE per-type owner constant of the property-cycle guard (Contract 13 in EK9_BACKEND_IR_CONTRACTS.md) - use this, never a String literal built per call.

The guard keys a frame by the object's identity plus the type whose operator runs. That type name is made ONCE, when the type is initialised, into a static field of the type, through the same mechanism an enumeration's constants use: a static Field, a STORE_STATIC_FIELD in _c_init, and a LOAD_STATIC_FIELD wherever a guarded operator needs it. Before this, every enter and every exit built the name again from a literal.

Only a type phase 5 found can reach itself through its properties (PropertyCycles.isCyclic(IAggregateSymbol)) gets the constant - the same test that decides whether its generated operators are guarded, so the two cannot disagree. Its name starts with an underscore, which no EK9 identifier can, so it can never collide with a property.

  • Field Details

    • FIELD_NAME

      public static final String FIELD_NAME
      The static field holding the owning type's fully qualified name.
      See Also:
  • Method Details

    • addIfNeeded

      public static void addIfNeeded(IRConstruct construct, IScope scope, IRInstructionBuilder cInitBuilder, DebugInfo debugInfo, Ek9Types ek9Types)
      THE step every _c_init generator calls (there are two: AbstractDfnGenerator and Scenario3SourceIRGenerator for a developer's parameterised generic): when the type's generated operators are guarded, declare the constant on the construct and make it in the _c_init being built. Missing it on one route is a NoSuchFieldError the first time a guarded operator runs.
    • isNeeded

      public static boolean isNeeded(IScope scope)
      Does this construct's type carry the owner constant? True exactly when its generated operators are guarded.
    • declare

      public static void declare(IRConstruct construct, DebugInfo debugInfo, Ek9Types ek9Types)
      Declare the static field on the construct (not traced: it holds a constant that lives as long as the type).
    • initialise

      public static List<IRInstr> initialise(IAggregateSymbol aggregate, String tempVar, DebugInfo debugInfo)
      Make the constant, once, in the type's _c_init. The literal's +1 is handed to the static field, which keeps it for the life of the type, so it is not registered for release.
        tempVar = LOAD_LITERAL module::Type, org.ek9.lang::String
        STORE_STATIC_FIELD _cycleGuardOwner, module::Type, org.ek9.lang::String, tempVar
      
    • load

      public static IRInstr load(String resultVar, IAggregateSymbol aggregate, DebugInfo debugInfo)
      Load the constant for a guarded operator - a borrowed reference, neither retained nor released.
        resultVar = LOAD_STATIC_FIELD _cycleGuardOwner, module::Type, org.ek9.lang::String