]>
git.saurik.com Git - cycript.git/blob - sig/copy.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2012 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
26 #include <apr_strings.h>
27 #include "Pooling.hpp"
28 #include "sig/parse.hpp"
38 void Copy(apr_pool_t
*pool
, Element
&lhs
, Element
&rhs
) {
39 lhs
.name
= apr_pstrdup(pool
, rhs
.name
);
43 lhs
.type
= new(pool
) Type
;
44 Copy(pool
, *lhs
.type
, *rhs
.type
);
46 lhs
.offset
= rhs
.offset
;
49 void Copy(apr_pool_t
*pool
, Signature
&lhs
, Signature
&rhs
) {
50 size_t count(rhs
.count
);
52 lhs
.elements
= new(pool
) Element
[count
];
53 for (size_t index(0); index
!= count
; ++index
)
54 Copy(pool
, lhs
.elements
[index
], rhs
.elements
[index
]);
57 void Copy(apr_pool_t
*pool
, Type
&lhs
, Type
&rhs
) {
58 lhs
.primitive
= rhs
.primitive
;
59 lhs
.name
= apr_pstrdup(pool
, rhs
.name
);
60 lhs
.flags
= rhs
.flags
;
62 if (sig::IsAggregate(rhs
.primitive
))
63 Copy(pool
, lhs
.data
.signature
, rhs
.data
.signature
);
65 sig::Type
*&lht(lhs
.data
.data
.type
);
66 sig::Type
*&rht(rhs
.data
.data
.type
);
72 Copy(pool
, *lht
, *rht
);
75 lhs
.data
.data
.size
= rhs
.data
.data
.size
;
79 void Copy(apr_pool_t
*pool
, ffi_type
&lhs
, ffi_type
&rhs
) {
81 lhs
.alignment
= rhs
.alignment
;
83 if (rhs
.elements
== NULL
)
87 while (rhs
.elements
[count
] != NULL
)
90 lhs
.elements
= new(pool
) ffi_type
*[count
+ 1];
91 lhs
.elements
[count
] = NULL
;
93 for (size_t index(0); index
!= count
; ++index
) {
94 // XXX: if these are libffi native then you can just take them
95 ffi_type
*ffi(new(pool
) ffi_type
);
96 lhs
.elements
[index
] = ffi
;
97 sig::Copy(pool
, *ffi
, *rhs
.elements
[index
]);