]>
git.saurik.com Git - cycript.git/blob - sig/copy.cpp
1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
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.
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.
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/>.
26 #include "Pooling.hpp"
27 #include "sig/parse.hpp"
31 void Copy(CYPool
&pool
, Element
&lhs
, const Element
&rhs
) {
32 lhs
.name
= pool
.strdup(rhs
.name
);
36 lhs
.type
= rhs
.type
->Copy(pool
);
37 lhs
.offset
= rhs
.offset
;
40 void Copy(CYPool
&pool
, Signature
&lhs
, const Signature
&rhs
) {
41 size_t count(rhs
.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
]);
48 Void
*Void::Copy(CYPool
&pool
, const char *rename
) const {
49 return new(pool
) Void();
52 Unknown
*Unknown::Copy(CYPool
&pool
, const char *rename
) const {
53 return new(pool
) Unknown();
56 String
*String::Copy(CYPool
&pool
, const char *rename
) const {
57 return new(pool
) String();
61 Meta
*Meta::Copy(CYPool
&pool
, const char *rename
) const {
62 return new(pool
) Meta();
65 Selector
*Selector::Copy(CYPool
&pool
, const char *rename
) const {
66 return new(pool
) Selector();
70 Bits
*Bits::Copy(CYPool
&pool
, const char *rename
) const {
71 return new(pool
) Bits(size
);
74 Pointer
*Pointer::Copy(CYPool
&pool
, const char *rename
) const {
75 return new(pool
) Pointer(*type
.Copy(pool
));
78 Array
*Array::Copy(CYPool
&pool
, const char *rename
) const {
79 return new(pool
) Array(*type
.Copy(pool
), size
);
83 Object
*Object::Copy(CYPool
&pool
, const char *rename
) const {
84 return new(pool
) Object(pool
.strdup(name
));
88 Enum
*Enum::Copy(CYPool
&pool
, const char *rename
) const {
90 rename
= pool
.strdup(name
);
91 else if (rename
[0] == '\0')
93 Enum
*copy(new(pool
) Enum(*type
.Copy(pool
), count
, rename
));
94 copy
->constants
= new(pool
) Constant
[count
];
95 for (size_t i(0); i
!= count
; ++i
) {
96 copy
->constants
[i
].name
= pool
.strdup(constants
[i
].name
);
97 copy
->constants
[i
].value
= constants
[i
].value
;
102 Aggregate
*Aggregate::Copy(CYPool
&pool
, const char *rename
) const {
104 rename
= pool
.strdup(name
);
105 else if (rename
[0] == '\0')
107 Aggregate
*copy(new(pool
) Aggregate(overlap
, rename
));
108 sig::Copy(pool
, copy
->signature
, signature
);
112 Function
*Function::Copy(CYPool
&pool
, const char *rename
) const {
113 Function
*copy(new(pool
) Function(variadic
));
114 sig::Copy(pool
, copy
->signature
, signature
);
119 Block
*Block::Copy(CYPool
&pool
, const char *rename
) const {
120 Block
*copy(new(pool
) Block());
121 sig::Copy(pool
, copy
->signature
, signature
);
126 void Copy(CYPool
&pool
, ffi_type
&lhs
, ffi_type
&rhs
) {
128 lhs
.alignment
= rhs
.alignment
;
130 if (rhs
.elements
== NULL
)
134 while (rhs
.elements
[count
] != NULL
)
137 lhs
.elements
= new(pool
) ffi_type
*[count
+ 1];
138 lhs
.elements
[count
] = NULL
;
140 for (size_t index(0); index
!= count
; ++index
) {
141 // XXX: if these are libffi native then you can just take them
142 ffi_type
*ffi(new(pool
) ffi_type
);
143 lhs
.elements
[index
] = ffi
;
144 sig::Copy(pool
, *ffi
, *rhs
.elements
[index
]);
149 const char *Type::GetName() const {
153 const char *Enum::GetName() const {
157 const char *Aggregate::GetName() const {