0df9adbbbca8037add029de607dd616d88473215
[m6w6/ext-psi] / src / types / cpp_macro_call.c
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 #include "php_psi_stdinc.h"
27
28 #include "cpp.h"
29 #include "data.h"
30
31 struct psi_cpp_macro_call *psi_cpp_macro_call_init(const char *name,
32 struct psi_plist *args)
33 {
34 struct psi_cpp_macro_call *call = calloc(1, sizeof(*call));
35 call->name = strdup(name);
36 call->args = args;
37 return call;
38 }
39
40 struct psi_cpp_macro_call *psi_cpp_macro_call_copy(
41 struct psi_cpp_macro_call *call)
42 {
43 struct psi_cpp_macro_call *copy = calloc(1, sizeof(*copy));
44 copy->name = strdup(call->name);
45 if (call->token) {
46 copy->token = psi_token_copy(call->token);
47 }
48 if (call->args) {
49 copy->args = psi_plist_copy(call->args,
50 (void (*)(void*)) psi_token_copy_ctor);
51 }
52 return copy;
53 }
54
55 void psi_cpp_macro_call_free(struct psi_cpp_macro_call **call_ptr)
56 {
57 if (*call_ptr) {
58 struct psi_cpp_macro_call *call = *call_ptr;
59
60 *call_ptr = NULL;
61
62 free(call->name);
63 if (call->args) {
64 psi_plist_free(call->args);
65 }
66 if (call->token) {
67 free(call->token);
68 }
69 free(call);
70 }
71 }
72