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 static gboolean is_native(IDL_tree_func_data *tfd, gpointer user_data)
145 IDL_tree tree = tfd->tree;
146 if (IDL_NODE_TYPE (tree) == IDLN_NATIVE) {
147 *(bool*)user_data = true;
148 return FALSE; /* Stop recursing */
150 return TRUE; /* continue */
154 contains_native_type(IDL_tree tree)
157 IDL_tree_walk_in_order(tree, is_native, &found);
163 forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
165 fprintf (ci->fh, OIDL_C_WARNING);
166 fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
167 fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
169 fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
171 fprintf(ci->fh, "#include <forb/cdr_codec.h>\n");
172 if (!rinfo->is_pidl) {
173 fprintf(ci->fh, "#include <forb/object_type.h>\n");
175 fprintf(ci->fh, "#include <forb/basic_types.h>\n");
176 if (rinfo->include) {
177 fprintf(ci->fh, "#include <%s>\n", rinfo->include);
179 fprintf(ci->fh, "\n");
181 fprintf(ci->fh, "#ifdef __cplusplus\n");
182 fprintf(ci->fh, "extern \"C\" {\n");
183 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
185 /* Do all the typedefs, etc. */
186 fprintf(ci->fh, "\n/** typedefs **/\n");
187 ch_output_types(tree, rinfo, ci);
189 if ( ci->do_skel_defs ) {
190 /* /\* Do all the POA structures, etc. *\/ */
191 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
192 /* ch_output_poa(tree, rinfo, ci); */
194 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
195 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
196 /* ch_output_skel_protos(tree, rinfo, ci); */
198 fprintf(ci->fh, "\n/** stub prototypes **/\n");
199 ch_output_stub_protos(tree, rinfo, ci);
201 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
202 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
204 /* if (rinfo->idata) { */
205 /* /\* FIXME: hackish ? *\/ */
206 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
208 /* ch_output_itypes(tree, ci); */
213 fprintf (ci->fh, "\n/** Method indices */\n\n");
215 list = ch_build_interfaces (list, tree);
216 ch_output_method_indices (list, ci);
219 fprintf(ci->fh, "#ifdef __cplusplus\n");
220 fprintf(ci->fh, "}\n");
221 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
223 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
224 /* fprintf(ci->fh, "#include <forb.h>\n\n"); */
225 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
227 fprintf(ci->fh, "#endif\n");
229 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
233 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
235 forb_cbe_write_typespec(ci->fh, val);
237 fprintf(ci->fh, " ");
238 switch(IDL_NODE_TYPE(name)) {
240 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
242 case IDLN_TYPE_ARRAY:
246 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
247 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
248 fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
253 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
256 fprintf(ci->fh, ";\n");
259 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
260 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
261 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
262 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
263 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
264 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
265 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
266 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
267 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
268 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
271 ch_output_types (IDL_tree tree,
272 OIDL_Run_Info *rinfo,
278 switch (IDL_NODE_TYPE (tree)) {
279 case IDLN_EXCEPT_DCL: {
280 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
283 /* id = IDL_ns_ident_to_qstring ( */
284 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
286 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
287 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
288 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
292 /* ch_output_type_struct (tree, rinfo, ci); */
295 case IDLN_FORWARD_DCL:
297 ch_output_interface (tree, rinfo, ci);
299 case IDLN_TYPE_STRUCT:
300 ch_output_type_struct (tree, rinfo, ci);
303 ch_output_type_enum (tree, rinfo, ci);
306 ch_output_type_dcl (tree, rinfo, ci);
308 case IDLN_TYPE_UNION:
309 ch_output_type_union (tree, rinfo, ci);
312 ch_output_codefrag (tree, rinfo, ci);
315 char *idlfn = IDL_SRCFILE (tree).filename;
316 if (rinfo->onlytop) {
318 if (!IDL_SRCFILE (tree).seenCnt &&
319 !IDL_SRCFILE(tree).isTop &&
320 !IDL_SRCFILE(tree).wasInhibit) {
323 hfn = g_path_get_basename (idlfn);
324 htail = strrchr (hfn,'.');
326 g_assert (htail && strlen (htail) >= 2);
331 fprintf (ci->fh, "#include \"%s\"\n", hfn);
336 fprintf (ci->fh, "/* from IDL source file \"%s\" "
337 "(seen %d, isTop %d, wasInhibit %d) */ \n",
339 IDL_SRCFILE (tree).seenCnt,
340 IDL_SRCFILE (tree).isTop,
341 IDL_SRCFILE (tree).wasInhibit);
346 ch_output_const_dcl (tree, rinfo, ci);
348 /* case IDLN_NATIVE: */
349 /* ch_output_native (tree, rinfo, ci); */
355 switch (IDL_NODE_TYPE (tree)) {
357 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
362 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
363 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
368 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
376 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
380 switch(IDL_NODE_TYPE(tree)) {
385 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
386 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
394 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
395 /* InheritedOutputInfo ioi; */
396 /* ioi.of = ci->fh; */
397 /* ioi.realif = tree; */
398 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
401 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
404 cur = IDL_LIST(sub).data;
406 switch(IDL_NODE_TYPE(cur)) {
408 forb_idl_check_oneway_op (cur);
409 fprintf(ci->fh, " ");
410 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
411 fprintf(ci->fh, ";\n");
413 /* case IDLN_ATTR_DCL: */
415 /* OIDL_Attr_Info *ai; */
416 /* IDL_tree curitem; */
418 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
419 /* ai = IDL_LIST(curitem).data->data; */
421 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
422 /* fprintf(ci->fh, ";\n"); */
425 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
426 /* fprintf(ci->fh, ";\n"); */
442 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
445 fullname = forb_cbe_get_typespec_str(tree);
446 fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
447 ch_output_impl_struct_members(tree, rinfo, ci);
448 fprintf(ci->fh, "};\n\n");
453 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
456 fullname = forb_cbe_get_typespec_str(tree);
457 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n"
458 "#define FORB_DECL_%s 1\n",
461 if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
462 /* PIDL interfaces are not normal CORBA Objects */
463 fprintf(ci->fh, "// PIDL: %s\n", fullname);
464 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
465 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
466 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
467 /* fprintf(ci->fh, "#endif\n"); */
470 fprintf(ci->fh, " #if !defined(_%s_defined)\n"
471 " #define _%s_defined 1\n",
473 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
474 fprintf(ci->fh, " typedef forb_object %s;\n"
475 " #endif\n", fullname);
476 fprintf(ci->fh, " #define %s_serialize(codec, obj) forb_object_serialize((codec), (obj))\n", fullname);
477 fprintf(ci->fh, " #define %s_deserialize(codec, obj) forb_object_deserialize((codec), (obj))\n", fullname);
478 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
480 ch_output_impl_struct(tree, rinfo, ci);
482 /* fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname); */
483 fprintf(ci->fh, " %s forb_%s_new(forb_orb orb,\n"
484 " const struct forb_%s_impl *impl,\n"
485 " void *instance_data);\n\n",
486 fullname, fullname, fullname);
488 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
491 fprintf(ci->fh, "#endif\n\n");
496 ch_output_type_enum (IDL_tree tree,
497 OIDL_Run_Info *rinfo,
503 /* CORBA spec says to do
504 * typedef unsigned int enum_name;
505 * and then #defines for each enumerator.
506 * This works just as well and seems cleaner.
509 enumid = IDL_ns_ident_to_qstring (
510 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
511 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
512 fprintf (ci->fh, "typedef enum {\n");
514 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
517 id = IDL_ns_ident_to_qstring (
518 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
520 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
525 fprintf (ci->fh, "} %s;\n", enumid);
527 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
528 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
529 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
531 fprintf (ci->fh, "#endif\n\n");
537 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
541 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
543 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
546 IDL_tree ent = IDL_LIST (l).data;
548 switch (IDL_NODE_TYPE(ent)) {
550 ctmp = IDL_ns_ident_to_qstring (
551 IDL_IDENT_TO_NS (ent), "_", 0);
553 case IDLN_TYPE_ARRAY:
554 ctmp = IDL_ns_ident_to_qstring (
555 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
558 g_assert_not_reached ();
562 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
563 fprintf (ci->fh, "typedef ");
564 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
566 switch (IDL_NODE_TYPE (ent)) {
568 fprintf (ci->fh, " %s;\n", ctmp);
569 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
570 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
571 fprintf (ci->fh, "_serialize((x),(y))\n");
573 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
574 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
575 fprintf (ci->fh, "_deserialize((x),(y))\n");
577 case IDLN_TYPE_ARRAY: {
580 fprintf (ci->fh, " %s", ctmp);
581 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
582 fprintf (ci->fh, "[%" IDL_LL "d]",
583 IDL_INTEGER (IDL_LIST (sub).data).value);
585 fprintf (ci->fh, ";\n");
586 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
587 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s array);\n", ctmp, ctmp);
588 /* fprintf (ci->fh, "typedef "); */
589 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
590 /* fprintf (ci->fh, " %s_slice", ctmp); */
591 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
592 /* sub; sub = IDL_LIST (sub).next) */
593 /* fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
594 /* fprintf(ci->fh, ";\n"); */
601 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
602 fprintf (ci->fh, "#endif\n");
608 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
611 /* IDL_tree id = IDL_NATIVE(tree).ident; */
612 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
613 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
614 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
615 /* /\* Dont even think about emitting a typecode. *\/ */
616 /* fprintf(ci->fh, "#endif\n"); */
621 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
624 IDL_tree cur, curmem;
626 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
628 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
629 /* put typedef out first for recursive seq */
630 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
632 /* Scan for any nested decls */
633 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
635 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
636 ch_prep(ts, rinfo, ci);
639 fprintf(ci->fh, "struct %s_type {\n", id);
641 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
642 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
643 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
646 if(!IDL_TYPE_STRUCT(tree).member_list)
647 fprintf(ci->fh, "int dummy;\n");
648 fprintf(ci->fh, "};\n");
650 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", id, id);
651 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", id, id);
653 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
655 fprintf(ci->fh, "#endif\n\n");
662 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
667 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
668 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
670 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
671 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
672 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
674 /* Scan for any nested decls */
675 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
676 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
677 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
680 fprintf(ci->fh, "struct %s_type {\n", id);
681 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
682 fprintf(ci->fh, " _d;\nunion {\n");
684 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
687 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
688 ch_output_var(IDL_MEMBER(member).type_spec,
689 IDL_LIST(IDL_MEMBER(member).dcls).data,
693 fprintf(ci->fh, "} _u;\n};\n");
695 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
697 fprintf(ci->fh, "#endif\n");
703 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
707 for(list = IDL_CODEFRAG(tree).lines; list;
708 list = g_slist_next(list)) {
709 if(!strncmp(list->data,
710 "#pragma include_defs",
711 sizeof("#pragma include_defs")-1)) {
713 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
714 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
716 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
718 fprintf(ci->fh, "#include <%s>\n", ctmp);
720 fprintf(ci->fh, "%s\n", (char *)list->data);
725 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
731 ident = IDL_CONST_DCL (tree).ident;
732 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
734 fprintf(ci->fh, "#ifndef %s\n", id);
735 fprintf(ci->fh, "#define %s ", id);
737 forb_cbe_write_const(ci->fh,
738 IDL_CONST_DCL(tree).const_exp);
740 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
741 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
742 !IDL_TYPE_INTEGER (typespec).f_signed)
743 fprintf(ci->fh, "U");
745 fprintf(ci->fh, "\n");
746 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
752 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
756 ctmp = forb_cbe_get_typespec_str(tree);
758 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
759 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
763 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
767 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
769 char *ctmp, *fullname, *fullname_def, *ctmp2;
771 gboolean separate_defs, fake_if;
772 IDL_tree fake_seq = NULL;
774 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
775 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
776 ctmp2 = forb_cbe_get_typespec_str(tts);
777 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
781 ctmp2 = g_strdup("CORBA_Object");
783 separate_defs = strcmp(ctmp, ctmp2);
784 fullname = forb_cbe_get_typespec_str(tree);
785 //printf("YYY %s\n", fullname);
790 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
791 //forb_idl_print_node(tree, 2);
793 tts = IDL_type_object_new();
794 fake_seq = IDL_type_sequence_new(tts, NULL);
795 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
796 ch_prep_sequence(fake_seq, rinfo, ci);
797 member_type = forb_cbe_type_is_builtin (tts) ?
798 ctmp2 + strlen ("CORBA_") : ctmp2;
799 fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
802 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
805 fullname_def = g_strdup(fullname);
807 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
808 == IDLN_TYPE_SEQUENCE)
809 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
811 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
812 * while _%s_defined protects only the struct */
814 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
816 /* if ( ci->do_impl_hack ) */
817 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
821 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
823 if(!strcmp(ctmp, "CORBA_RepositoryId"))
824 fprintf(ci->fh, "/* CRACKHEADS */\n");
825 fprintf(ci->fh, "typedef %s\n %s;\n", fullname_def, fullname);
826 fprintf(ci->fh, "#endif\n");
827 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
828 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
829 /* fullname, fullname_def); */
830 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
831 /* fullname, fullname_def); */
832 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
834 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
836 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
837 IDL_tree_free(fake_seq);
843 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
845 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
846 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
847 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n ");
848 forb_cbe_write_typespec(ci->fh, tree);
849 fprintf(ci->fh, ";\n#endif\n");
851 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
852 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
853 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
855 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
856 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
857 ctmp + strlen ("CORBA_") : ctmp;
859 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
860 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
861 member_type, ctmp, ctmp);
866 fprintf(ci->fh, "#endif\n\n");
871 g_free(fullname_def);
875 void ch_prep (IDL_tree tree,
876 OIDL_Run_Info *rinfo,
879 switch (IDL_NODE_TYPE (tree)) {
880 case IDLN_TYPE_SEQUENCE:
881 ch_prep_sequence (tree, rinfo, ci);
883 case IDLN_TYPE_FIXED:
884 ch_prep_fixed (tree, rinfo, ci);
886 case IDLN_TYPE_STRUCT:
887 ch_output_type_struct (tree, rinfo, ci);
890 ch_output_type_enum (tree, rinfo, ci);
898 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
899 /* OIDL_C_Info *ci, gboolean do_alloc) */
904 /* ctmp = forb_cbe_get_typespec_str(tree); */
906 /* if ( ci->do_impl_hack ) { */
907 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
908 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
911 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
912 /* fprintf (ci->fh, "static\n"); */
913 /* fprintf (ci->fh, "#else\n"); */
914 /* fprintf (ci->fh, "extern\n"); */
915 /* fprintf (ci->fh, "#endif\n"); */
916 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
918 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
919 /* if (ci->do_impl_hack) */
920 /* fprintf (ci->fh, "#endif\n"); */
925 /* tts = forb_cbe_get_typespec(tree); */
927 /* tc = forb_cbe_get_typecode_name (tts); */
929 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
930 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
932 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
934 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
936 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
937 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
938 /* member_type + strlen ("CORBA_") : member_type; */
940 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
941 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
942 /* ctmp, member_name, tc); */
944 /* g_free (member_type); */
953 /************************/
955 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
957 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
959 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
965 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
967 /* if(!tree) return; */
969 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
972 /* switch(IDL_NODE_TYPE(tree)) { */
973 /* case IDLN_MODULE: */
974 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
976 /* case IDLN_LIST: */
980 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
981 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
985 /* case IDLN_INTERFACE: */
991 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
993 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
996 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
997 /* fprintf(ci->fh, "typedef struct {\n"); */
998 /* fprintf(ci->fh, " void *_private;\n"); */
999 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1002 /* cur = IDL_LIST(sub).data; */
1004 /* switch(IDL_NODE_TYPE(cur)) { */
1005 /* case IDLN_OP_DCL: */
1006 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
1007 /* fprintf(ci->fh, ";\n"); */
1009 /* case IDLN_ATTR_DCL: */
1011 /* OIDL_Attr_Info *ai; */
1012 /* IDL_tree curitem; */
1014 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
1015 /* ai = IDL_LIST(curitem).data->data; */
1017 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
1018 /* fprintf(ci->fh, ";\n"); */
1021 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
1022 /* fprintf(ci->fh, ";\n"); */
1032 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
1034 /* fprintf(ci->fh, "typedef struct {\n"); */
1035 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
1036 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1037 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1039 /* fprintf(ci->fh, "typedef struct {\n"); */
1040 /* fprintf(ci->fh, " void *_private;\n"); */
1041 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1042 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1044 /* fprintf(ci->fh, */
1045 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1046 /* fprintf(ci->fh, */
1047 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1049 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1059 /************************/
1063 } InheritedOutputInfo;
1064 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1067 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1072 switch(IDL_NODE_TYPE(tree)) {
1074 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1080 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1081 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1085 case IDLN_INTERFACE:
1089 if(IDL_INTERFACE(tree).inheritance_spec) {
1090 InheritedOutputInfo ioi;
1093 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1096 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1099 cur = IDL_LIST(sub).data;
1101 switch(IDL_NODE_TYPE(cur)) {
1103 forb_idl_check_oneway_op (cur);
1104 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1105 fprintf(ci->fh, ";\n");
1112 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1113 ai = IDL_LIST(curitem).data->data;
1115 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1116 fprintf(ci->fh, ";\n");
1119 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1120 fprintf(ci->fh, ";\n");
1137 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1142 if(curif == ioi->realif)
1145 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1146 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1148 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1149 IDL_tree curop = IDL_LIST(curitem).data;
1151 switch(IDL_NODE_TYPE(curop)) {
1153 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1154 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1155 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1161 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1162 and therefore don't have the OIDL_Attr_Info generated on them */
1164 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1167 ident = IDL_LIST(curitem).data;
1169 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1170 realid, IDL_IDENT(ident).str,
1171 id, IDL_IDENT(ident).str);
1173 if(!IDL_ATTR_DCL(curop).f_readonly)
1174 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1175 realid, IDL_IDENT(ident).str,
1176 id, IDL_IDENT(ident).str);
1190 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1194 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1196 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1197 /* "FORB_CDR_Codec *codec, %s *obj", */
1199 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1200 /* fprintf(ci->fh, ");\n"); */
1206 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1208 /* if(!tree) return; */
1210 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1213 /* switch(IDL_NODE_TYPE(tree)) { */
1214 /* case IDLN_MODULE: */
1215 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1217 /* case IDLN_LIST: */
1221 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1222 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1226 /* case IDLN_INTERFACE: */
1231 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1233 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1236 /* cur = IDL_LIST(sub).data; */
1238 /* switch(IDL_NODE_TYPE(cur)) { */
1239 /* case IDLN_OP_DCL: */
1240 /* doskel(cur, rinfo, ifid, ci); */
1242 /* case IDLN_ATTR_DCL: */
1243 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1245 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1246 /* /\* IDL_tree curitem; *\/ */
1248 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1249 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1251 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1252 /* /\* if(ai->op2) *\/ */
1253 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1270 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1272 /* static int num_methods = 0; */
1277 /* switch(IDL_NODE_TYPE(tree)) { */
1278 /* case IDLN_MODULE: */
1279 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1281 /* case IDLN_LIST: { */
1283 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1284 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1287 /* case IDLN_ATTR_DCL: { */
1288 /* OIDL_Attr_Info *ai = tree->data; */
1290 /* IDL_tree curitem; */
1292 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1293 /* curitem = IDL_LIST(curitem).next) { */
1294 /* ai = IDL_LIST(curitem).data->data; */
1296 /* ch_output_itypes (ai->op1, ci); */
1298 /* ch_output_itypes (ai->op2, ci); */
1303 /* case IDLN_INTERFACE: { */
1306 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1307 /* IDL_INTERFACE (tree).ident), "_", 0); */
1309 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1311 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1312 /* ci->c_base_name); */
1313 /* fprintf (ci->fh, "static \n"); */
1314 /* fprintf (ci->fh, "#else\n"); */
1315 /* fprintf (ci->fh, "extern \n"); */
1316 /* fprintf (ci->fh, "#endif\n"); */
1317 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1319 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1321 /* if (num_methods == 0) */
1322 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1324 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1325 /* ci->c_base_name); */
1326 /* fprintf (ci->fh, "static \n"); */
1327 /* fprintf (ci->fh, "#else\n"); */
1328 /* fprintf (ci->fh, "extern \n"); */
1329 /* fprintf (ci->fh, "#endif\n"); */
1330 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1334 /* num_methods = 0; */
1339 /* case IDLN_OP_DCL: */
1340 /* num_methods++; */