1 /* Marshalling and unmarshalling of C++-specific types.
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef CC1_PLUGIN_MARSHALL_CXX_HH
21 #define CC1_PLUGIN_MARSHALL_CXX_HH
23 #include "marshall.hh"
24 #include "gcc-cp-interface.h"
30 struct deleter
<gcc_vbase_array
>
32 void operator() (gcc_vbase_array
*p
)
41 struct deleter
<gcc_cp_template_args
>
43 void operator() (gcc_cp_template_args
*p
)
52 struct deleter
<gcc_cp_function_args
>
54 void operator() (gcc_cp_function_args
*p
)
61 // Send a gcc_vbase_array marker followed by the array.
63 marshall (connection
*conn
, const gcc_vbase_array
*a
)
72 if (!marshall_array_start (conn
, 'v', len
))
78 if (!marshall_array_elmts (conn
, len
* sizeof (a
->elements
[0]),
82 return marshall_array_elmts (conn
, len
* sizeof (a
->flags
[0]),
86 // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
87 // resulting array must be freed by the caller, using 'delete[]' on
88 // elements and virtualp, and 'delete' on the array object itself.
90 unmarshall (connection
*conn
, struct gcc_vbase_array
**result
)
94 if (!unmarshall_array_start (conn
, 'v', &len
))
97 if (len
== (size_t)-1)
103 cc1_plugin::unique_ptr
<gcc_vbase_array
> gva (new gcc_vbase_array
{});
105 gva
->n_elements
= len
;
106 gva
->elements
= new gcc_type
[len
];
108 if (!unmarshall_array_elmts (conn
,
109 len
* sizeof (gva
->elements
[0]),
113 gva
->flags
= new enum gcc_cp_symbol_kind
[len
];
115 if (!unmarshall_array_elmts (conn
,
116 len
* sizeof (gva
->flags
[0]),
120 *result
= gva
.release ();
124 // Send a gcc_cp_template_args marker followed by the array.
126 marshall (connection
*conn
, const gcc_cp_template_args
*a
)
135 if (!marshall_array_start (conn
, 't', len
))
141 if (!marshall_array_elmts (conn
, len
* sizeof (a
->kinds
[0]),
145 return marshall_array_elmts (conn
, len
* sizeof (a
->elements
[0]),
149 // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
150 // resulting array must be freed by the caller, using 'delete[]' on
151 // elements and virtualp, and 'delete' on the array object itself.
153 unmarshall (connection
*conn
, struct gcc_cp_template_args
**result
)
157 if (!unmarshall_array_start (conn
, 't', &len
))
160 if (len
== (size_t)-1)
166 cc1_plugin::unique_ptr
<gcc_cp_template_args
> gva
167 (new gcc_cp_template_args
{});
169 gva
->n_elements
= len
;
170 gva
->kinds
= new char[len
];
172 if (!unmarshall_array_elmts (conn
,
173 len
* sizeof (gva
->kinds
[0]),
177 gva
->elements
= new gcc_cp_template_arg
[len
];
179 if (!unmarshall_array_elmts (conn
,
180 len
* sizeof (gva
->elements
[0]),
184 *result
= gva
.release ();
188 // Send a gcc_cp_function_args marker followed by the array.
190 marshall (connection
*conn
, const gcc_cp_function_args
*a
)
199 if (!marshall_array_start (conn
, 'd', len
))
205 return marshall_array_elmts (conn
, len
* sizeof (a
->elements
[0]),
209 // Read a gcc_cp_function_args marker, followed by a
210 // gcc_cp_function_args. The resulting array must be freed
211 // by the caller, using 'delete[]' on elements and virtualp, and
212 // 'delete' on the array object itself.
214 unmarshall (connection
*conn
, struct gcc_cp_function_args
**result
)
218 if (!unmarshall_array_start (conn
, 'd', &len
))
221 if (len
== (size_t)-1)
227 cc1_plugin::unique_ptr
<gcc_cp_function_args
> gva
228 (new gcc_cp_function_args
{});
230 gva
->n_elements
= len
;
231 gva
->elements
= new gcc_expr
[len
];
233 if (!unmarshall_array_elmts (conn
,
234 len
* sizeof (gva
->elements
[0]),
238 *result
= gva
.release ();
244 #endif // CC1_PLUGIN_MARSHALL_CP_HH