1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
8 #include "dfa/DFAState.h"
11 class SingleWriteMultipleReadLock;
17 class ANTLR4CPP_PUBLIC DFA {
19 /// A set of all DFA states. Use a map so we can get old state back.
20 /// Set only allows you to see if it's there.
22 /// From which ATN state did we create this DFA?
23 atn::DecisionState *atnStartState;
24 std::unordered_set<DFAState *, DFAState::Hasher, DFAState::Comparer> states; // States are owned by this class.
28 DFA(atn::DecisionState *atnStartState);
29 DFA(atn::DecisionState *atnStartState, size_t decision);
30 DFA(const DFA &other) = delete;
35 * Gets whether this DFA is a precedence DFA. Precedence DFAs use a special
36 * start state {@link #s0} which is not stored in {@link #states}. The
37 * {@link DFAState#edges} array for this start state contains outgoing edges
38 * supplying individual start states corresponding to specific precedence
41 * @return {@code true} if this is a precedence DFA; otherwise,
43 * @see Parser#getPrecedence()
45 bool isPrecedenceDfa() const;
48 * Get the start state for a specific precedence value.
50 * @param precedence The current precedence.
51 * @return The start state corresponding to the specified precedence, or
52 * {@code null} if no start state exists for the specified precedence.
54 * @throws IllegalStateException if this is not a precedence DFA.
55 * @see #isPrecedenceDfa()
57 DFAState* getPrecedenceStartState(int precedence) const;
60 * Set the start state for a specific precedence value.
62 * @param precedence The current precedence.
63 * @param startState The start state corresponding to the specified
66 * @throws IllegalStateException if this is not a precedence DFA.
67 * @see #isPrecedenceDfa()
69 void setPrecedenceStartState(int precedence, DFAState *startState, antlrcpp::SingleWriteMultipleReadLock &lock);
71 /// Return a list of all states in this DFA, ordered by state number.
72 virtual std::vector<DFAState *> getStates() const;
75 * @deprecated Use {@link #toString(Vocabulary)} instead.
77 virtual std::string toString(const std::vector<std::string>& tokenNames);
78 std::string toString(const Vocabulary &vocabulary) const;
80 virtual std::string toLexerString();
84 * {@code true} if this DFA is for a precedence decision; otherwise,
85 * {@code false}. This is the backing field for {@link #isPrecedenceDfa}.