2 #include "forb-idl-c-backend.h"
3 #include "forb_config.h"
10 static void ch_output_types(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
11 /* static void ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
12 /* static void ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci); */
13 static void ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
14 /* static void ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
15 static GSList *ch_build_interfaces (GSList *list, IDL_tree tree);
16 static void ch_output_method (FILE *of, IDL_tree tree, const char *id);
17 /* static void ch_output_imethods_index (GSList *list, OIDL_C_Info *ci); */
21 GSList *methods; /* IDLN_OP_DCLs */
24 /* this is hardcopy from cc_build_interfaces() defined in forb-idl-c-common.c */
26 ch_build_interfaces (GSList *list, IDL_tree tree)
31 switch (IDL_NODE_TYPE (tree)) {
33 list = ch_build_interfaces (
34 list, IDL_MODULE (tree).definition_list);
38 for (sub = tree; sub; sub = IDL_LIST (sub).next)
39 list = ch_build_interfaces (
40 list, IDL_LIST (sub).data);
46 for (curitem = IDL_ATTR_DCL (tree).simple_declarations;
47 curitem; curitem = IDL_LIST (curitem).next) {
48 OIDL_Attr_Info *ai = IDL_LIST (curitem).data->data;
50 list = ch_build_interfaces (list, ai->op1);
52 list = ch_build_interfaces (list, ai->op2);
56 case IDLN_INTERFACE: {
57 Interface *i = g_new0 (Interface, 1);
61 list = g_slist_append (list, i);
63 list = ch_build_interfaces (list, IDL_INTERFACE(tree).body);
70 g_return_val_if_fail (list != NULL, NULL);
72 i = ( g_slist_last(list) )->data;
73 i->methods = g_slist_append (i->methods, tree);
86 ch_output_method (FILE *of, IDL_tree tree, const char *id)
88 char *fullname = NULL;
90 fullname = g_strconcat (id, "_", IDL_IDENT (
91 IDL_OP_DCL (tree).ident).str, NULL);
93 fprintf (of, "\t%s__method_index", fullname);
99 ch_output_method_indices (GSList *list, OIDL_C_Info *ci)
104 for (l = list; l; l = l->next) {
105 Interface *i = l->data;
109 id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (
110 IDL_INTERFACE (i->tree).ident), "_", 0);
114 fprintf (of, "#ifndef __%s__method_indices\n", id);
115 fprintf (of, "#define __%s__method_indices\n", id);
117 fprintf (of, "typedef enum {\n");
119 for (m = i->methods; m; m = m->next) {
120 ch_output_method (of, m->data, id);
127 fprintf (of, "} %s__method_indices;\n", id);
128 fprintf (of, "#endif /* __%s__method_indices */\n\n", id);
134 for (l = list; l; l = l->next) {
135 g_slist_free (((Interface *)l->data)->methods);
144 static gboolean is_native(IDL_tree_func_data *tfd, gpointer user_data)
146 IDL_tree tree = tfd->tree;
147 if (IDL_NODE_TYPE (tree) == IDLN_NATIVE) {
148 *(bool*)user_data = true;
149 return FALSE; /* Stop recursing */
151 return TRUE; /* continue */
155 contains_native_type(IDL_tree tree)
158 IDL_tree_walk_in_order(tree, is_native, &found);
164 forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
166 fprintf (ci->fh, OIDL_C_WARNING);
167 fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
168 fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
170 fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
172 fprintf(ci->fh, "#include <forb/cdr_codec.h>\n");
173 if (!rinfo->is_pidl) {
174 fprintf(ci->fh, "#include <forb/object_type.h>\n");
176 fprintf(ci->fh, "#include <forb/basic_types.h>\n");
177 if (rinfo->include) {
178 fprintf(ci->fh, "#include <%s>\n", rinfo->include);
180 fprintf(ci->fh, "\n");
182 fprintf(ci->fh, "#ifdef __cplusplus\n");
183 fprintf(ci->fh, "extern \"C\" {\n");
184 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
186 /* Do all the typedefs, etc. */
187 fprintf(ci->fh, "\n/** typedefs **/\n");
188 ch_output_types(tree, rinfo, ci);
190 if ( ci->do_skel_defs ) {
191 /* /\* Do all the POA structures, etc. *\/ */
192 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
193 /* ch_output_poa(tree, rinfo, ci); */
195 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
196 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
197 /* ch_output_skel_protos(tree, rinfo, ci); */
199 fprintf(ci->fh, "\n/** stub prototypes **/\n");
200 ch_output_stub_protos(tree, rinfo, ci);
202 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
203 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
205 /* if (rinfo->idata) { */
206 /* /\* FIXME: hackish ? *\/ */
207 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
209 /* ch_output_itypes(tree, ci); */
214 fprintf (ci->fh, "\n/** Method indices */\n\n");
216 list = ch_build_interfaces (list, tree);
217 ch_output_method_indices (list, ci);
220 fprintf(ci->fh, "#ifdef __cplusplus\n");
221 fprintf(ci->fh, "}\n");
222 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
224 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
225 /* fprintf(ci->fh, "#include <forb.h>\n\n"); */
226 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
228 fprintf(ci->fh, "#endif\n");
230 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
234 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
236 forb_cbe_write_typespec(ci->fh, val);
238 fprintf(ci->fh, " ");
239 switch(IDL_NODE_TYPE(name)) {
241 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
243 case IDLN_TYPE_ARRAY:
247 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
248 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
249 fprintf(ci->fh, "[%" PRId64 "]", IDL_INTEGER(IDL_LIST(curitem).data).value);
254 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
257 fprintf(ci->fh, ";\n");
260 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
261 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
262 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
263 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
264 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
265 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
266 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
267 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
268 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
269 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
272 ch_output_types (IDL_tree tree,
273 OIDL_Run_Info *rinfo,
279 switch (IDL_NODE_TYPE (tree)) {
280 case IDLN_EXCEPT_DCL: {
281 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
284 /* id = IDL_ns_ident_to_qstring ( */
285 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
287 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
288 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
289 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
293 /* ch_output_type_struct (tree, rinfo, ci); */
296 case IDLN_FORWARD_DCL:
298 ch_output_interface (tree, rinfo, ci);
300 case IDLN_TYPE_STRUCT:
301 ch_output_type_struct (tree, rinfo, ci);
304 ch_output_type_enum (tree, rinfo, ci);
307 ch_output_type_dcl (tree, rinfo, ci);
309 case IDLN_TYPE_UNION:
310 ch_output_type_union (tree, rinfo, ci);
313 ch_output_codefrag (tree, rinfo, ci);
316 char *idlfn = IDL_SRCFILE (tree).filename;
317 if (rinfo->onlytop) {
319 if (!IDL_SRCFILE (tree).seenCnt &&
320 !IDL_SRCFILE(tree).isTop &&
321 !IDL_SRCFILE(tree).wasInhibit) {
324 hfn = g_path_get_basename (idlfn);
325 htail = strrchr (hfn,'.');
327 g_assert (htail && strlen (htail) >= 2);
332 fprintf (ci->fh, "#include \"%s\"\n", hfn);
337 fprintf (ci->fh, "/* from IDL source file \"%s\" "
338 "(seen %d, isTop %d, wasInhibit %d) */ \n",
340 IDL_SRCFILE (tree).seenCnt,
341 IDL_SRCFILE (tree).isTop,
342 IDL_SRCFILE (tree).wasInhibit);
347 ch_output_const_dcl (tree, rinfo, ci);
349 /* case IDLN_NATIVE: */
350 /* ch_output_native (tree, rinfo, ci); */
356 switch (IDL_NODE_TYPE (tree)) {
358 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
363 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
364 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
369 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
377 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
381 switch(IDL_NODE_TYPE(tree)) {
386 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
387 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
395 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
396 /* InheritedOutputInfo ioi; */
397 /* ioi.of = ci->fh; */
398 /* ioi.realif = tree; */
399 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
402 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
405 cur = IDL_LIST(sub).data;
407 switch(IDL_NODE_TYPE(cur)) {
409 forb_idl_check_oneway_op (cur);
410 fprintf(ci->fh, " ");
411 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
412 fprintf(ci->fh, ";\n");
414 /* case IDLN_ATTR_DCL: */
416 /* OIDL_Attr_Info *ai; */
417 /* IDL_tree curitem; */
419 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
420 /* ai = IDL_LIST(curitem).data->data; */
422 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
423 /* fprintf(ci->fh, ";\n"); */
426 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
427 /* fprintf(ci->fh, ";\n"); */
443 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
446 fullname = forb_cbe_get_typespec_str(tree);
447 fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
448 ch_output_impl_struct_members(tree, rinfo, ci);
449 fprintf(ci->fh, "};\n\n");
454 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
457 fullname = forb_cbe_get_typespec_str(tree);
458 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n"
459 "#define FORB_DECL_%s 1\n",
462 if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
463 /* PIDL interfaces are not normal CORBA Objects */
464 fprintf(ci->fh, "// PIDL: %s\n", fullname);
465 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
466 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
467 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
468 /* fprintf(ci->fh, "#endif\n"); */
471 fprintf(ci->fh, " #if !defined(_%s_defined)\n"
472 " #define _%s_defined 1\n",
474 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
475 fprintf(ci->fh, " typedef forb_object %s;\n"
476 " #endif\n", fullname);
477 fprintf(ci->fh, " #define %s_serialize(codec, obj) forb_object_serialize((codec), (obj))\n", fullname);
478 fprintf(ci->fh, " #define %s_deserialize(codec, obj) forb_object_deserialize((codec), (obj))\n", fullname);
479 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
481 ch_output_impl_struct(tree, rinfo, ci);
483 /* fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname); */
484 fprintf(ci->fh, " %s forb_%s_new(forb_orb orb,\n"
485 " const struct forb_%s_impl *impl,\n"
486 " void *instance_data);\n\n",
487 fullname, fullname, fullname);
489 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
492 fprintf(ci->fh, "#endif\n\n");
497 ch_output_type_enum (IDL_tree tree,
498 OIDL_Run_Info *rinfo,
504 /* CORBA spec says to do
505 * typedef unsigned int enum_name;
506 * and then #defines for each enumerator.
507 * This works just as well and seems cleaner.
510 enumid = IDL_ns_ident_to_qstring (
511 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
512 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
513 fprintf (ci->fh, "typedef enum {\n");
515 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
518 id = IDL_ns_ident_to_qstring (
519 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
521 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
526 fprintf (ci->fh, "} %s;\n", enumid);
528 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
529 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
530 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
532 fprintf (ci->fh, "#endif\n\n");
538 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
542 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
544 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
547 IDL_tree ent = IDL_LIST (l).data;
549 switch (IDL_NODE_TYPE(ent)) {
551 ctmp = IDL_ns_ident_to_qstring (
552 IDL_IDENT_TO_NS (ent), "_", 0);
554 case IDLN_TYPE_ARRAY:
555 ctmp = IDL_ns_ident_to_qstring (
556 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
559 g_assert_not_reached ();
563 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
564 fprintf (ci->fh, "typedef ");
565 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
567 switch (IDL_NODE_TYPE (ent)) {
569 fprintf (ci->fh, " %s;\n", ctmp);
570 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
571 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
572 fprintf (ci->fh, "_serialize((x),(y))\n");
574 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
575 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
576 fprintf (ci->fh, "_deserialize((x),(y))\n");
578 case IDLN_TYPE_ARRAY: {
581 fprintf (ci->fh, " %s", ctmp);
582 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
583 fprintf (ci->fh, "[%" PRId64 "]",
584 IDL_INTEGER (IDL_LIST (sub).data).value);
586 fprintf (ci->fh, ";\n");
587 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
588 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s array);\n", ctmp, ctmp);
589 /* fprintf (ci->fh, "typedef "); */
590 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
591 /* fprintf (ci->fh, " %s_slice", ctmp); */
592 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
593 /* sub; sub = IDL_LIST (sub).next) */
594 /* fprintf (ci->fh, "[%" PRId64 "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
595 /* fprintf(ci->fh, ";\n"); */
602 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
603 fprintf (ci->fh, "#endif\n");
609 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
612 /* IDL_tree id = IDL_NATIVE(tree).ident; */
613 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
614 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
615 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
616 /* /\* Dont even think about emitting a typecode. *\/ */
617 /* fprintf(ci->fh, "#endif\n"); */
622 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
625 IDL_tree cur, curmem;
627 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
629 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
630 /* put typedef out first for recursive seq */
631 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
633 /* Scan for any nested decls */
634 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
636 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
637 ch_prep(ts, rinfo, ci);
640 fprintf(ci->fh, "struct %s_type {\n", id);
642 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
643 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
644 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
647 if(!IDL_TYPE_STRUCT(tree).member_list)
648 fprintf(ci->fh, "int dummy;\n");
649 fprintf(ci->fh, "};\n");
651 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", id, id);
652 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", id, id);
654 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
656 fprintf(ci->fh, "#endif\n\n");
663 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
668 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
669 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
671 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
672 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
673 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
675 /* Scan for any nested decls */
676 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
677 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
678 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
681 fprintf(ci->fh, "struct %s_type {\n", id);
682 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
683 fprintf(ci->fh, " _d;\nunion {\n");
685 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
688 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
689 ch_output_var(IDL_MEMBER(member).type_spec,
690 IDL_LIST(IDL_MEMBER(member).dcls).data,
694 fprintf(ci->fh, "} _u;\n};\n");
696 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
698 fprintf(ci->fh, "#endif\n");
704 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
708 for(list = IDL_CODEFRAG(tree).lines; list;
709 list = g_slist_next(list)) {
710 if(!strncmp(list->data,
711 "#pragma include_defs",
712 sizeof("#pragma include_defs")-1)) {
714 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
715 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
717 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
719 fprintf(ci->fh, "#include <%s>\n", ctmp);
721 fprintf(ci->fh, "%s\n", (char *)list->data);
726 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
732 ident = IDL_CONST_DCL (tree).ident;
733 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
735 fprintf(ci->fh, "#ifndef %s\n", id);
736 fprintf(ci->fh, "#define %s ", id);
738 forb_cbe_write_const(ci->fh,
739 IDL_CONST_DCL(tree).const_exp);
741 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
742 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
743 !IDL_TYPE_INTEGER (typespec).f_signed)
744 fprintf(ci->fh, "U");
746 fprintf(ci->fh, "\n");
747 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
753 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
757 ctmp = forb_cbe_get_typespec_str(tree);
759 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
760 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
764 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
768 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
770 char *ctmp, *fullname, *fullname_def, *ctmp2;
772 gboolean separate_defs, fake_if;
773 IDL_tree fake_seq = NULL;
775 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
776 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
777 ctmp2 = forb_cbe_get_typespec_str(tts);
778 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
782 ctmp2 = g_strdup("CORBA_Object");
784 separate_defs = strcmp(ctmp, ctmp2);
785 fullname = forb_cbe_get_typespec_str(tree);
786 //printf("YYY %s\n", fullname);
791 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
792 //forb_idl_print_node(tree, 2);
794 tts = IDL_type_object_new();
795 fake_seq = IDL_type_sequence_new(tts, NULL);
796 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
797 ch_prep_sequence(fake_seq, rinfo, ci);
798 member_type = forb_cbe_type_is_builtin (tts) ?
799 ctmp2 + strlen ("CORBA_") : ctmp2;
800 fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
803 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
806 fullname_def = g_strdup(fullname);
808 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
809 == IDLN_TYPE_SEQUENCE)
810 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
812 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
813 * while _%s_defined protects only the struct */
815 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
817 /* if ( ci->do_impl_hack ) */
818 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
822 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
824 if(!strcmp(ctmp, "CORBA_RepositoryId"))
825 fprintf(ci->fh, "/* CRACKHEADS */\n");
826 fprintf(ci->fh, "typedef %s\n %s;\n", fullname_def, fullname);
827 fprintf(ci->fh, "#endif\n");
828 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
829 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
830 /* fullname, fullname_def); */
831 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
832 /* fullname, fullname_def); */
833 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
835 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
837 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
838 IDL_tree_free(fake_seq);
844 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
846 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
847 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
848 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n ");
849 forb_cbe_write_typespec(ci->fh, tree);
850 fprintf(ci->fh, ";\n#endif\n");
852 fprintf(ci->fh, "CORBA_boolean %s_serialize(FORB_CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
853 fprintf(ci->fh, "CORBA_boolean %s_deserialize(FORB_CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
854 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
856 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
857 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
858 ctmp + strlen ("CORBA_") : ctmp;
860 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
861 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
862 member_type, ctmp, ctmp);
867 fprintf(ci->fh, "#endif\n\n");
872 g_free(fullname_def);
876 void ch_prep (IDL_tree tree,
877 OIDL_Run_Info *rinfo,
880 switch (IDL_NODE_TYPE (tree)) {
881 case IDLN_TYPE_SEQUENCE:
882 ch_prep_sequence (tree, rinfo, ci);
884 case IDLN_TYPE_FIXED:
885 ch_prep_fixed (tree, rinfo, ci);
887 case IDLN_TYPE_STRUCT:
888 ch_output_type_struct (tree, rinfo, ci);
891 ch_output_type_enum (tree, rinfo, ci);
899 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
900 /* OIDL_C_Info *ci, gboolean do_alloc) */
905 /* ctmp = forb_cbe_get_typespec_str(tree); */
907 /* if ( ci->do_impl_hack ) { */
908 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
909 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
912 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
913 /* fprintf (ci->fh, "static\n"); */
914 /* fprintf (ci->fh, "#else\n"); */
915 /* fprintf (ci->fh, "extern\n"); */
916 /* fprintf (ci->fh, "#endif\n"); */
917 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
919 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
920 /* if (ci->do_impl_hack) */
921 /* fprintf (ci->fh, "#endif\n"); */
926 /* tts = forb_cbe_get_typespec(tree); */
928 /* tc = forb_cbe_get_typecode_name (tts); */
930 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
931 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
933 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
935 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
937 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
938 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
939 /* member_type + strlen ("CORBA_") : member_type; */
941 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
942 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
943 /* ctmp, member_name, tc); */
945 /* g_free (member_type); */
954 /************************/
956 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
958 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
960 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
966 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
968 /* if(!tree) return; */
970 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
973 /* switch(IDL_NODE_TYPE(tree)) { */
974 /* case IDLN_MODULE: */
975 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
977 /* case IDLN_LIST: */
981 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
982 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
986 /* case IDLN_INTERFACE: */
992 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
994 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
997 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
998 /* fprintf(ci->fh, "typedef struct {\n"); */
999 /* fprintf(ci->fh, " void *_private;\n"); */
1000 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1003 /* cur = IDL_LIST(sub).data; */
1005 /* switch(IDL_NODE_TYPE(cur)) { */
1006 /* case IDLN_OP_DCL: */
1007 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
1008 /* fprintf(ci->fh, ";\n"); */
1010 /* case IDLN_ATTR_DCL: */
1012 /* OIDL_Attr_Info *ai; */
1013 /* IDL_tree curitem; */
1015 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
1016 /* ai = IDL_LIST(curitem).data->data; */
1018 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
1019 /* fprintf(ci->fh, ";\n"); */
1022 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
1023 /* fprintf(ci->fh, ";\n"); */
1033 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
1035 /* fprintf(ci->fh, "typedef struct {\n"); */
1036 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
1037 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1038 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1040 /* fprintf(ci->fh, "typedef struct {\n"); */
1041 /* fprintf(ci->fh, " void *_private;\n"); */
1042 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1043 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1045 /* fprintf(ci->fh, */
1046 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1047 /* fprintf(ci->fh, */
1048 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1050 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1060 /************************/
1064 } InheritedOutputInfo;
1065 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1068 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1073 switch(IDL_NODE_TYPE(tree)) {
1075 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1081 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1082 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1086 case IDLN_INTERFACE:
1090 if(IDL_INTERFACE(tree).inheritance_spec) {
1091 InheritedOutputInfo ioi;
1094 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1097 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1100 cur = IDL_LIST(sub).data;
1102 switch(IDL_NODE_TYPE(cur)) {
1104 forb_idl_check_oneway_op (cur);
1105 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1106 fprintf(ci->fh, ";\n");
1113 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1114 ai = IDL_LIST(curitem).data->data;
1116 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1117 fprintf(ci->fh, ";\n");
1120 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1121 fprintf(ci->fh, ";\n");
1138 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1143 if(curif == ioi->realif)
1146 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1147 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1149 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1150 IDL_tree curop = IDL_LIST(curitem).data;
1152 switch(IDL_NODE_TYPE(curop)) {
1154 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1155 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1156 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1162 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1163 and therefore don't have the OIDL_Attr_Info generated on them */
1165 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1168 ident = IDL_LIST(curitem).data;
1170 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1171 realid, IDL_IDENT(ident).str,
1172 id, IDL_IDENT(ident).str);
1174 if(!IDL_ATTR_DCL(curop).f_readonly)
1175 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1176 realid, IDL_IDENT(ident).str,
1177 id, IDL_IDENT(ident).str);
1191 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1195 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1197 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1198 /* "FORB_CDR_Codec *codec, %s *obj", */
1200 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1201 /* fprintf(ci->fh, ");\n"); */
1207 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1209 /* if(!tree) return; */
1211 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1214 /* switch(IDL_NODE_TYPE(tree)) { */
1215 /* case IDLN_MODULE: */
1216 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1218 /* case IDLN_LIST: */
1222 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1223 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1227 /* case IDLN_INTERFACE: */
1232 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1234 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1237 /* cur = IDL_LIST(sub).data; */
1239 /* switch(IDL_NODE_TYPE(cur)) { */
1240 /* case IDLN_OP_DCL: */
1241 /* doskel(cur, rinfo, ifid, ci); */
1243 /* case IDLN_ATTR_DCL: */
1244 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1246 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1247 /* /\* IDL_tree curitem; *\/ */
1249 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1250 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1252 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1253 /* /\* if(ai->op2) *\/ */
1254 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1271 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1273 /* static int num_methods = 0; */
1278 /* switch(IDL_NODE_TYPE(tree)) { */
1279 /* case IDLN_MODULE: */
1280 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1282 /* case IDLN_LIST: { */
1284 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1285 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1288 /* case IDLN_ATTR_DCL: { */
1289 /* OIDL_Attr_Info *ai = tree->data; */
1291 /* IDL_tree curitem; */
1293 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1294 /* curitem = IDL_LIST(curitem).next) { */
1295 /* ai = IDL_LIST(curitem).data->data; */
1297 /* ch_output_itypes (ai->op1, ci); */
1299 /* ch_output_itypes (ai->op2, ci); */
1304 /* case IDLN_INTERFACE: { */
1307 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1308 /* IDL_INTERFACE (tree).ident), "_", 0); */
1310 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1312 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1313 /* ci->c_base_name); */
1314 /* fprintf (ci->fh, "static \n"); */
1315 /* fprintf (ci->fh, "#else\n"); */
1316 /* fprintf (ci->fh, "extern \n"); */
1317 /* fprintf (ci->fh, "#endif\n"); */
1318 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1320 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1322 /* if (num_methods == 0) */
1323 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1325 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1326 /* ci->c_base_name); */
1327 /* fprintf (ci->fh, "static \n"); */
1328 /* fprintf (ci->fh, "#else\n"); */
1329 /* fprintf (ci->fh, "extern \n"); */
1330 /* fprintf (ci->fh, "#endif\n"); */
1331 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1335 /* num_methods = 0; */
1340 /* case IDLN_OP_DCL: */
1341 /* num_methods++; */