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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final shortprotected static final shortprotected static final shortprotected static final shortprotected static final shortprotected static final shortprotected static final shortprotected static final intNumber of flag bits occupied by this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBasicState(int id, short flags, T[] emptyTransitions) protectedBasicState(int id, T[] emptyTransitions) protectedBasicState(BasicState<S, T> original) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPredecessor(T predecessor) Add a predecessor-transition to this state's predecessor array.voidaddPredecessorUnchecked(T predecessor) Identical toaddPredecessor(AbstractTransition), but does not assert that the predecessor transition's target isthis.protected abstract T[]createTransitionsArray(int length) protected booleangetFlag(short flag) protected shortgetFlags()final intgetId()Unique ID of this state.protected intReturns the current value ofnPredecessorsset byincPredecessors(), which is not necessarily the final number of predecessors.T[]T[]getPredecessors(boolean forward) T[]T[]getSuccessors(boolean forward) booleanbooleanprotected abstract booleanhasTransitionToUnAnchoredFinalState(boolean forward) voidHelper for predecessor initialization.booleanAnchored final states are implicitly guarded by a$-PositionAssertion.booleanisAnchoredFinalState(boolean forward) booleanAnchored final states are implicitly guarded by a^-PositionAssertion.booleanisAnchoredInitialState(boolean forward) booleanisDead(boolean forward) Returnstrueiff this state is non-final and has no successors/predecessors (depending onforwardother than itself.booleanbooleanisFinalState(boolean forward) booleanbooleanisInitialState(boolean forward) booleanbooleanisUnAnchoredFinalState(boolean forward) booleanbooleanisUnAnchoredInitialState(boolean forward) voidvoidprotected voidsetFlag(short flag) protected voidsetFlag(short flag, boolean value) voidsetPredecessors(T[] predecessors) voidsetSuccessors(T[] successors) voidvoidvoidsetUnAnchoredInitialState(boolean value)
-
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_FLAGSNumber of flag bits occupied by this class. Child classes may add their own flags withbyte NEW_FLAG = 1 << N_FLAGS; byte NEW_FLAG2 = 1 << (N_FLAGS + 1)etc.- See Also:
-
-
Constructor Details
-
BasicState
- Parameters:
id- unique id.emptyTransitions- static final empty array of transitions. This will be shared for all empty transition arrays.
-
BasicState
-
BasicState
-
-
Method Details
-
getId
public final int getId()Description copied from interface:AbstractStateUnique ID of this state. Uniqueness holds only for the automaton the state belongs to.- Specified by:
getIdin interfaceAbstractState<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
-
setSuccessors
-
getPredecessors
-
setPredecessors
-
getSuccessors
-
getPredecessors
-
hasSuccessors
public boolean hasSuccessors() -
hasPredecessors
public boolean hasPredecessors() -
isDead
public boolean isDead(boolean forward) Returnstrueiff this state is non-final and has no successors/predecessors (depending onforwardother 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
Add a predecessor-transition to this state's predecessor array. The transition'ssourceis the predecessor state, andtargetisthis. Before calling this method, the automaton generator must make the total number of predecessors known viaincPredecessors(). -
addPredecessorUnchecked
Identical toaddPredecessor(AbstractTransition), but does not assert that the predecessor transition's target isthis. -
getNPredecessors
protected int getNPredecessors()Returns the current value ofnPredecessorsset byincPredecessors(), which is not necessarily the final number of predecessors. Use with caution. -
createTransitionsArray
-