api refactoring
[m6w6/ext-psi] / src / types.h
1 #ifndef _PSI_TYPES_H
2 #define _PSI_TYPES_H
3
4 #include "Zend/zend_API.h"
5 typedef struct zend_fcall {
6 zend_fcall_info fci;
7 zend_fcall_info_cache fcc;
8 } zend_fcall;
9
10 #include "token.h"
11
12 #include "types/impl_val.h"
13 #include "types/decl_type.h"
14 #include "types/decl_var.h"
15 #include "types/decl_struct_layout.h"
16 #include "types/decl_arg.h"
17 #include "types/decl_typedefs.h"
18 #include "types/decl_vars.h"
19 #include "types/decl_args.h"
20 #include "types/decl_abi.h"
21 #include "types/decl_callinfo.h"
22 #include "types/decl.h"
23 #include "types/decls.h"
24 #include "types/decl_struct.h"
25 #include "types/decl_structs.h"
26 #include "types/decl_union.h"
27 #include "types/decl_unions.h"
28 #include "types/impl_type.h"
29 #include "types/impl_var.h"
30 #include "types/impl_def_val.h"
31 #include "types/const_type.h"
32 #include "types/constant.h"
33 #include "types/constants.h"
34 #include "types/impl_arg.h"
35 #include "types/impl_args.h"
36 #include "types/impl_func.h"
37 #include "types/num_exp.h"
38 #include "types/decl_enum_item.h"
39 #include "types/decl_enum_items.h"
40 #include "types/decl_enum.h"
41 #include "types/decl_enums.h"
42 #include "types/let_calloc.h"
43 #include "types/let_callback.h"
44 #include "types/let_func.h"
45 #include "types/let_val.h"
46 #include "types/let_stmt.h"
47 #include "types/set_func.h"
48 #include "types/set_value.h"
49 #include "types/set_values.h"
50 #include "types/set_stmt.h"
51 #include "types/return_stmt.h"
52 #include "types/free_call.h"
53 #include "types/free_calls.h"
54 #include "types/free_stmt.h"
55 #include "types/impl_stmt.h"
56 #include "types/impl_stmts.h"
57 #include "types/impl.h"
58 #include "types/impls.h"
59 #include "types/decl_file.h"
60 #include "types/decl_libs.h"
61
62
63 static inline int weak_decl_type(decl_type *type) {
64 switch (type->type) {
65 case PSI_T_CHAR:
66 case PSI_T_SHORT:
67 case PSI_T_INT:
68 case PSI_T_LONG:
69 case PSI_T_NAME:
70 return type->type;
71 default:
72 return 0;
73 }
74 }
75
76 static inline decl_type *real_decl_type(decl_type *type) {
77 while (weak_decl_type(type)) {
78 type = type->real.def->type;
79 }
80 return type;
81 }
82
83 static inline impl_val *deref_impl_val(impl_val *ret_val, decl_var *var) {
84 unsigned i;
85
86 ZEND_ASSERT(var->arg->var != var);
87 #if 0
88 fprintf(stderr, "deref: %s pl=%u:%u as=%u:%u %p\n",
89 var->name, var->pointer_level, var->arg->var->pointer_level,
90 var->array_size, var->arg->var->array_size, ret_val);
91 #endif
92 for (i = 0; i < var->pointer_level; ++i) {
93 #if 0
94 fprintf(stderr, "-- %p %p %p\n", ret_val, *(void**)ret_val, ret_val->ptr);
95 #endif
96 ret_val = *(void **) ret_val;
97 }
98 return ret_val;
99 }
100
101 static inline impl_val *enref_impl_val(void *ptr, decl_var *var) {
102 impl_val *val, *val_ptr;
103 unsigned i;
104
105 ZEND_ASSERT(var->arg->var == var);
106 #if 0
107 fprintf(stderr, "enref: %s pl=%u:%u as=%u:%u\n",
108 var->name, var->pointer_level, var->arg->var->pointer_level,
109 var->array_size, var->arg->var->array_size);
110 #endif
111 if (!var->pointer_level ){//&& real_decl_type(var->arg->type)->type != PSI_T_STRUCT) {
112 return ptr;
113 }
114
115 val = val_ptr = calloc(var->pointer_level + 1, sizeof(void *));
116 for (i = !var->arg->var->array_size; i < var->pointer_level; ++i) {
117 #if 0
118 fprintf(stderr, "++\n");
119 #endif
120 val_ptr->ptr = (void **) val_ptr + 1;
121 val_ptr = val_ptr->ptr;
122 }
123 val_ptr->ptr = ptr;
124 return val;
125 }
126
127 static inline impl_val *struct_member_ref(decl_arg *set_arg, impl_val *struct_ptr, impl_val **to_free) {
128 void *ptr = (char *) struct_ptr + set_arg->layout->pos;
129 #if 0
130 fprintf(stderr, "struct member %s: %p\n", set_arg->var->name, ptr);
131 #endif
132 return ptr;
133 }
134
135
136 #define PSI_ERROR 16
137 #define PSI_WARNING 32
138 typedef void (*psi_error_cb)(void *context, struct psi_token *token, int type, const char *msg, ...);
139
140 #endif