w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

parser.c File Reference
#include "ffi.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Classes

struct  token
 

Macros

#define IS_CONST(tok)   (IS_LITERAL(tok, "const") || IS_LITERAL(tok, "__const") || IS_LITERAL(tok, "__const__"))
 
#define IS_VOLATILE(tok)   (IS_LITERAL(tok, "volatile") || IS_LITERAL(tok, "__volatile") || IS_LITERAL(tok, "__volatile__"))
 
#define IS_RESTRICT(tok)   (IS_LITERAL(tok, "restrict") || IS_LITERAL(tok, "__restrict") || IS_LITERAL(tok, "__restrict__"))
 
#define IS_INLINE(tok)   (IS_LITERAL(tok, "inline") || IS_LITERAL(tok, "__inline") || IS_LITERAL(tok, "__inline__"))
 
#define IS_LITERAL(TOK, STR)    (((TOK).size == sizeof(STR) - 1) && 0 == memcmp((TOK).str, STR, sizeof(STR) - 1))
 
#define require_token(L, P, tok)   require_token_line(L, P, tok, __FILE__, __LINE__)
 
#define max(a, b)   ((a) < (b) ? (b) : (a))
 
#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define SHORT_TYPE(u)   (sizeof(short) == sizeof(int64_t) ? u "int64_t" : sizeof(short) == sizeof(int32_t) ? u "int32_t" : u "int16_t")
 
#define LONG_TYPE(u)   (sizeof(long) == sizeof(int64_t) ? u "int64_t" : u "int32_t")
 
#define INT_TYPE(u)   (sizeof(int) == sizeof(int64_t) ? u "int64_t" : sizeof(int) == sizeof(int32_t) ? u "int32_t" : u "int16_t")
 
#define END   0
 
#define PRAGMA_POP   1
 

Enumerations

enum  etoken {
  TOK_NIL , TOK_NUMBER , TOK_STRING , TOK_TOKEN ,
  TOK_3_BEGIN , TOK_VA_ARG , TOK_2_BEGIN , TOK_LEFT_SHIFT ,
  TOK_RIGHT_SHIFT , TOK_LOGICAL_AND , TOK_LOGICAL_OR , TOK_LESS_EQUAL ,
  TOK_GREATER_EQUAL , TOK_EQUAL , TOK_NOT_EQUAL , TOK_1_BEGIN ,
  TOK_OPEN_CURLY , TOK_CLOSE_CURLY , TOK_SEMICOLON , TOK_COMMA ,
  TOK_COLON , TOK_ASSIGN , TOK_OPEN_PAREN , TOK_CLOSE_PAREN ,
  TOK_OPEN_SQUARE , TOK_CLOSE_SQUARE , TOK_DOT , TOK_AMPERSAND ,
  TOK_LOGICAL_NOT , TOK_BITWISE_NOT , TOK_MINUS , TOK_PLUS ,
  TOK_STAR , TOK_DIVIDE , TOK_MODULUS , TOK_LESS ,
  TOK_GREATER , TOK_BITWISE_XOR , TOK_BITWISE_OR , TOK_QUESTION ,
  TOK_POUND , TOK_REFERENCE = TOK_AMPERSAND , TOK_MULTIPLY = TOK_STAR , TOK_BITWISE_AND = TOK_AMPERSAND
}
 
enum  test { TEST }
 
enum  name_type { BOTH , FRONT , BACK }
 

Functions

static int next_token (lua_State *L, struct parser *P, struct token *tok)
 
static void require_token_line (lua_State *L, struct parser *P, struct token *tok, const char *file, int line)
 
static void check_token (lua_State *L, struct parser *P, int type, const char *str, const char *err,...)
 
static void put_back (struct parser *P)
 
int64_t calculate_constant (lua_State *L, struct parser *P)
 
static int parse_enum (lua_State *L, struct parser *P, struct ctype *type)
 
