fix tests
[m6w6/ext-psi] / src / data.h
1 /*******************************************************************************
2 Copyright (c) 2016, 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_DATA_H
27 #define PSI_DATA_H
28
29 #include "types.h"
30 #include "error.h"
31 #include "plist.h"
32 #include "validate.h"
33
34 #define PSI_DEBUG 0x1
35 #define PSI_SILENT 0x2
36
37 #include <stdarg.h>
38
39 #define PSI_DEBUG_PRINT(ctx, msg, ...) do { \
40 if ((ctx) && (PSI_DATA(ctx)->flags & PSI_DEBUG)) { \
41 fprintf(stderr, msg, __VA_ARGS__); \
42 } \
43 } while(0)
44
45
46 #define PSI_DATA(D) ((struct psi_data *) (D))
47
48 #define PSI_DATA_MEMBERS \
49 struct psi_decl_file file; \
50 struct psi_plist *consts; \
51 struct psi_plist *types; \
52 struct psi_plist *structs; \
53 struct psi_plist *unions; \
54 struct psi_plist *enums; \
55 struct psi_plist *decls; \
56 struct psi_plist *vars; \
57 struct psi_plist *impls; \
58 psi_error_cb error; \
59 char last_error[0x1000]; \
60 unsigned errors; \
61 unsigned flags
62
63 struct psi_data {
64 PSI_DATA_MEMBERS;
65 };
66
67 struct psi_data *psi_data_ctor(struct psi_data *data, psi_error_cb error, unsigned flags);
68 struct psi_data *psi_data_ctor_with_dtors(struct psi_data *data, psi_error_cb error, unsigned flags);
69 struct psi_data *psi_data_exchange(struct psi_data *dest, struct psi_data *src);
70 void psi_data_dtor(struct psi_data *data);
71 void psi_data_dump(int fd, struct psi_data *data);
72
73 #endif