Class FunctionScope

java.lang.Object
me.topchetoeu.j2s.compilation.scope.FunctionScope

public final class FunctionScope extends Object
  • Field Details

    • locals

      protected final VariableList locals
    • capturables

      protected final VariableList capturables
    • parent

      public final FunctionScope parent
    • passthrough

      public final boolean passthrough
  • Constructor Details

    • FunctionScope

      public FunctionScope(FunctionScope parent)
    • FunctionScope

      public FunctionScope(boolean passthrough)
  • Method Details

    • define

      public Variable define(Variable var)
      Returns:
      If a variable with the same name exists, the old variable. Otherwise, the given variable
    • define

      public Variable define(String name)
      Returns:
      A variable with the given name, or null if a global variable
    • defineCatch

      public Variable defineCatch(String name)
      Creates a catch variable and returns it
    • defineCatch

      public Variable defineCatch(String name, Variable var)
      Creates a catch variable, using a specific variable instance Used in the second pass
    • undefineCatch

      public void undefineCatch()
      Removes the last catch variable. NOTE: the variable is still in the internal list. It just won't be findable by its name
    • get

      public Variable get(String name, boolean capture)
      Gets the index supplier of the given variable name, or null if it is a global
      Parameters:
      capture - If true, the variable is being captured by a function
    • get

      public Variable get(Variable var, boolean capture)
      If the variable given is contained in this function, just returns the variable itself. However, this function is important to handle cases in which you might want to access a captured variable. In such cases, this function will return a capture to the given variable.
      Parameters:
      capture - Whether or not to execute this capturing logic
    • has

      public boolean has(String name, boolean capture)
      Checks if the given variable name is accessible
      Parameters:
      capture - If true, will check beyond this function's scope
    • localsCount

      public int localsCount()
    • capturesCount

      public int capturesCount()
    • capturablesCount

      public int capturablesCount()
    • getCaptureIndices

      public int[] getCaptureIndices()
    • capturables

      public Iterable<Variable> capturables()
    • locals

      public Iterable<Variable> locals()
    • captureNames

      public String[] captureNames()
    • localNames

      public String[] localNames()
    • capturableNames

      public String[] capturableNames()