extvar: skip decl registration
[m6w6/ext-psi] / src / validate.h
1 /*******************************************************************************
2 Copyright (c) 2017, 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_VALIDATE_H
27 #define PSI_VALIDATE_H
28
29 struct psi_data;
30
31 struct psi_validate_scope {
32 HashTable *defs;
33 HashTable types;
34 HashTable structs;
35 HashTable unions;
36 struct psi_impl *impl;
37 struct psi_decl *cb_decl;
38 struct psi_cpp_macro_decl *macro;
39 struct psi_let_exp *current_let;
40 struct psi_set_exp *current_set;
41 struct psi_decl_enum *current_enum;
42 };
43
44 bool psi_validate(struct psi_validate_scope *scope, struct psi_data *dst,
45 struct psi_data *src);
46
47 static inline void psi_validate_scope_ctor(struct psi_validate_scope *scope)
48 {
49 zend_hash_init(&scope->types, 0, NULL, NULL, 0);
50 zend_hash_init(&scope->structs, 0, NULL, NULL, 0);
51 zend_hash_init(&scope->unions, 0, NULL, NULL, 0);
52 }
53
54 static inline void psi_validate_scope_dtor(struct psi_validate_scope *scope)
55 {
56 zend_hash_destroy(&scope->types);
57 zend_hash_destroy(&scope->structs);
58 zend_hash_destroy(&scope->unions);
59 }
60
61 #define psi_validate_scope_has_type(s, t) \
62 ((s) ? zend_hash_str_exists(&(s)->types, (t), strlen(t)) : false)
63 #define psi_validate_scope_has_struct(s, t) \
64 ((s) ? zend_hash_str_exists(&(s)->structs, (t), strlen(t)) : false)
65 #define psi_validate_scope_has_union(s, t) \
66 ((s) ? zend_hash_str_exists(&(s)->unions, (t), strlen(t)) : false)
67
68 #define psi_validate_scope_add_type(s, t, p) \
69 do { if (s) zend_hash_str_add_ptr(&(s)->types, (t), strlen(t), (p)); } while(0)
70 #define psi_validate_scope_add_struct(s, t, p) \
71 do { if (s) zend_hash_str_add_ptr(&(s)->structs, (t), strlen(t), (p)); } while(0)
72 #define psi_validate_scope_add_union(s, t, p) \
73 do { if (s) zend_hash_str_add_ptr(&(s)->unions, (t), strlen(t), (p)); } while(0)
74
75 #define psi_validate_scope_get_type(s, t) \
76 ((s) ? zend_hash_str_find_ptr(&(s)->types, (t), strlen(t)) : NULL)
77 #define psi_validate_scope_get_struct(s, t) \
78 ((s) ? zend_hash_str_find_ptr(&(s)->structs, (t), strlen(t)) : NULL)
79 #define psi_validate_scope_get_union(s, t) \
80 ((s) ? zend_hash_str_find_ptr(&(s)->unions, (t), strlen(t)) : NULL)
81
82 #define psi_validate_scope_del_type(s, t) \
83 do { if (s) zend_hash_str_del(&(s)->types, (t), strlen(t)); } while(0)
84 #define psi_validate_scope_del_struct(s, t) \
85 do { if (s) zend_hash_str_del(&(s)->structs, (t), strlen(t)); } while(0)
86 #define psi_validate_scope_del_union(s, t) \
87 do { if (s) zend_hash_str_del(&(s)->unions, (t), strlen(t)); } while(0)
88
89
90 #endif /* PSI_VALIDATE_H */