Home | History | Annotate | Download | only in include
      1 /** \file
      2  * Basic type and constant definitions for ANTLR3 Runtime.
      3  */
      4 #ifndef	_ANTLR3DEFS_HPP
      5 #define	_ANTLR3DEFS_HPP
      6 
      7 // [The "BSD licence"]
      8 // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
      9 
     10 //
     11 // All rights reserved.
     12 //
     13 // Redistribution and use in source and binary forms, with or without
     14 // modification, are permitted provided that the following conditions
     15 // are met:
     16 // 1. Redistributions of source code must retain the above copyright
     17 //    notice, this list of conditions and the following disclaimer.
     18 // 2. Redistributions in binary form must reproduce the above copyright
     19 //    notice, this list of conditions and the following disclaimer in the
     20 //    documentation and/or other materials provided with the distribution.
     21 // 3. The name of the author may not be used to endorse or promote products
     22 //    derived from this software without specific prior written permission.
     23 //
     24 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34 
     35 /* Following are for generated code, they are not referenced internally!!!
     36  */
     37 #if !defined(ANTLR_HUGE) && !defined(ANTLR_AVERAGE) && !defined(ANTLR_SMALL)
     38 #define	ANTLR_AVERAGE
     39 #endif
     40 
     41 #ifdef	ANTLR_HUGE
     42 #ifndef	ANTLR_SIZE_HINT
     43 #define	ANTLR_SIZE_HINT        2049
     44 #endif
     45 #ifndef	ANTLR_LIST_SIZE_HINT
     46 #define	ANTLR_LIST_SIZE_HINT   127
     47 #endif
     48 #endif
     49 
     50 #ifdef	ANTLR_AVERAGE
     51 #ifndef	ANTLR_SIZE_HINT
     52 #define	ANTLR_SIZE_HINT        1025
     53 #define	ANTLR_LIST_SIZE_HINT   63
     54 #endif
     55 #endif
     56 
     57 #ifdef	ANTLR_SMALL
     58 #ifndef	ANTLR_SIZE_HINT
     59 #define	ANTLR_SIZE_HINT        211
     60 #define	ANTLR_LIST_SIZE_HINT   31
     61 #endif
     62 #endif
     63 
     64 // Definitions that indicate the encoding scheme character streams and strings etc
     65 //
     66 /// Indicates Big Endian for encodings where this makes sense
     67 ///
     68 #define ANTLR_BE           1
     69 
     70 /// Indicates Little Endian for encoidngs where this makes sense
     71 ///
     72 #define ANTLR_LE           2
     73 
     74 /// General latin-1 or other 8 bit encoding scheme such as straight ASCII
     75 ///
     76 #define ANTLR_ENC_8BIT     4
     77 
     78 /// UTF-8 encoding scheme
     79 ///
     80 #define ANTLR_ENC_UTF8     8
     81 
     82 /// UTF-16 encoding scheme (which also covers UCS2 as that does not have surrogates)
     83 ///
     84 #define ANTLR_ENC_UTF16        16
     85 #define ANTLR_ENC_UTF16BE      16 + ANTLR_BE
     86 #define ANTLR_ENC_UTF16LE      16 + ANTLR_LE
     87 
     88 /// UTF-32 encoding scheme (basically straight 32 bit)
     89 ///
     90 #define ANTLR_ENC_UTF32        32
     91 #define ANTLR_ENC_UTF32BE      32 + ANTLR_BE
     92 #define ANTLR_ENC_UTF32LE      32 + ANTLR_LE
     93 
     94 /// Input is 8 bit EBCDIC (which we convert to 8 bit ASCII on the fly
     95 ///
     96 #define ANTLR_ENC_EBCDIC       64
     97 
     98 #define ANTLR_BEGIN_NAMESPACE() namespace antlr3 {
     99 #define ANTLR_END_NAMESPACE() }
    100 
    101 #define ANTLR_USE_64BIT
    102 
    103 /* Common definitions come first
    104  */
    105 #include    <antlr3errors.hpp>
    106 
    107 /* Work out what operating system/compiler this is. We just do this once
    108  * here and use an internal symbol after this.
    109  */
    110 #ifdef	_WIN64
    111 
    112 # ifndef	ANTLR_WINDOWS
    113 #   define	ANTLR_WINDOWS
    114 # endif
    115 # define	ANTLR_WIN64
    116 # define	ANTLR_USE_64BIT
    117 
    118 #else
    119 
    120 #ifdef	_WIN32
    121 # ifndef	ANTLR_WINDOWS
    122 #  define	ANTLR_WINDOWS
    123 # endif
    124 
    125 #define	ANTLR_WIN32
    126 #endif
    127 
    128 #endif
    129 
    130 #ifdef	ANTLR_WINDOWS
    131 
    132 #ifndef WIN32_LEAN_AND_MEAN
    133 #define	WIN32_LEAN_AND_MEAN
    134 #endif
    135 
    136 /* Allow VC 8 (vs2005) and above to use 'secure' versions of various functions such as sprintf
    137  */
    138 #ifndef	_CRT_SECURE_NO_DEPRECATE
    139 #define	_CRT_SECURE_NO_DEPRECATE
    140 #endif
    141 
    142 #include    <stdlib.h>
    143 #include    <winsock2.h>
    144 #include    <sys/types.h>
    145 #include    <sys/stat.h>
    146 #include    <stdarg.h>
    147 
    148 #define	ANTLR_API      __declspec(dllexport)
    149 #define	ANTLR_CDECL    __cdecl
    150 #define ANTLR_FASTCALL __fastcall
    151 
    152 
    153 #ifndef __MINGW32__
    154 // Standard Windows types
    155 //
    156 typedef	INT32	ANTLR_CHAR;
    157 typedef	UINT32	ANTLR_UCHAR;
    158 
    159 typedef	INT8	ANTLR_INT8;
    160 typedef	INT16	ANTLR_INT16;
    161 typedef	INT32	ANTLR_INT32;
    162 typedef	INT64	ANTLR_INT64;
    163 typedef	UINT8	ANTLR_UINT8;
    164 typedef	UINT16	ANTLR_UINT16;
    165 typedef	UINT32	ANTLR_UINT32;
    166 typedef	UINT64	ANTLR_UINT64;
    167 typedef UINT64  ANTLR_BITWORD;
    168 
    169 #else
    170 // Mingw uses stdint.h and fails to define standard Microsoft typedefs
    171 // such as UINT16, hence we must use stdint.h for Mingw.
    172 //
    173 #include <stdint.h>
    174 typedef int32_t     ANTLR_CHAR;
    175 typedef uint32_t    ANTLR_UCHAR;
    176 
    177 typedef int8_t	    ANTLR_INT8;
    178 typedef int16_t	    ANTLR_INT16;
    179 typedef int32_t	    ANTLR_INT32;
    180 typedef int64_t	    ANTLR_INT64;
    181 
    182 typedef uint8_t	    ANTLR_UINT8;
    183 typedef uint16_t    ANTLR_UINT16;
    184 typedef uint32_t    ANTLR_UINT32;
    185 typedef uint64_t    ANTLR_UINT64;
    186 typedef uint64_t    ANTLR_BITWORD;
    187 
    188 #endif
    189 
    190 
    191 
    192 #define	ANTLR_UINT64_LIT(lit)  lit##ULL
    193 
    194 #define	ANTLR_INLINE	        __inline
    195 
    196 typedef FILE *	    ANTLR_FDSC;
    197 typedef	struct stat ANTLR_FSTAT_STRUCT;
    198 
    199 
    200 
    201 #ifdef	ANTLR_USE_64BIT
    202 #define ANTLR_UINT64_CAST(ptr) ((ANTLR_UINT64)(ptr))
    203 #define	ANTLR_UINT32_CAST(ptr)	(ANTLR_UINT32)((ANTLR_UINT64)(ptr))
    204 typedef ANTLR_INT64		ANTLR_MARKER;
    205 typedef ANTLR_UINT64		ANTLR_INTKEY;
    206 #else
    207 #define ANTLR_UINT64_CAST(ptr) (ANTLR_UINT64)((ANTLR_UINT32)(ptr))
    208 #define	ANTLR_UINT32_CAST(ptr)	(ANTLR_UINT32)(ptr)
    209 typedef	ANTLR_INT32		ANTLR_MARKER;
    210 typedef ANTLR_UINT32	ANTLR_INTKEY;
    211 #endif
    212 
    213 #ifdef	ANTLR_WIN32
    214 #endif
    215 
    216 #ifdef	ANTLR_WIN64
    217 #endif
    218 
    219 
    220 typedef	int			ANTLR_SALENT;								// Type used for size of accept structure
    221 typedef struct sockaddr_in	ANTLR_SOCKADDRT, * pANTLR_SOCKADDRT;	// Type used for socket address declaration
    222 typedef struct sockaddr		ANTLR_SOCKADDRC, * pANTLR_SOCKADDRC;	// Type used for cast on accept()
    223 
    224 #define	ANTLR_CLOSESOCKET	closesocket
    225 
    226 /* Warnings that are over-zealous such as complaining about strdup, we
    227  * can turn off.
    228  */
    229 
    230 /* Don't complain about "deprecated" functions such as strdup
    231  */
    232 #pragma warning( disable : 4996 )
    233 
    234 #else
    235 
    236 #ifdef __LP64__
    237 #define ANTLR_USE_64BIT
    238 #endif
    239 
    240 #include <stdio.h>
    241 #include <stdint.h>
    242 #include <sys/types.h>
    243 #include <sys/stat.h>
    244 #include <stdlib.h>
    245 #include <stddef.h>
    246 #include <stdarg.h>
    247 #include <stdlib.h>
    248 #include <stdarg.h>
    249 #include <inttypes.h>
    250 #include <unistd.h>
    251 
    252 #define _stat stat
    253 
    254 typedef int SOCKET;
    255 
    256 /* Inherit type definitions for autoconf
    257  */
    258 typedef int32_t	    ANTLR_CHAR;
    259 typedef uint32_t    ANTLR_UCHAR;
    260 
    261 typedef int8_t	    ANTLR_INT8;
    262 typedef int16_t	    ANTLR_INT16;
    263 typedef int32_t	    ANTLR_INT32;
    264 typedef int64_t	    ANTLR_INT64;
    265 
    266 typedef uint8_t	    ANTLR_UINT8;
    267 typedef uint16_t    ANTLR_UINT16;
    268 typedef uint32_t    ANTLR_UINT32;
    269 typedef uint64_t    ANTLR_UINT64;
    270 typedef uint64_t    ANTLR_BITWORD;
    271 
    272 #define ANTLR_INLINE   inline
    273 #define	ANTLR_API
    274 
    275 typedef FILE *	    ANTLR_FDSC;
    276 typedef	struct stat ANTLR_FSTAT_STRUCT;
    277 
    278 #ifdef	ANTLR_USE_64BIT
    279 #define	ANTLR_FUNC_PTR(ptr)    (void *)((ANTLR_UINT64)(ptr))
    280 #define ANTLR_UINT64_CAST(ptr)	(ANTLR_UINT64)(ptr))
    281 #define	ANTLR_UINT32_CAST(ptr) (ANTLR_UINT32)((ANTLR_UINT64)(ptr))
    282 typedef ANTLR_INT64		ANTLR_MARKER;
    283 typedef ANTLR_UINT64		ANTLR_INTKEY;
    284 #else
    285 #define	ANTLR_FUNC_PTR(ptr)	(void *)((ANTLR_UINT32)(ptr))
    286 #define ANTLR_UINT64_CAST(ptr) (ANTLR_UINT64)((ANTLR_UINT32)(ptr))
    287 #define	ANTLR_UINT32_CAST(ptr)	(ANTLR_UINT32)(ptr)
    288 typedef	ANTLR_INT32		ANTLR_MARKER;
    289 typedef ANTLR_UINT32		ANTLR_INTKEY;
    290 #endif
    291 #define	ANTLR_UINT64_LIT(lit)	lit##ULL
    292 
    293 #endif
    294 
    295 #ifdef ANTLR_USE_64BIT
    296 #define ANTLR_TRIE_DEPTH 63
    297 #else
    298 #define ANTLR_TRIE_DEPTH 31
    299 #endif
    300 /* Pre declare the typedefs for all the interfaces, then
    301  * they can be inter-dependant and we will let the linker
    302  * sort it out for us.
    303  */
    304 #include    <antlr3interfaces.hpp>
    305 
    306 // Include the unicode.org conversion library header.
    307 //
    308 #include    <antlr3convertutf.hpp>
    309 
    310 enum ChannelType
    311 {
    312 	/** Default channel for a token
    313 	*/
    314 	TOKEN_DEFAULT_CHANNEL	 = 0
    315 	/** Reserved channel number for a HIDDEN token - a token that
    316 		*  is hidden from the parser.
    317 		*/
    318 	,	HIDDEN		=		99
    319 };
    320 
    321 #endif	/* _ANTLR3DEFS_H	*/
    322