diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_cparse.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/lj_cparse.h b/src/lj_cparse.h new file mode 100644 index 00000000..2d2f4684 --- /dev/null +++ b/src/lj_cparse.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | ** C declaration parser. | ||
3 | ** Copyright (C) 2005-2010 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_CPARSE_H | ||
7 | #define _LJ_CPARSE_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | #include "lj_ctype.h" | ||
11 | |||
12 | #if LJ_HASFFI | ||
13 | |||
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. */ | ||
19 | |||
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 | |||
27 | typedef int CPChar; /* C parser character. Unsigned ext. from char. */ | ||
28 | typedef int CPToken; /* C parser token. */ | ||
29 | |||
30 | /* C parser internal value representation. */ | ||
31 | typedef struct CPValue { | ||
32 | union { | ||
33 | int32_t i32; /* Value for CTID_INT32. */ | ||
34 | uint32_t u32; /* Value for CTID_UINT32. */ | ||
35 | }; | ||
36 | CTypeID id; /* C Type ID of the value. */ | ||
37 | } CPValue; | ||
38 | |||
39 | /* C parser state. */ | ||
40 | typedef struct CPState { | ||
41 | CPChar c; /* Current character. */ | ||
42 | CPToken tok; /* Current token. */ | ||
43 | CPValue val; /* Token value. */ | ||
44 | GCstr *str; /* Interned string of identifier/keyword. */ | ||
45 | CType *ct; /* C type table entry. */ | ||
46 | const char *p; /* Current position in input buffer. */ | ||
47 | SBuf sb; /* String buffer for tokens. */ | ||
48 | lua_State *L; /* Lua state. */ | ||
49 | CTState *cts; /* C type state. */ | ||
50 | const char *srcname; /* Current source name. */ | ||
51 | BCLine linenumber; /* Input line counter. */ | ||
52 | int depth; /* Recursive declaration depth. */ | ||
53 | uint32_t tmask; /* Type mask for next identifier. */ | ||
54 | uint32_t mode; /* C parser mode. */ | ||
55 | uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */ | ||
56 | uint8_t curpack; /* Current position in pack pragma stack. */ | ||
57 | } CPState; | ||
58 | |||
59 | LJ_FUNC int lj_cparse(CPState *cp); | ||
60 | |||
61 | #endif | ||
62 | |||
63 | #endif | ||