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