Class CycleGuardOwner
java.lang.Object
org.ek9lang.compiler.phase7.support.CycleGuardOwner
THE per-type owner constant of the property-cycle guard (Contract 13 in
EK9_BACKEND_IR_CONTRACTS.md) -
hold one and use it, 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 (HasPropertyCycle) 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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIfNeeded(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.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.booleanDoes this construct's type carry the owner constant? True exactly when its generated operators are guarded.load(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:
-
-
Constructor Details
-
CycleGuardOwner
public CycleGuardOwner()
-
-
Method Details
-
addIfNeeded
public 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
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 STATIC_FIELD_ASSIGN _cycleGuardOwner, module::Type, org.ek9.lang::String, tempVar [consume, init]
-
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
-