xref: /aosp_15_r20/external/antlr/runtime/Cpp/include/antlr3cyclicdfa.hpp (revision 16467b971bd3e2009fad32dd79016f2c7e421deb)
1*16467b97STreehugger Robot /// Definition of a cyclic dfa structure such that it can be
2*16467b97STreehugger Robot /// initialized at compile time and have only a single
3*16467b97STreehugger Robot /// runtime function that can deal with all cyclic dfa
4*16467b97STreehugger Robot /// structures and show Java how it is done ;-)
5*16467b97STreehugger Robot ///
6*16467b97STreehugger Robot #ifndef	ANTLR3_CYCLICDFA_HPP
7*16467b97STreehugger Robot #define	ANTLR3_CYCLICDFA_HPP
8*16467b97STreehugger Robot 
9*16467b97STreehugger Robot // [The "BSD licence"]
10*16467b97STreehugger Robot // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
11*16467b97STreehugger Robot 
12*16467b97STreehugger Robot //
13*16467b97STreehugger Robot // All rights reserved.
14*16467b97STreehugger Robot //
15*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without
16*16467b97STreehugger Robot // modification, are permitted provided that the following conditions
17*16467b97STreehugger Robot // are met:
18*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright
19*16467b97STreehugger Robot //    notice, this list of conditions and the following disclaimer.
20*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright
21*16467b97STreehugger Robot //    notice, this list of conditions and the following disclaimer in the
22*16467b97STreehugger Robot //    documentation and/or other materials provided with the distribution.
23*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products
24*16467b97STreehugger Robot //    derived from this software without specific prior written permission.
25*16467b97STreehugger Robot //
26*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36*16467b97STreehugger Robot 
37*16467b97STreehugger Robot #include   "antlr3defs.hpp"
38*16467b97STreehugger Robot 
39*16467b97STreehugger Robot #ifdef ANTLR3_WINDOWS
40*16467b97STreehugger Robot #pragma warning	(push)
41*16467b97STreehugger Robot #pragma warning (disable : 4510)
42*16467b97STreehugger Robot #pragma warning (disable : 4512)
43*16467b97STreehugger Robot #pragma warning (disable : 4610)
44*16467b97STreehugger Robot #endif
45*16467b97STreehugger Robot 
46*16467b97STreehugger Robot ANTLR_BEGIN_NAMESPACE()
47*16467b97STreehugger Robot 
48*16467b97STreehugger Robot template<class ImplTraits, class CtxType>
49*16467b97STreehugger Robot class CyclicDFA : public ImplTraits::AllocPolicyType
50*16467b97STreehugger Robot {
51*16467b97STreehugger Robot public:
52*16467b97STreehugger Robot 	typedef typename CtxType::StreamType StreamType;
53*16467b97STreehugger Robot 	typedef typename CtxType::ExceptionBaseType ExceptionBaseType;
54*16467b97STreehugger Robot 	typedef typename ImplTraits::template RecognizerType<StreamType> RecognizerType;
55*16467b97STreehugger Robot 	typedef typename StreamType::IntStreamType IntStreamType;
56*16467b97STreehugger Robot 	typedef typename StreamType::TokenType	TokenType;
57*16467b97STreehugger Robot 	typedef TokenType	CommonTokenType;
58*16467b97STreehugger Robot 	typedef CtxType ContextType;
59*16467b97STreehugger Robot 
60*16467b97STreehugger Robot private:
61*16467b97STreehugger Robot     /// Decision number that a particular static structure
62*16467b97STreehugger Robot     ///  represents.
63*16467b97STreehugger Robot     ///
64*16467b97STreehugger Robot     const ANTLR_INT32		m_decisionNumber;
65*16467b97STreehugger Robot 
66*16467b97STreehugger Robot     /// What this decision represents
67*16467b97STreehugger Robot     ///
68*16467b97STreehugger Robot     const ANTLR_UCHAR*			m_description;
69*16467b97STreehugger Robot 	const ANTLR_INT32* const	m_eot;
70*16467b97STreehugger Robot     const ANTLR_INT32* const	m_eof;
71*16467b97STreehugger Robot     const ANTLR_INT32* const	m_min;
72*16467b97STreehugger Robot     const ANTLR_INT32* const	m_max;
73*16467b97STreehugger Robot     const ANTLR_INT32* const	m_accept;
74*16467b97STreehugger Robot     const ANTLR_INT32* const	m_special;
75*16467b97STreehugger Robot     const ANTLR_INT32* const *const	m_transition;
76*16467b97STreehugger Robot 
77*16467b97STreehugger Robot public:
78*16467b97STreehugger Robot 	CyclicDFA( ANTLR_INT32	decisionNumber
79*16467b97STreehugger Robot 				, const ANTLR_UCHAR*	description
80*16467b97STreehugger Robot 				, const ANTLR_INT32* const	eot
81*16467b97STreehugger Robot 				, const ANTLR_INT32* const	eof
82*16467b97STreehugger Robot 				, const ANTLR_INT32* const	min
83*16467b97STreehugger Robot 				, const ANTLR_INT32* const	max
84*16467b97STreehugger Robot 				, const ANTLR_INT32* const	accept
85*16467b97STreehugger Robot 				, const ANTLR_INT32* const	special
86*16467b97STreehugger Robot 				, const ANTLR_INT32* const *const	transition );
87*16467b97STreehugger Robot 	CyclicDFA( const CyclicDFA& cdfa );
88*16467b97STreehugger Robot     CyclicDFA& operator=( const CyclicDFA& dfa);
89*16467b97STreehugger Robot 
90*16467b97STreehugger Robot 	ANTLR_INT32	specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
91*16467b97STreehugger Robot     ANTLR_INT32	specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
92*16467b97STreehugger Robot 
93*16467b97STreehugger Robot 	template<typename SuperType>
94*16467b97STreehugger Robot     ANTLR_INT32	predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super);
95*16467b97STreehugger Robot 
96*16467b97STreehugger Robot private:
97*16467b97STreehugger Robot 	void noViableAlt(RecognizerType* rec, ANTLR_UINT32	s);
98*16467b97STreehugger Robot };
99*16467b97STreehugger Robot 
100*16467b97STreehugger Robot ANTLR_END_NAMESPACE()
101*16467b97STreehugger Robot 
102*16467b97STreehugger Robot #ifdef ANTLR3_WINDOWS
103*16467b97STreehugger Robot #pragma warning	(pop)
104*16467b97STreehugger Robot #endif
105*16467b97STreehugger Robot 
106*16467b97STreehugger Robot #include "antlr3cyclicdfa.inl"
107*16467b97STreehugger Robot 
108*16467b97STreehugger Robot #endif
109