Class LexicalScope

java.lang.Object
org.apache.commons.jexl3.internal.LexicalScope
Direct Known Subclasses:
LexicalFrame

public class LexicalScope extends 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 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

    Constructors
    Modifier
    Constructor
    Description
     
    Create a scope.
    protected
    Frame copy ctor base.
  • Method Summary

    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.
    final void
    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
    Ensures more symbols can be stored.
    private boolean
    set(int bit)
    Sets a given bit (not symbol).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BITS_PER_LONG

      protected static final int BITS_PER_LONG
      Number of bits in a long.
      See Also:
    • BITS_PER_SYMBOL

      protected static final int BITS_PER_SYMBOL
      Bits per symbol. let (b + 0) + const (b + 1).
      See Also:
    • SYMBOL_SHIFT

      protected static final int SYMBOL_SHIFT
      From a symbol number to a starting symbol bit number.
      See Also:
    • SYMBOL_MASK

      protected static final long SYMBOL_MASK
      Bitmask for symbols.
      See Also:
    • count

      protected int count
      Number of symbols.
    • symbols

      protected long symbols
      The mask of symbols in the scope.
    • moreSymbols

      protected BitSet moreSymbols
      Symbols after bit 64 (aka symbol 32 when 2 bits per symbol).
  • Constructor Details

    • LexicalScope

      public LexicalScope()
      Create a scope.
    • LexicalScope

      protected LexicalScope(LexicalScope other)
      Frame copy ctor base.
  • Method Details

    • moreBits

      private BitSet 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

      public final void clearSymbols(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.