annotate libcc1/marshall.hh @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Marshalling and unmarshalling.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2014-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef CC1_PLUGIN_MARSHALL_HH
kono
parents:
diff changeset
21 #define CC1_PLUGIN_MARSHALL_HH
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 #include "status.hh"
kono
parents:
diff changeset
24 #include "gcc-interface.h"
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 namespace cc1_plugin
kono
parents:
diff changeset
27 {
kono
parents:
diff changeset
28 class connection;
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 // Only a single kind of integer is ever sent over the wire, and
kono
parents:
diff changeset
31 // this is it.
kono
parents:
diff changeset
32 typedef unsigned long long protocol_int;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 // Read an integer from the connection and verify that it has the
kono
parents:
diff changeset
35 // value V.
kono
parents:
diff changeset
36 status unmarshall_check (connection *, protocol_int v);
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 // Write an integer, prefixed with the integer type marker, to the
kono
parents:
diff changeset
39 // connection.
kono
parents:
diff changeset
40 status marshall_intlike (connection *, protocol_int);
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 // Read a type marker from the connection and verify that it is an
kono
parents:
diff changeset
43 // integer type marker. If not, return FAIL. If so, read an
kono
parents:
diff changeset
44 // integer store it in the out argument.
kono
parents:
diff changeset
45 status unmarshall_intlike (connection *, protocol_int *);
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 status marshall_array_start (connection *, char, size_t);
kono
parents:
diff changeset
48 status marshall_array_elmts (connection *, size_t, void *);
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 status unmarshall_array_start (connection *, char, size_t *);
kono
parents:
diff changeset
51 status unmarshall_array_elmts (connection *, size_t, void *);
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 // A template function that can handle marshalling various integer
kono
parents:
diff changeset
54 // objects to the connection.
kono
parents:
diff changeset
55 template<typename T>
kono
parents:
diff changeset
56 status marshall (connection *conn, T scalar)
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 return marshall_intlike (conn, scalar);
kono
parents:
diff changeset
59 }
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 // A template function that can handle unmarshalling various integer
kono
parents:
diff changeset
62 // objects from the connection. Note that this can't be
kono
parents:
diff changeset
63 // instantiated for enum types. Note also that there's no way at
kono
parents:
diff changeset
64 // the protocol level to distinguish different int types.
kono
parents:
diff changeset
65 template<typename T>
kono
parents:
diff changeset
66 status unmarshall (connection *conn, T *scalar)
kono
parents:
diff changeset
67 {
kono
parents:
diff changeset
68 protocol_int result;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 if (!unmarshall_intlike (conn, &result))
kono
parents:
diff changeset
71 return FAIL;
kono
parents:
diff changeset
72 *scalar = result;
kono
parents:
diff changeset
73 return OK;
kono
parents:
diff changeset
74 }
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 // Send a string type marker followed by a string.
kono
parents:
diff changeset
77 status marshall (connection *, const char *);
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 // Read a string type marker followed by a string. The caller is
kono
parents:
diff changeset
80 // responsible for freeing the resulting string using 'delete[]'.
kono
parents:
diff changeset
81 status unmarshall (connection *, char **);
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 // Send a gcc_type_array marker followed by the array.
kono
parents:
diff changeset
84 status marshall (connection *, const gcc_type_array *);
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 // Read a gcc_type_array marker, followed by a gcc_type_array. The
kono
parents:
diff changeset
87 // resulting array must be freed by the caller, using 'delete[]' on
kono
parents:
diff changeset
88 // the elements, and 'delete' on the array object itself.
kono
parents:
diff changeset
89 status unmarshall (connection *, struct gcc_type_array **);
kono
parents:
diff changeset
90 };
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 #endif // CC1_PLUGIN_MARSHALL_HH