static void calculate_member_position (lua_State *L, struct parser *P, struct ctype *ct, struct ctype *mt, int *pbit_offset, int *pbitfield_type)
 
static int copy_submembers (lua_State *L, int to_usr, int from_usr, const struct ctype *ft, int *midx)
 
static int add_member (lua_State *L, int ct_usr, int mname, int mbr_usr, const struct ctype *mt, int *midx)
 
static int parse_struct (lua_State *L, struct parser *P, int tmp_usr, const struct ctype *ct)
 
static int calculate_struct_offsets (lua_State *L, struct parser *P, int ct_usr, struct ctype *ct, int tmp_usr)
 
static void instantiate_typedef (struct parser *P, struct ctype *tt, const struct ctype *ft)
 
static int parse_record (lua_State *L, struct parser *P, struct ctype *ct)
 
static int parse_type_name (lua_State *L, struct parser *P)
 
static int parse_attribute (lua_State *L, struct parser *P, struct token *tok, struct ctype *ct, struct parser *asmname)
 
int parse_type (lua_State *L, struct parser *P, struct ctype *ct)
 
static void append_type_name (luaL_Buffer *B, int usr, const struct ctype *ct, enum name_type type)
 
void push_type_name (lua_State *L, int usr, const struct ctype *ct)
 
static void push_function_type_strings (lua_State *L, int usr, const struct ctype *ct)
 
static void parse_function_arguments (lua_State *L, struct parser *P, int ct_usr, struct ctype *ct)
 
static int max_bitfield_size (int type)
 
static struct ctypeparse_argument2 (lua_State *L, struct parser *P, int ct_usr, struct ctype *ct, struct token *name, struct parser *asmname)
 
static struct ctypeparse_function (lua_State *L, struct parser *P, int ct_usr, struct ctype *ct, struct token *name, struct parser *asmname)
 
static void find_canonical_usr (lua_State *L, int ct_usr, const struct ctype *ct)
 
void parse_argument (lua_State *L, struct parser *P, int ct_usr, struct ctype *ct, struct token *pname, struct parser *asmname)
 
static void parse_typedef (lua_State *L, struct parser *P)
 
static Bool__ is_hex (char ch)
 
static Bool__ is_digit (char ch)
 
static int from_hex (char ch)
 
static void push_strings (lua_State *L, struct parser *P)
 
static void parse_constant_assignemnt (lua_State *L, struct parser *P, const struct ctype *type, const struct token *name)
 
static int parse_root (lua_State *L, struct parser *P)
 
int ffi_cdef (lua_State *L)
 
static int64_t string_to_int (const char *str, size_t size)
 
static int try_cast (lua_State *L)
 
static int64_t calculate_constant2 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant1 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant3 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant4 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant5 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant6 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant7 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant8 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant9 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant10 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant11 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant12 (lua_State *L, struct parser *P, struct token *tok)
 
static int64_t calculate_constant13 (lua_State *L, struct parser *P, struct token *tok)
 

Variables

static char tok3 [][4]
 
static char tok2 [][3]
 
static char tok1 []
 
static int g_name_key
 
static int g_front_name_key
 
static int g_back_name_key
 

Macro Definition Documentation

◆ END

#define END   0

Definition at line 2040 of file parser.c.

◆ INT_TYPE

#define INT_TYPE (   u)    (sizeof(int) == sizeof(int64_t) ? u "int64_t" : sizeof(int) == sizeof(int32_t) ? u "int32_t" : u "int16_t")

◆ IS_CONST

#define IS_CONST (   tok)    (IS_LITERAL(tok, "const") || IS_LITERAL(tok, "__const") || IS_LITERAL(tok, "__const__"))

Definition at line 11 of file parser.c.

◆ IS_INLINE

#define IS_INLINE (   tok)    (IS_LITERAL(tok, "inline") || IS_LITERAL(tok, "__inline") || IS_LITERAL(tok, "__inline__"))

Definition at line 14 of file parser.c.

◆ IS_LITERAL

