1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
33 #include <sys/param.h>
35 static inline size_t psi_align(size_t s
, size_t a
) {
36 return ((s
- 1) | (a
- 1)) + 1;
39 static inline size_t psi_offset_padding(size_t diff
, size_t alignment
) {
40 if (diff
&& diff
<= psi_align(diff
, alignment
)) {
47 #include "parser_proc.h"
49 #define PSI_T_POINTER PSI_T_ASTERISK
50 #define PSI_T_LONG_DOUBLE (PSI_T_DOUBLE << 16)
51 #define PSI_T_BSLASH (PSI_T_SLASH << 16)
52 #define PSI_T_WHITESPACE -PSI_T_NO_WHITESPACE
56 static inline size_t psi_t_alignment(token_t t
)
58 #define PSI_ALIGNOF(T) case PSI_T_## T: return ALIGNOF_## T ##_T;
71 return ALIGNOF_DOUBLE
;
74 return ALIGNOF_VOID_P
;
77 #ifdef HAVE_LONG_DOUBLE
78 case PSI_T_LONG_DOUBLE
:
79 return ALIGNOF_LONG_DOUBLE
;
87 static inline size_t psi_t_size(token_t t
)
89 #define PSI_SIZEOF(T) case PSI_T_## T : return SIZEOF_## T ##_T;
102 return SIZEOF_DOUBLE
;
106 return SIZEOF_VOID_P
;
109 #ifdef HAVE_LONG_DOUBLE
110 case PSI_T_LONG_DOUBLE
:
111 return SIZEOF_LONG_DOUBLE
;
119 static inline const char *psi_t_indent(unsigned level
) {
120 static const char indent
[] =
121 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
122 return &indent
[32 - MIN(32, level
)];
125 static inline const char *psi_t_indirection(unsigned pointer_level
) {
126 static const char indir
[] = "********************************";
127 return &indir
[32 - MIN(32, pointer_level
)];
132 unsigned size
, line
, col
;
139 struct psi_token
*psi_token_alloc(struct psi_parser
*P
);
140 size_t psi_token_alloc_size(size_t token_len
, size_t fname_len
);
141 struct psi_token
*psi_token_copy(struct psi_token
*src
);
142 void psi_token_copy_ctor(struct psi_token
**src
);
143 struct psi_token
*psi_token_cat(const char *sep
, unsigned argc
, ...);
144 struct psi_token
*psi_token_prepend(const char *sep
, struct psi_token
*T
, unsigned argc
, ...);
145 struct psi_token
*psi_token_append(const char *sep
, struct psi_token
*T
, unsigned argc
, ...);
146 struct psi_token
*psi_token_translit(struct psi_token
*T
, char *from
, char *to
);
147 uint64_t psi_token_hash(struct psi_token
*t
, char *digest_buf
);
148 void psi_token_dump(int fd
, struct psi_token
*t
);
149 void psi_token_free(struct psi_token
**token
);