]> rtime.felk.cvut.cz Git - orte.git/blob - orte/idl-compiler/orte-idl-c-headers.c
ee1a5a67abacf8d71305f82598c44ae8d0fa2ba4
[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, "#endif\n");
249
250         g_free (enumid);
251 }
252
253 static void
254 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
255 {
256         IDL_tree  l;
257
258         ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
259
260         for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
261                 char *ctmp = NULL;
262
263                 IDL_tree ent = IDL_LIST (l).data;
264
265                 switch (IDL_NODE_TYPE(ent)) {
266                 case IDLN_IDENT:
267                         ctmp = IDL_ns_ident_to_qstring (
268                                         IDL_IDENT_TO_NS (ent), "_", 0);
269                         break;
270                 case IDLN_TYPE_ARRAY:
271                         ctmp = IDL_ns_ident_to_qstring (
272                                         IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
273                         break;
274                 default:
275                         g_assert_not_reached ();
276                         break;
277                 }
278
279                 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
280                 fprintf (ci->fh, "typedef ");
281                 orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
282
283                 switch (IDL_NODE_TYPE (ent)) {
284                 case IDLN_IDENT:
285                         fprintf (ci->fh, " %s;\n", ctmp);
286                         fprintf (ci->fh, "#define %s_serialize(x) ", ctmp);
287                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
288                         fprintf (ci->fh, "_serialize(x)\n");
289
290                         fprintf (ci->fh, "#define %s_deserialize(x) ", ctmp);
291                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
292                         fprintf (ci->fh, "_deserialize(x)\n");
293
294                         fprintf(ci->fh, "#define %s_get_max_size(x, num) ", ctmp);
295                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
296                         fprintf (ci->fh, "_get_max_size(x, num)\n");
297                         break;
298                 case IDLN_TYPE_ARRAY: {
299                         IDL_tree sub;
300
301                         fprintf (ci->fh, " %s", ctmp);
302                         for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
303                                 fprintf (ci->fh, "[%" IDL_LL "d]",
304                                          IDL_INTEGER (IDL_LIST (sub).data).value);
305
306                         fprintf (ci->fh, ";\n");
307                         fprintf (ci->fh, "typedef ");
308                         orte_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
309                         fprintf (ci->fh, " %s_slice", ctmp);
310                         for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next;
311                              sub; sub = IDL_LIST (sub).next)
312                                 fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value);
313                         fprintf(ci->fh, ";\n");
314                         }
315                         break;
316                 default:
317                         break;
318                 }
319
320 //              ch_type_alloc_and_tc (ent, rinfo, ci, TRUE);
321                 fprintf (ci->fh, "#endif\n");
322                 g_free (ctmp);
323         }
324 }
325
326 static void
327 ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
328 {
329     char *ctmp;
330     IDL_tree id = IDL_NATIVE(tree).ident;
331     ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0);
332     fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
333     fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp);
334     /* Dont even think about emitting a typecode. */
335     fprintf(ci->fh, "#endif\n");
336     g_free(ctmp);
337 }
338
339 static void
340 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
341 {
342   char *id;
343   IDL_tree cur, curmem;
344
345   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
346     "_", 0);
347   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
348   /* put typedef out first for recursive seq */
349   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
350
351   /* Scan for any nested decls */
352   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
353     IDL_tree ts;
354     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
355     ch_prep(ts, rinfo, ci);
356   }
357
358   fprintf(ci->fh, "struct %s_type {\n", id);
359
360   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
361     for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
362       ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
363     }
364   }
365   if(!IDL_TYPE_STRUCT(tree).member_list)
366     fprintf(ci->fh, "int dummy;\n");
367   fprintf(ci->fh, "};\n\n");
368
369 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
370
371   fprintf(ci->fh, "#endif\n");
372
373   g_free(id);
374 }
375
376 static void
377 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
378 {
379   char *id;
380   IDL_tree curitem;
381
382   if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
383     ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
384
385   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
386   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
387   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
388
389   /* Scan for any nested decls */
390   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
391     IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
392     ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
393   }
394
395   fprintf(ci->fh, "struct %s_type {\n", id);
396   orte_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
397   fprintf(ci->fh, " _d;\nunion {\n");
398
399   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
400     IDL_tree member;
401
402     member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
403     ch_output_var(IDL_MEMBER(member).type_spec,
404                   IDL_LIST(IDL_MEMBER(member).dcls).data,
405                   ci);
406   }
407
408   fprintf(ci->fh, "} _u;\n};\n");
409
410 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
411
412   fprintf(ci->fh, "#endif\n");
413
414   g_free(id);
415 }
416
417 static void
418 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
419 {
420   GSList *list;
421
422   for(list = IDL_CODEFRAG(tree).lines; list;
423       list = g_slist_next(list)) {
424     if(!strncmp(list->data,
425                 "#pragma include_defs",
426                 sizeof("#pragma include_defs")-1)) {
427         char *ctmp, *cte;
428         ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
429         while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
430         cte = ctmp;
431         while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
432         *cte = '\0';
433       fprintf(ci->fh, "#include <%s>\n", ctmp);
434     } else
435       fprintf(ci->fh, "%s\n", (char *)list->data);
436   }
437 }
438
439 static void
440 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
441 {
442         char    *id;
443         IDL_tree ident;
444         IDL_tree typespec;
445
446         ident = IDL_CONST_DCL (tree).ident;
447         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
448
449         fprintf(ci->fh, "#ifndef %s\n", id);
450         fprintf(ci->fh, "#define %s ", id);
451
452         orte_cbe_write_const(ci->fh,
453                               IDL_CONST_DCL(tree).const_exp);
454
455         typespec = orte_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
456         if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
457             !IDL_TYPE_INTEGER (typespec).f_signed)
458                 fprintf(ci->fh, "U");
459
460         fprintf(ci->fh, "\n");
461         fprintf(ci->fh, "#endif /* !%s */\n\n", id);
462
463         g_free(id);
464 }
465
466 static void
467 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
468 {
469   char *ctmp;
470
471   ctmp = orte_cbe_get_typespec_str(tree);
472   fprintf(ci->fh,
473           "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
474           (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
475           ctmp);
476   g_free(ctmp);
477
478 //  ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
479 }
480
481 static void
482 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
483 {
484   char *ctmp, *fullname, *fullname_def, *ctmp2;
485   IDL_tree tts;
486   gboolean separate_defs, fake_if;
487   IDL_tree fake_seq = NULL;
488
489   tts = orte_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
490   ctmp = orte_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
491   ctmp2 = orte_cbe_get_typespec_str(tts);
492   fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
493   if(fake_if)
494     {
495       g_free(ctmp2);
496       ctmp2 = g_strdup("CORBA_Object");
497     }
498   separate_defs = strcmp((const char *)ctmp, (const char*)ctmp2);
499   fullname = orte_cbe_get_typespec_str(tree);
500
501   if(separate_defs)
502     {
503       if(fake_if)
504         tts = IDL_type_object_new();
505       fake_seq = IDL_type_sequence_new(tts, NULL);
506       IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
507       ch_prep_sequence(fake_seq, rinfo, ci);
508       fullname_def = g_strdup_printf("CORBA_sequence_%s", ctmp2);
509       if(!fake_if)
510         IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
511     }
512   else
513     fullname_def = g_strdup(fullname);
514
515   if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
516      == IDLN_TYPE_SEQUENCE)
517     ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
518
519   /* NOTE: ORTE_DECL_%s protects redef of everything (struct,TC,externs)
520    * while _%s_defined protects only the struct */
521
522   fprintf(ci->fh, "#if !defined(ORTE_DECL_%s)\n#define ORTE_DECL_%s 1\n",
523           fullname, fullname);
524   if ( ci->do_impl_hack )
525       orte_cbe_id_define_hack(ci->fh, "ORTE_IMPL", fullname, ci->c_base_name);
526
527   if(separate_defs)
528     {
529       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
530               fullname, fullname);
531       if(!strcmp((const char *)ctmp, (const char*)"CORBA_RepositoryId"))
532         fprintf(ci->fh, "/* CRACKHEADS */\n");
533       fprintf(ci->fh, "typedef %s %s;\n", fullname_def, fullname);
534       fprintf(ci->fh, "#endif\n");
535 //      ch_type_alloc_and_tc(tree, rinfo, ci, FALSE);
536       fprintf(ci->fh, "#define %s__alloc %s__alloc\n",
537               fullname, fullname_def);
538       fprintf(ci->fh, "#define %s__freekids %s__freekids\n",
539               fullname, fullname_def);
540       fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf CORBA_sequence_%s_allocbuf\n",
541               ctmp, ctmp2);
542       fprintf(ci->fh, "#define %s_serialize(x) %s_serialize(x)\n", fullname, fullname_def);
543
544       fprintf(ci->fh, "#define %s_deserialize(x) %s_deserialize(x)\n", fullname, fullname_def);
545       IDL_tree_free(fake_seq);
546     }
547   else
548     {
549       char *tc, *member_type;
550
551       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
552               fullname, fullname);
553       fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
554       orte_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
555       fprintf(ci->fh, "* _buffer; CORBA_boolean _release; } ");
556       orte_cbe_write_typespec(ci->fh, tree);
557       fprintf(ci->fh, ";\n#endif\n");
558 //      ch_type_alloc_and_tc(tree, rinfo, ci, TRUE);
559
560       tc = orte_cbe_get_typecode_name (orte_cbe_get_typespec (tree));
561       member_type = orte_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
562                                 ctmp + strlen ("CORBA_") : ctmp;
563
564       fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
565                        "((%s*)ORTE_small_allocbuf (%s, (l)))\n",
566                        member_type, member_type, tc);
567
568       g_free (tc);
569     }
570
571   fprintf(ci->fh, "#endif\n");
572
573   g_free(ctmp2);
574   g_free(ctmp);
575   g_free(fullname);
576   g_free(fullname_def);
577 }
578
579
580 static
581 void ch_prep (IDL_tree       tree,
582               OIDL_Run_Info *rinfo,
583               OIDL_C_Info   *ci)
584 {
585         switch (IDL_NODE_TYPE (tree)) {
586         case IDLN_TYPE_SEQUENCE:
587                 ch_prep_sequence (tree, rinfo, ci);
588                 break;
589         case IDLN_TYPE_FIXED:
590                 ch_prep_fixed (tree, rinfo, ci);
591                 break;
592         case IDLN_TYPE_STRUCT:
593                 ch_output_type_struct (tree, rinfo, ci);
594                 break;
595         case IDLN_TYPE_ENUM:
596                 ch_output_type_enum (tree, rinfo, ci);
597                 break;
598         default:
599                 break;
600         }
601 }
602
603 static void
604 ch_output_decl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
605 {
606   char *id;
607   IDL_tree cur;
608
609   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
610     "_", 0);
611   fprintf(ci->fh, "void %s_serialize(CDR_Codec *cdrCodec,%s *object);\n", id, id);
612   fprintf(ci->fh, "void %s_deserialize(CDR_Codec *cdrCodec,%s *object);\n", id, id);
613   fprintf(ci->fh, "int %s_get_max_size(ORTEGetMaxSizeParam *gms, int num);\n", id);
614   fprintf(ci->fh, "Boolean %s_type_register(ORTEDomain *d);\n", id);
615   fprintf(ci->fh, "\n");
616
617   /* Scan for any nested decls */
618   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
619     IDL_tree ts;
620     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
621     switch (IDL_NODE_TYPE (ts)) {
622         case IDLN_TYPE_STRUCT:
623                 ch_output_decl(ts, rinfo, ci);
624                 break;
625         default:
626                 break;
627         }
628   }
629
630   g_free(id);
631 }
632
633
634 static void
635 ch_output_impls_decl (IDL_tree       tree,
636                  OIDL_Run_Info *rinfo,
637                  OIDL_C_Info   *ci)
638 {
639         if (!tree)
640                 return;
641
642         switch (IDL_NODE_TYPE (tree)) {
643         case IDLN_TYPE_STRUCT:
644                 ch_output_decl (tree, rinfo, ci);
645                 break;
646         default:
647                 break;
648         }
649
650         switch (IDL_NODE_TYPE (tree)) {
651         case IDLN_MODULE:
652                 ch_output_impls_decl (IDL_MODULE (tree).definition_list, rinfo, ci);
653                 break;
654         case IDLN_LIST: {
655                 IDL_tree sub;
656
657                 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
658                         ch_output_impls_decl (IDL_LIST (sub).data, rinfo, ci);
659                 }
660                 }
661                 break;
662         case IDLN_INTERFACE:
663                 ch_output_impls_decl (IDL_INTERFACE (tree).body, rinfo, ci);
664                 break;
665         default:
666                 break;
667         }
668 }