types refactoring
[m6w6/ext-psi] / src / types / let_val.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_VAL_H
27 #define PSI_TYPES_LET_VAL_H
28
29 #include "decl_var.h"
30 #include "num_exp.h"
31 #include "let_calloc.h"
32 #include "let_callback.h"
33 #include "let_func.h"
34
35 enum let_val_kind {
36 PSI_LET_NULL,
37 PSI_LET_NUMEXP,
38 PSI_LET_CALLOC,
39 PSI_LET_CALLBACK,
40 PSI_LET_FUNC,
41 PSI_LET_TMP,
42 };
43
44 #define PSI_LET_REFERENCE 0x1;
45
46 typedef struct let_val {
47 enum let_val_kind kind;
48 decl_var *var;
49 union {
50 num_exp *num;
51 let_calloc *alloc;
52 let_callback *callback;
53 let_func *func;
54 decl_var *var;
55 } data;
56 union {
57 struct {
58 unsigned is_reference:1;
59 } one;
60 unsigned all;
61 } flags;
62 } let_val;
63
64 let_val* init_let_val(enum let_val_kind kind, void* data);
65 void free_let_val(let_val* let);
66 void dump_let_val(int fd, let_val *val, unsigned level, int last);
67
68 struct psi_data;
69 struct impl;
70
71 int validate_let_val(struct psi_data *data, let_val *val, decl_var *let_var, struct impl *impl);
72
73 static inline decl_arg *locate_let_val_inner_ref(let_val *val) {
74 decl_arg *ref = NULL;
75
76 switch (val->kind) {
77 case PSI_LET_CALLBACK:
78 ref = val->data.callback->func->ref;
79 break;
80 case PSI_LET_FUNC:
81 ref = val->data.func->ref;
82 break;
83 default:
84 break;
85 }
86 return ref;
87 }
88 static inline impl_var *locate_let_val_impl_var(let_val *val) {
89 if (val) {
90 switch (val->kind) {
91 case PSI_LET_CALLBACK:
92 return val->data.callback->func->var;
93 case PSI_LET_FUNC:
94 return val->data.func->var;
95 default:
96 break;
97 }
98 }
99 return NULL;
100 }
101
102 static inline const char *locate_let_val_varname(let_val *val) {
103 impl_var *var = locate_let_val_impl_var(val);
104
105 if (var) {
106 return &var->name[1];
107 }
108 return NULL;
109 }
110
111 #endif