]> git.saurik.com Git - cycript.git/blob - sig/copy.cpp
Fix compilation errors using gcc from Android NDK.
[cycript.git] / sig / copy.cpp
1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef _GNU_SOURCE
23 #define _GNU_SOURCE
24 #endif
25
26 #include "Pooling.hpp"
27 #include "sig/parse.hpp"
28
29 namespace sig {
30
31 void Copy(CYPool &pool, Element &lhs, const Element &rhs) {
32 lhs.name = pool.strdup(rhs.name);
33 if (rhs.type == NULL)
34 lhs.type = NULL;
35 else
36 lhs.type = rhs.type->Copy(pool);
37 lhs.offset = rhs.offset;
38 }
39
40 void Copy(CYPool &pool, Signature &lhs, const Signature &rhs) {
41 size_t count(rhs.count);
42 lhs.count = count;
43 lhs.elements = new(pool) Element[count];
44 for (size_t index(0); index != count; ++index)
45 Copy(pool, lhs.elements[index], rhs.elements[index]);
46 }
47
48 Void *Void::Copy(CYPool &pool, const char *rename) const {
49 return new(pool) Void();
50 }
51
52 Unknown *Unknown::Copy(CYPool &pool, const char *rename) const {
53 return new(pool) Unknown();
54 }
55
56 String *String::Copy(CYPool &pool, const char *rename) const {
57 return new(pool) String();
58 }
59
60 #ifdef CY_OBJECTIVEC
61 Meta *Meta::Copy(CYPool &pool, const char *rename) const {
62 return new(pool) Meta();
63 }
64
65 Selector *Selector::Copy(CYPool &pool, const char *rename) const {
66 return new(pool) Selector();
67 }
68 #endif
69
70 Bits *Bits::Copy(CYPool &pool, const char *rename) const {
71 return new(pool) Bits(size);
72 }
73
74 Pointer *Pointer::Copy(CYPool &pool, const char *rename) const {
75 return new(pool) Pointer(*type.Copy(pool));
76 }
77
78 Array *Array::Copy(CYPool &pool, const char *rename) const {
79 return new(pool) Array(*type.Copy(pool), size);
80 }
81
82 #ifdef CY_OBJECTIVEC
83 Object *Object::Copy(CYPool &pool, const char *rename) const {
84 return new(pool) Object(pool.strdup(name));
85 }
86 #endif
87
88 Aggregate *Aggregate::Copy(CYPool &pool, const char *rename) const {
89 Aggregate *copy(new(pool) Aggregate(overlap, rename ?: pool.strdup(name)));
90 sig::Copy(pool, copy->signature, signature);
91 return copy;
92 }
93
94 Function *Function::Copy(CYPool &pool, const char *rename) const {
95 Function *copy(new(pool) Function(variadic));
96 sig::Copy(pool, copy->signature, signature);
97 return copy;
98 }
99
100 #ifdef CY_OBJECTIVEC
101 Block *Block::Copy(CYPool &pool, const char *rename) const {
102 Block *copy(new(pool) Block());
103 sig::Copy(pool, copy->signature, signature);
104 return copy;
105 }
106 #endif
107
108 void Copy(CYPool &pool, ffi_type &lhs, ffi_type &rhs) {
109 lhs.size = rhs.size;
110 lhs.alignment = rhs.alignment;
111 lhs.type = rhs.type;
112 if (rhs.elements == NULL)
113 lhs.elements = NULL;
114 else {
115 size_t count(0);
116 while (rhs.elements[count] != NULL)
117 ++count;
118
119 lhs.elements = new(pool) ffi_type *[count + 1];
120 lhs.elements[count] = NULL;
121
122 for (size_t index(0); index != count; ++index) {
123 // XXX: if these are libffi native then you can just take them
124 ffi_type *ffi(new(pool) ffi_type);
125 lhs.elements[index] = ffi;
126 sig::Copy(pool, *ffi, *rhs.elements[index]);
127 }
128 }
129 }
130
131 const char *Type::GetName() const {
132 return NULL;
133 }
134
135 const char *Aggregate::GetName() const {
136 return name;
137 }
138
139 }