#define IS_LITERAL (   TOK,
  STR 
)     (((TOK).size == sizeof(STR) - 1) && 0 == memcmp((TOK).str, STR, sizeof(STR) - 1))

Definition at line 50 of file parser.c.

◆ IS_RESTRICT

#define IS_RESTRICT (   tok)    (IS_LITERAL(tok, "restrict") || IS_LITERAL(tok, "__restrict") || IS_LITERAL(tok, "__restrict__"))

Definition at line 13 of file parser.c.

◆ IS_VOLATILE

#define IS_VOLATILE (   tok)    (IS_LITERAL(tok, "volatile") || IS_LITERAL(tok, "__volatile") || IS_LITERAL(tok, "__volatile__"))

Definition at line 12 of file parser.c.

◆ LONG_TYPE

#define LONG_TYPE (   u)    (sizeof(long) == sizeof(int64_t) ? u "int64_t" : u "int32_t")

◆ max

#define max (   a,
  b 
)    ((a) < (b) ? (b) : (a))

Definition at line 250 of file parser.c.

◆ min

#define min (   a,
  b 
)    ((a) < (b) ? (a) : (b))

Definition at line 254 of file parser.c.

◆ PRAGMA_POP

#define PRAGMA_POP   1

Definition at line 2041 of file parser.c.

◆ require_token

#define require_token (   L,
  P,
  tok 
)    require_token_line(L, P, tok, __FILE__, __LINE__)

Definition at line 219 of file parser.c.

◆ SHORT_TYPE

#define SHORT_TYPE (   u)    (sizeof(short) == sizeof(int64_t) ? u "int64_t" : sizeof(short) == sizeof(int32_t) ? u "int32_t" : u "int16_t")

Enumeration Type Documentation

◆ etoken

enum etoken
Enumerator
TOK_NIL 
TOK_NUMBER 
TOK_STRING 
TOK_TOKEN 
TOK_3_BEGIN 
TOK_VA_ARG 
TOK_2_BEGIN 
TOK_LEFT_SHIFT 
TOK_RIGHT_SHIFT 
TOK_LOGICAL_AND 
TOK_LOGICAL_OR 
TOK_LESS_EQUAL 
TOK_GREATER_EQUAL 
TOK_EQUAL 
TOK_NOT_EQUAL 
TOK_1_BEGIN 
TOK_OPEN_CURLY 
TOK_CLOSE_CURLY 
TOK_SEMICOLON 
TOK_COMMA 
TOK_COLON 
TOK_ASSIGN 
TOK_OPEN_PAREN 
TOK_CLOSE_PAREN 
TOK_OPEN_SQUARE 
TOK_CLOSE_SQUARE 
TOK_DOT 
TOK_AMPERSAND 
TOK_LOGICAL_NOT 
TOK_BITWISE_NOT 
TOK_MINUS 
TOK_PLUS 
TOK_STAR 
TOK_DIVIDE 
TOK_MODULUS 
TOK_LESS 
TOK_GREATER 
TOK_BITWISE_XOR 
TOK_BITWISE_OR 
TOK_QUESTION 
TOK_POUND 
TOK_REFERENCE 
TOK_MULTIPLY 
TOK_BITWISE_AND 

Definition at line 16 of file parser.c.

◆ name_type

enum name_type
Enumerator
BOTH 
FRONT 
BACK 

Definition at line 1268 of file parser.c.

◆ test

enum test
Enumerator
TEST 

Definition at line 257 of file parser.c.

Function Documentation

◆ add_member()

static int add_member ( lua_State L,
int  ct_usr,
int  mname,
int  mbr_usr,
const struct ctype mt,
int midx 
)
static

Definition at line 528 of file parser.c.

References L, lua_absindex, lua_pop, lua_pushvalue(), lua_rawset(), lua_rawseti(), mt, and push_ctype().

Referenced by calculate_struct_offsets(), and parse_struct().

◆ append_type_name()

