Tweak
[official-gcc.git] / libcc1 / marshall-cp.hh
blobeec80f359a6c4e6527c894c0847910e8810cbb38
1 /* Marshalling and unmarshalling of C++-specific types.
2 Copyright (C) 2014-2017 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
9 version.
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
14 for more details.
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"
26 namespace cc1_plugin
28 status
29 unmarshall (connection *conn, enum gcc_cp_symbol_kind *result)
31 protocol_int p;
32 if (!unmarshall_intlike (conn, &p))
33 return FAIL;
34 *result = (enum gcc_cp_symbol_kind) p;
35 return OK;
38 status
39 unmarshall (connection *conn, enum gcc_cp_oracle_request *result)
41 protocol_int p;
42 if (!unmarshall_intlike (conn, &p))
43 return FAIL;
44 *result = (enum gcc_cp_oracle_request) p;
45 return OK;
48 status
49 unmarshall (connection *conn, enum gcc_cp_qualifiers *result)
51 protocol_int p;
52 if (!unmarshall_intlike (conn, &p))
53 return FAIL;
54 *result = (enum gcc_cp_qualifiers) p;
55 return OK;
58 status
59 unmarshall (connection *conn, enum gcc_cp_ref_qualifiers *result)
61 protocol_int p;
62 if (!unmarshall_intlike (conn, &p))
63 return FAIL;
64 *result = (enum gcc_cp_ref_qualifiers) p;
65 return OK;
68 // Send a gcc_vbase_array marker followed by the array.
69 status
70 marshall (connection *conn, const gcc_vbase_array *a)
72 size_t len;
74 if (a)
75 len = a->n_elements;
76 else
77 len = (size_t)-1;
79 if (!marshall_array_start (conn, 'v', len))
80 return FAIL;
82 if (!a)
83 return OK;
85 if (!marshall_array_elmts (conn, len * sizeof (a->elements[0]),
86 a->elements))
87 return FAIL;
89 return marshall_array_elmts (conn, len * sizeof (a->flags[0]),
90 a->flags);
93 // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
94 // resulting array must be freed by the caller, using 'delete[]' on
95 // elements and virtualp, and 'delete' on the array object itself.
96 status
97 unmarshall (connection *conn, struct gcc_vbase_array **result)
99 size_t len;
101 if (!unmarshall_array_start (conn, 'v', &len))
102 return FAIL;
104 if (len == (size_t)-1)
106 *result = NULL;
107 return OK;
110 struct gcc_vbase_array *gva = new gcc_vbase_array;
112 gva->n_elements = len;
113 gva->elements = new gcc_type[len];
115 if (!unmarshall_array_elmts (conn,
116 len * sizeof (gva->elements[0]),
117 gva->elements))
119 delete[] gva->elements;
120 delete gva;
121 return FAIL;
124 gva->flags = new enum gcc_cp_symbol_kind[len];
126 if (!unmarshall_array_elmts (conn,
127 len * sizeof (gva->flags[0]),
128 gva->flags))
130 delete[] gva->flags;
131 delete[] gva->elements;
132 delete gva;
133 return FAIL;
136 *result = gva;
137 return OK;
140 // Send a gcc_cp_template_args marker followed by the array.
141 status
142 marshall (connection *conn, const gcc_cp_template_args *a)
144 size_t len;
146 if (a)
147 len = a->n_elements;
148 else
149 len = (size_t)-1;
151 if (!marshall_array_start (conn, 't', len))
152 return FAIL;
154 if (!a)
155 return OK;
157 if (!marshall_array_elmts (conn, len * sizeof (a->kinds[0]),
158 a->kinds))
159 return FAIL;
161 return marshall_array_elmts (conn, len * sizeof (a->elements[0]),
162 a->elements);
165 // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
166 // resulting array must be freed by the caller, using 'delete[]' on
167 // elements and virtualp, and 'delete' on the array object itself.
168 status
169 unmarshall (connection *conn, struct gcc_cp_template_args **result)
171 size_t len;
173 if (!unmarshall_array_start (conn, 't', &len))
174 return FAIL;
176 if (len == (size_t)-1)
178 *result = NULL;
179 return OK;
182 struct gcc_cp_template_args *gva = new gcc_cp_template_args;
184 gva->n_elements = len;
185 gva->kinds = new char[len];
187 if (!unmarshall_array_elmts (conn,
188 len * sizeof (gva->kinds[0]),
189 gva->kinds))
191 delete[] gva->kinds;
192 delete gva;
193 return FAIL;
196 gva->elements = new gcc_cp_template_arg[len];
198 if (!unmarshall_array_elmts (conn,
199 len * sizeof (gva->elements[0]),
200 gva->elements))
202 delete[] gva->elements;
203 delete[] gva->kinds;
204 delete gva;
205 return FAIL;
208 *result = gva;
209 return OK;
212 // Send a gcc_cp_function_args marker followed by the array.
213 status
214 marshall (connection *conn, const gcc_cp_function_args *a)
216 size_t len;
218 if (a)
219 len = a->n_elements;
220 else
221 len = (size_t)-1;
223 if (!marshall_array_start (conn, 'd', len))
224 return FAIL;
226 if (!a)
227 return OK;
229 return marshall_array_elmts (conn, len * sizeof (a->elements[0]),
230 a->elements);
233 // Read a gcc_cp_function_args marker, followed by a
234 // gcc_cp_function_args. The resulting array must be freed
235 // by the caller, using 'delete[]' on elements and virtualp, and
236 // 'delete' on the array object itself.
237 status
238 unmarshall (connection *conn, struct gcc_cp_function_args **result)
240 size_t len;
242 if (!unmarshall_array_start (conn, 'd', &len))
243 return FAIL;
245 if (len == (size_t)-1)
247 *result = NULL;
248 return OK;
251 struct gcc_cp_function_args *gva = new gcc_cp_function_args;
253 gva->n_elements = len;
254 gva->elements = new gcc_expr[len];
256 if (!unmarshall_array_elmts (conn,
257 len * sizeof (gva->elements[0]),
258 gva->elements))
260 delete[] gva->elements;
261 delete gva;
262 return FAIL;
265 *result = gva;
267 return OK;
271 #endif // CC1_PLUGIN_MARSHALL_CP_HH