2 ** C declaration parser.
3 ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
14 /* C parser limits. */
15 #define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
16 #define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
17 #define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
18 #define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
20 /* Flags for C parser mode. */
21 #define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
22 #define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
23 #define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
24 #define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
25 #define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
26 #define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
28 typedef int CPChar
; /* C parser character. Unsigned ext. from char. */
29 typedef int CPToken
; /* C parser token. */
31 /* C parser internal value representation. */
32 typedef struct CPValue
{
34 int32_t i32
; /* Value for CTID_INT32. */
35 uint32_t u32
; /* Value for CTID_UINT32. */
37 CTypeID id
; /* C Type ID of the value. */
41 typedef struct CPState
{
42 CPChar c
; /* Current character. */
43 CPToken tok
; /* Current token. */
44 CPValue val
; /* Token value. */
45 GCstr
*str
; /* Interned string of identifier/keyword. */
46 CType
*ct
; /* C type table entry. */
47 const char *p
; /* Current position in input buffer. */
48 SBuf sb
; /* String buffer for tokens. */
49 lua_State
*L
; /* Lua state. */
50 CTState
*cts
; /* C type state. */
51 TValue
*param
; /* C type parameters. */
52 const char *srcname
; /* Current source name. */
53 BCLine linenumber
; /* Input line counter. */
54 int depth
; /* Recursive declaration depth. */
55 uint32_t tmask
; /* Type mask for next identifier. */
56 uint32_t mode
; /* C parser mode. */
57 uint8_t packstack
[CPARSE_MAX_PACKSTACK
]; /* Stack for pack pragmas. */
58 uint8_t curpack
; /* Current position in pack pragma stack. */
61 LJ_FUNC
int lj_cparse(CPState
*cp
);