allVariablesWithVisibility method Null safety

List<Variable<T>> allVariablesWithVisibility(
  1. Visibility visibility
)

Retrieves every variable of the given visibility within this scope and its ancestors.

Variable names will not be repeated; this produces the effect of shadowed variables.

Use this to "export" symbols out of a library or class.

This list is unmodifiable.

Implementation

List<Variable<T>> allVariablesWithVisibility(Visibility visibility) {
  var distinct = <String>[];
  var out = <Variable<T>>[];

  void crawl(SymbolTable<T> table) {
    for (var v in table._variables) {
      if (!distinct.contains(v.name) && v.visibility == visibility) {
        distinct.add(v.name);
        out.add(v);
      }
    }

    if (table._parent != null) crawl(table._parent!);
  }

  crawl(this);
  return List<Variable<T>>.unmodifiable(out);
}