Class MustExecutePosition

java.lang.Object
org.ek9lang.compiler.support.MustExecutePosition
All Implemented Interfaces:
Predicate<org.antlr.v4.runtime.tree.ParseTree>

public final class MustExecutePosition extends Object implements Predicate<org.antlr.v4.runtime.tree.ParseTree>
THE answer to "does this code run every time its enclosing body runs?", read from its position in the parse tree. Use it wherever an analysis may only follow what ALWAYS executes; do not re-derive it. Written for FE77's construction-recursion check (E08263), where following a call that might not run would report legal, guarded recursion as an error.

The walk climbs from the node to the body it belongs to - a function, method, operator, service operation or dynamic function body, or a property initialiser - and every step must be a position that is always evaluated: a statement in a body, an initialiser, an argument, an operand, the first condition of an if, the subject of a switch, the condition and collection of a loop, a try body, a finally block, the source of a stream.

Everything conditional answers false: if/else bodies and later conditions, case and default bodies, loop bodies (a do body too, deliberately, for now), catch blocks, the right operand of and/or/xor and of every coalescing operator, the arms of a ternary, the right of :=?, a condition after a guard, stream stages and assertions.

🔑 It is a whitelist. Any position it does not recognise answers false, so a construct added to the grammar later can only make an analysis miss something, never report something that cannot happen. A code path that always throws before a call is not considered: the call still counts as executed.

  • Constructor Details

    • MustExecutePosition

      public MustExecutePosition()
  • Method Details

    • test

      public boolean test(org.antlr.v4.runtime.tree.ParseTree node)
      Specified by:
      test in interface Predicate<org.antlr.v4.runtime.tree.ParseTree>