cpp: token stringification and pasting
[m6w6/ext-psi] / src / cpp.h
1 /*******************************************************************************
2 Copyright (c) 2017, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
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.
13
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 *******************************************************************************/
25
26 #ifndef PSI_CPP_H
27 #define PSI_CPP_H
28
29 #include "data.h"
30
31 #ifndef PSI_CPP_DEBUG
32 # define PSI_CPP_DEBUG 1
33 #endif
34
35 struct psi_cpp_data {
36 HashTable defs;
37 unsigned level;
38 unsigned skip;
39 unsigned seen;
40 size_t index;
41 struct psi_plist *tokens;
42 unsigned expanded;
43 struct psi_cpp_exp *exp;
44 };
45
46 bool psi_cpp_preprocess(struct psi_parser *P, struct psi_cpp_data *cpp);
47 bool psi_cpp_if(struct psi_cpp_exp *exp, HashTable *defs, struct psi_data *D);
48 bool psi_cpp_defined(struct psi_cpp_data *cpp, struct psi_token *tok);
49 void psi_cpp_define(struct psi_cpp_data *cpp, struct psi_cpp_macro_decl *decl);
50 bool psi_cpp_undef(struct psi_cpp_data *cpp, struct psi_token *tok);
51
52 void psi_cpp_tokiter_reset(struct psi_cpp_data *cpp);
53 bool psi_cpp_tokiter_seek(struct psi_cpp_data *cpp, size_t index);
54 void psi_cpp_tokiter_dump(int fd, struct psi_cpp_data *cpp);
55 struct psi_token *psi_cpp_tokiter_current(struct psi_cpp_data *cpp);
56 size_t psi_cpp_tokiter_index(struct psi_cpp_data *cpp);
57 void psi_cpp_tokiter_next(struct psi_cpp_data *cpp);
58 void psi_cpp_tokiter_prev(struct psi_cpp_data *cpp);
59 bool psi_cpp_tokiter_valid(struct psi_cpp_data *cpp);
60 bool psi_cpp_tokiter_del_cur(struct psi_cpp_data *cpp, bool free_token);
61 bool psi_cpp_tokiter_del_range(struct psi_cpp_data *cpp, size_t offset,
62 size_t num_eles, bool free_tokens);
63 bool psi_cpp_tokiter_ins_cur(struct psi_cpp_data *cpp, struct psi_token *tok);
64 bool psi_cpp_tokiter_ins_range(struct psi_cpp_data *cpp, size_t offset,
65 size_t num_eles, void **eles);
66 bool psi_cpp_tokiter_defined(struct psi_cpp_data *cpp);
67 bool psi_cpp_tokiter_expand(struct psi_cpp_data *cpp);
68
69 #endif