Class SymbolWrites

java.lang.Object
org.ek9lang.compiler.support.SymbolWrites

public final class SymbolWrites extends Object
THE "where is this symbol written?" for the compiler's own analyses and the mcp.oracle tools - use this, never a by-name test such as body.contains("this." + name) or a set of assigned NAMES.

It lives in compiler-main (moved down from compiler-services, 2026-10-04) so a phase-5 analysis - the infinite stream source check, phase5/NeverEndingIterationMarker - reads the SAME write set the refactoring editors do, rather than a second write-finder.

A write is any place the symbol's value can change:

  • an assignment to it - : := = :=? (a pre-flow if x := next() then x? included);
  • a MUTATING operator applied to it - += -= *= /= :~: :^: :=: ++ -- - decided by OperatorMap.isThisMutatingOperator(String), never a copied list. total += 5 performs NO store to total (Integer._addAss mutates the object in place), so a test that looks only for assignments misses most EK9 mutation.

Built on RecordedSymbols, so it is by symbol IDENTITY: a same-named local in another scope, a longer name sharing a prefix (countLimit vs count), a comment or a String is never a write. A write through a dynamic function's captured copy counts (the copy shares the object). A property written through any object counts (other.total += 1 writes the property total). A mutating METHOD call (items.add(x)) is not a write here: only the grammar's assignments and operators are.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    One write.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Does operator write the thing it is applied to - an assignment, or a mutating operator.
    static boolean
    isWrittenBetween(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, Set<ISymbol> symbols, int afterTokenIndex, int beforeTokenIndex)
    Is any of symbols written in region strictly between two token positions (token indexes in the compiled token stream: pass first.getStop().getTokenIndex() and second.getStart().getTokenIndex() to ask "does anything change these between the two occurrences?").
    static boolean
    isWrittenIn(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, Set<ISymbol> symbols)
    Is any of symbols written anywhere in region.
    writesOf(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, ISymbol symbol)
    Every write to symbol (or to a captured copy of it) in region, in source order.
    static String
    writingOperator(org.antlr.v4.runtime.ParserRuleContext node)
    The operator that writes the thing node names, or null when this occurrence only reads it.

    Methods inherited from class Object

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

    • writesOf

      public static List<SymbolWrites.Write> writesOf(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, ISymbol symbol)
      Every write to symbol (or to a captured copy of it) in region, in source order.
    • isWrittenIn

      public static boolean isWrittenIn(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, Set<ISymbol> symbols)
      Is any of symbols written anywhere in region.
    • isWrittenBetween

      public static boolean isWrittenBetween(ParsedModule parsedModule, org.antlr.v4.runtime.tree.ParseTree region, Set<ISymbol> symbols, int afterTokenIndex, int beforeTokenIndex)
      Is any of symbols written in region strictly between two token positions (token indexes in the compiled token stream: pass first.getStop().getTokenIndex() and second.getStart().getTokenIndex() to ask "does anything change these between the two occurrences?").
    • isWritingOperator

      public static boolean isWritingOperator(String operator)
      Does operator write the thing it is applied to - an assignment, or a mutating operator.
    • writingOperator

      public static String writingOperator(org.antlr.v4.runtime.ParserRuleContext node)
      The operator that writes the thing node names, or null when this occurrence only reads it. Purely structural (it needs no recorded symbol), so a caller holding an identifier occurrence - of the compiled tree or of a re-parsed body - asks HERE whether it is written rather than re-deriving the grammar's write positions.
      Parameters:
      node - the identifier node of the occurrence (as RecordedSymbols.Reference.node())