/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ #pragma once #include "RuleContext.h" // GCC generates a warning when forward-declaring ATN if ATN has already been // declared due to the attributes added by ANTLR4CPP_PUBLIC. // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39159 // Add constant that can be checked so forward-declarations can be omitted. #define ANTLR4CPP_ATN_DECLARED namespace antlr4 { namespace atn { class LexerATNSimulator; class ParserATNSimulator; class ANTLR4CPP_PUBLIC ATN { public: static constexpr size_t INVALID_ALT_NUMBER = 0; /// Used for runtime deserialization of ATNs from strings. ATN(); ATN(ATNType grammarType, size_t maxTokenType); ATN(const ATN&) = delete; ATN(ATN&&) = delete; ~ATN(); ATN& operator=(const ATN&) = delete; ATN& operator=(ATN&&) = delete; std::vector states; /// Each subrule/rule is a decision point and we must track them so we /// can go back later and build DFA predictors for them. This includes /// all the rules, subrules, optional blocks, ()+, ()* etc... std::vector decisionToState; /// Maps from rule index to starting state number. std::vector ruleToStartState; /// Maps from rule index to stop state number. std::vector ruleToStopState; /// The type of the ATN. ATNType grammarType; /// The maximum value for any symbol recognized by a transition in the ATN. size_t maxTokenType; /// /// For lexer ATNs, this maps the rule index to the resulting token type. /// For parser ATNs, this maps the rule index to the generated bypass token /// type if the /// /// deserialization option was specified; otherwise, this is {@code null}. /// std::vector ruleToTokenType; /// For lexer ATNs, this is an array of {@link LexerAction} objects which may /// be referenced by action transitions in the ATN. std::vector> lexerActions; std::vector modeToStartState; /// /// Compute the set of valid tokens that can occur starting in state {@code s}. /// If {@code ctx} is null, the set of tokens will not include what can follow /// the rule surrounding {@code s}. In other words, the set will be /// restricted to tokens reachable staying within {@code s}'s rule. /// misc::IntervalSet nextTokens(ATNState *s, RuleContext *ctx) const; /// /// Compute the set of valid tokens that can occur starting in {@code s} and /// staying in same rule. is in set if we reach end of /// rule. /// misc::IntervalSet const& nextTokens(ATNState *s) const; void addState(ATNState *state); void removeState(ATNState *state); int defineDecisionState(DecisionState *s); DecisionState *getDecisionState(size_t decision) const; size_t getNumberOfDecisions() const; /// /// Computes the set of input symbols which could follow ATN state number /// {@code stateNumber} in the specified full {@code context}. This method /// considers the complete parser context, but does not evaluate semantic /// predicates (i.e. all predicates encountered during the calculation are /// assumed true). If a path in the ATN exists from the starting state to the /// of the outermost context without matching any /// symbols, is added to the returned set. ///

/// If {@code context} is {@code null}, it is treated as /// . ///

/// the ATN state number /// the full parse context /// The set of potentially valid input symbols which could follow the /// specified state in the specified context. /// if the ATN does not contain a state with /// number {@code stateNumber} misc::IntervalSet getExpectedTokens(size_t stateNumber, RuleContext *context) const; std::string toString() const; private: friend class LexerATNSimulator; friend class ParserATNSimulator; mutable std::mutex _mutex; mutable std::shared_mutex _stateMutex; mutable std::shared_mutex _edgeMutex; }; } // namespace atn } // namespace antlr4