]>
git.saurik.com Git - cycript.git/blob - sig/copy.cpp
cdb2f4c08516ead29d4d79e7439af6d4da3e68ed
   1 /* Cycript - Optimizing JavaScript Compiler/Runtime 
   2  * Copyright (C) 2009-2014  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" 
  37 void Copy(CYPool 
&pool
, Element 
&lhs
, const Element 
&rhs
) { 
  38     lhs
.name 
= pool
.strdup(rhs
.name
); 
  42         lhs
.type 
= new(pool
) Type
; 
  43         Copy(pool
, *lhs
.type
, *rhs
.type
); 
  45     lhs
.offset 
= rhs
.offset
; 
  48 void Copy(CYPool 
&pool
, Signature 
&lhs
, const Signature 
&rhs
) { 
  49     size_t count(rhs
.count
); 
  51     lhs
.elements 
= new(pool
) Element
[count
]; 
  52     for (size_t index(0); index 
!= count
; ++index
) 
  53         Copy(pool
, lhs
.elements
[index
], rhs
.elements
[index
]); 
  56 void Copy(CYPool 
&pool
, Type 
&lhs
, const Type 
&rhs
) { 
  57     lhs
.primitive 
= rhs
.primitive
; 
  58     lhs
.name 
= pool
.strdup(rhs
.name
); 
  59     lhs
.flags 
= rhs
.flags
; 
  61     if (sig::IsFunctional(rhs
.primitive
) || sig::IsAggregate(rhs
.primitive
)) 
  62         Copy(pool
, lhs
.data
.signature
, rhs
.data
.signature
); 
  64         sig::Type 
*&lht(lhs
.data
.data
.type
); 
  65         sig::Type 
*const &rht(rhs
.data
.data
.type
); 
  71             Copy(pool
, *lht
, *rht
); 
  74         lhs
.data
.data
.size 
= rhs
.data
.data
.size
; 
  78 void Copy(CYPool 
&pool
, ffi_type 
&lhs
, ffi_type 
&rhs
) { 
  80     lhs
.alignment 
= rhs
.alignment
; 
  82     if (rhs
.elements 
== NULL
) 
  86         while (rhs
.elements
[count
] != NULL
) 
  89         lhs
.elements 
= new(pool
) ffi_type 
*[count 
+ 1]; 
  90         lhs
.elements
[count
] = NULL
; 
  92         for (size_t index(0); index 
!= count
; ++index
) { 
  93             // XXX: if these are libffi native then you can just take them 
  94             ffi_type 
*ffi(new(pool
) ffi_type
); 
  95             lhs
.elements
[index
] = ffi
; 
  96             sig::Copy(pool
, *ffi
, *rhs
.elements
[index
]);