Class SafeAccessWithdrawal

java.lang.Object
org.ek9lang.compiler.phase5.SafeAccessWithdrawal

final class SafeAccessWithdrawal extends Object
THE withdrawal of safe-access proofs (E08030) as the walk passes code that may change a proven Optional / Result / Iterator (ProvenContainerChange decides what may): from that point on, in the current scope and every scope enclosing it, get() / ok() / error() / next() needs a new check. So if name? then forget(name) then name.get() is E08030 at the get(), and so is a second it.next() after one it.hasNext().

Branches of one if / switch are exclusive: a change in one branch is withheld from its siblings (never from the code after the statement) - the enclosing scopes take it when the statement ends (enterBranches(Collection) / exitBranches()). A loop is read AHEAD (enterLoop(ParseTree, Predicate)): a change anywhere in its body may come before an access on the next pass, so what the loop may change is withdrawn before it is entered.

The walk follows the order things RUN in, where that differs from the order they are written: what the target of an assignment does (this :=: from.get(), alias :=: Optional(name.get())) is done after its right-hand side (enterAssignment()), and a proof a construct makes from its own condition was made looking ahead over that condition (holdOwnProofs(IScope, ParseTree)), so walking the condition does not withdraw it.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SafeAccessWithdrawal(SymbolsAndScopes symbolsAndScopes, ProvenContainerChange provenContainerChange, ContainerChangedBetween containerChangedBetween)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    An assignment statement begins: what its target does is withdrawn when its right-hand side has run.
    (package private) void
    An if / switch begins; branchScopes are the scopes of its exclusive branches.
    (package private) void
    enterLoop(org.antlr.v4.runtime.tree.ParseTree loop, Predicate<ISymbol> reprovedOnEveryLaterPass)
    A loop is about to be entered: what its body (or its condition) may change is withdrawn now, before any of it is walked - a change late in the body comes before an access early in it on the next pass.
    (package private) void
    The assignment statement has run: what its target does is withdrawn now.
    (package private) void
    The if / switch has ended: what any branch withdrew holds after it.
    (package private) void
    exitRule(org.antlr.v4.runtime.tree.ParseTree node)
    A part of the tree has been walked: if it ends a held condition, the hold ends.
    (package private) void
    holdOwnProofs(IScope scope, org.antlr.v4.runtime.tree.ParseTree end)
    A construct has just made its proofs in its own scope from its condition, looking ahead over it to end (ConstructSafeAccessMarker.conditionEndOf): while that condition is walked, nothing is withdrawn from scope (the enclosing scopes still are).
    (package private) void
    occurrence(ISymbol occurrenceSymbol, List<ObjectSharing.Use> uses, boolean assignmentTarget)
    One occurrence of a variable, with what it does to the object (ProvenContainerChange.usesOf(EK9Parser.IdentifierContext, ISymbol)): withdraw every proof that may break.
    (package private) void
    A place where code of the program's own runs (ProgramCodeSites): withdraw what it may change - beyond the names a call is given (those are their own occurrences), and the names an in-place write or an iteration changes in place.
    (package private) void
    The right-hand side of the innermost open assignment statement begins.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • occurrence

      void occurrence(ISymbol occurrenceSymbol, List<ObjectSharing.Use> uses, boolean assignmentTarget)
      One occurrence of a variable, with what it does to the object (ProvenContainerChange.usesOf(EK9Parser.IdentifierContext, ISymbol)): withdraw every proof that may break. The occurrence that is the assignmentTarget itself (alias in alias :=: Optional(name.get())) acts once the right-hand side has run.
    • programCode

      void programCode(ProgramCodeSites.Site site)
      A place where code of the program's own runs (ProgramCodeSites): withdraw what it may change - beyond the names a call is given (those are their own occurrences), and the names an in-place write or an iteration changes in place. An in-place write in an assignment's target is the assignment's own operator, which runs once the right-hand side has.
    • enterAssignment

      void enterAssignment()
      An assignment statement begins: what its target does is withdrawn when its right-hand side has run.
    • rightHandSideBegins

      void rightHandSideBegins()
      The right-hand side of the innermost open assignment statement begins.
    • exitAssignment

      void exitAssignment()
      The assignment statement has run: what its target does is withdrawn now.
    • enterLoop

      void enterLoop(org.antlr.v4.runtime.tree.ParseTree loop, Predicate<ISymbol> reprovedOnEveryLaterPass)
      A loop is about to be entered: what its body (or its condition) may change is withdrawn now, before any of it is walked - a change late in the body comes before an access early in it on the next pass. Except what reprovedOnEveryLaterPass: the trailing condition of a do/while that proves it again.
    • holdOwnProofs

      void holdOwnProofs(IScope scope, org.antlr.v4.runtime.tree.ParseTree end)
      A construct has just made its proofs in its own scope from its condition, looking ahead over it to end (ConstructSafeAccessMarker.conditionEndOf): while that condition is walked, nothing is withdrawn from scope (the enclosing scopes still are).
    • exitRule

      void exitRule(org.antlr.v4.runtime.tree.ParseTree node)
      A part of the tree has been walked: if it ends a held condition, the hold ends.
    • enterBranches

      void enterBranches(Collection<IScope> branchScopes)
      An if / switch begins; branchScopes are the scopes of its exclusive branches.
    • exitBranches

      void exitBranches()
      The if / switch has ended: what any branch withdrew holds after it.