travis: update
[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 0
33 #endif
34
35 struct psi_cpp {
36 HashTable defs;
37 HashTable once;
38 struct psi_parser *parser;
39 struct {
40 struct psi_plist *iter;
41 struct psi_plist *next;
42 struct psi_plist *exec;
43 } tokens;
44 HashTable expanding;
45 const char *search;
46 size_t index;
47 unsigned level;
48 unsigned skip;
49 unsigned seen;
50 unsigned expanded;
51 unsigned counter;
52 unsigned include_level;
53 bool do_cpp;
54 };
55
56 struct psi_cpp *psi_cpp_init(struct psi_parser *parser);
57 bool psi_cpp_process(struct psi_cpp *cpp, struct psi_plist **tokens,
58 struct psi_token *expanding);
59 void psi_cpp_free(struct psi_cpp **cpp_ptr);
60
61 bool psi_cpp_if(struct psi_cpp *cpp, struct psi_cpp_exp *exp);
62 bool psi_cpp_defined(struct psi_cpp *cpp, struct psi_token *tok);
63 void psi_cpp_define(struct psi_cpp *cpp, struct psi_cpp_macro_decl *decl);
64 bool psi_cpp_undef(struct psi_cpp *cpp, struct psi_token *tok);
65
66 #define PSI_CPP_INCLUDE 0x0
67 #define PSI_CPP_INCLUDE_NEXT 0x1
68 #define PSI_CPP_INCLUDE_ONCE 0x2
69
70 bool psi_cpp_has_include(struct psi_cpp *cpp, const struct psi_token *file, unsigned flags, char *path);
71 bool psi_cpp_include(struct psi_cpp *cpp, const struct psi_token *file, unsigned flags);
72
73 bool psi_cpp_pragma(struct psi_cpp *cpp, struct psi_cpp_macro_decl *decl);
74
75 void psi_cpp_tokiter_reset(struct psi_cpp *cpp);
76 bool psi_cpp_tokiter_seek(struct psi_cpp *cpp, size_t index);
77 #if PSI_CPP_DEBUG > 1
78 void psi_cpp_tokiter_dump(struct psi_dump *dump, struct psi_cpp *cpp);
79 #endif
80 struct psi_token *psi_cpp_tokiter_current(struct psi_cpp *cpp);
81 size_t psi_cpp_tokiter_index(struct psi_cpp *cpp);
82 void psi_cpp_tokiter_next(struct psi_cpp *cpp);
83 void psi_cpp_tokiter_prev(struct psi_cpp *cpp);
84 bool psi_cpp_tokiter_valid(struct psi_cpp *cpp);
85 bool psi_cpp_tokiter_del_cur(struct psi_cpp *cpp, bool free_token);
86 bool psi_cpp_tokiter_del_prev(struct psi_cpp *cpp, bool free_token);
87 bool psi_cpp_tokiter_del_range(struct psi_cpp *cpp, size_t offset,
88 size_t num_eles, bool free_tokens);
89 bool psi_cpp_tokiter_add(struct psi_cpp *cpp, struct psi_token *tok);
90 bool psi_cpp_tokiter_add_cur(struct psi_cpp *cpp);
91 bool psi_cpp_tokiter_add_range(struct psi_cpp *cpp,
92 size_t num_eles, void **eles);
93 bool psi_cpp_tokiter_ins_range(struct psi_cpp *cpp,
94 size_t num_eles, void **eles);
95 bool psi_cpp_tokiter_defined(struct psi_cpp *cpp);
96 bool psi_cpp_tokiter_expand(struct psi_cpp *cpp);
97
98 #endif