efc7cea43c979999eac8256b6a88a7b1aff94129
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
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.
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 *******************************************************************************/
29 # include "php_config.h"
37 void *add_impl_stmt_ex(void *list
, size_t count
, void *stmt
) {
38 list
= realloc(list
, count
* sizeof(list
));
39 ((void**) list
)[count
- 1] = stmt
;
43 impl_stmts
*add_impl_stmt(impl_stmts
*stmts
, impl_stmt
*stmt
) {
46 stmts
->ret
.list
= add_impl_stmt_ex(stmts
->ret
.list
, ++stmts
->ret
.count
,
50 stmts
->let
.list
= add_impl_stmt_ex(stmts
->let
.list
, ++stmts
->let
.count
,
54 stmts
->set
.list
= add_impl_stmt_ex(stmts
->set
.list
, ++stmts
->set
.count
,
58 stmts
->fre
.list
= add_impl_stmt_ex(stmts
->fre
.list
, ++stmts
->fre
.count
,
66 impl_stmts
*init_impl_stmts(impl_stmt
*stmt
) {
67 impl_stmts
*stmts
= calloc(1, sizeof(*stmts
));
68 return add_impl_stmt(stmts
, stmt
);
71 void free_impl_stmts(impl_stmts
*stmts
) {
73 for (i
= 0; i
< stmts
->let
.count
; ++i
) {
74 free_let_stmt(stmts
->let
.list
[i
]);
76 free(stmts
->let
.list
);
77 for (i
= 0; i
< stmts
->ret
.count
; ++i
) {
78 free_return_stmt(stmts
->ret
.list
[i
]);
80 free(stmts
->ret
.list
);
81 for (i
= 0; i
< stmts
->set
.count
; ++i
) {
82 free_set_stmt(stmts
->set
.list
[i
]);
84 free(stmts
->set
.list
);
85 for (i
= 0; i
< stmts
->fre
.count
; ++i
) {
86 free_free_stmt(stmts
->fre
.list
[i
]);
88 free(stmts
->fre
.list
);
92 void dump_impl_stmts(int fd
, impl_stmts
*stmts
) {
95 for (j
= 0; j
< stmts
->let
.count
; ++j
) {
96 let_stmt
*let
= stmts
->let
.list
[j
];
97 dump_let_stmt(fd
, let
);
100 for (j
= 0; j
< stmts
->ret
.count
; ++j
) {
101 return_stmt
*ret
= stmts
->ret
.list
[j
];
102 dump_return_stmt(fd
, ret
);
105 for (j
= 0; j
< stmts
->set
.count
; ++j
) {
106 set_stmt
*set
= stmts
->set
.list
[j
];
108 dump_set_stmt(fd
, set
);
111 for (j
= 0; j
< stmts
->fre
.count
; ++j
) {
112 free_stmt
*fre
= stmts
->fre
.list
[j
];
114 dump_free_stmt(fd
, fre
);
119 int validate_impl_stmts(struct psi_data
*data
, impl
*impl
) {
121 data
->error(data
, impl
->func
->token
, PSI_WARNING
,
122 "Missing body for implementation %s!",
127 if (!validate_return_stmt(data
, impl
)) {
131 if (!validate_let_stmts(data
, impl
)) {
134 if (!validate_set_stmts(data
, impl
)) {
137 if (!validate_free_stmts(data
, impl
)) {