Class ScopeVariableCollector

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

final class ScopeVariableCollector extends Object
Walks a callable's parse tree to collect the variable symbols accessible within it - the local variables declared in its (possibly nested) instruction blocks, and the property fields of its enclosing aggregate. The caller supplies a Predicate so each name-quality check can apply its own admission rule (e.g. a permissive 'is a variable' filter, or a restrictive one that also excludes returning parameters, property fields and loop variables).

This centralises the ~150-line grammar-shape navigation that was previously copy-pasted across the three name-quality checks (confusingly-similar, non-descriptive and operator-keyword names), where any grammar change had to be applied in triplicate.

  • Constructor Details

    • ScopeVariableCollector

      ScopeVariableCollector(SymbolsAndScopes symbolsAndScopes)
  • Method Details

    • collectLocalVariables

      List<ISymbol> collectLocalVariables(org.antlr.v4.runtime.tree.ParseTree node, Predicate<ISymbol> filter)
      Collect the local variable symbols declared inside the callable's instruction blocks (including those nested in if/while/for/try/switch), admitting only those for which the filter holds.
    • getAccessibleFields

      List<ISymbol> getAccessibleFields(IScope scope)
      The property fields of the nearest enclosing aggregate, or an empty list if there is none.