parser: fix parsing escaped characters
[m6w6/ext-psi] / src / types.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_TYPES_H
27 #define PSI_TYPES_H
28
29 #include "token.h"
30 #include "types/impl_val.h"
31 #include "types/decl_type.h"
32 #include "types/decl_var.h"
33 #include "types/decl_arg.h"
34 #include "types/decl_abi.h"
35 #include "types/decl.h"
36 #include "types/decl_struct.h"
37 #include "types/decl_union.h"
38 #include "types/impl_type.h"
39 #include "types/impl_var.h"
40 #include "types/impl_def_val.h"
41 #include "types/const_type.h"
42 #include "types/const.h"
43 #include "types/impl_arg.h"
44 #include "types/impl_func.h"
45 #include "types/number.h"
46 #include "types/num_exp.h"
47 #include "types/decl_enum_item.h"
48 #include "types/decl_enum.h"
49 #include "types/let_calloc.h"
50 #include "types/let_callback.h"
51 #include "types/let_func.h"
52 #include "types/let_exp.h"
53 #include "types/let_stmt.h"
54 #include "types/set_func.h"
55 #include "types/set_exp.h"
56 #include "types/set_stmt.h"
57 #include "types/return_stmt.h"
58 #include "types/free_stmt.h"
59 #include "types/impl.h"
60 #include "types/decl_file.h"
61 #include "types/free_exp.h"
62 #include "types/free_stmt.h"
63 #include "types/assert_stmt.h"
64 #include "types/layout.h"
65 #include "types/cpp_exp.h"
66 #include "types/cpp_macro_call.h"
67 #include "types/cpp_macro_decl.h"
68
69 static inline impl_val *deref_impl_val(impl_val *ret_val, struct psi_decl_var *var) {
70 unsigned i;
71
72 ZEND_ASSERT(!var->arg || var->arg->var != var);
73 #if 0
74 fprintf(stderr, "deref: %s pl=%u:%u as=%u:%u %p\n",
75 var->name, var->pointer_level, var->arg->var->pointer_level,
76 var->array_size, var->arg->var->array_size, ret_val);
77 #endif
78 for (i = 0; i < var->pointer_level; ++i) {
79 #if 0
80 fprintf(stderr, "-- %p %p %p\n", ret_val, *(void**)ret_val, ret_val->ptr);
81 #endif
82 ret_val = *(void **) ret_val;
83 }
84 return ret_val;
85 }
86
87 static inline impl_val *enref_impl_val(void *ptr, struct psi_decl_var *var) {
88 impl_val *val, *val_ptr;
89 unsigned i;
90
91 ZEND_ASSERT(var->arg->var == var);
92 #if 0
93 fprintf(stderr, "enref: %s pl=%u:%u as=%u:%u\n",
94 var->name, var->pointer_level, var->arg->var->pointer_level,
95 var->array_size, var->arg->var->array_size);
96 #endif
97 if (!var->pointer_level ){//&& real_decl_type(var->arg->type)->type != PSI_T_STRUCT) {
98 return ptr;
99 }
100
101 val = calloc(var->pointer_level + 1, sizeof(void *));
102 val_ptr = val;
103 for (i = !var->arg->var->array_size; i < var->pointer_level; ++i) {
104 #if 0
105 fprintf(stderr, "++\n");
106 #endif
107 val_ptr->ptr = (void **) val_ptr + 1;
108 val_ptr = val_ptr->ptr;
109 }
110 val_ptr->ptr = ptr;
111 return val;
112 }
113
114 static inline impl_val *struct_member_ref(struct psi_decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) {
115 void *ptr = (char *) struct_ptr + set_arg->layout->pos;
116 #if 0
117 fprintf(stderr, "struct member %s: %p\n", set_arg->var->name, ptr);
118 #endif
119 return ptr;
120 }
121
122 #endif