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