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