Class LexicalScope
- java.lang.Object
-
- org.apache.commons.jexl3.internal.LexicalScope
-
- Direct Known Subclasses:
LexicalFrame
public class LexicalScope extends java.lang.Object
The set of symbols declared in a lexical scope.The symbol identifiers are determined by the functional scope.
We use 2 bits per symbol s; bit (s*2)+0 sets the actual symbol as lexical (let), bit (s*2)+1 as a const. There are actually only 2 used states: 1 and 3
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
BITS_PER_LONG
Number of bits in a long.protected static int
BITS_PER_SYMBOL
Bits per symbol.protected int
count
Number of symbols.protected java.util.BitSet
moreSymbols
Symbols after bit 64 (aka symbol 32 when 2 bits per symbol).protected static long
SYMBOL_MASK
Bitmask for symbols.protected static int
SYMBOL_SHIFT
From a symbol number to a starting symbol bit number.protected long
symbols
The mask of symbols in the scope.
-
Constructor Summary
Constructors Modifier Constructor Description LexicalScope()
Create a scope.protected
LexicalScope(LexicalScope other)
Frame copy ctor base.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addConstant(int symbol)
Adds a constant in this scope.boolean
addSymbol(int symbol)
Adds a symbol in this scope.void
clearSymbols(java.util.function.IntConsumer cleanSymbol)
Clear all symbols.int
getSymbolCount()
boolean
hasSymbol(int symbol)
Checks whether a symbol has already been declared.boolean
isConstant(int symbol)
Checks whether a symbol is declared as a constant.private boolean
isSet(int bit)
Whether a given bit (not symbol) is set.private java.util.BitSet
moreBits()
Ensures more symbols can be stored.private boolean
set(int bit)
Sets a given bit (not symbol).
-
-
-
Field Detail
-
BITS_PER_LONG
protected static final int BITS_PER_LONG
Number of bits in a long.- See Also:
- Constant Field Values
-
BITS_PER_SYMBOL
protected static final int BITS_PER_SYMBOL
Bits per symbol. let (b + 0) + const (b + 1).- See Also:
- Constant Field Values
-
SYMBOL_SHIFT
protected static final int SYMBOL_SHIFT
From a symbol number to a starting symbol bit number.- See Also:
- Constant Field Values
-
SYMBOL_MASK
protected static final long SYMBOL_MASK
Bitmask for symbols.- See Also:
- Constant Field Values
-
count
protected int count
Number of symbols.
-
symbols
protected long symbols
The mask of symbols in the scope.
-
moreSymbols
protected java.util.BitSet moreSymbols
Symbols after bit 64 (aka symbol 32 when 2 bits per symbol).
-
-
Constructor Detail
-
LexicalScope
public LexicalScope()
Create a scope.
-
LexicalScope
protected LexicalScope(LexicalScope other)
Frame copy ctor base.
-
-
Method Detail
-
addConstant
public boolean addConstant(int symbol)
Adds a constant in this scope.- Parameters:
symbol
- the symbol- Returns:
- true if registered, false if symbol was already registered
-
addSymbol
public boolean addSymbol(int symbol)
Adds a symbol in this scope.- Parameters:
symbol
- the symbol- Returns:
- true if registered, false if symbol was already registered
-
clearSymbols
public final void clearSymbols(java.util.function.IntConsumer cleanSymbol)
Clear all symbols.- Parameters:
cleanSymbol
- a (optional, may be null) functor to call for each cleaned symbol
-
getSymbolCount
public int getSymbolCount()
- Returns:
- the number of symbols defined in this scope.
-
hasSymbol
public boolean hasSymbol(int symbol)
Checks whether a symbol has already been declared.- Parameters:
symbol
- the symbol- Returns:
- true if declared, false otherwise
-
isConstant
public boolean isConstant(int symbol)
Checks whether a symbol is declared as a constant.- Parameters:
symbol
- the symbol- Returns:
- true if declared as constant, false otherwise
-
isSet
private boolean isSet(int bit)
Whether a given bit (not symbol) is set.- Parameters:
bit
- the bit- Returns:
- true if set
-
moreBits
private java.util.BitSet moreBits()
Ensures more symbols can be stored.- Returns:
- the set of more symbols
-
set
private boolean set(int bit)
Sets a given bit (not symbol).- Parameters:
bit
- the bit- Returns:
- true if it was actually set, false if it was set before
-
-