60fdefd2d5e62cc5cd51eaace2a32a9f6a3a1494
[m6w6/ext-psi] / src / types / let_func.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_LET_FUNC_H
27 #define PSI_TYPES_LET_FUNC_H
28
29 #include "token.h"
30
31 struct psi_data;
32 struct psi_impl;
33 struct psi_decl_arg;
34 struct psi_impl_var;
35 struct psi_let_exp;
36 struct psi_call_frame;
37
38 struct psi_let_func {
39 struct psi_token *token;
40 token_t type;
41 char *name;
42 struct psi_impl_var *var;
43 struct psi_plist *inner;
44 };
45
46 struct psi_let_func *psi_let_func_init(token_t type, const char *name, struct psi_impl_var *var);
47 void psi_let_func_free(struct psi_let_func **func_ptr);
48 void psi_let_func_dump(int fd, struct psi_let_func *func, unsigned level);
49
50 void *psi_let_func_exec(struct psi_let_exp *func_val, struct psi_let_func *func, struct psi_decl_arg *darg, struct psi_call_frame *frame);
51 bool psi_let_func_validate(struct psi_data *data, struct psi_let_func *func, struct psi_validate_scope *scope);
52
53 #include "marshal.h"
54
55 static inline psi_marshal_let locate_let_func_fn(token_t type) {
56 psi_marshal_let let_fn;
57
58 switch (type) {
59 case PSI_T_BOOLVAL: let_fn = psi_let_boolval; break;
60 case PSI_T_INTVAL: let_fn = psi_let_intval; break;
61 case PSI_T_FLOATVAL: let_fn = psi_let_floatval; break;
62 case PSI_T_STRVAL: let_fn = psi_let_strval; break;
63 case PSI_T_STRLEN: let_fn = psi_let_strlen; break;
64 case PSI_T_PATHVAL: let_fn = psi_let_pathval; break;
65 case PSI_T_OBJVAL: let_fn = psi_let_objval; break;
66 case PSI_T_ZVAL: let_fn = psi_let_zval; break;
67 case PSI_T_VOID: let_fn = psi_let_void; break;
68 case PSI_T_COUNT: let_fn = psi_let_count; break;
69 default: let_fn = NULL; break;
70 }
71 return let_fn;
72 }
73
74 #endif