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