source: trunk/ORBit2-2.14.0/src/idl-compiler/orbit-idl-c-imodule.c

Last change on this file was 92, checked in by cinc, 19 years ago

Orbit2 modified for use with NOM

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