Class BasicState<S extends BasicState<S,T>,T extends AbstractTransition<S,T>>

java.lang.Object
com.oracle.truffle.regex.tregex.automaton.BasicState<S,T>
All Implemented Interfaces:
AbstractState<S,T>
Direct Known Subclasses:
DFAStateNodeBuilder, NFAState, PureNFAState

public abstract class BasicState<S extends BasicState<S,T>,T extends AbstractTransition<S,T>> extends Object implements AbstractState<S,T>
Abstract base class for states of an automaton.
  • Field Details

    • FLAG_ANCHORED_INITIAL_STATE

      protected static final short FLAG_ANCHORED_INITIAL_STATE
      See Also:
    • FLAG_UN_ANCHORED_INITIAL_STATE

      protected static final short FLAG_UN_ANCHORED_INITIAL_STATE
      See Also:
    • FLAG_ANCHORED_FINAL_STATE

      protected static final short FLAG_ANCHORED_FINAL_STATE
      See Also:
    • FLAG_UN_ANCHORED_FINAL_STATE

      protected static final short FLAG_UN_ANCHORED_FINAL_STATE
      See Also:
    • FLAG_ANY_INITIAL_STATE

      protected static final short FLAG_ANY_INITIAL_STATE
      See Also:
    • FLAG_ANY_FINAL_STATE

      protected static final short FLAG_ANY_FINAL_STATE
      See Also:
    • FLAG_ANY_INITIAL_OR_FINAL_STATE

      protected static final short FLAG_ANY_INITIAL_OR_FINAL_STATE
      See Also:
    • N_FLAGS

      protected static final int N_FLAGS
      Number of flag bits occupied by this class. Child classes may add their own flags with byte NEW_FLAG = 1 << N_FLAGS; byte NEW_FLAG2 = 1 << (N_FLAGS + 1) etc.
      See Also:
  • Constructor Details

    • BasicState

      protected BasicState(int id, T[] emptyTransitions)
      Parameters:
      id - unique id.
      emptyTransitions - static final empty array of transitions. This will be shared for all empty transition arrays.
    • BasicState

      protected BasicState(int id, short flags, T[] emptyTransitions)
    • BasicState

      protected BasicState(BasicState<S,T> original)
  • Method Details

    • getId

      public final int getId()
      Description copied from interface: AbstractState
      Unique ID of this state. Uniqueness holds only for the automaton the state belongs to.
      Specified by:
      getId in interface AbstractState<S extends BasicState<S,T>,T extends AbstractTransition<S,T>>
    • getFlags

      protected short getFlags()
    • getFlag

      protected boolean getFlag(short flag)
    • setFlag

      protected void setFlag(short flag)
    • setFlag

      protected void setFlag(short flag, boolean value)
    • isInitialState

      public boolean isInitialState()
    • isAnchoredInitialState

      public boolean isAnchoredInitialState()
      Anchored final states are implicitly guarded by a ^-PositionAssertion.
    • setAnchoredInitialState

      public void setAnchoredInitialState()
    • isUnAnchoredInitialState

      public boolean isUnAnchoredInitialState()
    • setUnAnchoredInitialState

      public void setUnAnchoredInitialState()
    • setUnAnchoredInitialState

      public void setUnAnchoredInitialState(boolean value)
    • isFinalState

      public boolean isFinalState()
    • isAnchoredFinalState

      public boolean isAnchoredFinalState()
      Anchored final states are implicitly guarded by a $-PositionAssertion.
    • setAnchoredFinalState

      public void setAnchoredFinalState()
    • isUnAnchoredFinalState

      public boolean isUnAnchoredFinalState()
    • setUnAnchoredFinalState

      public void setUnAnchoredFinalState()
    • isAnchoredInitialState

      public boolean isAnchoredInitialState(boolean forward)
    • isUnAnchoredInitialState

      public boolean isUnAnchoredInitialState(boolean forward)
    • isInitialState

      public boolean isInitialState(boolean forward)
    • isFinalState

      public boolean isFinalState(boolean forward)
    • isAnchoredFinalState

      public boolean isAnchoredFinalState(boolean forward)
    • isUnAnchoredFinalState

      public boolean isUnAnchoredFinalState(boolean forward)
    • hasTransitionToUnAnchoredFinalState

      protected abstract boolean hasTransitionToUnAnchoredFinalState(boolean forward)
    • getSuccessors

      public T[] getSuccessors()
    • setSuccessors

      public void setSuccessors(T[] successors)
    • getPredecessors

      public T[] getPredecessors()
    • setPredecessors

      public void setPredecessors(T[] predecessors)
    • getSuccessors

      public T[] getSuccessors(boolean forward)
    • getPredecessors

      public T[] getPredecessors(boolean forward)
    • hasSuccessors

      public boolean hasSuccessors()
    • hasPredecessors

      public boolean hasPredecessors()
    • isDead

      public boolean isDead(boolean forward)
      Returns true iff this state is non-final and has no successors/predecessors (depending on forward other than itself.
    • incPredecessors

      public void incPredecessors()
      Helper for predecessor initialization. Since the number of predecessors of a given state is unknown during automaton construction, we cannot allocate a suitable array for them immediately. Instead, we capture the number of predecessors with this method, and initialize the array after automaton construction.
    • addPredecessor

      public void addPredecessor(T predecessor)
      Add a predecessor-transition to this state's predecessor array. The transition's source is the predecessor state, and target is this. Before calling this method, the automaton generator must make the total number of predecessors known via incPredecessors().
    • addPredecessorUnchecked

      public void addPredecessorUnchecked(T predecessor)
      Identical to addPredecessor(AbstractTransition), but does not assert that the predecessor transition's target is this.
    • getNPredecessors

      protected int getNPredecessors()
      Returns the current value of nPredecessors set by incPredecessors(), which is not necessarily the final number of predecessors. Use with caution.
    • createTransitionsArray

      protected abstract T[] createTransitionsArray(int length)