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