gdbinit
[m6w6/ext-psi] / src / call.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_CALL_H
27 #define PSI_CALL_H
28
29 #include "Zend/zend_types.h"
30
31 #include "data.h"
32
33 struct psi_call_frame_symbol {
34 impl_val *ival_ptr; /* marshaled */
35 void *ptr; /* possibly indirect (pointer to ival_ptr) */
36 impl_val temp_val;
37 };
38
39 struct psi_call_frame_argument {
40 impl_val ival; /* input */
41 impl_val temp_val; /* va */
42 impl_val *ival_ptr; /* marshaled, pointer to ival or temp_val */
43 zval *zval_ptr; /* input */
44 struct psi_impl_arg *spec;
45 token_t va_type;
46 };
47
48 struct psi_call_frame_callback {
49 struct psi_let_exp *cb;
50 size_t argc;
51 void **argv;
52 void *rval;
53 };
54
55 struct psi_call_frame_argument *psi_call_frame_argument_init(struct psi_impl_arg *spec, impl_val *ival, zval *zptr, int is_vararg);
56 void psi_call_frame_argument_free(struct psi_call_frame_argument *arg);
57
58 struct psi_call_frame_symbol *psi_call_frame_symbol_init();
59 void psi_call_frame_symbol_free(struct psi_call_frame_symbol *arg);
60
61 struct psi_call_frame {
62 struct psi_context *context;
63 struct psi_decl *decl;
64 struct psi_impl *impl;
65 HashTable arguments;
66 HashTable symbols;
67 void **pointers;
68 void *rpointer;
69 zend_llist temp;
70 };
71
72 struct psi_call_frame *psi_call_frame_init(struct psi_context *context, struct psi_decl *decl, struct psi_impl *impl);
73
74 ZEND_RESULT_CODE psi_call_frame_parse_args(struct psi_call_frame *frame, zend_execute_data *execute_data);
75
76 size_t psi_call_frame_num_var_args(struct psi_call_frame *frame);
77 size_t psi_call_frame_num_fixed_args(struct psi_call_frame *frame);
78
79 zval *psi_call_frame_new_argument(struct psi_call_frame *frame, struct psi_call_frame_argument *frame_arg);
80 zval *psi_call_frame_sub_argument(struct psi_call_frame *frame, struct psi_impl_var *inner_var, zval *outer_zval, const char *name);
81
82 struct psi_call_frame_argument *psi_call_frame_get_argument(struct psi_call_frame *frame, const char *name);
83 struct psi_call_frame_argument *psi_call_frame_get_var_argument(struct psi_call_frame *frame, zend_long index);
84
85 struct psi_call_frame_symbol *psi_call_frame_fetch_symbol(struct psi_call_frame *frame, struct psi_decl_var *dvar);
86
87 void psi_call_frame_enter(struct psi_call_frame *frame);
88
89 struct psi_context *psi_call_frame_get_context(struct psi_call_frame *frame);
90 struct psi_decl *psi_call_frame_get_decl(struct psi_call_frame *frame);
91 struct psi_impl *psi_call_frame_get_impl(struct psi_call_frame *frame);
92 void **psi_call_frame_get_arg_pointers(struct psi_call_frame *frame);
93 void *psi_call_frame_get_rpointer(struct psi_call_frame *frame);
94
95 ZEND_RESULT_CODE psi_call_frame_do_let(struct psi_call_frame *frame);
96 ZEND_RESULT_CODE psi_call_frame_do_assert(struct psi_call_frame *frame, enum psi_assert_kind kind);
97 void psi_call_frame_do_call(struct psi_call_frame *frame);
98 void psi_call_frame_do_callback(struct psi_call_frame *frame, struct psi_call_frame_callback *cb);
99 void psi_call_frame_do_return(struct psi_call_frame *frame, zval *return_value);
100 void psi_call_frame_do_set(struct psi_call_frame *frame);
101 void psi_call_frame_do_free(struct psi_call_frame *frame);
102
103 void **psi_call_frame_push_auto_ex(struct psi_call_frame *frame, void *auto_free, void (*dtor)(void*));
104 void **psi_call_frame_push_auto(struct psi_call_frame *frame, void *auto_free);
105
106 void psi_call_frame_free(struct psi_call_frame *frame);
107
108 #endif