Class Scope
java.lang.Object
org.apache.commons.jexl3.internal.Scope
A script scope, stores the declaration of parameters and local variables as symbols.
This also acts as the functional scope and variable definition store.
- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe map of local captured variables to parent scope variables, ie closure.private static final String[]
The empty string array.private LexicalScope
Let symbols.The map of named variables aka script parameters and local variables.private final Scope
The parent scope.private int
The number of parameters.(package private) static final Object
The value of an as-yet undeclared but variable, for instance: x; before var x;.(package private) static final Object
The value of a declared but undefined variable, for instance: var x;.private int
The number of local variables. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addLexical
(int s) Marks a symbol as a lexical, declared through let or const.createFrame
(Frame frame, Object... args) Creates a frame by copying values up to the number of parameters.int
declareParameter
(String name) Declares a parameter.int
declareVariable
(String name) Declares a local variable.int
Gets the (maximum) number of arguments this script expects.getCaptured
(int symbol) Gets the captured index of a given symbol, ie the target index of a symbol in a child scope.int
getCaptureDeclaration
(int symbol) Gets the index of a captured symbol, ie the source index of a symbol in a parent scope.String[]
Gets this script captured symbols names, i.e.String[]
Gets this script local variable, i.e.String[]
Gets this script parameters, i.e.(package private) String[]
getParameters
(int bound) Gets this script parameters.Checks whether an identifier is a local variable or argument, ie a symbol.private Integer
Checks whether an identifier is a local variable or argument, ie a symbol.String[]
Gets this script symbols names, i.e.boolean
isCapturedSymbol
(int symbol) Checks whether a given symbol is captured.boolean
isLexical
(int s) Checks whether a symbol is declared through a let or const.
-
Field Details
-
UNDECLARED
The value of an as-yet undeclared but variable, for instance: x; before var x;. -
UNDEFINED
The value of a declared but undefined variable, for instance: var x;. -
parent
The parent scope. -
parms
private int parmsThe number of parameters. -
vars
private int varsThe number of local variables. -
namedVariables
The map of named variables aka script parameters and local variables. Each parameter is associated to a symbol and is materialized as an offset in the stacked array used during evaluation. -
capturedVariables
The map of local captured variables to parent scope variables, ie closure. -
lexicalVariables
Let symbols. -
EMPTY_STRS
The empty string array.
-
-
Constructor Details
-
Scope
Creates a new scope with a list of parameters.- Parameters:
scope
- the parent scope if anyparameters
- the list of parameters
-
-
Method Details
-
getSymbol
Checks whether an identifier is a local variable or argument, ie a symbol. If this fails, look in parents for symbol that can be captured.- Parameters:
name
- the symbol name- Returns:
- the symbol index
-
getSymbol
Checks whether an identifier is a local variable or argument, ie a symbol.- Parameters:
name
- the symbol namecapture
- whether solving by capturing a parent symbol is allowed- Returns:
- the symbol index
-
addLexical
public boolean addLexical(int s) Marks a symbol as a lexical, declared through let or const.- Parameters:
s
- the symbol- Returns:
- true if the symbol was not already present in the lexical set
-
isLexical
public boolean isLexical(int s) Checks whether a symbol is declared through a let or const.- Parameters:
s
- the symbol- Returns:
- true if symbol was declared through let or const
-
isCapturedSymbol
public boolean isCapturedSymbol(int symbol) Checks whether a given symbol is captured.- Parameters:
symbol
- the symbol number- Returns:
- true if captured, false otherwise
-
declareParameter
Declares a parameter.This method creates an new entry in the symbol map.
- Parameters:
name
- the parameter name- Returns:
- the register index storing this variable
-
declareVariable
Declares a local variable.This method creates an new entry in the symbol map.
- Parameters:
name
- the variable name- Returns:
- the register index storing this variable
-
createFrame
Creates a frame by copying values up to the number of parameters.This captures the captured variables values.
- Parameters:
frame
- the caller frameargs
- the arguments- Returns:
- the arguments array
-
getCaptured
Gets the captured index of a given symbol, ie the target index of a symbol in a child scope.- Parameters:
symbol
- the symbol index- Returns:
- the target symbol index or null if the symbol is not captured
-
getCaptureDeclaration
public int getCaptureDeclaration(int symbol) Gets the index of a captured symbol, ie the source index of a symbol in a parent scope.- Parameters:
symbol
- the symbol index- Returns:
- the source symbol index or -1 if the symbol is not captured
-
getCapturedVariables
Gets this script captured symbols names, i.e. local variables defined in outer scopes and used by this scope.- Returns:
- the captured names
-
getArgCount
public int getArgCount()Gets the (maximum) number of arguments this script expects.- Returns:
- the number of parameters
-
getSymbols
Gets this script symbols names, i.e. parameters and local variables.- Returns:
- the symbol names
-
getParameters
Gets this script parameters, i.e. symbols assigned before creating local variables.- Returns:
- the parameter names
-
getParameters
Gets this script parameters.- Parameters:
bound
- number of known bound parameters (curry)- Returns:
- the parameter names
-
getLocalVariables
Gets this script local variable, i.e. symbols assigned to local variables excluding captured variables.- Returns:
- the local variable names
-