marshall-cp.hh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Marshalling and unmarshalling of C++-specific types.
  2. Copyright (C) 2014-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef CC1_PLUGIN_MARSHALL_CXX_HH
  16. #define CC1_PLUGIN_MARSHALL_CXX_HH
  17. #include "marshall.hh"
  18. #include "gcc-cp-interface.h"
  19. #include "deleter.hh"
  20. namespace cc1_plugin
  21. {
  22. template<>
  23. struct deleter<gcc_vbase_array>
  24. {
  25. void operator() (gcc_vbase_array *p)
  26. {
  27. delete[] p->flags;
  28. delete[] p->elements;
  29. delete p;
  30. }
  31. };
  32. template<>
  33. struct deleter<gcc_cp_template_args>
  34. {
  35. void operator() (gcc_cp_template_args *p)
  36. {
  37. delete[] p->elements;
  38. delete[] p->kinds;
  39. delete p;
  40. }
  41. };
  42. template<>
  43. struct deleter<gcc_cp_function_args>
  44. {
  45. void operator() (gcc_cp_function_args *p)
  46. {
  47. delete[] p->elements;
  48. delete p;
  49. }
  50. };
  51. // Send a gcc_vbase_array marker followed by the array.
  52. status
  53. marshall (connection *conn, const gcc_vbase_array *a)
  54. {
  55. size_t len;
  56. if (a)
  57. len = a->n_elements;
  58. else
  59. len = (size_t)-1;
  60. if (!marshall_array_start (conn, 'v', len))
  61. return FAIL;
  62. if (!a)
  63. return OK;
  64. if (!marshall_array_elmts (conn, len * sizeof (a->elements[0]),
  65. a->elements))
  66. return FAIL;
  67. return marshall_array_elmts (conn, len * sizeof (a->flags[0]),
  68. a->flags);
  69. }
  70. // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
  71. // resulting array must be freed by the caller, using 'delete[]' on
  72. // elements and virtualp, and 'delete' on the array object itself.
  73. status
  74. unmarshall (connection *conn, struct gcc_vbase_array **result)
  75. {
  76. size_t len;
  77. if (!unmarshall_array_start (conn, 'v', &len))
  78. return FAIL;
  79. if (len == (size_t)-1)
  80. {
  81. *result = NULL;
  82. return OK;
  83. }
  84. cc1_plugin::unique_ptr<gcc_vbase_array> gva (new gcc_vbase_array {});
  85. gva->n_elements = len;
  86. gva->elements = new gcc_type[len];
  87. if (!unmarshall_array_elmts (conn,
  88. len * sizeof (gva->elements[0]),
  89. gva->elements))
  90. return FAIL;
  91. gva->flags = new enum gcc_cp_symbol_kind[len];
  92. if (!unmarshall_array_elmts (conn,
  93. len * sizeof (gva->flags[0]),
  94. gva->flags))
  95. return FAIL;
  96. *result = gva.release ();
  97. return OK;
  98. }
  99. // Send a gcc_cp_template_args marker followed by the array.
  100. status
  101. marshall (connection *conn, const gcc_cp_template_args *a)
  102. {
  103. size_t len;
  104. if (a)
  105. len = a->n_elements;
  106. else
  107. len = (size_t)-1;
  108. if (!marshall_array_start (conn, 't', len))
  109. return FAIL;
  110. if (!a)
  111. return OK;
  112. if (!marshall_array_elmts (conn, len * sizeof (a->kinds[0]),
  113. a->kinds))
  114. return FAIL;
  115. return marshall_array_elmts (conn, len * sizeof (a->elements[0]),
  116. a->elements);
  117. }
  118. // Read a gcc_vbase_array marker, followed by a gcc_vbase_array. The
  119. // resulting array must be freed by the caller, using 'delete[]' on
  120. // elements and virtualp, and 'delete' on the array object itself.
  121. status
  122. unmarshall (connection *conn, struct gcc_cp_template_args **result)
  123. {
  124. size_t len;
  125. if (!unmarshall_array_start (conn, 't', &len))
  126. return FAIL;
  127. if (len == (size_t)-1)
  128. {
  129. *result = NULL;
  130. return OK;
  131. }
  132. cc1_plugin::unique_ptr<gcc_cp_template_args> gva
  133. (new gcc_cp_template_args {});
  134. gva->n_elements = len;
  135. gva->kinds = new char[len];
  136. if (!unmarshall_array_elmts (conn,
  137. len * sizeof (gva->kinds[0]),
  138. gva->kinds))
  139. return FAIL;
  140. gva->elements = new gcc_cp_template_arg[len];
  141. if (!unmarshall_array_elmts (conn,
  142. len * sizeof (gva->elements[0]),
  143. gva->elements))
  144. return FAIL;
  145. *result = gva.release ();
  146. return OK;
  147. }
  148. // Send a gcc_cp_function_args marker followed by the array.
  149. status
  150. marshall (connection *conn, const gcc_cp_function_args *a)
  151. {
  152. size_t len;
  153. if (a)
  154. len = a->n_elements;
  155. else
  156. len = (size_t)-1;
  157. if (!marshall_array_start (conn, 'd', len))
  158. return FAIL;
  159. if (!a)
  160. return OK;
  161. return marshall_array_elmts (conn, len * sizeof (a->elements[0]),
  162. a->elements);
  163. }
  164. // Read a gcc_cp_function_args marker, followed by a
  165. // gcc_cp_function_args. The resulting array must be freed
  166. // by the caller, using 'delete[]' on elements and virtualp, and
  167. // 'delete' on the array object itself.
  168. status
  169. unmarshall (connection *conn, struct gcc_cp_function_args **result)
  170. {
  171. size_t len;
  172. if (!unmarshall_array_start (conn, 'd', &len))
  173. return FAIL;
  174. if (len == (size_t)-1)
  175. {
  176. *result = NULL;
  177. return OK;
  178. }
  179. cc1_plugin::unique_ptr<gcc_cp_function_args> gva
  180. (new gcc_cp_function_args {});
  181. gva->n_elements = len;
  182. gva->elements = new gcc_expr[len];
  183. if (!unmarshall_array_elmts (conn,
  184. len * sizeof (gva->elements[0]),
  185. gva->elements))
  186. return FAIL;
  187. *result = gva.release ();
  188. return OK;
  189. }
  190. }
  191. #endif // CC1_PLUGIN_MARSHALL_CP_HH