num_exp: RPN calculator
[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/layout.h"
64
65 static inline impl_val *deref_impl_val(impl_val *ret_val, struct psi_decl_var *var) {
66 unsigned i;
67
68 ZEND_ASSERT(!var->arg || var->arg->var != var);
69 #if 0
70 fprintf(stderr, "deref: %s pl=%u:%u as=%u:%u %p\n",
71 var->name, var->pointer_level, var->arg->var->pointer_level,
72 var->array_size, var->arg->var->array_size, ret_val);
73 #endif
74 for (i = 0; i < var->pointer_level; ++i) {
75 #if 0
76 fprintf(stderr, "-- %p %p %p\n", ret_val, *(void**)ret_val, ret_val->ptr);
77 #endif
78 ret_val = *(void **) ret_val;
79 }
80 return ret_val;
81 }
82
83 static inline impl_val *enref_impl_val(void *ptr, struct psi_decl_var *var) {
84 impl_val *val, *val_ptr;
85 unsigned i;
86
87 ZEND_ASSERT(var->arg->var == var);
88 #if 0
89 fprintf(stderr, "enref: %s pl=%u:%u as=%u:%u\n",
90 var->name, var->pointer_level, var->arg->var->pointer_level,
91 var->array_size, var->arg->var->array_size);
92 #endif
93 if (!var->pointer_level ){//&& real_decl_type(var->arg->type)->type != PSI_T_STRUCT) {
94 return ptr;
95 }
96
97 val = val_ptr = calloc(var->pointer_level + 1, sizeof(void *));
98 for (i = !var->arg->var->array_size; i < var->pointer_level; ++i) {
99 #if 0
100 fprintf(stderr, "++\n");
101 #endif
102 val_ptr->ptr = (void **) val_ptr + 1;
103 val_ptr = val_ptr->ptr;
104 }
105 val_ptr->ptr = ptr;
106 return val;
107 }
108
109 static inline impl_val *struct_member_ref(struct psi_decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) {
110 void *ptr = (char *) struct_ptr + set_arg->layout->pos;
111 #if 0
112 fprintf(stderr, "struct member %s: %p\n", set_arg->var->name, ptr);
113 #endif
114 return ptr;
115 }
116
117 #endif