/src/tarantool/third_party/luajit/src/lj_strfmt.h
Line | Count | Source |
1 | | /* |
2 | | ** String formatting. |
3 | | ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h |
4 | | */ |
5 | | |
6 | | #ifndef _LJ_STRFMT_H |
7 | | #define _LJ_STRFMT_H |
8 | | |
9 | | #include "lj_obj.h" |
10 | | |
11 | | typedef uint32_t SFormat; /* Format indicator. */ |
12 | | |
13 | | /* Format parser state. */ |
14 | | typedef struct FormatState { |
15 | | const uint8_t *p; /* Current format string pointer. */ |
16 | | const uint8_t *e; /* End of format string. */ |
17 | | const char *str; /* Returned literal string. */ |
18 | | MSize len; /* Size of literal string. */ |
19 | | } FormatState; |
20 | | |
21 | | /* Format types (max. 16). */ |
22 | | typedef enum FormatType { |
23 | | STRFMT_EOF, STRFMT_ERR, STRFMT_LIT, |
24 | | STRFMT_INT, STRFMT_UINT, STRFMT_NUM, STRFMT_STR, STRFMT_CHAR, STRFMT_PTR |
25 | | } FormatType; |
26 | | |
27 | | /* Format subtypes (bits are reused). */ |
28 | 4.10M | #define STRFMT_T_HEX 0x0010 /* STRFMT_UINT */ |
29 | 4.09M | #define STRFMT_T_OCT 0x0020 /* STRFMT_UINT */ |
30 | | #define STRFMT_T_FP_A 0x0000 /* STRFMT_NUM */ |
31 | 87.2M | #define STRFMT_T_FP_E 0x0010 /* STRFMT_NUM */ |
32 | 22.8M | #define STRFMT_T_FP_F 0x0020 /* STRFMT_NUM */ |
33 | 22.3M | #define STRFMT_T_FP_G 0x0030 /* STRFMT_NUM */ |
34 | 13.2k | #define STRFMT_T_QUOTED 0x0010 /* STRFMT_STR */ |
35 | | |
36 | | /* Format flags. */ |
37 | 80.1M | #define STRFMT_F_LEFT 0x0100 |
38 | 20.9M | #define STRFMT_F_PLUS 0x0200 |
39 | 78.9M | #define STRFMT_F_ZERO 0x0400 |
40 | 21.0M | #define STRFMT_F_SPACE 0x0800 |
41 | 87.9M | #define STRFMT_F_ALT 0x1000 |
42 | 1.52M | #define STRFMT_F_UPPER 0x2000 |
43 | | |
44 | | /* Format indicator fields. */ |
45 | 26.9M | #define STRFMT_SH_WIDTH 16 |
46 | 51.7M | #define STRFMT_SH_PREC 24 |
47 | | |
48 | 69.0M | #define STRFMT_TYPE(sf) ((FormatType)((sf) & 15)) |
49 | 26.9M | #define STRFMT_WIDTH(sf) (((sf) >> STRFMT_SH_WIDTH) & 255u) |
50 | 29.3M | #define STRFMT_PREC(sf) ((((sf) >> STRFMT_SH_PREC) & 255u) - 1u) |
51 | 91.3M | #define STRFMT_FP(sf) (((sf) >> 4) & 3) |
52 | | |
53 | | /* Formats for conversion characters. */ |
54 | | #define STRFMT_A (STRFMT_NUM|STRFMT_T_FP_A) |
55 | | #define STRFMT_C (STRFMT_CHAR) |
56 | | #define STRFMT_D (STRFMT_INT) |
57 | | #define STRFMT_E (STRFMT_NUM|STRFMT_T_FP_E) |
58 | | #define STRFMT_F (STRFMT_NUM|STRFMT_T_FP_F) |
59 | 22.3M | #define STRFMT_G (STRFMT_NUM|STRFMT_T_FP_G) |
60 | | #define STRFMT_I STRFMT_D |
61 | | #define STRFMT_O (STRFMT_UINT|STRFMT_T_OCT) |
62 | | #define STRFMT_P (STRFMT_PTR) |
63 | | #define STRFMT_Q (STRFMT_STR|STRFMT_T_QUOTED) |
64 | | #define STRFMT_S (STRFMT_STR) |
65 | | #define STRFMT_U (STRFMT_UINT) |
66 | | #define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX) |
67 | 22.3M | #define STRFMT_G14 (STRFMT_G | ((14+1) << STRFMT_SH_PREC)) |
68 | | |
69 | | /* Maximum buffer sizes for conversions. */ |
70 | | #define STRFMT_MAXBUF_XINT (1+22) /* '0' prefix + uint64_t in octal. */ |
71 | 0 | #define STRFMT_MAXBUF_INT (1+10) /* Sign + int32_t in decimal. */ |
72 | 27.4M | #define STRFMT_MAXBUF_NUM 32 /* Must correspond with STRFMT_G14. */ |
73 | 354k | #define STRFMT_MAXBUF_PTR (2+2*sizeof(ptrdiff_t)) /* "0x" + hex ptr. */ |
74 | | |
75 | | /* Format parser. */ |
76 | | LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); |
77 | | |
78 | | static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) |
79 | 23.5M | { |
80 | 23.5M | fs->p = (const uint8_t *)p; |
81 | 23.5M | fs->e = (const uint8_t *)p + len; |
82 | | /* Must be NUL-terminated. May have NULs inside, too. */ |
83 | 23.5M | lj_assertX(*fs->e == 0, "format not NUL-terminated"); |
84 | 23.5M | } Unexecuted instantiation: lj_api.c:lj_strfmt_init Unexecuted instantiation: lj_debug.c:lj_strfmt_init Unexecuted instantiation: lj_err.c:lj_strfmt_init Unexecuted instantiation: lj_meta.c:lj_strfmt_init lj_strfmt.c:lj_strfmt_init Line | Count | Source | 79 | 22.9M | { | 80 | 22.9M | fs->p = (const uint8_t *)p; | 81 | 22.9M | fs->e = (const uint8_t *)p + len; | 82 | | /* Must be NUL-terminated. May have NULs inside, too. */ | 83 | 22.9M | lj_assertX(*fs->e == 0, "format not NUL-terminated"); | 84 | 22.9M | } |
Unexecuted instantiation: lj_strfmt_num.c:lj_strfmt_init Unexecuted instantiation: lj_bcread.c:lj_strfmt_init Unexecuted instantiation: lj_bcwrite.c:lj_strfmt_init Unexecuted instantiation: lj_lex.c:lj_strfmt_init Unexecuted instantiation: lj_parse.c:lj_strfmt_init Unexecuted instantiation: lj_ctype.c:lj_strfmt_init Unexecuted instantiation: lj_buf.c:lj_strfmt_init Unexecuted instantiation: lj_dispatch.c:lj_strfmt_init Unexecuted instantiation: lj_lib.c:lj_strfmt_init Unexecuted instantiation: lib_base.c:lj_strfmt_init Unexecuted instantiation: lib_ffi.c:lj_strfmt_init Unexecuted instantiation: lj_ir.c:lj_strfmt_init Unexecuted instantiation: lj_opt_fold.c:lj_strfmt_init Unexecuted instantiation: lj_clib.c:lj_strfmt_init Unexecuted instantiation: lj_cparse.c:lj_strfmt_init lj_ffrecord.c:lj_strfmt_init Line | Count | Source | 79 | 12.5k | { | 80 | 12.5k | fs->p = (const uint8_t *)p; | 81 | 12.5k | fs->e = (const uint8_t *)p + len; | 82 | | /* Must be NUL-terminated. May have NULs inside, too. */ | 83 | 12.5k | lj_assertX(*fs->e == 0, "format not NUL-terminated"); | 84 | 12.5k | } |
Unexecuted instantiation: lj_crecord.c:lj_strfmt_init Unexecuted instantiation: lib_bit.c:lj_strfmt_init lib_string.c:lj_strfmt_init Line | Count | Source | 79 | 523k | { | 80 | 523k | fs->p = (const uint8_t *)p; | 81 | 523k | fs->e = (const uint8_t *)p + len; | 82 | | /* Must be NUL-terminated. May have NULs inside, too. */ | 83 | 523k | lj_assertX(*fs->e == 0, "format not NUL-terminated"); | 84 | 523k | } |
Unexecuted instantiation: lib_io.c:lj_strfmt_init Unexecuted instantiation: lib_misc.c:lj_strfmt_init |
85 | | |
86 | | /* Raw conversions. */ |
87 | | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k); |
88 | | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v); |
89 | | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v); |
90 | | LJ_FUNC const char *lj_strfmt_wstrnum(lua_State *L, cTValue *o, MSize *lenp); |
91 | | |
92 | | /* Unformatted conversions to buffer. */ |
93 | | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k); |
94 | | #if LJ_HASJIT |
95 | | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o); |
96 | | #endif |
97 | | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putptr(SBuf *sb, const void *v); |
98 | | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str); |
99 | | |
100 | | /* Formatted conversions to buffer. */ |
101 | | LJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k); |
102 | | LJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n); |
103 | | LJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n); |
104 | | LJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n); |
105 | | LJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c); |
106 | | LJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str); |
107 | | |
108 | | /* Conversions to strings. */ |
109 | | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k); |
110 | | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o); |
111 | | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o); |
112 | | #if LJ_HASJIT |
113 | | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c); |
114 | | #endif |
115 | | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o); |
116 | | |
117 | | /* Internal string formatting. */ |
118 | | LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, |
119 | | va_list argp); |
120 | | LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) |
121 | | #if defined(__GNUC__) || defined(__clang__) |
122 | | __attribute__ ((format (printf, 2, 3))) |
123 | | #endif |
124 | | ; |
125 | | |
126 | | #endif |