◆ calculate_constant()

int64_t calculate_constant ( lua_State L,
struct parser P 
)

◆ calculate_constant1()

◆ calculate_constant10()

static int64_t calculate_constant10 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2534 of file parser.c.

References calculate_constant9(), L, P, require_token, tok(), and TOK_BITWISE_OR.

Referenced by calculate_constant11().

◆ calculate_constant11()

static int64_t calculate_constant11 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2550 of file parser.c.

References calculate_constant10(), L, P, require_token, tok(), and TOK_LOGICAL_AND.

Referenced by calculate_constant12().

◆ calculate_constant12()

static int64_t calculate_constant12 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2566 of file parser.c.

References calculate_constant11(), L, P, require_token, tok(), and TOK_LOGICAL_OR.

Referenced by calculate_constant13().

◆ calculate_constant13()

static int64_t calculate_constant13 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2582 of file parser.c.

References calculate_constant12(), L, luaL_error(), middle, P, require_token, right, tok(), TOK_COLON, and TOK_QUESTION.

◆ calculate_constant2()

◆ calculate_constant3()

static int64_t calculate_constant3 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2390 of file parser.c.

References calculate_constant2(), L, P, require_token, tok(), TOK_DIVIDE, TOK_MODULUS, and TOK_MULTIPLY.

Referenced by calculate_constant4().

◆ calculate_constant4()

static int64_t calculate_constant4 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2414 of file parser.c.

References calculate_constant3(), L, P, require_token, tok(), TOK_MINUS, and TOK_PLUS.

Referenced by calculate_constant5().

◆ calculate_constant5()

static int64_t calculate_constant5 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2434 of file parser.c.

References calculate_constant4(), L, P, require_token, tok(), TOK_LEFT_SHIFT, and TOK_RIGHT_SHIFT.

Referenced by calculate_constant6().

◆ calculate_constant6()

static int64_t calculate_constant6 ( lua_State L,
struct parser P,
struct token tok 
)
static

◆ calculate_constant7()

static int64_t calculate_constant7 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2482 of file parser.c.

References calculate_constant6(), L, P, require_token, tok(), TOK_EQUAL, and TOK_NOT_EQUAL.

Referenced by calculate_constant8().

◆ calculate_constant8()

static int64_t calculate_constant8 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2502 of file parser.c.

References calculate_constant7(), L, P, require_token, tok(), and TOK_BITWISE_AND.

Referenced by calculate_constant9().

◆ calculate_constant9()

static int64_t calculate_constant9 ( lua_State L,
struct parser P,
struct token tok 
)
static

Definition at line 2518 of file parser.c.

References calculate_constant8(), L, P, require_token, tok(), and TOK_BITWISE_XOR.

Referenced by calculate_constant10().

◆ calculate_member_position()

static void calculate_member_position ( lua_State L,
struct parser P,
struct ctype ct,
struct ctype mt,
int pbit_offset,
int pbitfield_type 
)
static

◆ calculate_struct_offsets()

◆ check_token()

static void check_token ( lua_State L,
struct parser P,
int  type,
const char *  str,
const char *  err,
  ... 
)
static

◆ copy_submembers()

static int copy_submembers ( lua_State L,
int  to_usr,
int  from_usr,
const struct ctype ft,
int midx 
)
static

◆ ffi_cdef()

int ffi_cdef ( lua_State L)

Definition at line 2189 of file parser.c.

References DEFAULT_ALIGN_MASK, L, luaL_checkstring, luaL_error(), P, parse_root(), and PRAGMA_POP.

◆ find_canonical_usr()

◆ from_hex()

static int from_hex ( char  ch)
static

Definition at line 1921 of file parser.c.

References ch.

Referenced by push_strings().

◆ instantiate_typedef()

static void instantiate_typedef ( struct parser P,
struct ctype tt,
const struct ctype ft 
)
static

Definition at line 697 of file parser.c.

References ctype::align_mask, ctype::const_mask, ctype::is_packed, max, min, P, and pt.

