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