2 #include "forb-idl-c-backend.h"
3 #include "forb_config.h"
9 static void ch_output_types(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
10 /* static void ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
11 /* static void ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci); */
12 static void ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
13 /* static void ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
14 static GSList *ch_build_interfaces (GSList *list, IDL_tree tree);
15 static void ch_output_method (FILE *of, IDL_tree tree, const char *id);
16 /* static void ch_output_imethods_index (GSList *list, OIDL_C_Info *ci); */
20 GSList *methods; /* IDLN_OP_DCLs */
23 /* this is hardcopy from cc_build_interfaces() defined in forb-idl-c-common.c */
25 ch_build_interfaces (GSList *list, IDL_tree tree)
30 switch (IDL_NODE_TYPE (tree)) {
32 list = ch_build_interfaces (
33 list, IDL_MODULE (tree).definition_list);
37 for (sub = tree; sub; sub = IDL_LIST (sub).next)
38 list = ch_build_interfaces (
39 list, IDL_LIST (sub).data);
45 for (curitem = IDL_ATTR_DCL (tree).simple_declarations;
46 curitem; curitem = IDL_LIST (curitem).next) {
47 OIDL_Attr_Info *ai = IDL_LIST (curitem).data->data;
49 list = ch_build_interfaces (list, ai->op1);
51 list = ch_build_interfaces (list, ai->op2);
55 case IDLN_INTERFACE: {
56 Interface *i = g_new0 (Interface, 1);
60 list = g_slist_append (list, i);
62 list = ch_build_interfaces (list, IDL_INTERFACE(tree).body);
69 g_return_val_if_fail (list != NULL, NULL);
71 i = ( g_slist_last(list) )->data;
72 i->methods = g_slist_append (i->methods, tree);
85 ch_output_method (FILE *of, IDL_tree tree, const char *id)
87 char *fullname = NULL;
89 fullname = g_strconcat (id, "_", IDL_IDENT (
90 IDL_OP_DCL (tree).ident).str, NULL);
92 fprintf (of, "\t%s__method_index", fullname);
98 ch_output_method_indices (GSList *list, OIDL_C_Info *ci)
103 for (l = list; l; l = l->next) {
104 Interface *i = l->data;
108 id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (
109 IDL_INTERFACE (i->tree).ident), "_", 0);
113 fprintf (of, "#ifndef __%s__method_indices\n", id);
114 fprintf (of, "#define __%s__method_indices\n", id);
116 fprintf (of, "typedef enum {\n");
118 for (m = i->methods; m; m = m->next) {
119 ch_output_method (of, m->data, id);
126 fprintf (of, "} %s__method_indices;\n", id);
127 fprintf (of, "#endif /* __%s__method_indices */\n\n", id);
133 for (l = list; l; l = l->next) {
134 g_slist_free (((Interface *)l->data)->methods);
143 forb_idl_output_c_headers (IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
145 fprintf (ci->fh, OIDL_C_WARNING);
146 fprintf(ci->fh, "#ifndef %s%s_H\n", rinfo->header_guard_prefix, ci->c_base_name);
147 fprintf(ci->fh, "#define %s%s_H 1\n", rinfo->header_guard_prefix, ci->c_base_name);
149 fprintf(ci->fh, "#include <forb/forb.h>\n");
150 fprintf(ci->fh, "#define FORB_IDL_SERIAL %d\n", FORB_CONFIG_SERIAL);
151 fprintf(ci->fh, "#include <forb/basic_types.h>\n\n");
153 fprintf(ci->fh, "#ifdef __cplusplus\n");
154 fprintf(ci->fh, "extern \"C\" {\n");
155 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
157 /* Do all the typedefs, etc. */
158 fprintf(ci->fh, "\n/** typedefs **/\n");
159 ch_output_types(tree, rinfo, ci);
161 if ( ci->do_skel_defs ) {
162 /* /\* Do all the POA structures, etc. *\/ */
163 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
164 /* ch_output_poa(tree, rinfo, ci); */
166 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
167 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
168 /* ch_output_skel_protos(tree, rinfo, ci); */
170 fprintf(ci->fh, "\n/** stub prototypes **/\n");
171 ch_output_stub_protos(tree, rinfo, ci);
173 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
174 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
176 /* if (rinfo->idata) { */
177 /* /\* FIXME: hackish ? *\/ */
178 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
180 /* ch_output_itypes(tree, ci); */
185 fprintf (ci->fh, "\n/** Method indices */\n\n");
187 list = ch_build_interfaces (list, tree);
188 ch_output_method_indices (list, ci);
191 fprintf(ci->fh, "#ifdef __cplusplus\n");
192 fprintf(ci->fh, "}\n");
193 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
195 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
196 /* fprintf(ci->fh, "#include <forb/forb.h>\n\n"); */
197 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
199 fprintf(ci->fh, "#endif\n");
201 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
205 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
207 forb_cbe_write_typespec(ci->fh, val);
209 fprintf(ci->fh, " ");
210 switch(IDL_NODE_TYPE(name)) {
212 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
214 case IDLN_TYPE_ARRAY:
218 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
219 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
220 fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
225 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
228 fprintf(ci->fh, ";\n");
231 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
232 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
233 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
234 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
235 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
236 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
237 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
238 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
239 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
240 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
243 ch_output_types (IDL_tree tree,
244 OIDL_Run_Info *rinfo,
250 switch (IDL_NODE_TYPE (tree)) {
251 case IDLN_EXCEPT_DCL: {
252 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
255 /* id = IDL_ns_ident_to_qstring ( */
256 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
258 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
259 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
260 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
264 /* ch_output_type_struct (tree, rinfo, ci); */
267 case IDLN_FORWARD_DCL:
269 ch_output_interface (tree, rinfo, ci);
271 case IDLN_TYPE_STRUCT:
272 ch_output_type_struct (tree, rinfo, ci);
275 ch_output_type_enum (tree, rinfo, ci);
278 ch_output_type_dcl (tree, rinfo, ci);
280 case IDLN_TYPE_UNION:
281 ch_output_type_union (tree, rinfo, ci);
284 ch_output_codefrag (tree, rinfo, ci);
287 char *idlfn = IDL_SRCFILE (tree).filename;
288 if (rinfo->onlytop) {
290 if (!IDL_SRCFILE (tree).seenCnt &&
291 !IDL_SRCFILE(tree).isTop &&
292 !IDL_SRCFILE(tree).wasInhibit) {
295 hfn = g_path_get_basename (idlfn);
296 htail = strrchr (hfn,'.');
298 g_assert (htail && strlen (htail) >= 2);
303 fprintf (ci->fh, "#include \"%s\"\n", hfn);
308 fprintf (ci->fh, "/* from IDL source file \"%s\" "
309 "(seen %d, isTop %d, wasInhibit %d) */ \n",
311 IDL_SRCFILE (tree).seenCnt,
312 IDL_SRCFILE (tree).isTop,
313 IDL_SRCFILE (tree).wasInhibit);
318 ch_output_const_dcl (tree, rinfo, ci);
320 /* case IDLN_NATIVE: */
321 /* ch_output_native (tree, rinfo, ci); */
327 switch (IDL_NODE_TYPE (tree)) {
329 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
334 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
335 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
340 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
348 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
352 switch(IDL_NODE_TYPE(tree)) {
357 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
358 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
366 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
367 /* InheritedOutputInfo ioi; */
368 /* ioi.of = ci->fh; */
369 /* ioi.realif = tree; */
370 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
373 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
376 cur = IDL_LIST(sub).data;
378 switch(IDL_NODE_TYPE(cur)) {
380 forb_idl_check_oneway_op (cur);
381 fprintf(ci->fh, " ");
382 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
383 fprintf(ci->fh, ";\n");
385 /* case IDLN_ATTR_DCL: */
387 /* OIDL_Attr_Info *ai; */
388 /* IDL_tree curitem; */
390 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
391 /* ai = IDL_LIST(curitem).data->data; */
393 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
394 /* fprintf(ci->fh, ";\n"); */
397 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
398 /* fprintf(ci->fh, ";\n"); */
414 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
417 fullname = forb_cbe_get_typespec_str(tree);
418 fprintf(ci->fh, "struct forb_%s_implementation {\n", fullname);
419 ch_output_impl_struct_members(tree, rinfo, ci);
420 fprintf(ci->fh, "};\n\n");
425 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
428 fullname = forb_cbe_get_typespec_str(tree);
429 fprintf(ci->fh, "#if !defined(FORB_DECL_%s) && !defined(_%s_defined)\n#define FORB_DECL_%s 1\n#define _%s_defined 1\n", fullname, fullname, fullname, fullname);
431 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) { */
432 /* /\* PIDL interfaces are not normal CORBA Objects *\/ */
433 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
434 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
435 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
436 /* fprintf(ci->fh, "#endif\n"); */
439 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
440 fprintf(ci->fh, "typedef forb_object %s;\n", fullname);
441 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
443 ch_output_impl_struct(tree, rinfo, ci);
445 fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname);
446 fprintf(ci->fh, "%s forb_%s_new(void *instance_data,\n"
447 " const struct forb_%s_implementation *impl);\n\n",
448 fullname, fullname, fullname);
450 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
453 fprintf(ci->fh, "#endif\n");
458 ch_output_type_enum (IDL_tree tree,
459 OIDL_Run_Info *rinfo,
465 /* CORBA spec says to do
466 * typedef unsigned int enum_name;
467 * and then #defines for each enumerator.
468 * This works just as well and seems cleaner.
471 enumid = IDL_ns_ident_to_qstring (
472 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
473 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
474 fprintf (ci->fh, "typedef enum {\n");
476 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
479 id = IDL_ns_ident_to_qstring (
480 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
482 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
487 fprintf (ci->fh, "} %s;\n", enumid);
489 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
490 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
491 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
493 fprintf (ci->fh, "#endif\n\n");
499 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
503 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
505 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
508 IDL_tree ent = IDL_LIST (l).data;
510 switch (IDL_NODE_TYPE(ent)) {
512 ctmp = IDL_ns_ident_to_qstring (
513 IDL_IDENT_TO_NS (ent), "_", 0);
515 case IDLN_TYPE_ARRAY:
516 ctmp = IDL_ns_ident_to_qstring (
517 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
520 g_assert_not_reached ();
524 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
525 fprintf (ci->fh, "typedef ");
526 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
528 switch (IDL_NODE_TYPE (ent)) {
530 fprintf (ci->fh, " %s;\n", ctmp);
531 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
532 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
533 fprintf (ci->fh, "_serialize((x),(y))\n");
535 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
536 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
537 fprintf (ci->fh, "_deserialize((x),(y))\n");
539 case IDLN_TYPE_ARRAY: {
542 fprintf (ci->fh, " %s", ctmp);
543 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
544 fprintf (ci->fh, "[%" IDL_LL "d]",
545 IDL_INTEGER (IDL_LIST (sub).data).value);
547 fprintf (ci->fh, ";\n");
548 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
549 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
550 /* fprintf (ci->fh, "typedef "); */
551 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
552 /* fprintf (ci->fh, " %s_slice", ctmp); */
553 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
554 /* sub; sub = IDL_LIST (sub).next) */
555 /* fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
556 /* fprintf(ci->fh, ";\n"); */
563 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
564 fprintf (ci->fh, "#endif\n");
570 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
573 /* IDL_tree id = IDL_NATIVE(tree).ident; */
574 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
575 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
576 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
577 /* /\* Dont even think about emitting a typecode. *\/ */
578 /* fprintf(ci->fh, "#endif\n"); */
583 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
586 IDL_tree cur, curmem;
588 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
590 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
591 /* put typedef out first for recursive seq */
592 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
594 /* Scan for any nested decls */
595 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
597 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
598 ch_prep(ts, rinfo, ci);
601 fprintf(ci->fh, "struct %s_type {\n", id);
603 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
604 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
605 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
608 if(!IDL_TYPE_STRUCT(tree).member_list)
609 fprintf(ci->fh, "int dummy;\n");
610 fprintf(ci->fh, "};\n");
612 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr);\n", id, id);
613 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", id, id);
615 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
617 fprintf(ci->fh, "#endif\n\n");
624 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
629 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
630 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
632 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
633 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
634 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
636 /* Scan for any nested decls */
637 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
638 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
639 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
642 fprintf(ci->fh, "struct %s_type {\n", id);
643 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
644 fprintf(ci->fh, " _d;\nunion {\n");
646 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
649 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
650 ch_output_var(IDL_MEMBER(member).type_spec,
651 IDL_LIST(IDL_MEMBER(member).dcls).data,
655 fprintf(ci->fh, "} _u;\n};\n");
657 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
659 fprintf(ci->fh, "#endif\n");
665 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
669 for(list = IDL_CODEFRAG(tree).lines; list;
670 list = g_slist_next(list)) {
671 if(!strncmp(list->data,
672 "#pragma include_defs",
673 sizeof("#pragma include_defs")-1)) {
675 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
676 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
678 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
680 fprintf(ci->fh, "#include <%s>\n", ctmp);
682 fprintf(ci->fh, "%s\n", (char *)list->data);
687 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
693 ident = IDL_CONST_DCL (tree).ident;
694 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
696 fprintf(ci->fh, "#ifndef %s\n", id);
697 fprintf(ci->fh, "#define %s ", id);
699 forb_cbe_write_const(ci->fh,
700 IDL_CONST_DCL(tree).const_exp);
702 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
703 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
704 !IDL_TYPE_INTEGER (typespec).f_signed)
705 fprintf(ci->fh, "U");
707 fprintf(ci->fh, "\n");
708 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
714 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
718 ctmp = forb_cbe_get_typespec_str(tree);
720 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
721 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
725 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
729 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
731 char *ctmp, *fullname, *fullname_def, *ctmp2;
733 gboolean separate_defs, fake_if;
734 IDL_tree fake_seq = NULL;
736 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
737 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
738 ctmp2 = forb_cbe_get_typespec_str(tts);
739 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
743 ctmp2 = g_strdup("CORBA_Object");
745 separate_defs = strcmp(ctmp, ctmp2);
746 fullname = forb_cbe_get_typespec_str(tree);
747 //printf("YYY %s\n", fullname);
751 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
752 //forb_idl_print_node(tree, 2);
754 tts = IDL_type_object_new();
755 fake_seq = IDL_type_sequence_new(tts, NULL);
756 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
757 ch_prep_sequence(fake_seq, rinfo, ci);
758 fullname_def = g_strdup_printf("CORBA_sequence_%s", ctmp2);
760 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
763 fullname_def = g_strdup(fullname);
765 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
766 == IDLN_TYPE_SEQUENCE)
767 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
769 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
770 * while _%s_defined protects only the struct */
772 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
774 /* if ( ci->do_impl_hack ) */
775 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
779 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
781 if(!strcmp(ctmp, "CORBA_RepositoryId"))
782 fprintf(ci->fh, "/* CRACKHEADS */\n");
783 fprintf(ci->fh, "typedef %s %s;\n", fullname_def, fullname);
784 fprintf(ci->fh, "#endif\n");
785 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
786 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
787 /* fullname, fullname_def); */
788 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
789 /* fullname, fullname_def); */
790 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf CORBA_sequence_%s_allocbuf\n",
792 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
794 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
795 IDL_tree_free(fake_seq);
799 char *tc, *member_type;
801 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
803 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
804 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
805 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; } ");
806 forb_cbe_write_typespec(ci->fh, tree);
807 fprintf(ci->fh, ";\n#endif\n");
809 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
810 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
811 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
813 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
814 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
815 ctmp + strlen ("CORBA_") : ctmp;
817 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
818 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
819 member_type, member_type, ctmp);
824 fprintf(ci->fh, "#endif\n");
829 g_free(fullname_def);
833 void ch_prep (IDL_tree tree,
834 OIDL_Run_Info *rinfo,
837 switch (IDL_NODE_TYPE (tree)) {
838 case IDLN_TYPE_SEQUENCE:
839 ch_prep_sequence (tree, rinfo, ci);
841 case IDLN_TYPE_FIXED:
842 ch_prep_fixed (tree, rinfo, ci);
844 case IDLN_TYPE_STRUCT:
845 ch_output_type_struct (tree, rinfo, ci);
848 ch_output_type_enum (tree, rinfo, ci);
856 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
857 /* OIDL_C_Info *ci, gboolean do_alloc) */
862 /* ctmp = forb_cbe_get_typespec_str(tree); */
864 /* if ( ci->do_impl_hack ) { */
865 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
866 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
869 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
870 /* fprintf (ci->fh, "static\n"); */
871 /* fprintf (ci->fh, "#else\n"); */
872 /* fprintf (ci->fh, "extern\n"); */
873 /* fprintf (ci->fh, "#endif\n"); */
874 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
876 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
877 /* if (ci->do_impl_hack) */
878 /* fprintf (ci->fh, "#endif\n"); */
883 /* tts = forb_cbe_get_typespec(tree); */
885 /* tc = forb_cbe_get_typecode_name (tts); */
887 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
888 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
890 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
892 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
894 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
895 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
896 /* member_type + strlen ("CORBA_") : member_type; */
898 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
899 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
900 /* ctmp, member_name, tc); */
902 /* g_free (member_type); */
911 /************************/
913 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
915 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
917 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
923 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
925 /* if(!tree) return; */
927 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
930 /* switch(IDL_NODE_TYPE(tree)) { */
931 /* case IDLN_MODULE: */
932 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
934 /* case IDLN_LIST: */
938 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
939 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
943 /* case IDLN_INTERFACE: */
949 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
951 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
954 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
955 /* fprintf(ci->fh, "typedef struct {\n"); */
956 /* fprintf(ci->fh, " void *_private;\n"); */
957 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
960 /* cur = IDL_LIST(sub).data; */
962 /* switch(IDL_NODE_TYPE(cur)) { */
963 /* case IDLN_OP_DCL: */
964 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
965 /* fprintf(ci->fh, ";\n"); */
967 /* case IDLN_ATTR_DCL: */
969 /* OIDL_Attr_Info *ai; */
970 /* IDL_tree curitem; */
972 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
973 /* ai = IDL_LIST(curitem).data->data; */
975 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
976 /* fprintf(ci->fh, ";\n"); */
979 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
980 /* fprintf(ci->fh, ";\n"); */
990 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
992 /* fprintf(ci->fh, "typedef struct {\n"); */
993 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
994 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
995 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
997 /* fprintf(ci->fh, "typedef struct {\n"); */
998 /* fprintf(ci->fh, " void *_private;\n"); */
999 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1000 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1002 /* fprintf(ci->fh, */
1003 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1004 /* fprintf(ci->fh, */
1005 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1007 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1017 /************************/
1021 } InheritedOutputInfo;
1022 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1025 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1030 switch(IDL_NODE_TYPE(tree)) {
1032 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1038 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1039 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1043 case IDLN_INTERFACE:
1047 if(IDL_INTERFACE(tree).inheritance_spec) {
1048 InheritedOutputInfo ioi;
1051 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1054 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1057 cur = IDL_LIST(sub).data;
1059 switch(IDL_NODE_TYPE(cur)) {
1061 forb_idl_check_oneway_op (cur);
1062 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1063 fprintf(ci->fh, ";\n");
1070 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1071 ai = IDL_LIST(curitem).data->data;
1073 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1074 fprintf(ci->fh, ";\n");
1077 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1078 fprintf(ci->fh, ";\n");
1095 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1100 if(curif == ioi->realif)
1103 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1104 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1106 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1107 IDL_tree curop = IDL_LIST(curitem).data;
1109 switch(IDL_NODE_TYPE(curop)) {
1111 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1112 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1113 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1119 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1120 and therefore don't have the OIDL_Attr_Info generated on them */
1122 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1125 ident = IDL_LIST(curitem).data;
1127 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1128 realid, IDL_IDENT(ident).str,
1129 id, IDL_IDENT(ident).str);
1131 if(!IDL_ATTR_DCL(curop).f_readonly)
1132 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1133 realid, IDL_IDENT(ident).str,
1134 id, IDL_IDENT(ident).str);
1148 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1152 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1154 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1155 /* "CDR_Codec *codec, %s *obj", */
1157 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1158 /* fprintf(ci->fh, ");\n"); */
1164 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1166 /* if(!tree) return; */
1168 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1171 /* switch(IDL_NODE_TYPE(tree)) { */
1172 /* case IDLN_MODULE: */
1173 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1175 /* case IDLN_LIST: */
1179 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1180 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1184 /* case IDLN_INTERFACE: */
1189 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1191 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1194 /* cur = IDL_LIST(sub).data; */
1196 /* switch(IDL_NODE_TYPE(cur)) { */
1197 /* case IDLN_OP_DCL: */
1198 /* doskel(cur, rinfo, ifid, ci); */
1200 /* case IDLN_ATTR_DCL: */
1201 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1203 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1204 /* /\* IDL_tree curitem; *\/ */
1206 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1207 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1209 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1210 /* /\* if(ai->op2) *\/ */
1211 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1228 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1230 /* static int num_methods = 0; */
1235 /* switch(IDL_NODE_TYPE(tree)) { */
1236 /* case IDLN_MODULE: */
1237 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1239 /* case IDLN_LIST: { */
1241 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1242 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1245 /* case IDLN_ATTR_DCL: { */
1246 /* OIDL_Attr_Info *ai = tree->data; */
1248 /* IDL_tree curitem; */
1250 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1251 /* curitem = IDL_LIST(curitem).next) { */
1252 /* ai = IDL_LIST(curitem).data->data; */
1254 /* ch_output_itypes (ai->op1, ci); */
1256 /* ch_output_itypes (ai->op2, ci); */
1261 /* case IDLN_INTERFACE: { */
1264 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1265 /* IDL_INTERFACE (tree).ident), "_", 0); */
1267 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1269 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1270 /* ci->c_base_name); */
1271 /* fprintf (ci->fh, "static \n"); */
1272 /* fprintf (ci->fh, "#else\n"); */
1273 /* fprintf (ci->fh, "extern \n"); */
1274 /* fprintf (ci->fh, "#endif\n"); */
1275 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1277 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1279 /* if (num_methods == 0) */
1280 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1282 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1283 /* ci->c_base_name); */
1284 /* fprintf (ci->fh, "static \n"); */
1285 /* fprintf (ci->fh, "#else\n"); */
1286 /* fprintf (ci->fh, "extern \n"); */
1287 /* fprintf (ci->fh, "#endif\n"); */
1288 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1292 /* num_methods = 0; */
1297 /* case IDLN_OP_DCL: */
1298 /* num_methods++; */