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