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, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
151 if (rinfo->is_pidl) {
152 /* Include only serialization stuff */
153 fprintf(ci->fh, "#include <forb/cdr.h>\n"
154 "#include <forb/basic_types.h>\n"
157 fprintf(ci->fh, "#include <forb/forb-internal.h>\n\n");
160 fprintf(ci->fh, "#ifdef __cplusplus\n");
161 fprintf(ci->fh, "extern \"C\" {\n");
162 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
164 /* Do all the typedefs, etc. */
165 fprintf(ci->fh, "\n/** typedefs **/\n");
166 ch_output_types(tree, rinfo, ci);
168 if ( ci->do_skel_defs ) {
169 /* /\* Do all the POA structures, etc. *\/ */
170 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
171 /* ch_output_poa(tree, rinfo, ci); */
173 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
174 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
175 /* ch_output_skel_protos(tree, rinfo, ci); */
177 fprintf(ci->fh, "\n/** stub prototypes **/\n");
178 ch_output_stub_protos(tree, rinfo, ci);
180 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
181 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
183 /* if (rinfo->idata) { */
184 /* /\* FIXME: hackish ? *\/ */
185 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
187 /* ch_output_itypes(tree, ci); */
192 fprintf (ci->fh, "\n/** Method indices */\n\n");
194 list = ch_build_interfaces (list, tree);
195 ch_output_method_indices (list, ci);
198 fprintf(ci->fh, "#ifdef __cplusplus\n");
199 fprintf(ci->fh, "}\n");
200 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
202 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
203 /* fprintf(ci->fh, "#include <forb/forb.h>\n\n"); */
204 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
206 fprintf(ci->fh, "#endif\n");
208 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
212 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
214 forb_cbe_write_typespec(ci->fh, val);
216 fprintf(ci->fh, " ");
217 switch(IDL_NODE_TYPE(name)) {
219 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
221 case IDLN_TYPE_ARRAY:
225 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
226 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
227 fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
232 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
235 fprintf(ci->fh, ";\n");
238 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
239 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
240 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
241 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
242 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
243 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
244 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
245 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
246 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
247 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
250 ch_output_types (IDL_tree tree,
251 OIDL_Run_Info *rinfo,
257 switch (IDL_NODE_TYPE (tree)) {
258 case IDLN_EXCEPT_DCL: {
259 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
262 /* id = IDL_ns_ident_to_qstring ( */
263 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
265 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
266 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
267 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
271 /* ch_output_type_struct (tree, rinfo, ci); */
274 case IDLN_FORWARD_DCL:
276 ch_output_interface (tree, rinfo, ci);
278 case IDLN_TYPE_STRUCT:
279 ch_output_type_struct (tree, rinfo, ci);
282 ch_output_type_enum (tree, rinfo, ci);
285 ch_output_type_dcl (tree, rinfo, ci);
287 case IDLN_TYPE_UNION:
288 ch_output_type_union (tree, rinfo, ci);
291 ch_output_codefrag (tree, rinfo, ci);
294 char *idlfn = IDL_SRCFILE (tree).filename;
295 if (rinfo->onlytop) {
297 if (!IDL_SRCFILE (tree).seenCnt &&
298 !IDL_SRCFILE(tree).isTop &&
299 !IDL_SRCFILE(tree).wasInhibit) {
302 hfn = g_path_get_basename (idlfn);
303 htail = strrchr (hfn,'.');
305 g_assert (htail && strlen (htail) >= 2);
310 fprintf (ci->fh, "#include \"%s\"\n", hfn);
315 fprintf (ci->fh, "/* from IDL source file \"%s\" "
316 "(seen %d, isTop %d, wasInhibit %d) */ \n",
318 IDL_SRCFILE (tree).seenCnt,
319 IDL_SRCFILE (tree).isTop,
320 IDL_SRCFILE (tree).wasInhibit);
325 ch_output_const_dcl (tree, rinfo, ci);
327 /* case IDLN_NATIVE: */
328 /* ch_output_native (tree, rinfo, ci); */
334 switch (IDL_NODE_TYPE (tree)) {
336 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
341 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
342 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
347 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
355 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
359 switch(IDL_NODE_TYPE(tree)) {
364 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
365 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
373 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
374 /* InheritedOutputInfo ioi; */
375 /* ioi.of = ci->fh; */
376 /* ioi.realif = tree; */
377 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
380 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
383 cur = IDL_LIST(sub).data;
385 switch(IDL_NODE_TYPE(cur)) {
387 forb_idl_check_oneway_op (cur);
388 fprintf(ci->fh, " ");
389 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
390 fprintf(ci->fh, ";\n");
392 /* case IDLN_ATTR_DCL: */
394 /* OIDL_Attr_Info *ai; */
395 /* IDL_tree curitem; */
397 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
398 /* ai = IDL_LIST(curitem).data->data; */
400 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
401 /* fprintf(ci->fh, ";\n"); */
404 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
405 /* fprintf(ci->fh, ";\n"); */
421 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
424 fullname = forb_cbe_get_typespec_str(tree);
425 fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
426 ch_output_impl_struct_members(tree, rinfo, ci);
427 fprintf(ci->fh, "};\n\n");
432 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
435 fullname = forb_cbe_get_typespec_str(tree);
436 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);
438 if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
439 /* PIDL interfaces are not normal CORBA Objects */
440 fprintf(ci->fh, "// PIDL: %s\n", fullname);
441 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
442 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
443 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
444 /* fprintf(ci->fh, "#endif\n"); */
447 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
448 fprintf(ci->fh, "typedef forb_object %s;\n", fullname);
449 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
451 ch_output_impl_struct(tree, rinfo, ci);
453 fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname);
454 fprintf(ci->fh, "%s forb_%s_new(void *instance_data,\n"
455 " const struct forb_%s_impl *impl, forb_orb orb);\n\n",
456 fullname, fullname, fullname);
458 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
461 fprintf(ci->fh, "#endif\n\n");
466 ch_output_type_enum (IDL_tree tree,
467 OIDL_Run_Info *rinfo,
473 /* CORBA spec says to do
474 * typedef unsigned int enum_name;
475 * and then #defines for each enumerator.
476 * This works just as well and seems cleaner.
479 enumid = IDL_ns_ident_to_qstring (
480 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
481 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
482 fprintf (ci->fh, "typedef enum {\n");
484 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
487 id = IDL_ns_ident_to_qstring (
488 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
490 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
495 fprintf (ci->fh, "} %s;\n", enumid);
497 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
498 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
499 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
501 fprintf (ci->fh, "#endif\n\n");
507 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
511 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
513 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
516 IDL_tree ent = IDL_LIST (l).data;
518 switch (IDL_NODE_TYPE(ent)) {
520 ctmp = IDL_ns_ident_to_qstring (
521 IDL_IDENT_TO_NS (ent), "_", 0);
523 case IDLN_TYPE_ARRAY:
524 ctmp = IDL_ns_ident_to_qstring (
525 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
528 g_assert_not_reached ();
532 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
533 fprintf (ci->fh, "typedef ");
534 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
536 switch (IDL_NODE_TYPE (ent)) {
538 fprintf (ci->fh, " %s;\n", ctmp);
539 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
540 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
541 fprintf (ci->fh, "_serialize((x),(y))\n");
543 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
544 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
545 fprintf (ci->fh, "_deserialize((x),(y))\n");
547 case IDLN_TYPE_ARRAY: {
550 fprintf (ci->fh, " %s", ctmp);
551 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
552 fprintf (ci->fh, "[%" IDL_LL "d]",
553 IDL_INTEGER (IDL_LIST (sub).data).value);
555 fprintf (ci->fh, ";\n");
556 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
557 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
558 /* fprintf (ci->fh, "typedef "); */
559 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
560 /* fprintf (ci->fh, " %s_slice", ctmp); */
561 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
562 /* sub; sub = IDL_LIST (sub).next) */
563 /* fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
564 /* fprintf(ci->fh, ";\n"); */
571 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
572 fprintf (ci->fh, "#endif\n");
578 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
581 /* IDL_tree id = IDL_NATIVE(tree).ident; */
582 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
583 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
584 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
585 /* /\* Dont even think about emitting a typecode. *\/ */
586 /* fprintf(ci->fh, "#endif\n"); */
591 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
594 IDL_tree cur, curmem;
596 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
598 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
599 /* put typedef out first for recursive seq */
600 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
602 /* Scan for any nested decls */
603 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
605 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
606 ch_prep(ts, rinfo, ci);
609 fprintf(ci->fh, "struct %s_type {\n", id);
611 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
612 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
613 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
616 if(!IDL_TYPE_STRUCT(tree).member_list)
617 fprintf(ci->fh, "int dummy;\n");
618 fprintf(ci->fh, "};\n");
620 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", id, id);
621 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", id, id);
623 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
625 fprintf(ci->fh, "#endif\n\n");
632 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
637 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
638 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
640 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
641 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
642 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
644 /* Scan for any nested decls */
645 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
646 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
647 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
650 fprintf(ci->fh, "struct %s_type {\n", id);
651 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
652 fprintf(ci->fh, " _d;\nunion {\n");
654 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
657 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
658 ch_output_var(IDL_MEMBER(member).type_spec,
659 IDL_LIST(IDL_MEMBER(member).dcls).data,
663 fprintf(ci->fh, "} _u;\n};\n");
665 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
667 fprintf(ci->fh, "#endif\n");
673 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
677 for(list = IDL_CODEFRAG(tree).lines; list;
678 list = g_slist_next(list)) {
679 if(!strncmp(list->data,
680 "#pragma include_defs",
681 sizeof("#pragma include_defs")-1)) {
683 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
684 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
686 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
688 fprintf(ci->fh, "#include <%s>\n", ctmp);
690 fprintf(ci->fh, "%s\n", (char *)list->data);
695 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
701 ident = IDL_CONST_DCL (tree).ident;
702 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
704 fprintf(ci->fh, "#ifndef %s\n", id);
705 fprintf(ci->fh, "#define %s ", id);
707 forb_cbe_write_const(ci->fh,
708 IDL_CONST_DCL(tree).const_exp);
710 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
711 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
712 !IDL_TYPE_INTEGER (typespec).f_signed)
713 fprintf(ci->fh, "U");
715 fprintf(ci->fh, "\n");
716 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
722 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
726 ctmp = forb_cbe_get_typespec_str(tree);
728 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
729 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
733 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
737 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
739 char *ctmp, *fullname, *fullname_def, *ctmp2;
741 gboolean separate_defs, fake_if;
742 IDL_tree fake_seq = NULL;
744 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
745 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
746 ctmp2 = forb_cbe_get_typespec_str(tts);
747 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
751 ctmp2 = g_strdup("CORBA_Object");
753 separate_defs = strcmp(ctmp, ctmp2);
754 fullname = forb_cbe_get_typespec_str(tree);
755 //printf("YYY %s\n", fullname);
760 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
761 //forb_idl_print_node(tree, 2);
763 tts = IDL_type_object_new();
764 fake_seq = IDL_type_sequence_new(tts, NULL);
765 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
766 ch_prep_sequence(fake_seq, rinfo, ci);
767 member_type = forb_cbe_type_is_builtin (tts) ?
768 ctmp2 + strlen ("CORBA_") : ctmp2;
769 fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
772 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
775 fullname_def = g_strdup(fullname);
777 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
778 == IDLN_TYPE_SEQUENCE)
779 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
781 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
782 * while _%s_defined protects only the struct */
784 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
786 /* if ( ci->do_impl_hack ) */
787 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
791 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
793 if(!strcmp(ctmp, "CORBA_RepositoryId"))
794 fprintf(ci->fh, "/* CRACKHEADS */\n");
795 fprintf(ci->fh, "typedef %s\n %s;\n", fullname_def, fullname);
796 fprintf(ci->fh, "#endif\n");
797 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
798 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
799 /* fullname, fullname_def); */
800 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
801 /* fullname, fullname_def); */
802 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
804 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
806 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
807 IDL_tree_free(fake_seq);
813 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
815 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
816 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
817 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n ");
818 forb_cbe_write_typespec(ci->fh, tree);
819 fprintf(ci->fh, ";\n#endif\n");
821 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
822 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
823 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
825 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
826 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
827 ctmp + strlen ("CORBA_") : ctmp;
829 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
830 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
831 member_type, ctmp, ctmp);
836 fprintf(ci->fh, "#endif\n\n");
841 g_free(fullname_def);
845 void ch_prep (IDL_tree tree,
846 OIDL_Run_Info *rinfo,
849 switch (IDL_NODE_TYPE (tree)) {
850 case IDLN_TYPE_SEQUENCE:
851 ch_prep_sequence (tree, rinfo, ci);
853 case IDLN_TYPE_FIXED:
854 ch_prep_fixed (tree, rinfo, ci);
856 case IDLN_TYPE_STRUCT:
857 ch_output_type_struct (tree, rinfo, ci);
860 ch_output_type_enum (tree, rinfo, ci);
868 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
869 /* OIDL_C_Info *ci, gboolean do_alloc) */
874 /* ctmp = forb_cbe_get_typespec_str(tree); */
876 /* if ( ci->do_impl_hack ) { */
877 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
878 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
881 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
882 /* fprintf (ci->fh, "static\n"); */
883 /* fprintf (ci->fh, "#else\n"); */
884 /* fprintf (ci->fh, "extern\n"); */
885 /* fprintf (ci->fh, "#endif\n"); */
886 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
888 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
889 /* if (ci->do_impl_hack) */
890 /* fprintf (ci->fh, "#endif\n"); */
895 /* tts = forb_cbe_get_typespec(tree); */
897 /* tc = forb_cbe_get_typecode_name (tts); */
899 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
900 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
902 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
904 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
906 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
907 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
908 /* member_type + strlen ("CORBA_") : member_type; */
910 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
911 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
912 /* ctmp, member_name, tc); */
914 /* g_free (member_type); */
923 /************************/
925 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
927 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
929 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
935 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
937 /* if(!tree) return; */
939 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
942 /* switch(IDL_NODE_TYPE(tree)) { */
943 /* case IDLN_MODULE: */
944 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
946 /* case IDLN_LIST: */
950 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
951 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
955 /* case IDLN_INTERFACE: */
961 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
963 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
966 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
967 /* fprintf(ci->fh, "typedef struct {\n"); */
968 /* fprintf(ci->fh, " void *_private;\n"); */
969 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
972 /* cur = IDL_LIST(sub).data; */
974 /* switch(IDL_NODE_TYPE(cur)) { */
975 /* case IDLN_OP_DCL: */
976 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
977 /* fprintf(ci->fh, ";\n"); */
979 /* case IDLN_ATTR_DCL: */
981 /* OIDL_Attr_Info *ai; */
982 /* IDL_tree curitem; */
984 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
985 /* ai = IDL_LIST(curitem).data->data; */
987 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
988 /* fprintf(ci->fh, ";\n"); */
991 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
992 /* fprintf(ci->fh, ";\n"); */
1002 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
1004 /* fprintf(ci->fh, "typedef struct {\n"); */
1005 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
1006 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1007 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1009 /* fprintf(ci->fh, "typedef struct {\n"); */
1010 /* fprintf(ci->fh, " void *_private;\n"); */
1011 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1012 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1014 /* fprintf(ci->fh, */
1015 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1016 /* fprintf(ci->fh, */
1017 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1019 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1029 /************************/
1033 } InheritedOutputInfo;
1034 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1037 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1042 switch(IDL_NODE_TYPE(tree)) {
1044 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1050 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1051 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1055 case IDLN_INTERFACE:
1059 if(IDL_INTERFACE(tree).inheritance_spec) {
1060 InheritedOutputInfo ioi;
1063 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1066 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1069 cur = IDL_LIST(sub).data;
1071 switch(IDL_NODE_TYPE(cur)) {
1073 forb_idl_check_oneway_op (cur);
1074 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1075 fprintf(ci->fh, ";\n");
1082 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1083 ai = IDL_LIST(curitem).data->data;
1085 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1086 fprintf(ci->fh, ";\n");
1089 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1090 fprintf(ci->fh, ";\n");
1107 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1112 if(curif == ioi->realif)
1115 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1116 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1118 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1119 IDL_tree curop = IDL_LIST(curitem).data;
1121 switch(IDL_NODE_TYPE(curop)) {
1123 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1124 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1125 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1131 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1132 and therefore don't have the OIDL_Attr_Info generated on them */
1134 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1137 ident = IDL_LIST(curitem).data;
1139 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1140 realid, IDL_IDENT(ident).str,
1141 id, IDL_IDENT(ident).str);
1143 if(!IDL_ATTR_DCL(curop).f_readonly)
1144 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1145 realid, IDL_IDENT(ident).str,
1146 id, IDL_IDENT(ident).str);
1160 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1164 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1166 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1167 /* "CDR_Codec *codec, %s *obj", */
1169 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1170 /* fprintf(ci->fh, ");\n"); */
1176 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1178 /* if(!tree) return; */
1180 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1183 /* switch(IDL_NODE_TYPE(tree)) { */
1184 /* case IDLN_MODULE: */
1185 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1187 /* case IDLN_LIST: */
1191 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1192 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1196 /* case IDLN_INTERFACE: */
1201 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1203 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1206 /* cur = IDL_LIST(sub).data; */
1208 /* switch(IDL_NODE_TYPE(cur)) { */
1209 /* case IDLN_OP_DCL: */
1210 /* doskel(cur, rinfo, ifid, ci); */
1212 /* case IDLN_ATTR_DCL: */
1213 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1215 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1216 /* /\* IDL_tree curitem; *\/ */
1218 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1219 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1221 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1222 /* /\* if(ai->op2) *\/ */
1223 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1240 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1242 /* static int num_methods = 0; */
1247 /* switch(IDL_NODE_TYPE(tree)) { */
1248 /* case IDLN_MODULE: */
1249 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1251 /* case IDLN_LIST: { */
1253 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1254 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1257 /* case IDLN_ATTR_DCL: { */
1258 /* OIDL_Attr_Info *ai = tree->data; */
1260 /* IDL_tree curitem; */
1262 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1263 /* curitem = IDL_LIST(curitem).next) { */
1264 /* ai = IDL_LIST(curitem).data->data; */
1266 /* ch_output_itypes (ai->op1, ci); */
1268 /* ch_output_itypes (ai->op2, ci); */
1273 /* case IDLN_INTERFACE: { */
1276 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1277 /* IDL_INTERFACE (tree).ident), "_", 0); */
1279 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1281 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1282 /* ci->c_base_name); */
1283 /* fprintf (ci->fh, "static \n"); */
1284 /* fprintf (ci->fh, "#else\n"); */
1285 /* fprintf (ci->fh, "extern \n"); */
1286 /* fprintf (ci->fh, "#endif\n"); */
1287 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1289 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1291 /* if (num_methods == 0) */
1292 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1294 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1295 /* ci->c_base_name); */
1296 /* fprintf (ci->fh, "static \n"); */
1297 /* fprintf (ci->fh, "#else\n"); */
1298 /* fprintf (ci->fh, "extern \n"); */
1299 /* fprintf (ci->fh, "#endif\n"); */
1300 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1304 /* num_methods = 0; */
1309 /* case IDLN_OP_DCL: */
1310 /* num_methods++; */