Class ConstructSafeAccessMarker<C extends org.antlr.v4.runtime.ParserRuleContext>
java.lang.Object
org.ek9lang.compiler.phase5.ConstructSafeAccessMarker<C>
- Type Parameters:
C- the construct's parse context.
- All Implemented Interfaces:
Consumer<C>
final class ConstructSafeAccessMarker<C extends org.antlr.v4.runtime.ParserRuleContext>
extends Object
implements Consumer<C>
THE marker of what a construct's pre-flow and control expression prove safe for Optional / Result / Iterator
access (E08030) - one class for
if, switch, try, while, for and the ternary
(it was six near-identical subclasses). The construct is described by three accessors, built by the factories
below; each says where that construct keeps its pre-flow and its control expression, and in which scope a proof is
safe.
The pre-flow's subject is safe in the construct ONLY when the pre-flow is a guard that skips the construct when
the subject is unset (<-, :=? - PreFlowCanSkipBody). A plain := checks nothing:
if o := empty() then gate ran its body with an empty o and o.get() threw. Before marking, a
pre-flow that re-points a subject the scope AROUND the construct has already proven safe is E08040 - judged here,
because the construct's own marking would hide it. Each top-level and conjunct of the control that is an
is-set check proves its subject safe in the scope, whatever the other conjuncts are (SafeAccessConjuncts).
The pre-flow is processed first, then the control expression.
-
Method Summary
Modifier and TypeMethodDescriptionvoid(package private) static ConstructSafeAccessMarker<EK9Parser.ForStatementExpressionContext> forFor(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Aforloop or for range: its pre-flow, and the control expression of aforloop only.(package private) static ConstructSafeAccessMarker<EK9Parser.IfControlBlockContext> forIfBlock(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Anif/else ifblock: pre-flow and control, safe in the block.(package private) static ConstructSafeAccessMarker<EK9Parser.SwitchStatementExpressionContext> forSwitch(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Aswitch: only its pre-flow, safe in the whole switch.(package private) static ConstructSafeAccessMarker<EK9Parser.ExpressionContext> forTernary(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) A ternary: its control may make the first part safe.(package private) static ConstructSafeAccessMarker<EK9Parser.TryStatementExpressionContext> forTry(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Atry: only its pre-flow, safe in the whole try/catch/finally.(package private) static ConstructSafeAccessMarker<EK9Parser.WhileStatementExpressionContext> forWhile(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Awhileordo/while: its pre-flow, and its control only on awhile- the body of ado/whileruns BEFORE its trailing condition.
-
Method Details
-
accept
-
forIfBlock
static ConstructSafeAccessMarker<EK9Parser.IfControlBlockContext> forIfBlock(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Anif/else ifblock: pre-flow and control, safe in the block. -
forSwitch
static ConstructSafeAccessMarker<EK9Parser.SwitchStatementExpressionContext> forSwitch(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Aswitch: only its pre-flow, safe in the whole switch. -
forTry
static ConstructSafeAccessMarker<EK9Parser.TryStatementExpressionContext> forTry(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Atry: only its pre-flow, safe in the whole try/catch/finally. -
forWhile
static ConstructSafeAccessMarker<EK9Parser.WhileStatementExpressionContext> forWhile(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Awhileordo/while: its pre-flow, and its control only on awhile- the body of ado/whileruns BEFORE its trailing condition. The discriminator isDO(), neverWHILE(): BOTH grammar alternatives contain a WHILE token (WHILE control ...andDO ... WHILE control), so ANTLR emits ONE scalar WHILE() accessor on the merged context andctx.WHILE() != nullis a TAUTOLOGY. It never excluded the do/while it says it excludes, so the trailing condition marked the symbol safe over a scope that encloses the body that had already run:do o.get() while o?compiled clean and threw at runtime. Only the do/while alternative carries DO. -
forFor
static ConstructSafeAccessMarker<EK9Parser.ForStatementExpressionContext> forFor(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) Aforloop or for range: its pre-flow, and the control expression of aforloop only. -
forTernary
static ConstructSafeAccessMarker<EK9Parser.ExpressionContext> forTernary(SymbolsAndScopes symbolsAndScopes, ErrorListener errorListener) A ternary: its control may make the first part safe.
-