]> rtime.felk.cvut.cz Git - orte.git/blob - orte/idl-compiler/orte-idl-c-headers.c
ROBOT_DEMO: implement voltage monitor
[orte.git] / orte / idl-compiler / orte-idl-c-headers.c
1 //#include "config.h"
2 #include "orte-idl-c-backend.h"
3
4 #include <string.h>
5 #include <ctype.h>
6
7 /* ch = C header */
8 static void ch_output_types(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
9 //static void ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
10 //static void ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci);
11 static void ch_output_impls_decl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
12 //static void ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
13
14 void
15 orte_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
16 {
17   fprintf (ci->fh, OIDL_C_WARNING);
18   fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
19   fprintf(ci->fh, "#define %s%s_H 1\n\n", rinfo->header_guard_prefix, ci->c_base_name);
20
21   fprintf(ci->fh, "#ifdef __cplusplus\n");
22   fprintf(ci->fh, "extern \"C\" {\n");
23   fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
24
25   fprintf(ci->fh, "#ifndef EXCLUDE_ORTE_H\n");
26   fprintf(ci->fh, "#include <orte.h>\n");
27   fprintf(ci->fh, "#endif /* EXCLUDE_ORTE_H */\n");
28
29   /* Do all the typedefs, etc. */
30   fprintf(ci->fh, "\n/** typedefs **/\n");
31   ch_output_types(tree, rinfo, ci);
32   
33   fprintf(ci->fh, "\n/** impls declarations **/\n");
34   ch_output_impls_decl(tree, rinfo, ci);
35
36   if ( ci->ext_dcls && ci->ext_dcls->str )
37     fputs( ci->ext_dcls->str, ci->fh);  /* this may be huge! */
38
39   fprintf(ci->fh, "\n");
40   fprintf(ci->fh, "#ifdef __cplusplus\n");
41   fprintf(ci->fh, "}\n");
42   fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
43
44   fprintf(ci->fh, "#endif\n");
45 }
46
47 static void
48 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
49 {
50   orte_cbe_write_typespec(ci->fh, val);
51
52   fprintf(ci->fh, " ");
53   switch(IDL_NODE_TYPE(name)) {
54   case IDLN_IDENT:
55     fprintf(ci->fh, "%s", IDL_IDENT(name).str);
56     break;
57   case IDLN_TYPE_ARRAY:
58     {
59       IDL_tree curitem;
60
61       fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
62       for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
63         fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
64       }
65     }
66     break;
67   default:
68     g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
69     break;
70   }
71   fprintf(ci->fh, ";\n");
72 }
73
74 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
75 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
76 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
77 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
78 static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
79 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
80 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
81 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
82 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
83
84 //static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc);
85
86 static void
87 ch_output_types (IDL_tree       tree,
88                  OIDL_Run_Info *rinfo,
89                  OIDL_C_Info   *ci)
90 {
91         if (!tree)
92                 return;
93
94         switch (IDL_NODE_TYPE (tree)) {
95         case IDLN_EXCEPT_DCL: {
96                 char *id;
97
98                 id = IDL_ns_ident_to_qstring (
99                         IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0);
100
101                 fprintf (ci->fh, "#undef ex_%s\n", id);
102                 fprintf (ci->fh, "#define ex_%s \"%s\"\n",
103                                 id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id);
104
105                 g_free (id);
106
107                 ch_output_type_struct (tree, rinfo, ci);
108                 }
109                 break;
110         case IDLN_FORWARD_DCL:
111         case IDLN_INTERFACE:
112                 ch_output_interface (tree, rinfo, ci);
113                 break;
114         case IDLN_TYPE_STRUCT:
115                 ch_output_type_struct (tree, rinfo, ci);
116                 break;
117         case IDLN_TYPE_ENUM:
118                 ch_output_type_enum (tree, rinfo, ci);
119                 break;
120         case IDLN_TYPE_DCL:
121                 ch_output_type_dcl (tree, rinfo, ci);
122                 break;
123         case IDLN_TYPE_UNION:
124                 ch_output_type_union (tree, rinfo, ci);
125                 break;
126         case IDLN_CODEFRAG:
127                 ch_output_codefrag (tree, rinfo, ci);
128                 break;
129         case IDLN_SRCFILE: {
130                 if (rinfo->onlytop) {
131                         char *idlfn = IDL_SRCFILE (tree).filename;
132
133                         if (!IDL_SRCFILE (tree).seenCnt &&
134                             !IDL_SRCFILE(tree).isTop    &&
135                             !IDL_SRCFILE(tree).wasInhibit) {
136                                 gchar *hfn, *htail;
137
138                                 hfn   = g_path_get_basename (idlfn);
139                                 htail = strrchr (hfn,'.');
140
141                                 g_assert (htail && strlen (htail) >= 2);
142
143                                 htail [1] = 'h';
144                                 htail [2] = 0;
145
146                                 fprintf (ci->fh, "#include \"%s\"\n", hfn);
147
148                                 g_free (hfn);
149                         }
150
151                 fprintf (ci->fh, "/* from IDL source file \"%s\" "
152                                  "(seen %d, isTop %d, wasInhibit %d) */ \n", 
153                                         idlfn,
154                                         IDL_SRCFILE (tree).seenCnt,
155                                         IDL_SRCFILE (tree).isTop,
156                                         IDL_SRCFILE (tree).wasInhibit);
157                 }
158                 }
159                 break;
160         case IDLN_CONST_DCL:
161                 ch_output_const_dcl (tree, rinfo, ci);
162                 break;
163         case IDLN_NATIVE:
164                 ch_output_native (tree, rinfo, ci);
165                 break;
166         default:
167                 break;
168         }
169
170         switch (IDL_NODE_TYPE (tree)) {
171         case IDLN_MODULE:
172                 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
173                 break;
174         case IDLN_LIST: {
175                 IDL_tree sub;
176
177                 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
178                         ch_output_types (IDL_LIST (sub).data, rinfo, ci);
179                 }
180                 }
181                 break;
182         case IDLN_INTERFACE:
183                 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
184                 break;
185         default:
186                 break;
187         }
188 }
189
190 static void
191 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
192 {
193     char *fullname;
194     fullname = orte_cbe_get_typespec_str(tree);
195     fprintf(ci->fh, "#if !defined(ORTE_DECL_%s) && !defined(_%s_defined)\n#define ORTE_DECL_%s 1\n#define _%s_defined 1\n", fullname, fullname, fullname, fullname);
196
197     if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
198         /* PIDL interfaces are not normal CORBA Objects */
199         fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname);
200         fprintf(ci->fh, "#ifndef TC_%s\n", fullname);
201         fprintf(ci->fh, "#  define TC_%s TC_CORBA_Object\n", fullname);
202         fprintf(ci->fh, "#endif\n");
203     } else {
204         fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname);
205         fprintf(ci->fh, "typedef CORBA_Object %s;\n", fullname);
206         fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname);
207 //      ch_type_alloc_and_tc(tree, rinfo, ci, FALSE);
208     }
209
210     fprintf(ci->fh, "#endif\n");
211     g_free(fullname);
212 }
213
214 static void
215 ch_output_type_enum (IDL_tree       tree,
216                      OIDL_Run_Info *rinfo,
217                      OIDL_C_Info   *ci)
218 {
219         IDL_tree  l;
220         char     *enumid;
221
222         /* CORBA spec says to do
223          * typedef unsigned int enum_name;
224          * and then #defines for each enumerator.
225          * This works just as well and seems cleaner.
226          */
227
228         enumid = IDL_ns_ident_to_qstring (
229                         IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
230         fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
231         fprintf (ci->fh, "typedef enum {\n");
232
233         for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
234                 char *id;
235
236                 id = IDL_ns_ident_to_qstring (
237                         IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
238
239                 fprintf (ci->fh, "  %s%s\n", id, IDL_LIST (l).next ? "," : "");
240
241                 g_free (id);
242         }
243
244         fprintf (ci->fh, "} %s;\n", enumid);
245
246 //      ch_type_alloc_and_tc (tree, rinfo, ci, FALSE);
247
248         fprintf (ci->fh, "#define %s_serialize(codec, obj) CORBA_long_serialize((codec), (obj))\n", enumid);
249         fprintf (ci->fh,
250                  "static inline void\n"
251                  "%s_deserialize(CDR_Codec *codec, %s *object) {\n"
252                  "  CORBA_long_deserialize(codec, (CORBA_long*)object);\n"
253                  "}\n", enumid, enumid);
254         fprintf(ci->fh, "#define %s_get_max_size(x, num) CORBA_long_get_max_size((x), (num))\n", enumid);
255
256         fprintf (ci->fh, "#endif\n");
257
258         g_free (enumid);
259 }
260
261 static void
262 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
263 {
264         IDL_tree  l;
265
266         ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
267
268         for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
269                 char *ctmp = NULL;
270
271                 IDL_tree ent = IDL_LIST (l).data;
272
273                 switch (IDL_NODE_TYPE(ent)) {
274                 case IDLN_IDENT:
275                         ctmp = IDL_ns_ident_to_qstring (
276                                         IDL_IDENT_TO_NS (ent), "_", 0);
277                         break;
278                 case IDLN_TYPE_ARRAY:
279                         ctmp = IDL_ns_ident_to_qstring (
280                                         IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
281                         break;
282                 default:
283                         g_assert_not_reached ();
284                         break;
285                 }
286
287                 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
288                 fprintf (ci->fh, "typedef ");
289                 orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
290
291                 switch (IDL_NODE_TYPE (ent)) {
292                 case IDLN_IDENT:
293                         fprintf (ci->fh, " %s;\n", ctmp);
294                         fprintf (ci->fh, "#define %s_serialize(codec, obj) ", ctmp);
295                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
296                         fprintf (ci->fh, "_serialize(codec, obj)\n");
297
298                         fprintf (ci->fh, "#define %s_deserialize(codec, obj) ", ctmp);
299                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
300                         fprintf (ci->fh, "_deserialize(codec, obj)\n");
301
302                         fprintf(ci->fh, "#define %s_get_max_size(x, num) ", ctmp);
303                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
304                         fprintf (ci->fh, "_get_max_size(x, num)\n");
305                         break;
306                 case IDLN_TYPE_ARRAY: {
307                         IDL_tree sub;
308
309                         fprintf (ci->fh, " %s", ctmp);
310                         for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
311                                 fprintf (ci->fh, "[%" IDL_LL "d]",
312                                          IDL_INTEGER (IDL_LIST (sub).data).value);
313
314                         fprintf (ci->fh, ";\n");
315                         fprintf (ci->fh, "typedef ");
316                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
317                         fprintf (ci->fh, " %s_slice", ctmp);
318                         for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next;
319                              sub; sub = IDL_LIST (sub).next)
320                                 fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value);
321                         fprintf(ci->fh, ";\n");
322                         }
323                         break;
324                 default:
325                         break;
326                 }
327
328 //              ch_type_alloc_and_tc (ent, rinfo, ci, TRUE);
329                 fprintf (ci->fh, "#endif\n");
330                 g_free (ctmp);
331         }
332 }
333
334 static void
335 ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
336 {
337     char *ctmp;
338     IDL_tree id = IDL_NATIVE(tree).ident;
339     ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0);
340     fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
341     fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp);
342     /* Dont even think about emitting a typecode. */
343     fprintf(ci->fh, "#endif\n");
344     g_free(ctmp);
345 }
346
347 static void
348 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
349 {
350   char *id;
351   IDL_tree cur, curmem;
352
353   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
354     "_", 0);
355   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
356   /* put typedef out first for recursive seq */
357   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
358
359   /* Scan for any nested decls */
360   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
361     IDL_tree ts;
362     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
363     ch_prep(ts, rinfo, ci);
364   }
365
366   fprintf(ci->fh, "struct %s_type {\n", id);
367
368   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
369     for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
370       ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
371     }
372   }
373   if(!IDL_TYPE_STRUCT(tree).member_list)
374     fprintf(ci->fh, "int dummy;\n");
375   fprintf(ci->fh, "};\n\n");
376
377 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
378
379   fprintf(ci->fh, "#endif\n");
380
381   g_free(id);
382 }
383
384 static void
385 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
386 {
387   char *id;
388   IDL_tree curitem;
389
390   if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
391     ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
392
393   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
394   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
395   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
396
397   /* Scan for any nested decls */
398   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
399     IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
400     ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
401   }
402
403   fprintf(ci->fh, "struct %s_type {\n", id);
404   orte_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
405   fprintf(ci->fh, " _d;\nunion {\n");
406
407   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
408     IDL_tree member;
409
410     member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
411     ch_output_var(IDL_MEMBER(member).type_spec,
412                   IDL_LIST(IDL_MEMBER(member).dcls).data,
413                   ci);
414   }
415
416   fprintf(ci->fh, "} _u;\n};\n");
417
418 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
419
420   fprintf(ci->fh, "#endif\n");
421
422   g_free(id);
423 }
424
425 static void
426 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
427 {
428   GSList *list;
429
430   for(list = IDL_CODEFRAG(tree).lines; list;
431       list = g_slist_next(list)) {
432     if(!strncmp(list->data,
433                 "#pragma include_defs",
434                 sizeof("#pragma include_defs")-1)) {
435         char *ctmp, *cte;
436         ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
437         while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
438         cte = ctmp;
439         while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
440         *cte = '\0';
441       fprintf(ci->fh, "#include <%s>\n", ctmp);
442     } else
443       fprintf(ci->fh, "%s\n", (char *)list->data);
444   }
445 }
446
447 static void
448 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
449 {
450         char    *id;
451         IDL_tree ident;
452         IDL_tree typespec;
453
454         ident = IDL_CONST_DCL (tree).ident;
455         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
456
457         fprintf(ci->fh, "#ifndef %s\n", id);
458         fprintf(ci->fh, "#define %s ", id);
459
460         orte_cbe_write_const(ci->fh,
461                               IDL_CONST_DCL(tree).const_exp);
462
463         typespec = orte_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
464         if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
465             !IDL_TYPE_INTEGER (typespec).f_signed)
466                 fprintf(ci->fh, "U");
467
468         fprintf(ci->fh, "\n");
469         fprintf(ci->fh, "#endif /* !%s */\n\n", id);
470
471         g_free(id);
472 }
473
474 static void
475 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
476 {
477   char *ctmp;
478
479   ctmp = orte_cbe_get_typespec_str(tree);
480   fprintf(ci->fh,
481           "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
482           (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
483           ctmp);
484   g_free(ctmp);
485
486 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
487 }
488
489 static void
490 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
491 {
492   char *ctmp, *fullname, *fullname_def, *ctmp2;
493   IDL_tree tts;
494   gboolean separate_defs, fake_if;
495   IDL_tree fake_seq = NULL;
496
497   tts = orte_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
498   ctmp = orte_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
499   ctmp2 = orte_cbe_get_typespec_str(tts);
500   fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
501   if(fake_if)
502     {
503       g_free(ctmp2);
504       ctmp2 = g_strdup("CORBA_Object");
505     }
506   separate_defs = strcmp((const char *)ctmp, (const char*)ctmp2);
507   fullname = orte_cbe_get_typespec_str(tree);
508
509   if(separate_defs)
510     {
511       if(fake_if)
512         tts = IDL_type_object_new();
513       fake_seq = IDL_type_sequence_new(tts, NULL);
514       IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
515       ch_prep_sequence(fake_seq, rinfo, ci);
516       fullname_def = g_strdup_printf("CORBA_sequence_%s", ctmp2);
517       if(!fake_if)
518         IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
519     }
520   else
521     fullname_def = g_strdup(fullname);
522
523   if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
524      == IDLN_TYPE_SEQUENCE)
525     ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
526
527   /* NOTE: ORTE_DECL_%s protects redef of everything (struct,TC,externs)
528    * while _%s_defined protects only the struct */
529
530   fprintf(ci->fh, "#if !defined(ORTE_DECL_%s)\n#define ORTE_DECL_%s 1\n",
531           fullname, fullname);
532   if ( ci->do_impl_hack )
533       orte_cbe_id_define_hack(ci->fh, "ORTE_IMPL", fullname, ci->c_base_name);
534
535   if(separate_defs)
536     {
537       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
538               fullname, fullname);
539       if(!strcmp((const char *)ctmp, (const char*)"CORBA_RepositoryId"))
540         fprintf(ci->fh, "/* CRACKHEADS */\n");
541       fprintf(ci->fh, "typedef %s %s;\n", fullname_def, fullname);
542       fprintf(ci->fh, "#endif\n");
543 //      ch_type_alloc_and_tc(tree, rinfo, ci, FALSE);
544       fprintf(ci->fh, "#define %s__alloc %s__alloc\n",
545               fullname, fullname_def);
546       fprintf(ci->fh, "#define %s__freekids %s__freekids\n",
547               fullname, fullname_def);
548       fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf CORBA_sequence_%s_allocbuf\n",
549               ctmp, ctmp2);
550       fprintf(ci->fh, "#define %s_serialize(x) %s_serialize(x)\n", fullname, fullname_def);
551
552       fprintf(ci->fh, "#define %s_deserialize(x) %s_deserialize(x)\n", fullname, fullname_def);
553       IDL_tree_free(fake_seq);
554     }
555   else
556     {
557       char *tc, *member_type;
558
559       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
560               fullname, fullname);
561       fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
562       orte_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
563       fprintf(ci->fh, "* _buffer; CORBA_boolean _release; } ");
564       orte_cbe_write_typespec(ci->fh, tree);
565       fprintf(ci->fh, ";\n#endif\n");
566 //      ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
567
568       tc = orte_cbe_get_typecode_name (orte_cbe_get_typespec (tree));
569       member_type = orte_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
570                                 ctmp + strlen ("CORBA_") : ctmp;
571
572       fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
573                        "((%s*)ORTE_small_allocbuf (%s, (l)))\n",
574                        member_type, member_type, tc);
575
576       g_free (tc);
577     }
578
579   fprintf(ci->fh, "#endif\n");
580
581   g_free(ctmp2);
582   g_free(ctmp);
583   g_free(fullname);
584   g_free(fullname_def);
585 }
586
587
588 static
589 void ch_prep (IDL_tree       tree,
590               OIDL_Run_Info *rinfo,
591               OIDL_C_Info   *ci)
592 {
593         switch (IDL_NODE_TYPE (tree)) {
594         case IDLN_TYPE_SEQUENCE:
595                 ch_prep_sequence (tree, rinfo, ci);
596                 break;
597         case IDLN_TYPE_FIXED:
598                 ch_prep_fixed (tree, rinfo, ci);
599                 break;
600         case IDLN_TYPE_STRUCT:
601                 ch_output_type_struct (tree, rinfo, ci);
602                 break;
603         case IDLN_TYPE_ENUM:
604                 ch_output_type_enum (tree, rinfo, ci);
605                 break;
606         default:
607                 break;
608         }
609 }
610
611 static void
612 ch_output_decl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
613 {
614   char *id;
615   IDL_tree cur;
616
617   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
618     "_", 0);
619   fprintf(ci->fh, "void %s_serialize(CDR_Codec *cdrCodec,%s *object);\n", id, id);
620   fprintf(ci->fh, "void %s_deserialize(CDR_Codec *cdrCodec,%s *object);\n", id, id);
621   fprintf(ci->fh, "int %s_get_max_size(ORTEGetMaxSizeParam *gms, int num);\n", id);
622   fprintf(ci->fh, "Boolean %s_type_register(ORTEDomain *d);\n", id);
623   fprintf(ci->fh, "\n");
624
625   /* Scan for any nested decls */
626   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
627     IDL_tree ts;
628     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
629     switch (IDL_NODE_TYPE (ts)) {
630         case IDLN_TYPE_STRUCT:
631                 ch_output_decl(ts, rinfo, ci);
632                 break;
633         default:
634                 break;
635         }
636   }
637
638   g_free(id);
639 }
640
641
642 static void
643 ch_output_impls_decl (IDL_tree       tree,
644                  OIDL_Run_Info *rinfo,
645                  OIDL_C_Info   *ci)
646 {
647         if (!tree)
648                 return;
649
650         switch (IDL_NODE_TYPE (tree)) {
651         case IDLN_TYPE_STRUCT:
652                 ch_output_decl (tree, rinfo, ci);
653                 break;
654         default:
655                 break;
656         }
657
658         switch (IDL_NODE_TYPE (tree)) {
659         case IDLN_MODULE:
660                 ch_output_impls_decl (IDL_MODULE (tree).definition_list, rinfo, ci);
661                 break;
662         case IDLN_LIST: {
663                 IDL_tree sub;
664
665                 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
666                         ch_output_impls_decl (IDL_LIST (sub).data, rinfo, ci);
667                 }
668                 }
669                 break;
670         case IDLN_INTERFACE:
671                 ch_output_impls_decl (IDL_INTERFACE (tree).body, rinfo, ci);
672                 break;
673         default:
674                 break;
675         }
676 }