]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
3c1c3635 JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
3c1c3635 | 6 | /* |
f95d2598 JF |
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 | |
c15969fd | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
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/>. | |
b3378a02 | 19 | **/ |
3c1c3635 JF |
20 | /* }}} */ |
21 | ||
22 | #ifndef _GNU_SOURCE | |
23 | #define _GNU_SOURCE | |
24 | #endif | |
25 | ||
3c1c3635 JF |
26 | #include "Pooling.hpp" |
27 | #include "sig/parse.hpp" | |
b128dfee | 28 | |
3c1c3635 JF |
29 | namespace sig { |
30 | ||
84aef9a7 | 31 | void Copy(CYPool &pool, Element &lhs, const Element &rhs) { |
b799113b | 32 | lhs.name = pool.strdup(rhs.name); |
3c1c3635 JF |
33 | if (rhs.type == NULL) |
34 | lhs.type = NULL; | |
0559abf8 JF |
35 | else |
36 | lhs.type = rhs.type->Copy(pool); | |
3c1c3635 JF |
37 | lhs.offset = rhs.offset; |
38 | } | |
39 | ||
84aef9a7 | 40 | void Copy(CYPool &pool, Signature &lhs, const Signature &rhs) { |
3c1c3635 JF |
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 | ||
a109809e | 48 | Void *Void::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
49 | return new(pool) Void(); |
50 | } | |
3c1c3635 | 51 | |
a109809e | 52 | Unknown *Unknown::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
53 | return new(pool) Unknown(); |
54 | } | |
3c1c3635 | 55 | |
a109809e | 56 | String *String::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
57 | return new(pool) String(); |
58 | } | |
59 | ||
a109809e | 60 | Meta *Meta::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
61 | return new(pool) Meta(); |
62 | } | |
63 | ||
a109809e | 64 | Selector *Selector::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
65 | return new(pool) Selector(); |
66 | } | |
67 | ||
a109809e | 68 | Bits *Bits::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
69 | return new(pool) Bits(size); |
70 | } | |
71 | ||
a109809e | 72 | Pointer *Pointer::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
73 | return new(pool) Pointer(*type.Copy(pool)); |
74 | } | |
75 | ||
a109809e | 76 | Array *Array::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
77 | return new(pool) Array(*type.Copy(pool), size); |
78 | } | |
79 | ||
a109809e JF |
80 | Object *Object::Copy(CYPool &pool, const char *rename) const { |
81 | return new(pool) Object(pool.strdup(name)); | |
0559abf8 JF |
82 | } |
83 | ||
a109809e JF |
84 | Aggregate *Aggregate::Copy(CYPool &pool, const char *rename) const { |
85 | Aggregate *copy(new(pool) Aggregate(overlap, rename ?: pool.strdup(name))); | |
0559abf8 | 86 | sig::Copy(pool, copy->signature, signature); |
0559abf8 JF |
87 | return copy; |
88 | } | |
89 | ||
a109809e | 90 | Function *Function::Copy(CYPool &pool, const char *rename) const { |
574d4720 | 91 | Function *copy(new(pool) Function(variadic)); |
0559abf8 JF |
92 | sig::Copy(pool, copy->signature, signature); |
93 | return copy; | |
94 | } | |
95 | ||
a109809e | 96 | Block *Block::Copy(CYPool &pool, const char *rename) const { |
0559abf8 JF |
97 | Block *copy(new(pool) Block()); |
98 | sig::Copy(pool, copy->signature, signature); | |
99 | return copy; | |
3c1c3635 JF |
100 | } |
101 | ||
b799113b | 102 | void Copy(CYPool &pool, ffi_type &lhs, ffi_type &rhs) { |
3c1c3635 JF |
103 | lhs.size = rhs.size; |
104 | lhs.alignment = rhs.alignment; | |
105 | lhs.type = rhs.type; | |
106 | if (rhs.elements == NULL) | |
107 | lhs.elements = NULL; | |
108 | else { | |
109 | size_t count(0); | |
110 | while (rhs.elements[count] != NULL) | |
111 | ++count; | |
112 | ||
113 | lhs.elements = new(pool) ffi_type *[count + 1]; | |
114 | lhs.elements[count] = NULL; | |
115 | ||
116 | for (size_t index(0); index != count; ++index) { | |
117 | // XXX: if these are libffi native then you can just take them | |
118 | ffi_type *ffi(new(pool) ffi_type); | |
119 | lhs.elements[index] = ffi; | |
120 | sig::Copy(pool, *ffi, *rhs.elements[index]); | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
0559abf8 JF |
125 | const char *Type::GetName() const { |
126 | return NULL; | |
127 | } | |
128 | ||
0559abf8 JF |
129 | const char *Aggregate::GetName() const { |
130 | return name; | |
131 | } | |
132 | ||
3c1c3635 | 133 | } |