]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - forb-idl/forb-idl-c-imodule.c
Prepared test cases for executors (thread specific data)
[frescor/forb.git] / forb-idl / forb-idl-c-imodule.c
1 #include "config.h"
2
3 #include "forb-idl-c-backend.h"
4
5 #include <string.h>
6 #include "forb_config.h"
7
8 static void
9 ci_build_interfaces (OIDL_C_Info *ci,
10                      IDL_tree     tree)
11 {
12         if (!tree)
13                 return;
14
15         switch (IDL_NODE_TYPE (tree)) {
16         case IDLN_MODULE:
17                 ci_build_interfaces (
18                         ci, IDL_MODULE (tree).definition_list);
19                 break;
20         case IDLN_LIST: {
21                 IDL_tree sub;
22                 for (sub = tree; sub; sub = IDL_LIST (sub).next)
23                         ci_build_interfaces (
24                                 ci, IDL_LIST (sub).data);
25                 break;
26         }
27         case IDLN_INTERFACE: {
28                 char *id;
29
30                 id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (
31                         IDL_INTERFACE (tree).ident), "_", 0);
32
33                 fprintf (ci->fh, "\t&%s__iinterface,\n", id);
34
35                 g_free (id);
36
37                 ci_build_interfaces (
38                         ci, IDL_INTERFACE(tree).body);
39                 break;
40         }
41         default:
42                 break;
43         }
44 }
45
46 static void
47 ci_build_types (OIDL_C_Info *ci,
48                 IDL_tree     tree,
49                 guint       *count)
50 {
51         if (!tree)
52                 return;
53
54         switch (IDL_NODE_TYPE (tree)) {
55         case IDLN_MODULE:
56                 ci_build_types (
57                         ci, IDL_MODULE (tree).definition_list, count);
58                 break;
59         case IDLN_LIST: {
60                 IDL_tree sub;
61                 for (sub = tree; sub; sub = IDL_LIST (sub).next)
62                         ci_build_types (
63                                 ci, IDL_LIST (sub).data, count);
64                 break;
65         }
66         case IDLN_INTERFACE:
67                 ci_build_types (
68                         ci, IDL_INTERFACE(tree).body, count);
69                 break;
70         case IDLN_TYPE_DCL: {
71             IDL_tree sub;
72             for (sub = IDL_TYPE_DCL (tree).dcls; sub; sub = IDL_LIST (sub).next) {
73                 IDL_tree ent = IDL_LIST (sub).data;
74                 gchar *id;
75
76                 id = forb_cbe_get_typespec_str (ent);
77
78                 fprintf (ci->fh, "\tTC_%s,\n", id);
79                 (*count)++;
80
81                 g_free (id);
82             }
83
84             break;
85         }
86         case IDLN_TYPE_STRUCT: {
87                 gchar *id;
88                 IDL_tree l;
89
90                 id = forb_cbe_get_typespec_str (tree);
91
92                 fprintf (ci->fh, "\tTC_%s,\n", id);
93                 (*count)++;
94
95                 g_free (id);
96
97                 /* check for nested structs/enums */
98                 for (l = IDL_TYPE_STRUCT (tree).member_list; l; l = IDL_LIST (l).next) {
99                         IDL_tree dcl;
100
101                         g_assert (IDL_NODE_TYPE (IDL_LIST (l).data) == IDLN_MEMBER);
102                         dcl = IDL_MEMBER (IDL_LIST (l).data).type_spec;
103
104                         /* skip straight declarations */
105                         if (IDL_NODE_TYPE(dcl) == IDLN_TYPE_STRUCT ||
106                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_UNION ||
107                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_ENUM)
108                                 ci_build_types (ci, dcl, count);
109                 }
110                 break;
111         };
112         case IDLN_TYPE_UNION: {
113                 gchar *id;
114                 IDL_tree l;
115
116                 id = forb_cbe_get_typespec_str (tree);
117
118                 fprintf (ci->fh, "\tTC_%s,\n", id);
119                 (*count)++;
120
121                 g_free (id);
122
123                 /* if discriminator is an enum, register it */
124                 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
125                         ci_build_types (
126                                 ci, IDL_TYPE_UNION (tree).switch_type_spec, count);
127
128                 /* check for nested structs/enums */
129                 for (l = IDL_TYPE_UNION (tree).switch_body; l; l = IDL_LIST (l).next) {
130                         IDL_tree dcl;
131
132                         g_assert (IDL_NODE_TYPE (IDL_LIST (l).data) == IDLN_CASE_STMT);
133                         dcl = IDL_MEMBER (
134                                 IDL_CASE_STMT (IDL_LIST (l).data).element_spec).type_spec;
135
136                         if (IDL_NODE_TYPE(dcl) == IDLN_TYPE_STRUCT ||
137                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_UNION ||
138                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_ENUM)
139                                 ci_build_types (ci, dcl, count);
140                 }
141                 break;
142         }
143         case IDLN_EXCEPT_DCL: {
144                 gchar *id;
145                 IDL_tree l;
146
147                 id = forb_cbe_get_typespec_str (tree);
148
149                 fprintf (ci->fh, "\tTC_%s,\n", id);
150                 (*count)++;
151
152                 g_free (id);
153
154                 /* check for nested structs/enums */
155                 for (l = IDL_EXCEPT_DCL (tree).members; l; l = IDL_LIST (l).next) {
156                         IDL_tree dcl;
157
158                         g_assert (IDL_NODE_TYPE (IDL_LIST (l).data) == IDLN_MEMBER);
159                         dcl = IDL_MEMBER (IDL_LIST (l).data).type_spec;
160
161                         /* skip straight declarations */
162                         if (IDL_NODE_TYPE(dcl) == IDLN_TYPE_STRUCT ||
163                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_UNION ||
164                             IDL_NODE_TYPE(dcl) == IDLN_TYPE_ENUM)
165                                 ci_build_types (ci, dcl, count);
166                 }
167                 break;
168         }
169         case IDLN_TYPE_INTEGER:
170         case IDLN_TYPE_ANY:
171         case IDLN_TYPE_STRING:
172         case IDLN_TYPE_WIDE_STRING:
173         case IDLN_TYPE_CHAR:
174         case IDLN_TYPE_WIDE_CHAR:
175         case IDLN_TYPE_FLOAT:
176         case IDLN_TYPE_BOOLEAN:
177         case IDLN_TYPE_OCTET:
178         case IDLN_TYPE_SEQUENCE:
179         case IDLN_TYPE_ENUM:
180         case IDLN_IDENT:
181         case IDLN_FORWARD_DCL:
182         case IDLN_TYPE_OBJECT: {
183                 gchar *id;
184
185                 id = forb_cbe_get_typespec_str (tree);
186
187                 fprintf (ci->fh, "\tTC_%s,\n", id);
188                 (*count)++;
189
190                 g_free (id);
191
192                 break;
193         }
194         default:
195                 break;
196         }
197 }
198
199 void
200 forb_idl_output_c_imodule (IDL_tree       tree,
201                             OIDL_Run_Info *rinfo,
202                             OIDL_C_Info   *ci)
203 {
204         guint count;
205
206         fprintf (ci->fh, OIDL_C_WARNING);
207         fprintf (ci->fh, "#include <string.h>\n");
208         fprintf (ci->fh, "#define FORB_IDL_C_IMODULE_%s\n\n",ci->c_base_name);
209
210         fprintf (ci->fh, "#include \"%s-common.c\"\n\n", ci->base_name);
211
212         fprintf (ci->fh, "#include <forb/orb-core/forb-small.h>\n\n");
213
214         fprintf (ci->fh, "static CORBA_TypeCode %s__itypes[] = {\n",
215                  ci->c_base_name);
216
217         count = 0;
218         ci_build_types (ci, tree, &count);
219
220         fprintf (ci->fh, "\tNULL\n};\n\n");
221
222         fprintf (ci->fh, "static Forb_IInterface *%s__iinterfaces[] = {\n",
223                  ci->c_base_name);
224
225         ci_build_interfaces (ci, tree);
226
227         fprintf (ci->fh, "\tNULL\n};\n");
228
229         fprintf (ci->fh, "Forb_IModule forb_imodule_data = {\n");
230         fprintf (ci->fh, "   %d,\n", FORB_CONFIG_SERIAL);
231         fprintf (ci->fh, "   %s__iinterfaces,\n", ci->c_base_name);
232         fprintf (ci->fh, " { %u, %u, %s__itypes, FALSE }\n",
233                  count, count, ci->c_base_name);
234         fprintf (ci->fh, "};\n\n");
235 }