]> rtime.felk.cvut.cz Git - frescor/forb.git/blob - forb-idl/forb-idl-c-common.c
Fixed include directive
[frescor/forb.git] / forb-idl / forb-idl-c-common.c
1 #include "config.h"
2
3 #include "forb-idl-c-backend.h"
4
5 #include <string.h>
6
7 typedef struct {
8         IDL_tree tree;
9         GSList  *methods; /* IDLN_OP_DCLs */
10 } Interface;
11
12 typedef struct {
13         FILE     *of;
14         IDL_tree cur_node; /* Current Interface */
15         char     *cur_id;
16         guint    parents;
17 } CCSmallInterfaceTraverseInfo;
18
19 /* TypeCodes */
20
21 /* static void cc_output_typecodes (IDL_tree     tree, */
22 /*                               OIDL_C_Info *ci); */
23
24 /* static void */
25 /* cc_typecode_prep_sequence (IDL_tree     tree, */
26 /*                         OIDL_C_Info *ci) */
27 /* { */
28 /*      IDL_tree  seq_type; */
29 /*      IDL_tree  fake_seq_type = NULL; */
30 /*      char     *type_str; */
31 /*      char     *seq_type_str; */
32
33 /*      seq_type = forb_cbe_get_typespec (IDL_TYPE_SEQUENCE (tree).simple_type_spec); */
34
35 /*      if (IDL_NODE_TYPE (seq_type) != IDLN_INTERFACE) */
36 /*              seq_type_str = forb_cbe_get_typespec_str (seq_type); */
37 /*      else { */
38 /*              seq_type_str = g_strdup ("CORBA_Object"); */
39 /*              fake_seq_type = IDL_type_object_new (); */
40 /*      } */
41
42 /*      type_str = forb_cbe_get_typespec_str (IDL_TYPE_SEQUENCE (tree).simple_type_spec); */
43
44 /*      if (strcmp (type_str, seq_type_str)) { */
45 /*              IDL_tree fake_seq; */
46
47 /*              fake_seq = IDL_type_sequence_new ( */
48 /*                              fake_seq_type ? fake_seq_type : seq_type, */
49 /*                              NULL); */
50 /*              IDL_NODE_UP (fake_seq) = IDL_NODE_UP (tree); */
51
52 /*              cc_output_typecodes (fake_seq, ci); */
53
54 /*              IDL_TYPE_SEQUENCE (fake_seq).simple_type_spec = NULL; */
55 /*              IDL_tree_free (fake_seq); */
56 /*      } */
57
58 /*      if (fake_seq_type) */
59 /*              IDL_tree_free (fake_seq_type); */
60
61 /*      g_free (type_str); */
62 /*      g_free (seq_type_str); */
63 /* } */
64  
65 /* static gboolean */
66 /* cc_output_tc_walker (IDL_tree_func_data *tfd, */
67 /*                   OIDL_C_Info        *ci) */
68 /* { */
69 /*      IDL_tree tree = tfd->tree; */
70
71 /*      switch(IDL_NODE_TYPE (tree)) { */
72 /*      case IDLN_CONST_DCL: */
73 /*      case IDLN_ATTR_DCL: */
74 /*      case IDLN_OP_DCL: */
75 /*              return FALSE; /\* dont recurse into these *\/ */
76
77 /*      case IDLN_TYPE_SEQUENCE: */
78 /*              if (!tfd->step) { */
79 /*                      cc_typecode_prep_sequence (tree, ci); */
80 /*                      break; */
81 /*              } */
82 /*              /\* drop through *\/ */
83
84 /*      case IDLN_INTERFACE: */
85 /*      case IDLN_EXCEPT_DCL: */
86 /*      case IDLN_TYPE_STRUCT: */
87 /*      case IDLN_TYPE_UNION: */
88 /*      case IDLN_TYPE_DCL: */
89 /*      case IDLN_TYPE_ENUM: */
90 /*      case IDLN_TYPE_FIXED: */
91 /*              if (tfd->step) */
92 /*                      forb_output_typecode (ci, tree); */
93 /*              break; */
94 /*      default: */
95 /*              break; */
96 /*      } */
97
98 /*      return TRUE; /\* continue walking *\/ */
99 /* } */
100
101 /* static void */
102 /* cc_output_typecodes (IDL_tree     tree, */
103 /*                   OIDL_C_Info *ci) */
104 /* { */
105 /*      IDL_tree_walk2 (tree, NULL, IDL_WalkF_TypespecOnly, */
106 /*                      (IDL_tree_func) cc_output_tc_walker, */
107 /*                      (IDL_tree_func) cc_output_tc_walker, */
108 /*                      ci); */
109 /* } */
110
111 /* serialization */
112
113 static void
114 cc_output_ser_struct(OIDL_C_Info *ci,
115                      IDL_tree     s)
116 {
117         IDL_tree cur, curmem;
118         char *id;
119         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(s).ident), "_", 0);
120         
121         fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr)\n", id, id);
122         fprintf(ci->fh, "{\n");
123         for(cur = IDL_TYPE_STRUCT(s).member_list; cur; cur = IDL_LIST(cur).next) {
124                 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
125                         forb_cbe_write_ser_var(
126                                 ci->fh,
127                                 IDL_MEMBER(IDL_LIST(cur).data).type_spec,
128                                 IDL_LIST(curmem).data,
129                                 true,
130                                 "ptr->",
131                                 SERIALIZE);
132                 }
133         }
134         
135         fprintf(ci->fh, "  return CORBA_TRUE;\n"
136                         "ser_exception:\n"
137                         "  return CORBA_FALSE;\n"
138                         "}\n\n");
139
140         fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr)\n", id, id);
141         fprintf(ci->fh, "{\n");
142         for(cur = IDL_TYPE_STRUCT(s).member_list; cur; cur = IDL_LIST(cur).next) {
143                 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
144                         forb_cbe_write_ser_var(
145                                 ci->fh,
146                                 IDL_MEMBER(IDL_LIST(cur).data).type_spec,
147                                 IDL_LIST(curmem).data,
148                                 true,
149                                 "ptr->",
150                                 DESERIALIZE);
151                 }
152         }
153         
154         fprintf(ci->fh, "  return CORBA_TRUE;\n"
155                         "ser_exception:\n"
156                         "  return CORBA_FALSE;\n"
157                         "}\n\n");
158
159
160         g_free(id);
161 }
162
163 static void
164 cc_output_ser_seqence(OIDL_C_Info *ci,
165                       IDL_tree     s)
166 {
167         //IDL_tree cur, curmem;
168         char *id, *type;
169         IDL_tree tts;
170         gboolean fake_if;
171         id = forb_cbe_get_typespec_str(s);
172         type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(s).simple_type_spec);
173 /*{
174         CORBA_boolean r;                                                
175         int i;                                                  
176         r = CORBA_unsigned_long_serialize(codec, (val)->_length); 
177         for (i=0; i<(val)->_length && r; i++)                   
178                 r = type ## _serialize(codec, &((val)->_buffer[i])); 
179 }*/
180         tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(s).simple_type_spec);
181         fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
182         if (fake_if) {
183                 /* Header file already contains defines for CORBA_sequence_Object_[de]serialize */
184                 return;
185         }
186
187         fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr)\n", id, id);
188         fprintf(ci->fh, "{\n"
189                         "  int i;\n"
190                         "  CORBA_boolean ok;\n"
191                         "  ok = CORBA_unsigned_long_serialize(codec, &ptr->_length);\n"
192                         "  for (i = 0; i<ptr->_length && ok; i++)\n");
193         fprintf(ci->fh, "    ok = %s_serialize(codec, &(ptr->_buffer[i]));\n", type);
194         
195         fprintf(ci->fh, "  return ok;\n"
196                         "}\n\n");
197
198         fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr)\n", id, id);
199         fprintf(ci->fh, "{\n"
200                         "  int i;\n"
201                         "  CORBA_boolean ok;\n"
202                         "  ok = CORBA_unsigned_long_deserialize(codec, &ptr->_length);\n"
203                         "  ok = ok && (ptr->_length <= ptr->_maximum);\n"
204                         "  if (ok) {\n"
205                         "    if (CORBA_sequence_get_release(ptr)) CORBA_free(ptr->_buffer);\n"
206                         "    ptr->_buffer = %s_allocbuf(ptr->_length);\n"
207                         "    CORBA_sequence_set_release(ptr, CORBA_TRUE);\n"
208                         "  }\n"
209                         "  for (i = 0; i<ptr->_length && ok; i++)\n", id);
210         fprintf(ci->fh, "    ok = %s_deserialize(codec, &(ptr->_buffer[i]));\n", type);
211         
212         fprintf(ci->fh, "  return ok;\n"
213                         "}\n\n");
214
215         g_free(id);
216         g_free(type);
217 }
218
219 static void
220 cc_output_ser_typedef_array(OIDL_C_Info *ci,
221                        IDL_tree     tree)
222 {
223         IDL_tree cur;
224         char *id;
225         
226         for(cur = IDL_TYPE_DCL(tree).dcls; cur; cur = IDL_LIST(cur).next) {
227                 if (IDL_NODE_TYPE(IDL_LIST(cur).data) == IDLN_TYPE_ARRAY) {
228                         id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_ARRAY(IDL_LIST(cur).data).ident), "_", 0);
229                         fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s array)\n", id, id);
230                         fprintf(ci->fh, "{\n");
231                         forb_cbe_write_ser_var(
232                                 ci->fh,
233                                 IDL_TYPE_DCL(tree).type_spec,
234                                 IDL_LIST(cur).data,
235                                 false,
236                                 "array",
237                                 SERIALIZE);
238                         fprintf(ci->fh, "  return CORBA_TRUE;\n"
239                                 "ser_exception:\n"
240                                 "  return CORBA_FALSE;\n"
241                                 "}\n\n");
242
243                         fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array)\n", id, id);
244                         fprintf(ci->fh, "{\n");
245                         forb_cbe_write_ser_var(
246                                 ci->fh,
247                                 IDL_TYPE_DCL(tree).type_spec,
248                                 IDL_LIST(cur).data,
249                                 false,
250                                 "array",
251                                 DESERIALIZE);
252                         fprintf(ci->fh, "  return CORBA_TRUE;\n"
253                                 "ser_exception:\n"
254                                 "  return CORBA_FALSE;\n"
255                                 "}\n\n");
256                         g_free(id);
257                 }
258         }
259 }
260
261 void
262 forb_output_serialization (OIDL_C_Info *ci,
263                            IDL_tree     node)
264 {
265         switch (IDL_NODE_TYPE (node)) {
266         case IDLN_TYPE_DCL:
267                 cc_output_ser_typedef_array(ci, node);
268                 break;
269         case IDLN_TYPE_STRUCT:
270                 cc_output_ser_struct(ci, node);
271                 break;
272         case IDLN_TYPE_UNION:
273         case IDLN_TYPE_ENUM:
274         case IDLN_EXCEPT_DCL:
275         case IDLN_INTERFACE:
276                 break;
277         case IDLN_TYPE_SEQUENCE:
278                 cc_output_ser_seqence(ci, node);
279                 break;
280         default:
281                 g_error ("You can't produce a serialization for a %s", 
282                          IDL_tree_type_names[IDL_NODE_TYPE (node)]);
283         }
284
285 /*      tci.ts            = node; */
286 /*      tci.structname    = forb_generate_tcstruct_name (node); */
287 /*      tci.substructname = NULL; */
288 /*      tci.array_gen_ctr = 0; */
289
290 /*      cbe_tc_generate (ci, &tci); */
291
292 /*      g_free (tci.structname); */
293 }
294
295 static gboolean
296 cc_output_serialization_walker (IDL_tree_func_data *tfd,
297                                 OIDL_C_Info        *ci)
298 {
299         IDL_tree tree = tfd->tree;
300
301         switch(IDL_NODE_TYPE (tree)) {
302         case IDLN_CONST_DCL:
303         case IDLN_ATTR_DCL:
304         case IDLN_OP_DCL:
305                 return FALSE; /* dont recurse into these */
306
307         case IDLN_TYPE_SEQUENCE:
308 /*              if (!tfd->step) { */
309 /*                      cc_typecode_prep_sequence (tree, ci); */
310 /*                      break; */
311 /*              } */
312                 /* drop through */
313
314         case IDLN_INTERFACE:
315         case IDLN_EXCEPT_DCL:
316         case IDLN_TYPE_STRUCT:
317         case IDLN_TYPE_UNION:
318         case IDLN_TYPE_DCL:
319         case IDLN_TYPE_ENUM:
320         case IDLN_TYPE_FIXED:
321                 if (tfd->step)
322                         forb_output_serialization (ci, tree);
323                 break;
324         case IDLN_SRCFILE:
325                 if (!IDL_SRCFILE(tree).isTop) {
326                         return FALSE;
327                 }
328                 break;
329         default:
330                 break;
331         }
332
333         return TRUE; /* continue walking */
334 }
335
336 static void
337 cc_output_serialization (IDL_tree     tree,
338                          OIDL_C_Info *ci)
339 {
340         IDL_tree_walk2 (tree, NULL, IDL_WalkF_TypespecOnly,
341                         (IDL_tree_func) cc_output_serialization_walker,
342                         (IDL_tree_func) cc_output_serialization_walker,
343                         ci);
344 }
345
346
347
348 /* class ids */
349
350 /* static void */
351 /* cc_output_class_id (IDL_tree       tree, */
352 /*                         OIDL_Run_Info *rinfo, */
353 /*                         OIDL_C_Info   *ci) */
354 /* { */
355 /*      char *iface_id; */
356
357 /*      iface_id = IDL_ns_ident_to_qstring ( */
358 /*              IDL_IDENT_TO_NS (IDL_INTERFACE (tree).ident), "_", 0); */
359
360 /*      fprintf (ci->fh, "\n#ifndef FORB_IDL_C_IMODULE_%s\n",ci->c_base_name); */
361 /*      fprintf (ci->fh, "CORBA_unsigned_long %s__classid = 0;\n", iface_id); */
362 /*      fprintf (ci->fh, "#endif\n"); */
363
364 /*      g_free (iface_id); */
365 /* } */
366
367 /* static void */
368 /* cc_output_class_ids (IDL_tree       tree, */
369 /*                   OIDL_Run_Info *rinfo, */
370 /*                   OIDL_C_Info   *ci) */
371 /* { */
372 /*      if (!tree || (tree->declspec & IDLF_DECLSPEC_PIDL)) */
373 /*              return; */
374
375 /*      switch (IDL_NODE_TYPE (tree)) { */
376 /*      case IDLN_MODULE: */
377 /*              cc_output_class_ids (IDL_MODULE (tree).definition_list, rinfo, ci); */
378 /*              break; */
379 /*      case IDLN_LIST: { */
380 /*              IDL_tree node; */
381
382 /*              for (node = tree; node; node = IDL_LIST (node).next) */
383 /*                      cc_output_class_ids (IDL_LIST (node).data, rinfo, ci); */
384 /*              break; */
385 /*              } */
386 /*      case IDLN_INTERFACE: */
387 /*              cc_output_class_id (tree, rinfo, ci); */
388 /*              break; */
389 /*      default: */
390 /*              break; */
391 /*      } */
392 /* } */
393
394 /* IInterfaces */
395
396 /* static void */
397 /* cc_output_iargs (FILE *of, const char *method, IDL_tree tree) */
398 /* { */
399 /*      IDL_tree sub; */
400 /*      int      arg_count = 0; */
401
402 /*      /\* Build a list of IArgs *\/ */
403 /*      for (sub = IDL_OP_DCL (tree).parameter_dcls; sub; */
404 /*           sub = IDL_LIST (sub).next) { */
405 /*              IDL_tree parm; */
406 /*              char    *tc; */
407
408 /*              if (!arg_count) */
409 /*                      fprintf (of, "static Forb_IArg %s__arginfo [] = {\n", method); */
410
411 /*              parm = IDL_LIST(sub).data; */
412
413 /*              fprintf (of, "\t{ "); */
414
415 /*              /\* TypeCode tc *\/ */
416 /*              tc = forb_cbe_get_typecode_name ( */
417 /*                      IDL_PARAM_DCL (parm).param_type_spec); */
418 /*              if (!tc) { */
419 /*                      g_warning ("Can't get typecode"); */
420 /*                      tc = g_strdup ("NULL /\* no typecode *\/"); */
421 /*              } */
422 /*              fprintf (of, "%s, ", tc); */
423
424 /*              /\* IArgFlag flags *\/ */
425 /*              switch (IDL_PARAM_DCL (parm).attr) { */
426 /*              case IDL_PARAM_IN: */
427 /*                      fprintf (of, " Forb_I_ARG_IN "); */
428 /*                      break; */
429 /*              case IDL_PARAM_OUT: */
430 /*                      fprintf (of, " Forb_I_ARG_OUT "); */
431 /*                      break; */
432 /*              case IDL_PARAM_INOUT: */
433 /*                      fprintf (of, " Forb_I_ARG_INOUT "); */
434 /*                      break; */
435 /*              } */
436
437 /*              if (forb_cbe_type_is_fixed_length ( */
438 /*                      IDL_PARAM_DCL (parm).param_type_spec)) */
439 /*                      fprintf (of, "| Forb_I_COMMON_FIXED_SIZE"); */
440
441 /*              else if (IDL_PARAM_DCL(parm).attr == IDL_PARAM_OUT) { */
442
443 /*                      IDL_tree ts = forb_cbe_get_typespec ( */
444 /*                              IDL_PARAM_DCL (parm).param_type_spec); */
445
446 /*                      switch(IDL_NODE_TYPE (ts)) { */
447 /*                      case IDLN_TYPE_STRUCT: */
448 /*                      case IDLN_TYPE_UNION: */
449 /*                      case IDLN_TYPE_ARRAY: */
450 /* /\*                          fprintf (of, "| FORB_I_ARG_FIXED");*\/ */
451 /*                              break; */
452 /*                      default: */
453 /*                              break; */
454 /*                      }; */
455 /*              } */
456
457 /*              fprintf (of, ", "); */
458
459 /*              /\* string name *\/ */
460 /*              fprintf (of, "(char *)\"%s\"", IDL_IDENT (IDL_PARAM_DCL ( */
461 /*                      IDL_LIST (sub).data).simple_declarator).str); */
462
463 /*              fprintf (of, " }%s\n", IDL_LIST (sub).next ? "," : ""); */
464
465 /*              g_free (tc); */
466 /*              arg_count++; */
467 /*      } */
468
469 /*      if (arg_count) */
470 /*              fprintf (of, "};\n"); */
471 /* } */
472
473 /* static void */
474 /* cc_output_contexts (FILE *of, const char *method, IDL_tree tree) */
475 /* { */
476 /*      /\* Build a list of contest names *\/ */
477 /*      if (IDL_OP_DCL (tree).context_expr) { */
478 /*              IDL_tree curitem; */
479
480 /*              fprintf (of, "/\* Exceptions *\/\n"); */
481 /*              fprintf (of, "static CORBA_string %s__contextinfo [] = {\n", */
482 /*                       method); */
483
484 /*              for (curitem = IDL_OP_DCL (tree).context_expr; curitem; */
485 /*                   curitem = IDL_LIST (curitem).next) { */
486 /*                      fprintf (of, "\"%s\"%c",  */
487 /*                               IDL_STRING (IDL_LIST (curitem).data).value, */
488 /*                               IDL_LIST (curitem).next ? ',' : ' '); */
489 /*              } */
490
491 /*              fprintf (of, "};\n"); */
492 /*      } */
493 /* } */
494
495 /* static void */
496 /* cc_output_exceptinfo (FILE *of, const char *method, IDL_tree tree) */
497 /* { */
498 /*      /\* Build a list of exception typecodes *\/ */
499 /*      if (IDL_OP_DCL (tree).raises_expr) { */
500 /*              IDL_tree curitem; */
501
502 /*              fprintf (of, "/\* Exceptions *\/\n"); */
503 /*              fprintf (of, "static CORBA_TypeCode %s__exceptinfo [] = {\n", */
504 /*                       method); */
505                 
506 /*              for (curitem = IDL_OP_DCL (tree).raises_expr; curitem; */
507 /*                   curitem = IDL_LIST(curitem).next) { */
508 /*                      char *type_id; */
509 /*                      IDL_tree curnode = IDL_LIST(curitem).data; */
510                         
511 /*                      type_id = forb_cbe_get_typecode_name (curnode); */
512 /*                      fprintf (of, "\t%s,\n", type_id); */
513 /*                      g_free (type_id); */
514 /*              } */
515 /*              fprintf (of, "\tNULL\n};\n"); */
516 /*      } */
517 /* } */
518
519 /* static void */
520 /* cc_output_method_bits (IDL_tree tree, const char *id, OIDL_C_Info *ci) */
521 /* { */
522 /*      FILE *of = ci->fh; */
523 /*      char *fullname; */
524
525 /*      fullname = g_strconcat (id, "_", IDL_IDENT ( */
526 /*              IDL_OP_DCL (tree).ident).str, NULL); */
527
528 /*      cc_output_iargs (of, fullname, tree); */
529
530 /*      cc_output_contexts (of, fullname, tree); */
531
532 /*      cc_output_exceptinfo (of, fullname, tree); */
533
534 /*      g_free (fullname); */
535 /* } */
536
537 /* static void */
538 /* cc_output_method (FILE *of, IDL_tree tree, const char *id) */
539 /* { */
540 /*      int arg_count; */
541 /*      int except_count; */
542 /*      int context_count; */
543 /*      const char *method; */
544 /*      char       *fullname; */
545
546 /*      fullname = g_strconcat (id, "_", IDL_IDENT ( */
547 /*              IDL_OP_DCL (tree).ident).str, NULL); */
548
549 /*      arg_count = IDL_list_length (IDL_OP_DCL (tree).parameter_dcls); */
550 /*      except_count = IDL_list_length (IDL_OP_DCL (tree).raises_expr); */
551 /*      context_count = IDL_list_length (IDL_OP_DCL (tree).context_expr); */
552         
553 /*      fprintf (of, "\t{\n"); */
554
555 /*      /\* IArgs arguments *\/ */
556 /*      if (arg_count) */
557 /*              fprintf (of, "\t\t{ %d, %d, %s__arginfo, FALSE },\n", */
558 /*                       arg_count, arg_count, fullname); */
559 /*      else */
560 /*              fprintf (of, "\t\t{ 0, 0, NULL, FALSE },\n"); */
561
562 /*      /\* IContexts contexts *\/ */
563 /*      if (context_count) */
564 /*              fprintf (of, "\t\t{ %d, %d, %s__contextinfo, FALSE },\n", */
565 /*                       context_count, context_count, fullname); */
566 /*      else */
567 /*              fprintf (of, "\t\t{ 0, 0, NULL, FALSE },\n"); */
568                 
569 /*      /\* ITypes exceptions *\/ */
570 /*      if (IDL_OP_DCL (tree).raises_expr) */
571 /*              fprintf (of, "\t\t{ %d, %d, %s__exceptinfo, FALSE },\n", */
572 /*                       except_count, except_count, fullname); */
573 /*      else */
574 /*              fprintf (of, "\t\t{ 0, 0, NULL, FALSE },\n"); */
575
576 /*      /\* TypeCode ret *\/ */
577 /*      if (IDL_OP_DCL (tree).op_type_spec) { */
578 /*              char *type_id; */
579
580 /*              type_id = forb_cbe_get_typespec_str ( */
581 /*                      IDL_OP_DCL (tree).op_type_spec); */
582 /*              fprintf (of, "\t\tTC_%s, ", type_id); */
583 /*              g_free (type_id); */
584 /*      } else */
585 /*              fprintf (of, "TC_void, "); */
586
587 /*      /\* string name, long name_len *\/ */
588 /*      method = IDL_IDENT (IDL_OP_DCL (tree).ident).str; */
589 /*      fprintf (of, "(char *)\"%s\", %d,\n", method, strlen (method)); */
590
591 /*      /\* IMethodFlags flags *\/ */
592 /*      fprintf (of, "\t\t0"); */
593
594 /*      if (IDL_OP_DCL(tree).f_oneway) */
595 /*              fprintf (of, " | Forb_I_METHOD_1_WAY"); */
596
597 /* /\* FIXME: re-scan for no_out *\/ */
598 /* /\*  if (no_out) */
599 /*      fprintf (of, " | Forb_I_METHOD_NO_OUT");*\/ */
600
601 /*      if (IDL_OP_DCL (tree).op_type_spec && */
602 /*          forb_cbe_type_is_fixed_length ( */
603 /*                  IDL_OP_DCL (tree).op_type_spec)) */
604 /*              fprintf (of, "| Forb_I_COMMON_FIXED_SIZE"); */
605
606 /*      if (IDL_OP_DCL(tree).context_expr) */
607 /*              fprintf (of, "| Forb_I_METHOD_HAS_CONTEXT"); */
608
609 /*      fprintf (of, "\n}\n"); */
610
611 /*      g_free (fullname); */
612 /* } */
613
614 /* static void */
615 /* cc_output_base_itypes(IDL_tree node, CCSmallInterfaceTraverseInfo *iti) */
616 /* { */
617 /*      if (iti->cur_node == node) */
618 /*              return; */
619
620 /*      fprintf (iti->of, "(char *)\"%s\",\n", */
621 /*               IDL_IDENT(IDL_INTERFACE(node).ident).repo_id); */
622
623 /*      iti->parents++; */
624 /* } */
625
626 /* static void */
627 /* cc_output_itypes (GSList *list, OIDL_C_Info *ci) */
628 /* { */
629 /*      GSList *l; */
630 /*      FILE   *of = ci->fh; */
631
632 /*      for (l = list; l; l = l->next) { */
633 /*              CCSmallInterfaceTraverseInfo iti; */
634 /*              Interface *i = l->data; */
635 /*              char      *id; */
636 /*              GSList    *m; */
637
638 /*              id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
639 /*                      IDL_INTERFACE (i->tree).ident), "_", 0); */
640
641 /*              for (m = i->methods; m; m = m->next) */
642 /*                      cc_output_method_bits (m->data, id, ci); */
643
644 /*              if (i->methods) { */
645 /*                      fprintf (of, "\n#ifdef FORB_IDL_C_IMODULE_%s\n", */
646 /*                               ci->c_base_name); */
647 /*                      fprintf (of, "static\n"); */
648 /*                      fprintf (of, "#endif\n"); */
649
650 /*                      fprintf (of, "Forb_IMethod %s__imethods [] = {\n", id); */
651
652 /*                      if (!(m = i->methods)) */
653 /*                              fprintf (of, "{{0}}"); */
654
655 /*                      else for (; m; m = m->next) { */
656 /*                              cc_output_method (of, m->data, id); */
657 /*                              if (m->next) */
658 /*                                      fprintf(of, ", "); */
659 /*                      } */
660
661 /*                      fprintf (of, "};\n\n"); */
662 /*              } */
663
664 /*              fprintf (of, "static CORBA_string %s__base_itypes[] = {\n", id); */
665
666 /*              iti.of = of; */
667 /*              iti.cur_node = i->tree; */
668 /*              iti.cur_id = id; */
669 /*              iti.parents = 0; */
670 /*              IDL_tree_traverse_parents(i->tree, (GFunc)cc_output_base_itypes, &iti); */
671
672 /*              fprintf (of, "(char *)\"IDL:omg.org/CORBA/Object:1.0\"\n};"); */
673
674 /*              fprintf (of, "\n#ifdef FORB_IDL_C_IMODULE_%s\n", */
675 /*                       ci->c_base_name); */
676 /*              fprintf (of, "static\n"); */
677 /*              fprintf (of, "#endif\n"); */
678 /*              fprintf (of, "Forb_IInterface %s__iinterface = {\n", id); */
679 /*              fprintf (of, "TC_%s,", id); */
680 /*              fprintf (of, "{%d, %d, %s__imethods, FALSE},\n", */
681 /*                       g_slist_length (i->methods), */
682 /*                       g_slist_length (i->methods), id); */
683
684 /*              fprintf (of, "{%d, %d, %s__base_itypes, FALSE}\n",  */
685 /*                       iti.parents + 1, iti.parents + 1, id); */
686
687 /*              fprintf (of, "};\n\n"); */
688
689 /*              g_free (id); */
690 /*      } */
691
692 /*      for (l = list; l; l = l->next) { */
693 /*              g_slist_free (((Interface *)l->data)->methods); */
694 /*              g_free (l->data); */
695 /*      } */
696
697 /*      g_slist_free (list); */
698 /* } */
699
700 /* static GSList * */
701 /* cc_build_interfaces (GSList *list, IDL_tree tree) */
702 /* { */
703 /*      if (!tree) */
704 /*              return list; */
705
706 /*      switch (IDL_NODE_TYPE (tree)) { */
707 /*      case IDLN_MODULE: */
708 /*              list = cc_build_interfaces ( */
709 /*                      list, IDL_MODULE (tree).definition_list); */
710 /*              break; */
711 /*      case IDLN_LIST: { */
712 /*              IDL_tree sub; */
713 /*              for (sub = tree; sub; sub = IDL_LIST (sub).next) */
714 /*                      list = cc_build_interfaces ( */
715 /*                              list, IDL_LIST (sub).data); */
716 /*              break; */
717 /*      } */
718 /*      case IDLN_ATTR_DCL: { */
719 /*              IDL_tree curitem; */
720       
721 /*              for (curitem = IDL_ATTR_DCL (tree).simple_declarations; */
722 /*                   curitem; curitem = IDL_LIST (curitem).next) { */
723 /*                      OIDL_Attr_Info *ai = IDL_LIST (curitem).data->data; */
724         
725 /*                      list = cc_build_interfaces (list, ai->op1); */
726 /*                      if (ai->op2) */
727 /*                              list = cc_build_interfaces (list, ai->op2); */
728 /*              } */
729 /*              break; */
730 /*      } */
731 /*      case IDLN_INTERFACE: { */
732 /*              Interface *i = g_new0 (Interface, 1); */
733
734 /*              i->tree = tree; */
735
736 /*              list = g_slist_append (list, i); */
737
738 /*              list = cc_build_interfaces (list, IDL_INTERFACE(tree).body); */
739
740 /*              break; */
741 /*      } */
742 /*      case IDLN_OP_DCL: { */
743 /*              Interface *i; */
744
745 /*              g_return_val_if_fail (list != NULL, NULL); */
746
747 /*              i = ( g_slist_last(list) )->data; */
748 /*              i->methods = g_slist_append (i->methods, tree); */
749 /*              break; */
750 /*      } */
751 /*      case IDLN_EXCEPT_DCL: */
752 /*              break; */
753 /*      default: */
754 /*              break; */
755 /*      } */
756
757 /*      return list; */
758 /* } */
759
760 /* static void */
761 /* cc_output_skel (IDL_tree     tree, */
762 /*              OIDL_C_Info *ci, */
763 /*              int         *idx) */
764 /* { */
765 /*      IDL_tree  intf; */
766 /*      gboolean  has_retval; */
767 /*      char     *opname; */
768 /*      char     *ifname; */
769
770 /*      g_return_if_fail (idx != NULL); */
771
772 /*      intf = IDL_get_parent_node (tree, IDLN_INTERFACE, NULL); */
773
774 /*      has_retval = IDL_OP_DCL (tree).op_type_spec != NULL; */
775
776 /*      opname = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (IDL_OP_DCL (tree).ident), "_", 0); */
777 /*      ifname = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (IDL_INTERFACE (intf).ident), "_", 0); */
778
779 /*      fprintf (ci->fh, "void _FORB_skel_small_%s(" */
780 /*                              "POA_%s             *_o_servant, " */
781 /*                              "gpointer            _o_retval," */
782 /*                              "gpointer           *_o_args," */
783 /*                              "CORBA_Context       _o_ctx," */
784 /*                              "CORBA_Environment  *_o_ev,\n", opname, ifname); */
785
786 /*      forb_cbe_op_write_proto (ci->fh, tree, "_impl_", TRUE); */
787
788 /*      fprintf (ci->fh, ") {\n"); */
789
790 /*      if (has_retval) { */
791 /*              fprintf (ci->fh, "*("); */
792 /*              forb_cbe_write_param_typespec (ci->fh, tree); */
793 /*              fprintf (ci->fh, " *)_o_retval = "); */
794 /*      } */
795
796 /*      fprintf (ci->fh, "_impl_%s (_o_servant, ", IDL_IDENT (IDL_OP_DCL (tree).ident).str); */
797   
798 /*      forb_cbe_unflatten_args (tree, ci->fh, "_o_args"); */
799
800 /*      if (IDL_OP_DCL (tree).context_expr) */
801 /*              fprintf (ci->fh, "_o_ctx, "); */
802
803 /*      fprintf (ci->fh, "_o_ev);\n"); */
804
805 /*      fprintf (ci->fh, "}\n"); */
806
807 /*      g_free (opname); */
808 /*      g_free (ifname); */
809
810 /*      (*idx)++; */
811 /* } */
812
813 /* static void */
814 /* cc_output_skels (IDL_tree       tree, */
815 /*               OIDL_Run_Info *rinfo, */
816 /*               OIDL_C_Info   *ci, */
817 /*               int           *idx) */
818 /* { */
819 /*      if (!tree || (tree->declspec & IDLF_DECLSPEC_PIDL)) */
820 /*              return; */
821
822 /*      switch (IDL_NODE_TYPE (tree)) { */
823 /*      case IDLN_MODULE: */
824 /*              cc_output_skels (IDL_MODULE (tree).definition_list, rinfo, ci, idx); */
825 /*              break; */
826 /*      case IDLN_LIST: { */
827 /*              IDL_tree node; */
828
829 /*              for (node = tree; node; node = IDL_LIST (node).next) */
830 /*                      cc_output_skels (IDL_LIST (node).data, rinfo, ci, idx); */
831 /*              break; */
832 /*              } */
833 /*      case IDLN_ATTR_DCL: { */
834 /*              OIDL_Attr_Info *ai = tree->data; */
835 /*              IDL_tree        node; */
836       
837 /*              for (node = IDL_ATTR_DCL (tree).simple_declarations; node; node = IDL_LIST (node).next) { */
838 /*                      ai = IDL_LIST (node).data->data; */
839         
840 /*                      cc_output_skels (ai->op1, rinfo, ci, idx); */
841 /*                      if (ai->op2) */
842 /*                              cc_output_skels (ai->op2, rinfo, ci, idx); */
843 /*              } */
844 /*              break; */
845 /*              } */
846 /*      case IDLN_INTERFACE: { */
847 /*              int real_idx = 0; */
848
849 /*              cc_output_skels (IDL_INTERFACE (tree).body, rinfo, ci, &real_idx); */
850 /*              } */
851 /*              break; */
852 /*      case IDLN_OP_DCL: */
853 /*              cc_output_skel (tree, ci, idx); */
854 /*              break; */
855 /*      default: */
856 /*              break; */
857 /*      } */
858 /* } */
859
860 void
861 forb_idl_output_c_common (IDL_tree       tree,
862                            OIDL_Run_Info *rinfo,
863                            OIDL_C_Info   *ci)
864 {
865         fprintf (ci->fh, OIDL_C_WARNING);
866 /*      fprintf (ci->fh, "#include <string.h>\n"); */
867 /*      fprintf (ci->fh, "#define FORB2_STUBS_API\n"); */
868 /*      fprintf (ci->fh, "#define FORB_IDL_C_COMMON\n"); */
869 /*      fprintf (ci->fh, "#define %s_COMMON\n", ci->c_base_name); */
870         fprintf (ci->fh, "#include \"%s.h\"\n", ci->base_name);
871         fprintf (ci->fh, "#include <forb/cdr.h>\n\n");
872 /*      fprintf (ci->fh, "static const CORBA_unsigned_long Forb_zero_int = 0;\n"); */
873
874         /* FIXME: this is slightly nasty, but we need these in common,
875            and this fixes an internal build issue */
876 /*      if (rinfo->enabled_passes & OUTPUT_SKELS || */
877 /*          rinfo->enabled_passes & OUTPUT_STUBS) { */
878 /*              fprintf (ci->fh, "\n#ifndef FORB_IDL_C_IMODULE_%s\n",ci->c_base_name); */
879 /*              cc_output_skels (tree, rinfo, ci, NULL); */
880 /*              fprintf (ci->fh, "\n#endif\n"); */
881 /*      } */
882
883         cc_output_serialization (tree, ci);
884 /*      cc_output_typecodes (tree, ci); */
885         
886 /*      cc_output_class_ids (tree, rinfo, ci); */
887
888 /*      if (rinfo->idata) { */
889 /*              GSList *list = NULL; */
890
891 /*              fprintf (ci->fh, "\n/\* Interface type data *\/\n\n"); */
892
893 /*              list = cc_build_interfaces (list, tree); */
894 /*              cc_output_itypes (list, ci); */
895 /*      } */
896 }