2 #include "forb-idl-c-backend.h"
3 #include "forb_config.h"
9 static void ch_output_types(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
10 /* static void ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
11 /* static void ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci); */
12 static void ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
13 /* static void ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
14 static GSList *ch_build_interfaces (GSList *list, IDL_tree tree);
15 static void ch_output_method (FILE *of, IDL_tree tree, const char *id);
16 /* static void ch_output_imethods_index (GSList *list, OIDL_C_Info *ci); */
20 GSList *methods; /* IDLN_OP_DCLs */
23 /* this is hardcopy from cc_build_interfaces() defined in forb-idl-c-common.c */
25 ch_build_interfaces (GSList *list, IDL_tree tree)
30 switch (IDL_NODE_TYPE (tree)) {
32 list = ch_build_interfaces (
33 list, IDL_MODULE (tree).definition_list);
37 for (sub = tree; sub; sub = IDL_LIST (sub).next)
38 list = ch_build_interfaces (
39 list, IDL_LIST (sub).data);
45 for (curitem = IDL_ATTR_DCL (tree).simple_declarations;
46 curitem; curitem = IDL_LIST (curitem).next) {
47 OIDL_Attr_Info *ai = IDL_LIST (curitem).data->data;
49 list = ch_build_interfaces (list, ai->op1);
51 list = ch_build_interfaces (list, ai->op2);
55 case IDLN_INTERFACE: {
56 Interface *i = g_new0 (Interface, 1);
60 list = g_slist_append (list, i);
62 list = ch_build_interfaces (list, IDL_INTERFACE(tree).body);
69 g_return_val_if_fail (list != NULL, NULL);
71 i = ( g_slist_last(list) )->data;
72 i->methods = g_slist_append (i->methods, tree);
85 ch_output_method (FILE *of, IDL_tree tree, const char *id)
87 char *fullname = NULL;
89 fullname = g_strconcat (id, "_", IDL_IDENT (
90 IDL_OP_DCL (tree).ident).str, NULL);
92 fprintf (of, "\t%s__method_index", fullname);
98 ch_output_method_indices (GSList *list, OIDL_C_Info *ci)
103 for (l = list; l; l = l->next) {
104 Interface *i = l->data;
108 id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (
109 IDL_INTERFACE (i->tree).ident), "_", 0);
113 fprintf (of, "#ifndef __%s__method_indices\n", id);
114 fprintf (of, "#define __%s__method_indices\n", id);
116 fprintf (of, "typedef enum {\n");
118 for (m = i->methods; m; m = m->next) {
119 ch_output_method (of, m->data, id);
126 fprintf (of, "} %s__method_indices;\n", id);
127 fprintf (of, "#endif /* __%s__method_indices */\n\n", id);
133 for (l = list; l; l = l->next) {
134 g_slist_free (((Interface *)l->data)->methods);
143 forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
145 fprintf (ci->fh, OIDL_C_WARNING);
146 fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
147 fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
149 fprintf(ci->fh, "#include <forb/forb.h>\n");
150 fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
151 fprintf(ci->fh, "#include <forb/basic_types.h>\n\n");
153 fprintf(ci->fh, "#ifdef __cplusplus\n");
154 fprintf(ci->fh, "extern \"C\" {\n");
155 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
157 /* Do all the typedefs, etc. */
158 fprintf(ci->fh, "\n/** typedefs **/\n");
159 ch_output_types(tree, rinfo, ci);
161 if ( ci->do_skel_defs ) {
162 /* /\* Do all the POA structures, etc. *\/ */
163 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
164 /* ch_output_poa(tree, rinfo, ci); */
166 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
167 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
168 /* ch_output_skel_protos(tree, rinfo, ci); */
170 fprintf(ci->fh, "\n/** stub prototypes **/\n");
171 ch_output_stub_protos(tree, rinfo, ci);
173 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
174 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
176 /* if (rinfo->idata) { */
177 /* /\* FIXME: hackish ? *\/ */
178 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
180 /* ch_output_itypes(tree, ci); */
185 fprintf (ci->fh, "\n/** Method indices */\n\n");
187 list = ch_build_interfaces (list, tree);
188 ch_output_method_indices (list, ci);
191 fprintf(ci->fh, "#ifdef __cplusplus\n");
192 fprintf(ci->fh, "}\n");
193 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
195 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
196 /* fprintf(ci->fh, "#include <forb/forb.h>\n\n"); */
197 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
199 fprintf(ci->fh, "#endif\n");
201 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
205 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
207 forb_cbe_write_typespec(ci->fh, val);
209 fprintf(ci->fh, " ");
210 switch(IDL_NODE_TYPE(name)) {
212 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
214 case IDLN_TYPE_ARRAY:
218 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
219 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
220 fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
225 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
228 fprintf(ci->fh, ";\n");
231 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
232 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
233 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
234 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
235 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
236 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
237 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
238 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
239 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
240 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
243 ch_output_types (IDL_tree tree,
244 OIDL_Run_Info *rinfo,
250 switch (IDL_NODE_TYPE (tree)) {
251 case IDLN_EXCEPT_DCL: {
252 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
255 /* id = IDL_ns_ident_to_qstring ( */
256 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
258 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
259 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
260 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
264 /* ch_output_type_struct (tree, rinfo, ci); */
267 case IDLN_FORWARD_DCL:
269 ch_output_interface (tree, rinfo, ci);
271 case IDLN_TYPE_STRUCT:
272 ch_output_type_struct (tree, rinfo, ci);
275 ch_output_type_enum (tree, rinfo, ci);
278 ch_output_type_dcl (tree, rinfo, ci);
280 case IDLN_TYPE_UNION:
281 ch_output_type_union (tree, rinfo, ci);
284 ch_output_codefrag (tree, rinfo, ci);
287 char *idlfn = IDL_SRCFILE (tree).filename;
288 if (rinfo->onlytop) {
290 if (!IDL_SRCFILE (tree).seenCnt &&
291 !IDL_SRCFILE(tree).isTop &&
292 !IDL_SRCFILE(tree).wasInhibit) {
295 hfn = g_path_get_basename (idlfn);
296 htail = strrchr (hfn,'.');
298 g_assert (htail && strlen (htail) >= 2);
303 fprintf (ci->fh, "#include \"%s\"\n", hfn);
308 fprintf (ci->fh, "/* from IDL source file \"%s\" "
309 "(seen %d, isTop %d, wasInhibit %d) */ \n",
311 IDL_SRCFILE (tree).seenCnt,
312 IDL_SRCFILE (tree).isTop,
313 IDL_SRCFILE (tree).wasInhibit);
318 ch_output_const_dcl (tree, rinfo, ci);
320 /* case IDLN_NATIVE: */
321 /* ch_output_native (tree, rinfo, ci); */
327 switch (IDL_NODE_TYPE (tree)) {
329 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
334 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
335 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
340 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
348 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
352 switch(IDL_NODE_TYPE(tree)) {
357 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
358 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
366 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
367 /* InheritedOutputInfo ioi; */
368 /* ioi.of = ci->fh; */
369 /* ioi.realif = tree; */
370 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
373 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
376 cur = IDL_LIST(sub).data;
378 switch(IDL_NODE_TYPE(cur)) {
380 forb_idl_check_oneway_op (cur);
381 fprintf(ci->fh, " ");
382 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
383 fprintf(ci->fh, ";\n");
385 /* case IDLN_ATTR_DCL: */
387 /* OIDL_Attr_Info *ai; */
388 /* IDL_tree curitem; */
390 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
391 /* ai = IDL_LIST(curitem).data->data; */
393 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
394 /* fprintf(ci->fh, ";\n"); */
397 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
398 /* fprintf(ci->fh, ";\n"); */
414 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
417 fullname = forb_cbe_get_typespec_str(tree);
418 fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
419 ch_output_impl_struct_members(tree, rinfo, ci);
420 fprintf(ci->fh, "};\n\n");
425 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
428 fullname = forb_cbe_get_typespec_str(tree);
429 fprintf(ci->fh, "#if !defined(FORB_DECL_%s) && !defined(_%s_defined)\n#define FORB_DECL_%s 1\n#define _%s_defined 1\n", fullname, fullname, fullname, fullname);
431 if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
432 /* PIDL interfaces are not normal CORBA Objects */
433 fprintf(ci->fh, "// PIDL: %s\n", fullname);
434 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
435 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
436 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
437 /* fprintf(ci->fh, "#endif\n"); */
440 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
441 fprintf(ci->fh, "typedef forb_object %s;\n", fullname);
442 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
444 ch_output_impl_struct(tree, rinfo, ci);
446 fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname);
447 fprintf(ci->fh, "%s forb_%s_new(void *instance_data,\n"
448 " const struct forb_%s_impl *impl, forb_orb orb);\n\n",
449 fullname, fullname, fullname);
451 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
454 fprintf(ci->fh, "#endif\n\n");
459 ch_output_type_enum (IDL_tree tree,
460 OIDL_Run_Info *rinfo,
466 /* CORBA spec says to do
467 * typedef unsigned int enum_name;
468 * and then #defines for each enumerator.
469 * This works just as well and seems cleaner.
472 enumid = IDL_ns_ident_to_qstring (
473 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
474 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
475 fprintf (ci->fh, "typedef enum {\n");
477 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
480 id = IDL_ns_ident_to_qstring (
481 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
483 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
488 fprintf (ci->fh, "} %s;\n", enumid);
490 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
491 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
492 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
494 fprintf (ci->fh, "#endif\n\n");
500 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
504 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
506 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
509 IDL_tree ent = IDL_LIST (l).data;
511 switch (IDL_NODE_TYPE(ent)) {
513 ctmp = IDL_ns_ident_to_qstring (
514 IDL_IDENT_TO_NS (ent), "_", 0);
516 case IDLN_TYPE_ARRAY:
517 ctmp = IDL_ns_ident_to_qstring (
518 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
521 g_assert_not_reached ();
525 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
526 fprintf (ci->fh, "typedef ");
527 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
529 switch (IDL_NODE_TYPE (ent)) {
531 fprintf (ci->fh, " %s;\n", ctmp);
532 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
533 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
534 fprintf (ci->fh, "_serialize((x),(y))\n");
536 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
537 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
538 fprintf (ci->fh, "_deserialize((x),(y))\n");
540 case IDLN_TYPE_ARRAY: {
543 fprintf (ci->fh, " %s", ctmp);
544 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
545 fprintf (ci->fh, "[%" IDL_LL "d]",
546 IDL_INTEGER (IDL_LIST (sub).data).value);
548 fprintf (ci->fh, ";\n");
549 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
550 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
551 /* fprintf (ci->fh, "typedef "); */
552 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
553 /* fprintf (ci->fh, " %s_slice", ctmp); */
554 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
555 /* sub; sub = IDL_LIST (sub).next) */
556 /* fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
557 /* fprintf(ci->fh, ";\n"); */
564 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
565 fprintf (ci->fh, "#endif\n");
571 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
574 /* IDL_tree id = IDL_NATIVE(tree).ident; */
575 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
576 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
577 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
578 /* /\* Dont even think about emitting a typecode. *\/ */
579 /* fprintf(ci->fh, "#endif\n"); */
584 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
587 IDL_tree cur, curmem;
589 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
591 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
592 /* put typedef out first for recursive seq */
593 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
595 /* Scan for any nested decls */
596 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
598 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
599 ch_prep(ts, rinfo, ci);
602 fprintf(ci->fh, "struct %s_type {\n", id);
604 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
605 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
606 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
609 if(!IDL_TYPE_STRUCT(tree).member_list)
610 fprintf(ci->fh, "int dummy;\n");
611 fprintf(ci->fh, "};\n");
613 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", id, id);
614 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", id, id);
616 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
618 fprintf(ci->fh, "#endif\n\n");
625 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
630 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
631 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
633 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
634 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
635 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
637 /* Scan for any nested decls */
638 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
639 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
640 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
643 fprintf(ci->fh, "struct %s_type {\n", id);
644 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
645 fprintf(ci->fh, " _d;\nunion {\n");
647 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
650 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
651 ch_output_var(IDL_MEMBER(member).type_spec,
652 IDL_LIST(IDL_MEMBER(member).dcls).data,
656 fprintf(ci->fh, "} _u;\n};\n");
658 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
660 fprintf(ci->fh, "#endif\n");
666 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
670 for(list = IDL_CODEFRAG(tree).lines; list;
671 list = g_slist_next(list)) {
672 if(!strncmp(list->data,
673 "#pragma include_defs",
674 sizeof("#pragma include_defs")-1)) {
676 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
677 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
679 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
681 fprintf(ci->fh, "#include <%s>\n", ctmp);
683 fprintf(ci->fh, "%s\n", (char *)list->data);
688 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
694 ident = IDL_CONST_DCL (tree).ident;
695 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
697 fprintf(ci->fh, "#ifndef %s\n", id);
698 fprintf(ci->fh, "#define %s ", id);
700 forb_cbe_write_const(ci->fh,
701 IDL_CONST_DCL(tree).const_exp);
703 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
704 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
705 !IDL_TYPE_INTEGER (typespec).f_signed)
706 fprintf(ci->fh, "U");
708 fprintf(ci->fh, "\n");
709 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
715 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
719 ctmp = forb_cbe_get_typespec_str(tree);
721 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
722 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
726 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
730 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
732 char *ctmp, *fullname, *fullname_def, *ctmp2;
734 gboolean separate_defs, fake_if;
735 IDL_tree fake_seq = NULL;
737 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
738 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
739 ctmp2 = forb_cbe_get_typespec_str(tts);
740 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
744 ctmp2 = g_strdup("CORBA_Object");
746 separate_defs = strcmp(ctmp, ctmp2);
747 fullname = forb_cbe_get_typespec_str(tree);
748 //printf("YYY %s\n", fullname);
753 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
754 //forb_idl_print_node(tree, 2);
756 tts = IDL_type_object_new();
757 fake_seq = IDL_type_sequence_new(tts, NULL);
758 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
759 ch_prep_sequence(fake_seq, rinfo, ci);
760 member_type = forb_cbe_type_is_builtin (tts) ?
761 ctmp2 + strlen ("CORBA_") : ctmp2;
762 fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
765 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
768 fullname_def = g_strdup(fullname);
770 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
771 == IDLN_TYPE_SEQUENCE)
772 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
774 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
775 * while _%s_defined protects only the struct */
777 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
779 /* if ( ci->do_impl_hack ) */
780 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
784 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
786 if(!strcmp(ctmp, "CORBA_RepositoryId"))
787 fprintf(ci->fh, "/* CRACKHEADS */\n");
788 fprintf(ci->fh, "typedef %s\n %s;\n", fullname_def, fullname);
789 fprintf(ci->fh, "#endif\n");
790 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
791 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
792 /* fullname, fullname_def); */
793 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
794 /* fullname, fullname_def); */
795 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
797 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
799 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
800 IDL_tree_free(fake_seq);
806 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
808 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
809 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
810 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n ");
811 forb_cbe_write_typespec(ci->fh, tree);
812 fprintf(ci->fh, ";\n#endif\n");
814 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
815 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
816 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
818 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
819 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
820 ctmp + strlen ("CORBA_") : ctmp;
822 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
823 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
824 member_type, ctmp, ctmp);
829 fprintf(ci->fh, "#endif\n\n");
834 g_free(fullname_def);
838 void ch_prep (IDL_tree tree,
839 OIDL_Run_Info *rinfo,
842 switch (IDL_NODE_TYPE (tree)) {
843 case IDLN_TYPE_SEQUENCE:
844 ch_prep_sequence (tree, rinfo, ci);
846 case IDLN_TYPE_FIXED:
847 ch_prep_fixed (tree, rinfo, ci);
849 case IDLN_TYPE_STRUCT:
850 ch_output_type_struct (tree, rinfo, ci);
853 ch_output_type_enum (tree, rinfo, ci);
861 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
862 /* OIDL_C_Info *ci, gboolean do_alloc) */
867 /* ctmp = forb_cbe_get_typespec_str(tree); */
869 /* if ( ci->do_impl_hack ) { */
870 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
871 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
874 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
875 /* fprintf (ci->fh, "static\n"); */
876 /* fprintf (ci->fh, "#else\n"); */
877 /* fprintf (ci->fh, "extern\n"); */
878 /* fprintf (ci->fh, "#endif\n"); */
879 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
881 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
882 /* if (ci->do_impl_hack) */
883 /* fprintf (ci->fh, "#endif\n"); */
888 /* tts = forb_cbe_get_typespec(tree); */
890 /* tc = forb_cbe_get_typecode_name (tts); */
892 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
893 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
895 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
897 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
899 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
900 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
901 /* member_type + strlen ("CORBA_") : member_type; */
903 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
904 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
905 /* ctmp, member_name, tc); */
907 /* g_free (member_type); */
916 /************************/
918 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
920 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
922 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
928 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
930 /* if(!tree) return; */
932 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
935 /* switch(IDL_NODE_TYPE(tree)) { */
936 /* case IDLN_MODULE: */
937 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
939 /* case IDLN_LIST: */
943 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
944 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
948 /* case IDLN_INTERFACE: */
954 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
956 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
959 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
960 /* fprintf(ci->fh, "typedef struct {\n"); */
961 /* fprintf(ci->fh, " void *_private;\n"); */
962 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
965 /* cur = IDL_LIST(sub).data; */
967 /* switch(IDL_NODE_TYPE(cur)) { */
968 /* case IDLN_OP_DCL: */
969 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
970 /* fprintf(ci->fh, ";\n"); */
972 /* case IDLN_ATTR_DCL: */
974 /* OIDL_Attr_Info *ai; */
975 /* IDL_tree curitem; */
977 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
978 /* ai = IDL_LIST(curitem).data->data; */
980 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
981 /* fprintf(ci->fh, ";\n"); */
984 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
985 /* fprintf(ci->fh, ";\n"); */
995 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
997 /* fprintf(ci->fh, "typedef struct {\n"); */
998 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
999 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1000 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1002 /* fprintf(ci->fh, "typedef struct {\n"); */
1003 /* fprintf(ci->fh, " void *_private;\n"); */
1004 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1005 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1007 /* fprintf(ci->fh, */
1008 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1009 /* fprintf(ci->fh, */
1010 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1012 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1022 /************************/
1026 } InheritedOutputInfo;
1027 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1030 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1035 switch(IDL_NODE_TYPE(tree)) {
1037 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1043 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1044 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1048 case IDLN_INTERFACE:
1052 if(IDL_INTERFACE(tree).inheritance_spec) {
1053 InheritedOutputInfo ioi;
1056 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1059 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1062 cur = IDL_LIST(sub).data;
1064 switch(IDL_NODE_TYPE(cur)) {
1066 forb_idl_check_oneway_op (cur);
1067 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1068 fprintf(ci->fh, ";\n");
1075 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1076 ai = IDL_LIST(curitem).data->data;
1078 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1079 fprintf(ci->fh, ";\n");
1082 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1083 fprintf(ci->fh, ";\n");
1100 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1105 if(curif == ioi->realif)
1108 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1109 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1111 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1112 IDL_tree curop = IDL_LIST(curitem).data;
1114 switch(IDL_NODE_TYPE(curop)) {
1116 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1117 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1118 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1124 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1125 and therefore don't have the OIDL_Attr_Info generated on them */
1127 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1130 ident = IDL_LIST(curitem).data;
1132 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1133 realid, IDL_IDENT(ident).str,
1134 id, IDL_IDENT(ident).str);
1136 if(!IDL_ATTR_DCL(curop).f_readonly)
1137 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1138 realid, IDL_IDENT(ident).str,
1139 id, IDL_IDENT(ident).str);
1153 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1157 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1159 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1160 /* "CDR_Codec *codec, %s *obj", */
1162 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1163 /* fprintf(ci->fh, ");\n"); */
1169 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1171 /* if(!tree) return; */
1173 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1176 /* switch(IDL_NODE_TYPE(tree)) { */
1177 /* case IDLN_MODULE: */
1178 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1180 /* case IDLN_LIST: */
1184 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1185 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1189 /* case IDLN_INTERFACE: */
1194 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1196 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1199 /* cur = IDL_LIST(sub).data; */
1201 /* switch(IDL_NODE_TYPE(cur)) { */
1202 /* case IDLN_OP_DCL: */
1203 /* doskel(cur, rinfo, ifid, ci); */
1205 /* case IDLN_ATTR_DCL: */
1206 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1208 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1209 /* /\* IDL_tree curitem; *\/ */
1211 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1212 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1214 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1215 /* /\* if(ai->op2) *\/ */
1216 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1233 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1235 /* static int num_methods = 0; */
1240 /* switch(IDL_NODE_TYPE(tree)) { */
1241 /* case IDLN_MODULE: */
1242 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1244 /* case IDLN_LIST: { */
1246 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1247 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1250 /* case IDLN_ATTR_DCL: { */
1251 /* OIDL_Attr_Info *ai = tree->data; */
1253 /* IDL_tree curitem; */
1255 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1256 /* curitem = IDL_LIST(curitem).next) { */
1257 /* ai = IDL_LIST(curitem).data->data; */
1259 /* ch_output_itypes (ai->op1, ci); */
1261 /* ch_output_itypes (ai->op2, ci); */
1266 /* case IDLN_INTERFACE: { */
1269 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1270 /* IDL_INTERFACE (tree).ident), "_", 0); */
1272 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1274 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1275 /* ci->c_base_name); */
1276 /* fprintf (ci->fh, "static \n"); */
1277 /* fprintf (ci->fh, "#else\n"); */
1278 /* fprintf (ci->fh, "extern \n"); */
1279 /* fprintf (ci->fh, "#endif\n"); */
1280 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1282 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1284 /* if (num_methods == 0) */
1285 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1287 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1288 /* ci->c_base_name); */
1289 /* fprintf (ci->fh, "static \n"); */
1290 /* fprintf (ci->fh, "#else\n"); */
1291 /* fprintf (ci->fh, "extern \n"); */
1292 /* fprintf (ci->fh, "#endif\n"); */
1293 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1297 /* num_methods = 0; */
1302 /* case IDLN_OP_DCL: */
1303 /* num_methods++; */