Class LexicalScope
java.lang.Object
org.apache.commons.jexl3.internal.LexicalScope
- Direct Known Subclasses:
LexicalFrame
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
FieldsModifier and TypeFieldDescriptionprotected static final int
Number of bits in a long.protected static final int
Bits per symbol.protected int
Number of symbols.protected BitSet
Symbols after bit 64 (aka symbol 32 when 2 bits per symbol).protected static final long
Bitmask for symbols.protected static final int
From a symbol number to a starting symbol bit number.protected long
The mask of symbols in the scope. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreate a scope.protected
LexicalScope
(LexicalScope other) Frame copy ctor base. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addConstant
(int symbol) Adds a constant in this scope.boolean
addSymbol
(int symbol) Adds a symbol in this scope.final void
clearSymbols
(IntConsumer cleanSymbol) Clear all symbols.int
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 BitSet
moreBits()
Ensures more symbols can be stored.private boolean
set
(int bit) Sets a given bit (not symbol).
-
Field Details
-
BITS_PER_LONG
protected static final int BITS_PER_LONGNumber of bits in a long.- See Also:
-
BITS_PER_SYMBOL
protected static final int BITS_PER_SYMBOLBits per symbol. let (b + 0) + const (b + 1).- See Also:
-
SYMBOL_SHIFT
protected static final int SYMBOL_SHIFTFrom a symbol number to a starting symbol bit number.- See Also:
-
SYMBOL_MASK
protected static final long SYMBOL_MASKBitmask for symbols.- See Also:
-
count
protected int countNumber of symbols. -
symbols
protected long symbolsThe mask of symbols in the scope. -
moreSymbols
Symbols after bit 64 (aka symbol 32 when 2 bits per symbol).
-
-
Constructor Details
-
LexicalScope
public LexicalScope()Create a scope. -
LexicalScope
Frame copy ctor base.
-
-
Method Details
-
moreBits
Ensures more symbols can be stored.- Returns:
- the set of more symbols
-
isSet
private boolean isSet(int bit) Whether a given bit (not symbol) is set.- Parameters:
bit
- the bit- Returns:
- true if set
-
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
-
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
-
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
-
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
-
clearSymbols
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.
-