raising the head after a three-weeks refactoring
[m6w6/ext-psi] / src / types / impl_var.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_IMPL_VAR_H
27 #define PSI_TYPES_IMPL_VAR_H
28
29 struct psi_token;
30 struct psi_impl;
31 struct psi_impl_arg;
32
33 struct psi_impl_var {
34 struct psi_token *token;
35 char *name, *fqn;
36 struct psi_impl_arg *arg;
37 unsigned reference:1;
38 };
39
40 struct psi_impl_var *psi_impl_var_init(const char *name, bool is_reference);
41 struct psi_impl_var *psi_impl_var_copy(struct psi_impl_var *var);
42 void psi_impl_var_free(struct psi_impl_var **var_ptr);
43
44 #include <string.h>
45
46 static inline char *psi_impl_var_name_prepend(char *current, const char *prepend) {
47 size_t c_len = strlen(current);
48 size_t p_len = strlen(prepend);
49
50 current = realloc(current, p_len
51 + c_len // includes '$'
52 + 1 // connecting dot
53 + 1 // terminating 0
54 );
55 if (current) {
56 if (c_len > 1) {
57 memmove(current + p_len + 1 + 1, current + 1, c_len - 1 + 1);
58 current[p_len + 1] = '.';
59 } else {
60 /* just '$' */
61 current[p_len + 1] = '\0';
62 }
63 memcpy(current + 1, prepend, p_len);
64 }
65 return current;
66 }
67
68 bool psi_impl_var_validate(struct psi_data *data, struct psi_impl_var *ivar, struct psi_impl *impl,
69 struct psi_let_exp *current_let_exp, struct psi_set_exp *current_set_exp);
70
71 #endif