]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - forb-idl/forb-idl-c-headers.c
Not finished attempt to support sequences
[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_implementation {\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, "typedef struct %s_type *%s;\n", fullname, fullname); */
434 /*      fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
435 /*      fprintf(ci->fh, "#  define TC_%s TC_CORBA_Object\n", fullname); */
436 /*      fprintf(ci->fh, "#endif\n"); */
437 /*     } else { */
438
439 /*         fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
440         fprintf(ci->fh, "typedef forb_object %s;\n", fullname);
441 /*      fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
442
443         ch_output_impl_struct(tree, rinfo, ci);
444
445         fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname);
446         fprintf(ci->fh, "%s forb_%s_new(void *instance_data,\n"
447                         "               const struct forb_%s_implementation *impl);\n\n",
448                 fullname, fullname, fullname);
449         
450         /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
451 /*     } */
452
453     fprintf(ci->fh, "#endif\n");
454     g_free(fullname);
455 }
456
457 static void
458 ch_output_type_enum (IDL_tree       tree,
459                      OIDL_Run_Info *rinfo,
460                      OIDL_C_Info   *ci)
461 {
462         IDL_tree  l;
463         char     *enumid;
464
465         /* CORBA spec says to do
466          * typedef unsigned int enum_name;
467          * and then #defines for each enumerator.
468          * This works just as well and seems cleaner.
469          */
470
471         enumid = IDL_ns_ident_to_qstring (
472                         IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
473         fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
474         fprintf (ci->fh, "typedef enum {\n");
475
476         for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
477                 char *id;
478
479                 id = IDL_ns_ident_to_qstring (
480                         IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
481
482                 fprintf (ci->fh, "  %s%s\n", id, IDL_LIST (l).next ? "," : "");
483
484                 g_free (id);
485         }
486
487         fprintf (ci->fh, "} %s;\n", enumid);
488
489         /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
490         fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
491         fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
492
493         fprintf (ci->fh, "#endif\n\n");
494
495         g_free (enumid);
496 }
497
498 static void
499 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
500 {
501         IDL_tree  l;
502
503         ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
504
505         for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
506                 char *ctmp = NULL;
507
508                 IDL_tree ent = IDL_LIST (l).data;
509
510                 switch (IDL_NODE_TYPE(ent)) {
511                 case IDLN_IDENT:
512                         ctmp = IDL_ns_ident_to_qstring (
513                                         IDL_IDENT_TO_NS (ent), "_", 0);
514                         break;
515                 case IDLN_TYPE_ARRAY:
516                         ctmp = IDL_ns_ident_to_qstring (
517                                         IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
518                         break;
519                 default:
520                         g_assert_not_reached ();
521                         break;
522                 }
523
524                 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
525                 fprintf (ci->fh, "typedef ");
526                 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
527
528                 switch (IDL_NODE_TYPE (ent)) {
529                 case IDLN_IDENT:
530                         fprintf (ci->fh, " %s;\n", ctmp);
531                         fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
532                         forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
533                         fprintf (ci->fh, "_serialize((x),(y))\n");
534
535                         fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
536                         forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
537                         fprintf (ci->fh, "_deserialize((x),(y))\n");
538                         break;
539                 case IDLN_TYPE_ARRAY: {
540                         IDL_tree sub;
541
542                         fprintf (ci->fh, " %s", ctmp);
543                         for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
544                                 fprintf (ci->fh, "[%" IDL_LL "d]",
545                                          IDL_INTEGER (IDL_LIST (sub).data).value);
546
547                         fprintf (ci->fh, ";\n");
548                         fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
549                         fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
550 /*                      fprintf (ci->fh, "typedef "); */
551 /*                      forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
552 /*                      fprintf (ci->fh, " %s_slice", ctmp); */
553 /*                      for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
554 /*                           sub; sub = IDL_LIST (sub).next) */
555 /*                              fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
556 /*                      fprintf(ci->fh, ";\n"); */
557                         }
558                         break;
559                 default:
560                         break;
561                 }
562
563                 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
564                 fprintf (ci->fh, "#endif\n");
565                 g_free (ctmp);
566         }
567 }
568
569 /* static void */
570 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
571 /* { */
572 /*     char *ctmp; */
573 /*     IDL_tree id = IDL_NATIVE(tree).ident; */
574 /*     ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
575 /*     fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
576 /*     fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
577 /*     /\* Dont even think about emitting a typecode. *\/ */
578 /*     fprintf(ci->fh, "#endif\n"); */
579 /*     g_free(ctmp); */
580 /* } */
581
582 static void
583 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
584 {
585   char *id;
586   IDL_tree cur, curmem;
587
588   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident), 
589     "_", 0);
590   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
591   /* put typedef out first for recursive seq */
592   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
593
594   /* Scan for any nested decls */
595   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
596     IDL_tree ts;
597     ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
598     ch_prep(ts, rinfo, ci);
599   }
600
601   fprintf(ci->fh, "struct %s_type {\n", id);
602
603   for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
604     for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
605       ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
606     }
607   }
608   if(!IDL_TYPE_STRUCT(tree).member_list)
609     fprintf(ci->fh, "int dummy;\n");
610   fprintf(ci->fh, "};\n");
611
612   fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr);\n", id, id);
613   fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", id, id);
614
615   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
616
617   fprintf(ci->fh, "#endif\n\n");
618
619   g_free(id);
620 }
621
622
623 static void
624 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
625 {
626   char *id;
627   IDL_tree curitem;
628
629   if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
630     ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
631
632   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
633   fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
634   fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
635
636   /* Scan for any nested decls */
637   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
638     IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
639     ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
640   }
641
642   fprintf(ci->fh, "struct %s_type {\n", id);
643   forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
644   fprintf(ci->fh, " _d;\nunion {\n");
645
646   for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
647     IDL_tree member;
648
649     member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
650     ch_output_var(IDL_MEMBER(member).type_spec,
651                   IDL_LIST(IDL_MEMBER(member).dcls).data,
652                   ci);
653   }
654
655   fprintf(ci->fh, "} _u;\n};\n");
656
657   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
658
659   fprintf(ci->fh, "#endif\n");
660
661   g_free(id);
662 }
663
664 static void
665 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
666 {
667   GSList *list;
668
669   for(list = IDL_CODEFRAG(tree).lines; list;
670       list = g_slist_next(list)) {
671     if(!strncmp(list->data,
672                 "#pragma include_defs",
673                 sizeof("#pragma include_defs")-1)) {
674         char *ctmp, *cte;
675         ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
676         while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
677         cte = ctmp;
678         while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
679         *cte = '\0';
680       fprintf(ci->fh, "#include <%s>\n", ctmp);
681     } else
682       fprintf(ci->fh, "%s\n", (char *)list->data);
683   }
684 }
685
686 static void
687 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
688 {
689         char    *id;
690         IDL_tree ident;
691         IDL_tree typespec;
692
693         ident = IDL_CONST_DCL (tree).ident;
694         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
695
696         fprintf(ci->fh, "#ifndef %s\n", id);
697         fprintf(ci->fh, "#define %s ", id);
698
699         forb_cbe_write_const(ci->fh,
700                               IDL_CONST_DCL(tree).const_exp);
701
702         typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
703         if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
704             !IDL_TYPE_INTEGER (typespec).f_signed)
705                 fprintf(ci->fh, "U");
706
707         fprintf(ci->fh, "\n");
708         fprintf(ci->fh, "#endif /* !%s */\n\n", id);
709
710         g_free(id);
711 }
712
713 static void
714 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
715 {
716   char *ctmp;
717
718   ctmp = forb_cbe_get_typespec_str(tree);
719   fprintf(ci->fh,
720           "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
721           (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
722           ctmp);
723   g_free(ctmp);
724
725   /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
726 }
727
728 static void
729 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
730 {
731   char *ctmp, *fullname, *fullname_def, *ctmp2;
732   IDL_tree tts;
733   gboolean separate_defs, fake_if;
734   IDL_tree fake_seq = NULL;
735
736   tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
737   ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
738   ctmp2 = forb_cbe_get_typespec_str(tts);
739   fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
740   if(fake_if)
741     {
742       g_free(ctmp2);
743       ctmp2 = g_strdup("CORBA_Object");
744     }
745   separate_defs = strcmp(ctmp, ctmp2);
746   fullname = forb_cbe_get_typespec_str(tree);
747   //printf("YYY %s\n", fullname);
748
749   if(separate_defs)
750     {
751       //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
752       //forb_idl_print_node(tree, 2);
753       if(fake_if)
754         tts = IDL_type_object_new();
755       fake_seq = IDL_type_sequence_new(tts, NULL);
756       IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
757       ch_prep_sequence(fake_seq, rinfo, ci);
758       fullname_def = g_strdup_printf("CORBA_sequence_%s", ctmp2);
759       if(!fake_if)
760         IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
761     }
762   else
763     fullname_def = g_strdup(fullname);
764
765   if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
766      == IDLN_TYPE_SEQUENCE)
767     ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
768
769   /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
770    * while _%s_defined protects only the struct */
771
772   fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
773           fullname, fullname);
774 /*   if ( ci->do_impl_hack ) */
775 /*       forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
776
777   if(separate_defs)
778     {
779       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
780               fullname, fullname);
781       if(!strcmp(ctmp, "CORBA_RepositoryId"))
782         fprintf(ci->fh, "/* CRACKHEADS */\n");
783       fprintf(ci->fh, "typedef %s %s;\n", fullname_def, fullname);
784       fprintf(ci->fh, "#endif\n");
785       /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
786 /*       fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
787 /*            fullname, fullname_def); */
788 /*       fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
789 /*            fullname, fullname_def); */
790       fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf CORBA_sequence_%s_allocbuf\n",
791               ctmp, ctmp2);
792       fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
793
794       fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
795       IDL_tree_free(fake_seq);
796     }
797   else
798     {
799       char *tc, *member_type;
800
801       fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
802               fullname, fullname);
803       fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
804       forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
805       fprintf(ci->fh, "* _buffer; CORBA_boolean _release; } ");
806       forb_cbe_write_typespec(ci->fh, tree);
807       fprintf(ci->fh, ";\n#endif\n");
808
809       fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
810       fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
811       /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
812
813 /*       tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
814       member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
815         ctmp + strlen ("CORBA_") : ctmp;
816
817       fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
818                        "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
819                        member_type, member_type, ctmp);
820
821 /*       g_free (tc); */
822     }
823
824   fprintf(ci->fh, "#endif\n");
825
826   g_free(ctmp2);
827   g_free(ctmp);
828   g_free(fullname);
829   g_free(fullname_def);
830 }
831
832 static
833 void ch_prep (IDL_tree       tree,
834               OIDL_Run_Info *rinfo,
835               OIDL_C_Info   *ci)
836 {
837         switch (IDL_NODE_TYPE (tree)) {
838         case IDLN_TYPE_SEQUENCE:
839                 ch_prep_sequence (tree, rinfo, ci);
840                 break;
841         case IDLN_TYPE_FIXED:
842                 ch_prep_fixed (tree, rinfo, ci);
843                 break;
844         case IDLN_TYPE_STRUCT:
845                 ch_output_type_struct (tree, rinfo, ci);
846                 break;
847         case IDLN_TYPE_ENUM:
848                 ch_output_type_enum (tree, rinfo, ci);
849                 break;
850         default:
851                 break;
852         }
853 }
854
855 /* static void */
856 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
857 /*                   OIDL_C_Info *ci, gboolean do_alloc) */
858 /* { */
859 /*   char *ctmp; */
860 /*   IDL_tree tts; */
861
862 /*   ctmp = forb_cbe_get_typespec_str(tree); */
863
864 /*   if ( ci->do_impl_hack ) { */
865 /*       fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
866 /*       forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
867 /*   } */
868
869 /*   fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
870 /*   fprintf (ci->fh, "static\n"); */
871 /*   fprintf (ci->fh, "#else\n"); */
872 /*   fprintf (ci->fh, "extern\n"); */
873 /*   fprintf (ci->fh, "#endif\n"); */
874 /*   fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
875
876 /*   fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
877 /*   if (ci->do_impl_hack) */
878 /*       fprintf (ci->fh, "#endif\n"); */
879
880 /*   if(do_alloc) { */
881 /*       char *tc; */
882
883 /*       tts = forb_cbe_get_typespec(tree); */
884
885 /*       tc = forb_cbe_get_typecode_name (tts); */
886
887 /*       fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
888 /*                 ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
889
890 /*       fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
891
892 /*       if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
893 /*       { */
894 /*      char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
895 /*      char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
896 /*        member_type + strlen ("CORBA_") : member_type; */
897         
898 /*      fprintf (ci->fh, "#define %s_allocbuf(l) " */
899 /*               "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
900 /*               ctmp, member_name, tc); */
901         
902 /*      g_free (member_type); */
903 /*       } */
904         
905 /*       g_free (tc); */
906 /*   } */
907
908 /*   g_free(ctmp); */
909 /* } */
910
911 /************************/
912 /* static void */
913 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
914 /* { */
915 /*   char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
916 /*                                   "_", 0); */
917 /*   fprintf(of, "  POA_%s__epv *%s_epv;\n", id, id); */
918 /*   g_free(id); */
919
920 /* } */
921
922 /* static void */
923 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
924 /* { */
925 /*   if(!tree) return; */
926
927 /*   if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
928 /*      return; */
929
930 /*   switch(IDL_NODE_TYPE(tree)) { */
931 /*   case IDLN_MODULE: */
932 /*     ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
933 /*     break; */
934 /*   case IDLN_LIST: */
935 /*     { */
936 /*       IDL_tree sub; */
937
938 /*       for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
939 /*      ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
940 /*       } */
941 /*     } */
942 /*     break; */
943 /*   case IDLN_INTERFACE: */
944 /*     { */
945 /*       IDL_tree sub; */
946 /*       char *id; */
947
948
949 /*       id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
950
951 /*       fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n",  */
952 /*         id, id); */
953
954 /*       /\* First, do epv for this interface, then vepv, then servant *\/ */
955 /*       fprintf(ci->fh, "typedef struct {\n"); */
956 /*       fprintf(ci->fh, "  void *_private;\n"); */
957 /*       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
958 /*      IDL_tree cur; */
959
960 /*      cur = IDL_LIST(sub).data; */
961
962 /*      switch(IDL_NODE_TYPE(cur)) { */
963 /*      case IDLN_OP_DCL: */
964 /*        forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
965 /*        fprintf(ci->fh, ";\n"); */
966 /*        break; */
967 /*      case IDLN_ATTR_DCL: */
968 /*        { */
969 /*          OIDL_Attr_Info *ai; */
970 /*          IDL_tree curitem; */
971
972 /*          for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
973 /*            ai = IDL_LIST(curitem).data->data; */
974               
975 /*            forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
976 /*            fprintf(ci->fh, ";\n"); */
977               
978 /*            if(ai->op2) { */
979 /*              forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
980 /*              fprintf(ci->fh, ";\n"); */
981 /*            } */
982 /*          } */
983 /*        } */
984 /*        break; */
985 /*      default: */
986 /*        break; */
987 /*      } */
988 /*       } */
989
990 /*       fprintf(ci->fh, "} POA_%s__epv;\n", id); */
991
992 /*       fprintf(ci->fh, "typedef struct {\n"); */
993 /*       fprintf(ci->fh, "  PortableServer_ServantBase__epv *_base_epv;\n"); */
994 /*       IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
995 /*       fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
996
997 /*       fprintf(ci->fh, "typedef struct {\n"); */
998 /*       fprintf(ci->fh, "  void *_private;\n"); */
999 /*       fprintf(ci->fh, "  POA_%s__vepv *vepv;\n", id); */
1000 /*       fprintf(ci->fh, "} POA_%s;\n", id); */
1001
1002 /*       fprintf(ci->fh, */
1003 /*            "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1004 /*       fprintf(ci->fh, */
1005 /*            "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1006
1007 /*       fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1008
1009 /*       g_free(id); */
1010 /*     } */
1011 /*     break; */
1012 /*   default: */
1013 /*     break; */
1014 /*   } */
1015 /* } */
1016
1017 /************************/
1018 typedef struct {
1019   FILE *of;
1020   IDL_tree realif;
1021 } InheritedOutputInfo;
1022 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1023
1024 static void
1025 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1026 {
1027   if(!tree) return;
1028
1029
1030   switch(IDL_NODE_TYPE(tree)) {
1031   case IDLN_MODULE:
1032     ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1033     break;
1034   case IDLN_LIST:
1035     {
1036       IDL_tree sub;
1037
1038       for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1039         ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1040       }
1041     }
1042     break;
1043   case IDLN_INTERFACE:
1044     {
1045       IDL_tree sub;
1046
1047       if(IDL_INTERFACE(tree).inheritance_spec) {
1048         InheritedOutputInfo ioi;
1049         ioi.of = ci->fh;
1050         ioi.realif = tree;
1051         IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1052       }
1053
1054       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1055         IDL_tree cur;
1056
1057         cur = IDL_LIST(sub).data;
1058
1059         switch(IDL_NODE_TYPE(cur)) {
1060         case IDLN_OP_DCL:
1061           forb_idl_check_oneway_op (cur);
1062           forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1063           fprintf(ci->fh, ";\n");
1064           break;
1065         case IDLN_ATTR_DCL:
1066           {
1067             OIDL_Attr_Info *ai;
1068             IDL_tree curitem;
1069
1070             for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1071               ai = IDL_LIST(curitem).data->data;
1072               
1073               forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1074               fprintf(ci->fh, ";\n");
1075               
1076               if(ai->op2) {
1077                 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1078                 fprintf(ci->fh, ";\n");
1079               }
1080             }
1081           }
1082           break;
1083         default:
1084           break;
1085         }
1086       }
1087     }
1088     break;
1089   default:
1090     break;
1091   }
1092 }
1093
1094 static void
1095 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1096 {
1097   char *id, *realid;
1098   IDL_tree curitem;
1099
1100   if(curif == ioi->realif)
1101     return;
1102
1103   realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1104   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1105
1106   for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1107     IDL_tree curop = IDL_LIST(curitem).data;
1108
1109     switch(IDL_NODE_TYPE(curop)) {
1110     case IDLN_OP_DCL:
1111       fprintf(ioi->of, "#define %s_%s %s_%s\n",
1112               realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1113               id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1114       break;
1115     case IDLN_ATTR_DCL:
1116       {
1117         IDL_tree curitem;
1118
1119         /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1120            and therefore don't have the OIDL_Attr_Info generated on them */
1121
1122         for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1123           IDL_tree ident;
1124
1125           ident = IDL_LIST(curitem).data;
1126           
1127           fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1128                   realid, IDL_IDENT(ident).str,
1129                   id, IDL_IDENT(ident).str);
1130
1131           if(!IDL_ATTR_DCL(curop).f_readonly)
1132             fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1133                     realid, IDL_IDENT(ident).str,
1134                     id, IDL_IDENT(ident).str);
1135         }
1136       }
1137       break;
1138         default:
1139           break;
1140     }
1141   }
1142
1143   g_free(id);
1144   g_free(realid);
1145 }
1146
1147 /* static void */
1148 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1149 /* { */
1150 /*   char *id; */
1151
1152 /*   id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1153
1154 /*   fprintf(ci->fh, "void _forb_skel_%s(" */
1155 /*        "CDR_Codec *codec, %s *obj", */
1156 /*        id, ifid); */
1157 /* /\*   forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1158 /*   fprintf(ci->fh, ");\n"); */
1159
1160 /*   g_free(id); */
1161 /* } */
1162
1163 /* static void */
1164 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1165 /* { */
1166 /*   if(!tree) return; */
1167
1168 /*   if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1169 /*      return; */
1170
1171 /*   switch(IDL_NODE_TYPE(tree)) { */
1172 /*   case IDLN_MODULE: */
1173 /*     ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1174 /*     break; */
1175 /*   case IDLN_LIST: */
1176 /*     { */
1177 /*       IDL_tree sub; */
1178
1179 /*       for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1180 /*      ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1181 /*       } */
1182 /*     } */
1183 /*     break; */
1184 /*   case IDLN_INTERFACE: */
1185 /*     { */
1186 /*       IDL_tree sub; */
1187 /*       char *ifid; */
1188
1189 /*       ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1190
1191 /*       for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1192 /*      IDL_tree cur; */
1193
1194 /*      cur = IDL_LIST(sub).data; */
1195
1196 /*      switch(IDL_NODE_TYPE(cur)) { */
1197 /*      case IDLN_OP_DCL: */
1198 /*        doskel(cur, rinfo, ifid, ci); */
1199 /*        break; */
1200 /*      case IDLN_ATTR_DCL: */
1201 /*        IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1202 /* /\*    { *\/ */
1203 /* /\*      OIDL_Attr_Info *ai = cur->data; *\/ */
1204 /* /\*      IDL_tree curitem; *\/ */
1205
1206 /* /\*      for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1207 /* /\*        ai = IDL_LIST(curitem).data->data; *\/ */
1208               
1209 /* /\*        doskel(ai->op1, rinfo, ifid, ci); *\/ */
1210 /* /\*        if(ai->op2) *\/ */
1211 /* /\*          doskel(ai->op2, rinfo, ifid, ci); *\/ */
1212 /* /\*      } *\/ */
1213 /* /\*    } *\/ */
1214 /*        break; */
1215 /*      default: */
1216 /*        break; */
1217 /*      } */
1218 /*       } */
1219 /*       g_free(ifid); */
1220 /*     } */
1221 /*     break; */
1222 /*   default: */
1223 /*     break; */
1224 /*   } */
1225 /* } */
1226
1227 /* static void */
1228 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1229 /* { */
1230 /*      static int num_methods = 0; */
1231
1232 /*      if (!tree) */
1233 /*              return; */
1234
1235 /*      switch(IDL_NODE_TYPE(tree)) { */
1236 /*      case IDLN_MODULE: */
1237 /*              ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1238 /*              break; */
1239 /*      case IDLN_LIST: { */
1240 /*              IDL_tree sub; */
1241 /*              for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1242 /*                      ch_output_itypes (IDL_LIST(sub).data, ci); */
1243 /*      } */
1244 /*      break; */
1245 /*      case IDLN_ATTR_DCL: { */
1246 /*              OIDL_Attr_Info *ai = tree->data; */
1247
1248 /*              IDL_tree curitem; */
1249       
1250 /*              for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1251 /*                  curitem = IDL_LIST(curitem).next) { */
1252 /*                      ai = IDL_LIST(curitem).data->data; */
1253         
1254 /*                      ch_output_itypes (ai->op1, ci); */
1255 /*                      if(ai->op2) */
1256 /*                              ch_output_itypes (ai->op2, ci); */
1257 /*              } */
1258 /*      } */
1259 /*      break; */
1260
1261 /*      case IDLN_INTERFACE: { */
1262 /*              char  *id; */
1263
1264 /*              id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1265 /*                      IDL_INTERFACE (tree).ident), "_", 0); */
1266
1267 /*              ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1268       
1269 /*              fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1270 /*                       ci->c_base_name); */
1271 /*              fprintf (ci->fh, "static \n"); */
1272 /*              fprintf (ci->fh, "#else\n"); */
1273 /*              fprintf (ci->fh, "extern \n"); */
1274 /*              fprintf (ci->fh, "#endif\n"); */
1275 /*              fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1276
1277 /*              fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1278
1279 /*              if (num_methods == 0) */
1280 /*                      fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1281 /*              else { */
1282 /*                      fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1283 /*                               ci->c_base_name); */
1284 /*                      fprintf (ci->fh, "static \n"); */
1285 /*                      fprintf (ci->fh, "#else\n"); */
1286 /*                      fprintf (ci->fh, "extern \n"); */
1287 /*                      fprintf (ci->fh, "#endif\n"); */
1288 /*                      fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1289 /*              } */
1290
1291
1292 /*              num_methods = 0; */
1293
1294 /*              break; */
1295 /*      } */
1296
1297 /*      case IDLN_OP_DCL: */
1298 /*              num_methods++; */
1299 /*              break; */
1300 /*      default: */
1301 /*              break; */
1302 /*      } */
1303 /* } */