Class CloseChain

java.lang.Object
org.ek9lang.compiler.phase7.generator.AbstractGenerator
org.ek9lang.compiler.phase7.generator.CloseChain

public final class CloseChain extends AbstractGenerator
THE generated close chain in IR - use it, never build a property close by hand (Steve, 2026-10-06: "if you hold it, you close it"; the C++/Swift destructor model). What is closed is CloseSteps's decision, read by the phase-5 call graph too; how it is closed is ResourceCloser's, the same shape B region try-with-resources and the statement-owned temporaries use (every close runs, the first EK9 Exception is kept, later ones are suppressed onto it, a Panic aborts the rest).
  • closeOperator(List, IAggregateSymbol, DebugInfo) - a type's operator close: the body (empty for default operator close) runs first with everything still open, then - as its finally - each closeable field it holds is closed if present, last acquired first, then the super class's close is called NON-virtually. Used by OperationDfnGenerator for a hand-written close and synthesis/CloseGenerator for the default one, for every construct kind and every parameterisation of a generic.
  • constructionFailure(List, IAggregateSymbol, DebugInfo) - a constructor that fails with an EK9 Exception after its object's own construction call (super(...)/this(...), or the implicit super) runs the same closes - the fields acquired so far, then the super part, which that call completed - and rethrows (D10, partial construction).

Nothing at all is emitted when CloseSteps.Steps.isEmpty(): a leaf resource's close and its constructors are exactly as written.

  • Constructor Details

  • Method Details

    • isEmpty

      public boolean isEmpty(IAggregateSymbol aggregate)
      True when a close of this type generates nothing.
    • closeOperator

      public List<IRInstr> closeOperator(List<IRInstr> body, IAggregateSymbol aggregate, DebugInfo debugInfo)
      The body of a type's close followed, on every path, by its generated chain.
      Parameters:
      body - the body's instructions (empty for default operator close)
      aggregate - the type whose close this is
      debugInfo - where the generated closes are attributed
    • constructionFailure

      public List<IRInstr> constructionFailure(List<IRInstr> body, IAggregateSymbol aggregate, DebugInfo debugInfo)
      A constructor's work after its construction call, with the chain run only if it fails.
      Parameters:
      body - the instructions after the construction call (_i_init and the constructor body)
      aggregate - the type being constructed
      debugInfo - where the generated closes are attributed
    • constructionFailureInOwnScope

      public List<IRInstr> constructionFailureInOwnScope(List<IRInstr> body, IAggregateSymbol aggregate, DebugInfo debugInfo)
      constructionFailure(List, IAggregateSymbol, DebugInfo) in a scope of its own (SCOPE_ENTER/SCOPE_EXIT around it), so what the region registers has an entered scope to be released by: a generated constructor has no body scope, and a written one's region sits after its body scope has been left (or, after an explicit super(...), inside it).