Referenced by parse_record(), and parse_type().

◆ is_digit()

static Bool__ is_digit ( char  ch)
static

Definition at line 1918 of file parser.c.

References ch.

Referenced by push_strings().

◆ is_hex()

static Bool__ is_hex ( char  ch)
static

Definition at line 1915 of file parser.c.

References ch.

Referenced by push_strings().

◆ max_bitfield_size()

static int max_bitfield_size ( int  type)
static

Definition at line 1546 of file parser.c.

References BOOL_TYPE, ENUM_TYPE, INT16_TYPE, INT32_TYPE, INT64_TYPE, INT8_TYPE, and type.

Referenced by parse_argument2().

◆ next_token()

◆ parse_argument()

void parse_argument ( lua_State L,
struct parser P,
int  ct_usr,
struct ctype ct,
struct token pname,
struct parser asmname 
)

◆ parse_argument2()

◆ parse_attribute()

◆ parse_constant_assignemnt()

static void parse_constant_assignemnt ( lua_State L,
struct parser P,
const struct ctype type,
const struct token name 
)
static

◆ parse_enum()

◆ parse_function()

◆ parse_function_arguments()

◆ parse_record()

◆ parse_root()

◆ parse_struct()

◆ parse_type()

◆ parse_type_name()

static int parse_type_name ( lua_State L,
struct parser P 
)
static

◆ parse_typedef()

◆ push_function_type_strings()

◆ push_strings()

static void push_strings ( lua_State L,
struct parser P 
)
static

◆ push_type_name()

◆ put_back()

◆ require_token_line()

static void require_token_line ( lua_State L,
struct parser P,
struct token tok,
const char *  file,
int  line 
)
static

Definition at line 221 of file parser.c.

References L, luaL_error(), next_token(), P, and tok().

◆ string_to_int()

static int64_t string_to_int ( const char *  str,
size_t  size 
)
static

Definition at line 2209 of file parser.c.

References c, d, end, size, and str.

Referenced by calculate_constant1().

◆ try_cast()

static int try_cast ( lua_State L)
static

Variable Documentation

◆ g_back_name_key

int g_back_name_key
static

Definition at line 247 of file parser.c.

Referenced by append_type_name(), and find_canonical_usr().

◆ g_front_name_key

int g_front_name_key
static

Definition at line 246 of file parser.c.

Referenced by append_type_name(), and find_canonical_usr().

◆ g_name_key

int g_name_key
static

Definition at line 245 of file parser.c.

Referenced by append_type_name(), find_canonical_usr(), and parse_record().

◆ tok1

char tok1[]
static
Initial value:
= {
'{', '}', ';', ',', ':',
'=', '(', ')', '[', ']',
'.', '&', '!', '~', '-',
'+', '*', '/', '%', '<',
'>', '^', '|', '?', '#'
}

Definition at line 65 of file parser.c.

Referenced by CMap_parse(), do_bfchar(), do_cidchar(), do_cidsysteminfo(), do_notdefchar(), get_coderange(), next_token(), UnicodeMap::parse(), CMap::parse2(), CharCodeToUnicode::parseCMap1(), and GlobalParams::parseNameToUnicode().

◆ tok2

char tok2[][3]
static
Initial value:
= {
"<<", ">>", "&&", "||", "<=",
">=", "==", "!=",
}

Definition at line 59 of file parser.c.

Referenced by CMap_parse(), do_bfchar(), do_cidchar(), do_cidsysteminfo(), do_notdefchar(), get_coderange(), next_token(), UnicodeMap::parse(), CMap::parse2(), CharCodeToUnicode::parseCMap1(), and GlobalParams::parseNameToUnicode().

◆ tok3

char tok3[][4]
static
Initial value:
= {
"...",
}

Definition at line 55 of file parser.c.

Referenced by next_token(), UnicodeMap::parse(), CMap::parse2(), and CharCodeToUnicode::parseCMap1().