Class MostSpecificScope

java.lang.Object
org.ek9lang.compiler.support.MostSpecificScope
All Implemented Interfaces:
Supplier<IScope>

public final class MostSpecificScope extends Object implements Supplier<IScope>
THE "whose code is running here?" - used when trying to locate the current class, dynamic class or dynamic function, to be able to check if access to fields or methods should be allowed, or even resolve methods without 'this' prefix. The nearest DYNAMIC block first (a dynamic class or function is what this means inside it), then the nearest non-block scope (a class, function, ...). Four places walked the enclosing construct by hand, two ways, and they differed on what to do when there is none and on skipping a construct (front-end rationalisation B-13); they ask here:
  • get() - along the enclosing SCOPES of the current scope, falling back to the current scope itself;
  • getIfAny() - the same without the fallback: empty when no construct encloses (what this/super need - they say nothing at all outside one);
  • beyond(IScope) - down the scope STACK, optionally only the scopes OUTSIDE a given construct (null: the whole stack): the scope whose code runs around a dynamic construct's capture list or outside it.
  • Constructor Details

    • MostSpecificScope

      public MostSpecificScope(SymbolsAndScopes symbolsAndScopes)
  • Method Details

    • get

      public IScope get()
      Specified by:
      get in interface Supplier<IScope>
    • getIfAny

      public Optional<ScopedSymbol> getIfAny()
      The nearest dynamic block, else the nearest non-block scope, of the current scope's enclosing scopes - empty when the code is in neither.
    • beyond

      public Optional<IScope> beyond(IScope beyond)
      The scope whose code runs, from the scope STACK, considering only the scopes outside beyond (null: the whole stack): the nearest dynamic block, else the nearest non-block scope.