1/*
2** C declaration parser.
3** Copyright (C) 2005-2014 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#define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
27
28typedef int CPChar; /* C parser character. Unsigned ext. from char. */
29typedef int CPToken; /* C parser token. */
30
31/* C parser internal value representation. */
32typedef struct CPValue {
33 union {
34 int32_t i32; /* Value for CTID_INT32. */
35 uint32_t u32; /* Value for CTID_UINT32. */
36 };
37 CTypeID id; /* C Type ID of the value. */
38} CPValue;
39
40/* C parser state. */
41typedef 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. */
59} CPState;
60
61LJ_FUNC int lj_cparse(CPState *cp);
62
63#endif
64
65#endif
66