Class CycleGuardOwner
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe static field holding the owning type's fully qualified name. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddIfNeeded(IRConstruct construct, IScope scope, IRInstructionBuilder cInitBuilder, DebugInfo debugInfo, Ek9Types ek9Types) THE step every_c_initgenerator calls (there are two:AbstractDfnGeneratorandScenario3SourceIRGeneratorfor 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_initbeing built.static voiddeclare(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(IAggregateSymbol aggregate, String tempVar, DebugInfo debugInfo) Make the constant, once, in the type's_c_init.static booleanDoes this construct's type carry the owner constant? True exactly when its generated operators are guarded.static IRInstrload(String resultVar, IAggregateSymbol aggregate, DebugInfo debugInfo) Load the constant for a guarded operator - a borrowed reference, neither retained nor released.
-
Field Details
-
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_initgenerator calls (there are two:AbstractDfnGeneratorandScenario3SourceIRGeneratorfor 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_initbeing built. Missing it on one route is aNoSuchFieldErrorthe first time a guarded operator runs. -
isNeeded
Does this construct's type carry the owner constant? True exactly when its generated operators are guarded. -
declare
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
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
-