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.
  • the TARGET of a stream - cat items > total and >>, and the tee target (| tee in seen): every item is piped (|) into the object in place (operator >, >> or tee; D-1, 2026-10-19 - the value tracker and CompileTimeKnownText saw only assignments).

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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The operator text of a write by a tee stage.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Is operator a plain store (: := = :=?) rather than a mutation.
    static boolean
    Is operator (as SymbolWrites.Write.operator()) the target of a stream - >, >> or tee.
    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
  • Field Details

  • 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.
    • isAssignmentOperator

      public static boolean isAssignmentOperator(String operator)
      Is operator a plain store (: := = :=?) rather than a mutation.
    • 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())
    • isStreamTarget

      public static boolean isStreamTarget(String operator)
      Is operator (as SymbolWrites.Write.operator()) the target of a stream - >, >> or tee.