]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - forb-idl/forb-idl-c-headers.c
061bd48ade37cbc7f6d6024d48585318136265f1
[frescor/forb.git] / forb-idl / forb-idl-c-headers.c
1 #include "config.h"
2 #include "forb-idl-c-backend.h"
3 #include "forb_config.h"
4
5 #include <string.h>
6 #include <ctype.h>
7
8 /* ch = C header */
9 static void ch_output_types(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
10 /* static void ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
11 /* static void ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci); */
12 static void ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
13 /* static void ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
14 static GSList *ch_build_interfaces (GSList *list, IDL_tree tree);
15 static void ch_output_method (FILE *of, IDL_tree tree, const char *id);
16 /* static void ch_output_imethods_index (GSList *list, OIDL_C_Info *ci); */
17
18 typedef struct {
19     IDL_tree tree;
20     GSList  *methods; /* IDLN_OP_DCLs */
21 } Interface;
22
23 /* this is hardcopy from cc_build_interfaces() defined in forb-idl-c-common.c */
24 static GSList *
25 ch_build_interfaces (GSList *list, IDL_tree tree)
26 {
27         if (!tree)
28                 return list;
29
30         switch (IDL_NODE_TYPE (tree)) {
31         case IDLN_MODULE:
32                 list = ch_build_interfaces (
33                         list, IDL_MODULE (tree).definition_list);
34                 break;
35         case IDLN_LIST: {
36                 IDL_tree sub;
37                 for (sub = tree; sub; sub = IDL_LIST (sub).next)
38                         list = ch_build_interfaces (
39                                 list, IDL_LIST (sub).data);
40                 break;
41         }
42         case IDLN_ATTR_DCL: {
43                 IDL_tree curitem;
44       
45                 for (curitem = IDL_ATTR_DCL (tree).simple_declarations;
46                      curitem; curitem = IDL_LIST (curitem).next) {
47                         OIDL_Attr_Info *ai = IDL_LIST (curitem).data->data;
48         
49                         list = ch_build_interfaces (list, ai->op1);
50                         if (ai->op2)
51                                 list = ch_build_interfaces (list, ai->op2);
52                 }
53                 break;
54         }
55         case IDLN_INTERFACE: {
56                 Interface *i = g_new0 (Interface, 1);
57
58                 i->tree = tree;
59
60                 list = g_slist_append (list, i);
61
62                 list = ch_build_interfaces (list, IDL_INTERFACE(tree).body);
63
64                 break;
65         }
66         case IDLN_OP_DCL: {
67                 Interface *i;
68
69                 g_return_val_if_fail (list != NULL, NULL);
70
71                 i = ( g_slist_last(list) )->data;
72                 i->methods = g_slist_append (i->methods, tree);
73                 break;
74         }
75         case IDLN_EXCEPT_DCL:
76                 break;
77         default:
78                 break;
79         }
80
81         return list;
82 }
83                                                                                                    
84 static void
85 ch_output_method (FILE *of, IDL_tree tree, const char *id)
86 {
87         char *fullname = NULL;
88
89         fullname = g_strconcat (id, "_", IDL_IDENT (
90                 IDL_OP_DCL (tree).ident).str, NULL);
91
92         fprintf (of, "\t%s__method_index", fullname);
93
94         g_free (fullname);
95 }
96
97 static void
98 ch_output_method_indices (GSList *list, OIDL_C_Info *ci)
99 {
100         GSList *l;
101         FILE *of = ci->fh;
102
103         for (l = list; l; l = l->next) {
104                 Interface *i = l->data;
105                 char      *id;
106                 GSList    *m;
107
108                 id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (
109                         IDL_INTERFACE (i->tree).ident), "_", 0);
110
111                 if (i->methods) {
112
113                         fprintf (of, "#ifndef __%s__method_indices\n", id);
114                         fprintf (of, "#define __%s__method_indices\n", id);
115
116                         fprintf (of, "typedef enum {\n");
117
118                         for (m = i->methods; m; m = m->next) {
119                                 ch_output_method (of, m->data, id);
120                                 if (m->next)
121                                         fprintf(of, ",\n");
122                                 else
123                                         fprintf(of, "\n");
124                         }
125
126                         fprintf (of, "} %s__method_indices;\n", id);
127                         fprintf (of, "#endif /* __%s__method_indices */\n\n", id);
128                 }
129
130                 g_free (id);
131         }
132
133         for (l = list; l; l = l->next) {
134                 g_slist_free (((Interface *)l->data)->methods);
135                 g_free (l->data);
136         }
137
138         g_slist_free (list);
139 }
140
141
142 #if 0
143 static gboolean is_native(IDL_tree_func_data *tfd, gpointer user_data)
144 {
145         IDL_tree tree = tfd->tree;
146         if (IDL_NODE_TYPE (tree) == IDLN_NATIVE) {
147                 *(bool*)user_data = true;
148                 return FALSE;   /* Stop recursing */
149         }
150         return TRUE;            /* continue */
151 }
152
153 static bool
154 contains_native_type(IDL_tree tree)
155 {
156         bool found = false;
157         IDL_tree_walk_in_order(tree, is_native, &found);
158         return found;
159 }
160 #endif
161
162 void
163 forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
164 {
165   fprintf (ci->fh, OIDL_C_WARNING);
166   fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
167   fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
168
169   fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
170
171   fprintf(ci->fh, "#include <forb/cdr_codec.h>\n");
172   if (!rinfo->is_pidl) {
173     fprintf(ci->fh, "#include <forb/object_type.h>\n");
174   }
175   fprintf(ci->fh, "#include <forb/basic_types.h>\n");
176   if (rinfo->include) {
177           fprintf(ci->fh, "#include <%s>\n", rinfo->include);
178   }
179   fprintf(ci->fh, "\n");
180
181   fprintf(ci->fh, "#ifdef __cplusplus\n");
182   fprintf(ci->fh, "extern \"C\" {\n");
183   fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
184
185   /* Do all the typedefs, etc. */
186   fprintf(ci->fh, "\n/** typedefs **/\n");
187   ch_output_types(tree, rinfo, ci);
188   
189   if ( ci->do_skel_defs ) {
190 /*      /\* Do all the POA structures, etc. *\/ */
191 /*      fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
192 /*      ch_output_poa(tree, rinfo, ci); */
193
194 /*      fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
195 /*      fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
196 /*      ch_output_skel_protos(tree, rinfo, ci); */
197   }
198   fprintf(ci->fh, "\n/** stub prototypes **/\n");
199   ch_output_stub_protos(tree, rinfo, ci);
200
201 /*   if ( ci->ext_dcls && ci->ext_dcls->str ) */
202 /*     fputs( ci->ext_dcls->str, ci->fh);       /\* this may be huge! *\/ */
203
204 /*   if (rinfo->idata) { */
205 /*     /\* FIXME: hackish ? *\/ */
206 /*     fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
207
208 /*     ch_output_itypes(tree, ci); */
209 /*   } */
210
211   if (rinfo->idata) {
212         GSList *list = NULL;
213         fprintf (ci->fh, "\n/** Method indices */\n\n");
214                                                                                                            
215         list = ch_build_interfaces (list, tree);
216         ch_output_method_indices (list, ci);
217   }
218
219   fprintf(ci->fh, "#ifdef __cplusplus\n");
220   fprintf(ci->fh, "}\n");
221   fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
222
223 /*   fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
224 /*   fprintf(ci->fh, "#include <forb.h>\n\n"); */
225 /*   fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
226
227   fprintf(ci->fh, "#endif\n");
228
229   fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
230 }
231
232 static void
233 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
234 {
235   forb_cbe_write_typespec(ci->fh, val);
236
237   fprintf(ci->fh, " ");
238   switch(IDL_NODE_TYPE(name)) {
239   case IDLN_IDENT:
240     fprintf(ci->fh, "%s", IDL_IDENT(name).str);
241     break;
242   case IDLN_TYPE_ARRAY:
243     {
244       IDL_tree curitem;
245
246       fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
247       for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
248         fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
249       }
250     }
251     break;
252   default:
253     g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
254     break;
255   }
256   fprintf(ci->fh, ";\n");
257 }
258
259 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
260 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
261 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
262 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
263 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
264 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
265 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
266 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
267 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
268 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
269
270 static void
271 ch_output_types (IDL_tree       tree,
272                  OIDL_Run_Info *rinfo,
273                  OIDL_C_Info   *ci)
274 {
275         if (!tree)
276                 return;
277         
278         switch (IDL_NODE_TYPE (tree)) {
279         case IDLN_EXCEPT_DCL: {
280           IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
281 /*              char *id; */
282
283 /*              id = IDL_ns_ident_to_qstring ( */
284 /*                      IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
285
286 /*              fprintf (ci->fh, "#undef ex_%s\n", id); */
287 /*              fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
288 /*                              id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
289
290 /*              g_free (id); */
291
292 /*              ch_output_type_struct (tree, rinfo, ci); */
293                 }
294                 break;
295         case IDLN_FORWARD_DCL:
296         case IDLN_INTERFACE:
297                 ch_output_interface (tree, rinfo, ci);
298                 break;
299         case IDLN_TYPE_STRUCT:
300                 ch_output_type_struct (tree, rinfo, ci);
301                 break;
302         case IDLN_TYPE_ENUM:
303                 ch_output_type_enum (tree, rinfo, ci);
304                 break;
305         case IDLN_TYPE_DCL:
306                 ch_output_type_dcl (tree, rinfo, ci);
307                 break;
308         case IDLN_TYPE_UNION:
309                 ch_output_type_union (tree, rinfo, ci);
310                 break;
311         case IDLN_CODEFRAG:
312                 ch_output_codefrag (tree, rinfo, ci);
313                 break;
314         case IDLN_SRCFILE: {
315                 char *idlfn = IDL_SRCFILE (tree).filename;
316                 if (rinfo->onlytop) {
317
318                         if (!IDL_SRCFILE (tree).seenCnt &&
319                             !IDL_SRCFILE(tree).isTop    &&
320                             !IDL_SRCFILE(tree).wasInhibit) {
321                                 gchar *hfn, *htail;
322
323                                 hfn   = g_path_get_basename (idlfn);
324                                 htail = strrchr (hfn,'.');
325
326                                 g_assert (htail && strlen (htail) >= 2);
327
328                                 htail [1] = 'h';
329                                 htail [2] = 0;
330
331                                 fprintf (ci->fh, "#include \"%s\"\n", hfn);
332
333                                 g_free (hfn);
334                         }
335                 } else {
336                 fprintf (ci->fh, "/* from IDL source file \"%s\" "
337                                  "(seen %d, isTop %d, wasInhibit %d) */ \n", 
338                                         idlfn,
339                                         IDL_SRCFILE (tree).seenCnt,
340                                         IDL_SRCFILE (tree).isTop,
341                                         IDL_SRCFILE (tree).wasInhibit);
342                 }
343                 }
344                 break;
345         case IDLN_CONST_DCL:
346                 ch_output_const_dcl (tree, rinfo, ci);
347                 break;
348 /*      case IDLN_NATIVE: */
349 /*              ch_output_native (tree, rinfo, ci); */
350 /*              break; */
351         default:
352                 break;
353         }
354
355         switch (IDL_NODE_TYPE (tree)) {
356         case IDLN_MODULE:
357                 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
358                 break;
359         case IDLN_LIST: {
360                 IDL_tree sub;
361
362                 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
363                         ch_output_types (IDL_LIST (sub).data, rinfo, ci);
364                 }
365                 }
366                 break;
367         case IDLN_INTERFACE:
368                 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
369                 break;
370         default:
371                 break;
372         }
373 }
374
375 static void
376 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
377 {
378   if(!tree) return;
379
380   switch(IDL_NODE_TYPE(tree)) {
381   case IDLN_LIST:
382     {
383       IDL_tree sub;
384
385       for(sub = tree; sub; sub = IDL_LIST(sub).next) {
386         ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
387       }
388     }
389     break;
390   case IDLN_INTERFACE:
391     {
392       IDL_tree sub;
393
394 /*       if(IDL_INTERFACE(tree).inheritance_spec) { */
395 /*      InheritedOutputInfo ioi; */
396 /*      ioi.of = ci->fh; */
397 /*      ioi.realif = tree; */
398 /*      IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
399 /*       } */
400
401       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
402         IDL_tree cur;
403
404         cur = IDL_LIST(sub).data;
405
406         switch(IDL_NODE_TYPE(cur)) {
407         case IDLN_OP_DCL:
408           forb_idl_check_oneway_op (cur);
409           fprintf(ci->fh, "  ");
410           forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
411           fprintf(ci->fh, ";\n");
412           break;
413 /*      case IDLN_ATTR_DCL: */
414 /*        { */
415 /*          OIDL_Attr_Info *ai; */
416 /*          IDL_tree curitem; */
417
418 /*          for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
419 /*            ai = IDL_LIST(curitem).data->data; */
420               
421 /*            forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
422 /*            fprintf(ci->fh, ";\n"); */
423               
424 /*            if(ai->op2) { */
425 /*              forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
426 /*              fprintf(ci->fh, ";\n"); */
427 /*            } */
428 /*          } */
429 /*        } */
430 /*        break; */
431         default:
432           break;
433         }
434       }
435     }
436     break;
437   default:
438     break;
439   }
440 }
441 static void
442 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
443 {
444     char *fullname;
445     fullname = forb_cbe_get_typespec_str(tree);
446     fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
447     ch_output_impl_struct_members(tree, rinfo, ci);
448     fprintf(ci->fh, "};\n\n");
449     g_free(fullname);
450 }
451
452 static void
453 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
454 {
455     char *fullname;
456     fullname = forb_cbe_get_typespec_str(tree);
457     fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n"
458                     "#define FORB_DECL_%s 1\n",
459                     fullname, fullname);
460
461     if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
462         /* PIDL interfaces are not normal CORBA Objects */
463       fprintf(ci->fh, "// PIDL: %s\n", fullname);
464 /*      fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
465 /*      fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
466 /*      fprintf(ci->fh, "#  define TC_%s TC_CORBA_Object\n", fullname); */
467 /*      fprintf(ci->fh, "#endif\n"); */
468     } else {
469
470         fprintf(ci->fh, "  #if !defined(_%s_defined)\n"
471                         "  #define _%s_defined 1\n",
472                         fullname, fullname);
473 /*         fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
474         fprintf(ci->fh, "    typedef forb_object %s;\n"
475                         "  #endif\n", fullname);
476         fprintf(ci->fh, "  #define %s_serialize(codec, obj) forb_object_serialize((codec), (obj))\n", fullname);
477         fprintf(ci->fh, "  #define %s_deserialize(codec, obj) forb_object_deserialize((codec), (obj))\n", fullname);
478 /*      fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
479
480         ch_output_impl_struct(tree, rinfo, ci);
481
482 /*      fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname); */
483         fprintf(ci->fh, "  %s forb_%s_new(forb_orb orb,\n"
484                         "                 const struct forb_%s_impl *impl,\n"
485                         "                 void *instance_data);\n\n",
486                 fullname, fullname, fullname);
487         
488         /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
489     }
490
491     fprintf(ci->fh, "#endif\n\n");
492     g_free(fullname);
493 }
494
495 static void
496 ch_output_type_enum (IDL_tree       tree,
497                      OIDL_Run_Info *rinfo,
498                      OIDL_C_Info   *ci)
499 {
500         IDL_tree  l;
501         char     *enumid;
502
503         /* CORBA spec says to do
504          * typedef unsigned int enum_name;
505          * and then #defines for each enumerator.
506          * This works just as well and seems cleaner.
507          */
508
509         enumid = IDL_ns_ident_to_qstring (
510                         IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
511         fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
512         fprintf (ci->fh, "typedef enum {\n");
513
514         for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
515                 char *id;
516
517                 id = IDL_ns_ident_to_qstring (
518                         IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
519
520                 fprintf (ci->fh, "  %s%s\n", id, IDL_LIST (l).next ? "," : "");
521
522                 g_free (id);
523         }
524
525         fprintf (ci->fh, "} %s;\n", enumid);
526
527         /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
528         fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
529         fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
530
531         fprintf (ci->fh, "#endif\n\n");
532
533         g_free (enumid);
534 }
535
536 static void
537 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
538 {
539         IDL_tree  l;
540
541         ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
542
543         for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
544                 char *ctmp = NULL;
545
546                 IDL_tree ent = IDL_LIST (l).data;
547
548                 switch (IDL_NODE_TYPE(ent)) {
549                 case IDLN_IDENT:
550                         ctmp = IDL_ns_ident_to_qstring (
551                                         IDL_IDENT_TO_NS (ent), "_", 0);
552                         break;
553                 case IDLN_TYPE_ARRAY:
554                         ctmp = IDL_ns_ident_to_qstring (
555                                         IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
556                         break;
557                 default:
558                         g_assert_not_reached ();
559                         break;
560                 }
561
562                 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
563                 fprintf (ci->fh, "typedef ");
564                 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
565
566                 switch (IDL_NODE_TYPE (ent)) {
567                 case IDLN_IDENT:
568                         fprintf (ci->fh, " %s;\n", ctmp);
569                         fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
570                         forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
571                         fprintf (ci->fh, "_serialize((x),(y))\n");
572
573                         fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
574                         forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
575                         fprintf (ci->fh, "_deserialize((x),(y))\n");
576                         break;
577                 case IDLN_TYPE_ARRAY: {
578                         IDL_tree sub;
579
580                         fprintf (ci->fh, " %s", ctmp);
581                         for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
582                                 fprintf (ci->fh, "[%" IDL_LL "d]",
583                                          IDL_INTEGER (IDL_LIST (sub).data).value);
584
585                         fprintf (ci->fh, ";\n");
586                         fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
587                         fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s array);\n", ctmp, ctmp);
588 /*                      fprintf (ci->fh, "typedef "); */
589 /*                      forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
590 /*                      fprintf (ci->fh, " %s_slice", ctmp); */
591 /*                      for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
592 /*                           sub; sub = IDL_LIST (sub).next) */
593 /*                              fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
594 /*                      fprintf(ci->fh, ";\n"); */
595                         }
596                         break;
597                 default:
598                         break;
599                 }
600
601                 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
602                 fprintf (ci->fh, "#endif\n");
603                 g_free (ctmp);
604         }
605 }
606
607 /* static void */
608 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
609 /* { */
610 /*     char *ctmp; */
611 /*     IDL_tree id = IDL_NATIVE(tree).ident; */
612 /*     ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
613 /*     fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
614 /*     fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
615 /*     /\* Dont even think about emitting a typecode. *\/ */
616 /*     fprintf(ci->fh, "#endif\n"); */
617 /*     g_free(ctmp); */
618 /* } */
619
620 static void
621 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
622 {
623   char *id;
624   IDL_tree cur, curmem;
625
626   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
627     "_", 0);
628   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
629   /* put typedef out first for recursive seq */
630   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
631
632   /* Scan for any nested decls */
633   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
634     IDL_tree ts;
635     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
636     ch_prep(ts, rinfo, ci);
637   }
638
639   fprintf(ci->fh, "struct %s_type {\n", id);
640
641   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
642     for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
643       ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
644     }
645   }
646   if(!IDL_TYPE_STRUCT(tree).member_list)
647     fprintf(ci->fh, "int dummy;\n");
648   fprintf(ci->fh, "};\n");
649
650   fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", id, id);
651   fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", id, id);
652
653   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
654
655   fprintf(ci->fh, "#endif\n\n");
656
657   g_free(id);
658 }
659
660
661 static void
662 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
663 {
664   char *id;
665   IDL_tree curitem;
666
667   if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
668     ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
669
670   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
671   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
672   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
673
674   /* Scan for any nested decls */
675   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
676     IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
677     ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
678   }
679
680   fprintf(ci->fh, "struct %s_type {\n", id);
681   forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
682   fprintf(ci->fh, " _d;\nunion {\n");
683
684   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
685     IDL_tree member;
686
687     member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
688     ch_output_var(IDL_MEMBER(member).type_spec,
689                   IDL_LIST(IDL_MEMBER(member).dcls).data,
690                   ci);
691   }
692
693   fprintf(ci->fh, "} _u;\n};\n");
694
695   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
696
697   fprintf(ci->fh, "#endif\n");
698
699   g_free(id);
700 }
701
702 static void
703 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
704 {
705   GSList *list;
706
707   for(list = IDL_CODEFRAG(tree).lines; list;
708       list = g_slist_next(list)) {
709     if(!strncmp(list->data,
710                 "#pragma include_defs",
711                 sizeof("#pragma include_defs")-1)) {
712         char *ctmp, *cte;
713         ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
714         while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
715         cte = ctmp;
716         while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
717         *cte = '\0';
718       fprintf(ci->fh, "#include <%s>\n", ctmp);
719     } else
720       fprintf(ci->fh, "%s\n", (char *)list->data);
721   }
722 }
723
724 static void
725 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
726 {
727         char    *id;
728         IDL_tree ident;
729         IDL_tree typespec;
730
731         ident = IDL_CONST_DCL (tree).ident;
732         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
733
734         fprintf(ci->fh, "#ifndef %s\n", id);
735         fprintf(ci->fh, "#define %s ", id);
736
737         forb_cbe_write_const(ci->fh,
738                               IDL_CONST_DCL(tree).const_exp);
739
740         typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
741         if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
742             !IDL_TYPE_INTEGER (typespec).f_signed)
743                 fprintf(ci->fh, "U");
744
745         fprintf(ci->fh, "\n");
746         fprintf(ci->fh, "#endif /* !%s */\n\n", id);
747
748         g_free(id);
749 }
750
751 static void
752 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
753 {
754   char *ctmp;
755
756   ctmp = forb_cbe_get_typespec_str(tree);
757   fprintf(ci->fh,
758           "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
759           (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
760           ctmp);
761   g_free(ctmp);
762
763   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
764 }
765
766 static void
767 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
768 {
769   char *ctmp, *fullname, *fullname_def, *ctmp2;
770   IDL_tree tts;
771   gboolean separate_defs, fake_if;
772   IDL_tree fake_seq = NULL;
773
774   tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
775   ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
776   ctmp2 = forb_cbe_get_typespec_str(tts);
777   fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
778   if(fake_if)
779     {
780       g_free(ctmp2);
781       ctmp2 = g_strdup("CORBA_Object");
782     }
783   separate_defs = strcmp(ctmp, ctmp2);
784   fullname = forb_cbe_get_typespec_str(tree);
785   //printf("YYY %s\n", fullname);
786
787   if(separate_defs)
788     {
789       char *member_type;
790       //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
791       //forb_idl_print_node(tree, 2);
792       if(fake_if)
793         tts = IDL_type_object_new();
794       fake_seq = IDL_type_sequence_new(tts, NULL);
795       IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
796       ch_prep_sequence(fake_seq, rinfo, ci);
797       member_type = forb_cbe_type_is_builtin (tts) ?
798         ctmp2 + strlen ("CORBA_") : ctmp2;
799       fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
800
801       if(!fake_if)
802         IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
803     }
804   else
805     fullname_def = g_strdup(fullname);
806
807   if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
808      == IDLN_TYPE_SEQUENCE)
809     ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
810
811   /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
812    * while _%s_defined protects only the struct */
813
814   fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
815           fullname, fullname);
816 /*   if ( ci->do_impl_hack ) */
817 /*       forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
818
819   if(separate_defs)
820     {
821       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
822               fullname, fullname);
823       if(!strcmp(ctmp, "CORBA_RepositoryId"))
824         fprintf(ci->fh, "/* CRACKHEADS */\n");
825       fprintf(ci->fh, "typedef %s\n  %s;\n", fullname_def, fullname);
826       fprintf(ci->fh, "#endif\n");
827       /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
828 /*       fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
829 /*            fullname, fullname_def); */
830 /*       fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
831 /*            fullname, fullname_def); */
832       fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
833               ctmp, fullname_def);
834       fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
835
836       fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
837       IDL_tree_free(fake_seq);
838     }
839   else
840     {
841       char *member_type;
842
843       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
844               fullname, fullname);
845       fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
846       forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
847       fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n  ");
848       forb_cbe_write_typespec(ci->fh, tree);
849       fprintf(ci->fh, ";\n#endif\n");
850
851       fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
852       fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
853       /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
854
855 /*       tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
856       member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
857         ctmp + strlen ("CORBA_") : ctmp;
858
859       fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
860                        "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
861                        member_type, ctmp, ctmp);
862
863 /*       g_free (tc); */
864     }
865
866   fprintf(ci->fh, "#endif\n\n");
867
868   g_free(ctmp2);
869   g_free(ctmp);
870   g_free(fullname);
871   g_free(fullname_def);
872 }
873
874 static
875 void ch_prep (IDL_tree       tree,
876               OIDL_Run_Info *rinfo,
877               OIDL_C_Info   *ci)
878 {
879         switch (IDL_NODE_TYPE (tree)) {
880         case IDLN_TYPE_SEQUENCE:
881                 ch_prep_sequence (tree, rinfo, ci);
882                 break;
883         case IDLN_TYPE_FIXED:
884                 ch_prep_fixed (tree, rinfo, ci);
885                 break;
886         case IDLN_TYPE_STRUCT:
887                 ch_output_type_struct (tree, rinfo, ci);
888                 break;
889         case IDLN_TYPE_ENUM:
890                 ch_output_type_enum (tree, rinfo, ci);
891                 break;
892         default:
893                 break;
894         }
895 }
896
897 /* static void */
898 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
899 /*                   OIDL_C_Info *ci, gboolean do_alloc) */
900 /* { */
901 /*   char *ctmp; */
902 /*   IDL_tree tts; */
903
904 /*   ctmp = forb_cbe_get_typespec_str(tree); */
905
906 /*   if ( ci->do_impl_hack ) { */
907 /*       fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
908 /*       forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
909 /*   } */
910
911 /*   fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
912 /*   fprintf (ci->fh, "static\n"); */
913 /*   fprintf (ci->fh, "#else\n"); */
914 /*   fprintf (ci->fh, "extern\n"); */
915 /*   fprintf (ci->fh, "#endif\n"); */
916 /*   fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
917
918 /*   fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
919 /*   if (ci->do_impl_hack) */
920 /*       fprintf (ci->fh, "#endif\n"); */
921
922 /*   if(do_alloc) { */
923 /*       char *tc; */
924
925 /*       tts = forb_cbe_get_typespec(tree); */
926
927 /*       tc = forb_cbe_get_typecode_name (tts); */
928
929 /*       fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
930 /*                 ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
931
932 /*       fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
933
934 /*       if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
935 /*       { */
936 /*      char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
937 /*      char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
938 /*        member_type + strlen ("CORBA_") : member_type; */
939         
940 /*      fprintf (ci->fh, "#define %s_allocbuf(l) " */
941 /*               "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
942 /*               ctmp, member_name, tc); */
943         
944 /*      g_free (member_type); */
945 /*       } */
946         
947 /*       g_free (tc); */
948 /*   } */
949
950 /*   g_free(ctmp); */
951 /* } */
952
953 /************************/
954 /* static void */
955 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
956 /* { */
957 /*   char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
958 /*                                   "_", 0); */
959 /*   fprintf(of, "  POA_%s__epv *%s_epv;\n", id, id); */
960 /*   g_free(id); */
961
962 /* } */
963
964 /* static void */
965 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
966 /* { */
967 /*   if(!tree) return; */
968
969 /*   if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
970 /*      return; */
971
972 /*   switch(IDL_NODE_TYPE(tree)) { */
973 /*   case IDLN_MODULE: */
974 /*     ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
975 /*     break; */
976 /*   case IDLN_LIST: */
977 /*     { */
978 /*       IDL_tree sub; */
979
980 /*       for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
981 /*      ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
982 /*       } */
983 /*     } */
984 /*     break; */
985 /*   case IDLN_INTERFACE: */
986 /*     { */
987 /*       IDL_tree sub; */
988 /*       char *id; */
989
990
991 /*       id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
992
993 /*       fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n",  */
994 /*         id, id); */
995
996 /*       /\* First, do epv for this interface, then vepv, then servant *\/ */
997 /*       fprintf(ci->fh, "typedef struct {\n"); */
998 /*       fprintf(ci->fh, "  void *_private;\n"); */
999 /*       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1000 /*      IDL_tree cur; */
1001
1002 /*      cur = IDL_LIST(sub).data; */
1003
1004 /*      switch(IDL_NODE_TYPE(cur)) { */
1005 /*      case IDLN_OP_DCL: */
1006 /*        forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
1007 /*        fprintf(ci->fh, ";\n"); */
1008 /*        break; */
1009 /*      case IDLN_ATTR_DCL: */
1010 /*        { */
1011 /*          OIDL_Attr_Info *ai; */
1012 /*          IDL_tree curitem; */
1013
1014 /*          for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
1015 /*            ai = IDL_LIST(curitem).data->data; */
1016               
1017 /*            forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
1018 /*            fprintf(ci->fh, ";\n"); */
1019               
1020 /*            if(ai->op2) { */
1021 /*              forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
1022 /*              fprintf(ci->fh, ";\n"); */
1023 /*            } */
1024 /*          } */
1025 /*        } */
1026 /*        break; */
1027 /*      default: */
1028 /*        break; */
1029 /*      } */
1030 /*       } */
1031
1032 /*       fprintf(ci->fh, "} POA_%s__epv;\n", id); */
1033
1034 /*       fprintf(ci->fh, "typedef struct {\n"); */
1035 /*       fprintf(ci->fh, "  PortableServer_ServantBase__epv *_base_epv;\n"); */
1036 /*       IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1037 /*       fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1038
1039 /*       fprintf(ci->fh, "typedef struct {\n"); */
1040 /*       fprintf(ci->fh, "  void *_private;\n"); */
1041 /*       fprintf(ci->fh, "  POA_%s__vepv *vepv;\n", id); */
1042 /*       fprintf(ci->fh, "} POA_%s;\n", id); */
1043
1044 /*       fprintf(ci->fh, */
1045 /*            "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1046 /*       fprintf(ci->fh, */
1047 /*            "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1048
1049 /*       fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1050
1051 /*       g_free(id); */
1052 /*     } */
1053 /*     break; */
1054 /*   default: */
1055 /*     break; */
1056 /*   } */
1057 /* } */
1058
1059 /************************/
1060 typedef struct {
1061   FILE *of;
1062   IDL_tree realif;
1063 } InheritedOutputInfo;
1064 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1065
1066 static void
1067 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1068 {
1069   if(!tree) return;
1070
1071
1072   switch(IDL_NODE_TYPE(tree)) {
1073   case IDLN_MODULE:
1074     ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1075     break;
1076   case IDLN_LIST:
1077     {
1078       IDL_tree sub;
1079
1080       for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1081         ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1082       }
1083     }
1084     break;
1085   case IDLN_INTERFACE:
1086     {
1087       IDL_tree sub;
1088
1089       if(IDL_INTERFACE(tree).inheritance_spec) {
1090         InheritedOutputInfo ioi;
1091         ioi.of = ci->fh;
1092         ioi.realif = tree;
1093         IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1094       }
1095
1096       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1097         IDL_tree cur;
1098
1099         cur = IDL_LIST(sub).data;
1100
1101         switch(IDL_NODE_TYPE(cur)) {
1102         case IDLN_OP_DCL:
1103           forb_idl_check_oneway_op (cur);
1104           forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1105           fprintf(ci->fh, ";\n");
1106           break;
1107         case IDLN_ATTR_DCL:
1108           {
1109             OIDL_Attr_Info *ai;
1110             IDL_tree curitem;
1111
1112             for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1113               ai = IDL_LIST(curitem).data->data;
1114               
1115               forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1116               fprintf(ci->fh, ";\n");
1117               
1118               if(ai->op2) {
1119                 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1120                 fprintf(ci->fh, ";\n");
1121               }
1122             }
1123           }
1124           break;
1125         default:
1126           break;
1127         }
1128       }
1129     }
1130     break;
1131   default:
1132     break;
1133   }
1134 }
1135
1136 static void
1137 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1138 {
1139   char *id, *realid;
1140   IDL_tree curitem;
1141
1142   if(curif == ioi->realif)
1143     return;
1144
1145   realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1146   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1147
1148   for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1149     IDL_tree curop = IDL_LIST(curitem).data;
1150
1151     switch(IDL_NODE_TYPE(curop)) {
1152     case IDLN_OP_DCL:
1153       fprintf(ioi->of, "#define %s_%s %s_%s\n",
1154               realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1155               id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1156       break;
1157     case IDLN_ATTR_DCL:
1158       {
1159         IDL_tree curitem;
1160
1161         /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1162            and therefore don't have the OIDL_Attr_Info generated on them */
1163
1164         for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1165           IDL_tree ident;
1166
1167           ident = IDL_LIST(curitem).data;
1168           
1169           fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1170                   realid, IDL_IDENT(ident).str,
1171                   id, IDL_IDENT(ident).str);
1172
1173           if(!IDL_ATTR_DCL(curop).f_readonly)
1174             fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1175                     realid, IDL_IDENT(ident).str,
1176                     id, IDL_IDENT(ident).str);
1177         }
1178       }
1179       break;
1180         default:
1181           break;
1182     }
1183   }
1184
1185   g_free(id);
1186   g_free(realid);
1187 }
1188
1189 /* static void */
1190 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1191 /* { */
1192 /*   char *id; */
1193
1194 /*   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1195
1196 /*   fprintf(ci->fh, "void _forb_skel_%s(" */
1197 /*        "FORB_CDR_Codec *codec, %s *obj", */
1198 /*        id, ifid); */
1199 /* /\*   forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1200 /*   fprintf(ci->fh, ");\n"); */
1201
1202 /*   g_free(id); */
1203 /* } */
1204
1205 /* static void */
1206 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1207 /* { */
1208 /*   if(!tree) return; */
1209
1210 /*   if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1211 /*      return; */
1212
1213 /*   switch(IDL_NODE_TYPE(tree)) { */
1214 /*   case IDLN_MODULE: */
1215 /*     ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1216 /*     break; */
1217 /*   case IDLN_LIST: */
1218 /*     { */
1219 /*       IDL_tree sub; */
1220
1221 /*       for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1222 /*      ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1223 /*       } */
1224 /*     } */
1225 /*     break; */
1226 /*   case IDLN_INTERFACE: */
1227 /*     { */
1228 /*       IDL_tree sub; */
1229 /*       char *ifid; */
1230
1231 /*       ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1232
1233 /*       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1234 /*      IDL_tree cur; */
1235
1236 /*      cur = IDL_LIST(sub).data; */
1237
1238 /*      switch(IDL_NODE_TYPE(cur)) { */
1239 /*      case IDLN_OP_DCL: */
1240 /*        doskel(cur, rinfo, ifid, ci); */
1241 /*        break; */
1242 /*      case IDLN_ATTR_DCL: */
1243 /*        IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1244 /* /\*    { *\/ */
1245 /* /\*      OIDL_Attr_Info *ai = cur->data; *\/ */
1246 /* /\*      IDL_tree curitem; *\/ */
1247
1248 /* /\*      for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1249 /* /\*        ai = IDL_LIST(curitem).data->data; *\/ */
1250               
1251 /* /\*        doskel(ai->op1, rinfo, ifid, ci); *\/ */
1252 /* /\*        if(ai->op2) *\/ */
1253 /* /\*          doskel(ai->op2, rinfo, ifid, ci); *\/ */
1254 /* /\*      } *\/ */
1255 /* /\*    } *\/ */
1256 /*        break; */
1257 /*      default: */
1258 /*        break; */
1259 /*      } */
1260 /*       } */
1261 /*       g_free(ifid); */
1262 /*     } */
1263 /*     break; */
1264 /*   default: */
1265 /*     break; */
1266 /*   } */
1267 /* } */
1268
1269 /* static void */
1270 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1271 /* { */
1272 /*      static int num_methods = 0; */
1273
1274 /*      if (!tree) */
1275 /*              return; */
1276
1277 /*      switch(IDL_NODE_TYPE(tree)) { */
1278 /*      case IDLN_MODULE: */
1279 /*              ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1280 /*              break; */
1281 /*      case IDLN_LIST: { */
1282 /*              IDL_tree sub; */
1283 /*              for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1284 /*                      ch_output_itypes (IDL_LIST(sub).data, ci); */
1285 /*      } */
1286 /*      break; */
1287 /*      case IDLN_ATTR_DCL: { */
1288 /*              OIDL_Attr_Info *ai = tree->data; */
1289
1290 /*              IDL_tree curitem; */
1291       
1292 /*              for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1293 /*                  curitem = IDL_LIST(curitem).next) { */
1294 /*                      ai = IDL_LIST(curitem).data->data; */
1295         
1296 /*                      ch_output_itypes (ai->op1, ci); */
1297 /*                      if(ai->op2) */
1298 /*                              ch_output_itypes (ai->op2, ci); */
1299 /*              } */
1300 /*      } */
1301 /*      break; */
1302
1303 /*      case IDLN_INTERFACE: { */
1304 /*              char  *id; */
1305
1306 /*              id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1307 /*                      IDL_INTERFACE (tree).ident), "_", 0); */
1308
1309 /*              ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1310       
1311 /*              fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1312 /*                       ci->c_base_name); */
1313 /*              fprintf (ci->fh, "static \n"); */
1314 /*              fprintf (ci->fh, "#else\n"); */
1315 /*              fprintf (ci->fh, "extern \n"); */
1316 /*              fprintf (ci->fh, "#endif\n"); */
1317 /*              fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1318
1319 /*              fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1320
1321 /*              if (num_methods == 0) */
1322 /*                      fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1323 /*              else { */
1324 /*                      fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1325 /*                               ci->c_base_name); */
1326 /*                      fprintf (ci->fh, "static \n"); */
1327 /*                      fprintf (ci->fh, "#else\n"); */
1328 /*                      fprintf (ci->fh, "extern \n"); */
1329 /*                      fprintf (ci->fh, "#endif\n"); */
1330 /*                      fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1331 /*              } */
1332
1333
1334 /*              num_methods = 0; */
1335
1336 /*              break; */
1337 /*      } */
1338
1339 /*      case IDLN_OP_DCL: */
1340 /*              num_methods++; */
1341 /*              break; */
1342 /*      default: */
1343 /*              break; */
1344 /*      } */
1345 /* } */