marshall.hh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Marshalling and unmarshalling.
  2. Copyright (C) 2014 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_HH
  16. #define CC1_PLUGIN_MARSHALL_HH
  17. #include "status.hh"
  18. #include "gcc-c-interface.h"
  19. namespace cc1_plugin
  20. {
  21. class connection;
  22. // Only a single kind of integer is ever sent over the wire, and
  23. // this is it.
  24. typedef unsigned long long protocol_int;
  25. // Read an integer from the connection and verify that it has the
  26. // value V.
  27. status unmarshall_check (connection *, protocol_int v);
  28. // Write an integer, prefixed with the integer type marker, to the
  29. // connection.
  30. status marshall_intlike (connection *, protocol_int);
  31. // Read a type marker from the connection and verify that it is an
  32. // integer type marker. If not, return FAIL. If so, read an
  33. // integer store it in the out argument.
  34. status unmarshall_intlike (connection *, protocol_int *);
  35. // A template function that can handle marshalling various integer
  36. // objects to the connection.
  37. template<typename T>
  38. status marshall (connection *conn, T scalar)
  39. {
  40. return marshall_intlike (conn, scalar);
  41. }
  42. // A template function that can handle unmarshalling various integer
  43. // objects from the connection. Note that this can't be
  44. // instantiated for enum types. Note also that there's no way at
  45. // the protocol level to distinguish different int types.
  46. template<typename T>
  47. status unmarshall (connection *conn, T *scalar)
  48. {
  49. protocol_int result;
  50. if (!unmarshall_intlike (conn, &result))
  51. return FAIL;
  52. *scalar = result;
  53. return OK;
  54. }
  55. // Unmarshallers for some specific enum types. With C++11 we
  56. // wouldn't need these, as we could add type traits to the scalar
  57. // unmarshaller.
  58. status unmarshall (connection *, enum gcc_c_symbol_kind *);
  59. status unmarshall (connection *, enum gcc_qualifiers *);
  60. status unmarshall (connection *, enum gcc_c_oracle_request *);
  61. // Send a string type marker followed by a string.
  62. status marshall (connection *, const char *);
  63. // Read a string type marker followed by a string. The caller is
  64. // responsible for freeing the resulting string using 'delete[]'.
  65. status unmarshall (connection *, char **);
  66. // Send a gcc_type_array marker followed by the array.
  67. status marshall (connection *, const gcc_type_array *);
  68. // Read a gcc_type_array marker, followed by a gcc_type_array. The
  69. // resulting array must be freed by the caller, using 'delete[]' on
  70. // the elements, and 'delete' on the array object itself.
  71. status unmarshall (connection *, struct gcc_type_array **);
  72. };
  73. #endif // CC1_PLUGIN_MARSHALL_HH