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 fprintf(ci->fh, "#include <forb/cdr_codec.h>\n");
152 if (!rinfo->is_pidl) {
153 fprintf(ci->fh, "#include <forb/forb.h>\n");
155 fprintf(ci->fh, "#include <forb/basic_types.h>\n");
156 fprintf(ci->fh, "#include <idl_native.h> /* FIXME: Use some more general solution for native types */\n");
157 fprintf(ci->fh, "\n");
159 fprintf(ci->fh, "#ifdef __cplusplus\n");
160 fprintf(ci->fh, "extern \"C\" {\n");
161 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
163 /* Do all the typedefs, etc. */
164 fprintf(ci->fh, "\n/** typedefs **/\n");
165 ch_output_types(tree, rinfo, ci);
167 if ( ci->do_skel_defs ) {
168 /* /\* Do all the POA structures, etc. *\/ */
169 /* fprintf(ci->fh, "\n/\** POA structures **\/\n"); */
170 /* ch_output_poa(tree, rinfo, ci); */
172 /* fprintf(ci->fh, "\n/\** skel prototypes **\/\n"); */
173 /* fprintf(ci->fh, "/\* FIXME: Maybe we don't need this for FORB. *\/\n"); */
174 /* ch_output_skel_protos(tree, rinfo, ci); */
176 fprintf(ci->fh, "\n/** stub prototypes **/\n");
177 ch_output_stub_protos(tree, rinfo, ci);
179 /* if ( ci->ext_dcls && ci->ext_dcls->str ) */
180 /* fputs( ci->ext_dcls->str, ci->fh); /\* this may be huge! *\/ */
182 /* if (rinfo->idata) { */
183 /* /\* FIXME: hackish ? *\/ */
184 /* fprintf(ci->fh, "#include <forb/orb-core/forb-interface.h>\n\n"); */
186 /* ch_output_itypes(tree, ci); */
191 fprintf (ci->fh, "\n/** Method indices */\n\n");
193 list = ch_build_interfaces (list, tree);
194 ch_output_method_indices (list, ci);
197 fprintf(ci->fh, "#ifdef __cplusplus\n");
198 fprintf(ci->fh, "}\n");
199 fprintf(ci->fh, "#endif /* __cplusplus */\n\n");
201 /* fprintf(ci->fh, "#ifndef EXCLUDE_FORB_H\n"); */
202 /* fprintf(ci->fh, "#include <forb/forb.h>\n\n"); */
203 /* fprintf(ci->fh, "#endif /\* EXCLUDE_FORB_H *\/\n"); */
205 fprintf(ci->fh, "#endif\n");
207 fprintf(ci->fh, "#undef FORB_IDL_SERIAL\n");
211 ch_output_var(IDL_tree val, IDL_tree name, OIDL_C_Info *ci)
213 forb_cbe_write_typespec(ci->fh, val);
215 fprintf(ci->fh, " ");
216 switch(IDL_NODE_TYPE(name)) {
218 fprintf(ci->fh, "%s", IDL_IDENT(name).str);
220 case IDLN_TYPE_ARRAY:
224 fprintf(ci->fh, "%s", IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
225 for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
226 fprintf(ci->fh, "[%" IDL_LL "d]", IDL_INTEGER(IDL_LIST(curitem).data).value);
231 g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
234 fprintf(ci->fh, ";\n");
237 static void ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
238 static void ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
239 static void ch_output_type_enum(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
240 static void ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
241 /* static void ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci); */
242 static void ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
243 static void ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
244 static void ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
245 static void ch_prep(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci);
246 /* static void ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci, gboolean do_alloc); */
249 ch_output_types (IDL_tree tree,
250 OIDL_Run_Info *rinfo,
256 switch (IDL_NODE_TYPE (tree)) {
257 case IDLN_EXCEPT_DCL: {
258 IDL_tree_warning(tree, IDL_WARNING1, "Exceptions are not supperted\n");
261 /* id = IDL_ns_ident_to_qstring ( */
262 /* IDL_IDENT_TO_NS (IDL_EXCEPT_DCL (tree).ident), "_", 0); */
264 /* fprintf (ci->fh, "#undef ex_%s\n", id); */
265 /* fprintf (ci->fh, "#define ex_%s \"%s\"\n", */
266 /* id, IDL_IDENT (IDL_EXCEPT_DCL (tree).ident).repo_id); */
270 /* ch_output_type_struct (tree, rinfo, ci); */
273 case IDLN_FORWARD_DCL:
275 ch_output_interface (tree, rinfo, ci);
277 case IDLN_TYPE_STRUCT:
278 ch_output_type_struct (tree, rinfo, ci);
281 ch_output_type_enum (tree, rinfo, ci);
284 ch_output_type_dcl (tree, rinfo, ci);
286 case IDLN_TYPE_UNION:
287 ch_output_type_union (tree, rinfo, ci);
290 ch_output_codefrag (tree, rinfo, ci);
293 char *idlfn = IDL_SRCFILE (tree).filename;
294 if (rinfo->onlytop) {
296 if (!IDL_SRCFILE (tree).seenCnt &&
297 !IDL_SRCFILE(tree).isTop &&
298 !IDL_SRCFILE(tree).wasInhibit) {
301 hfn = g_path_get_basename (idlfn);
302 htail = strrchr (hfn,'.');
304 g_assert (htail && strlen (htail) >= 2);
309 fprintf (ci->fh, "#include \"%s\"\n", hfn);
314 fprintf (ci->fh, "/* from IDL source file \"%s\" "
315 "(seen %d, isTop %d, wasInhibit %d) */ \n",
317 IDL_SRCFILE (tree).seenCnt,
318 IDL_SRCFILE (tree).isTop,
319 IDL_SRCFILE (tree).wasInhibit);
324 ch_output_const_dcl (tree, rinfo, ci);
326 /* case IDLN_NATIVE: */
327 /* ch_output_native (tree, rinfo, ci); */
333 switch (IDL_NODE_TYPE (tree)) {
335 ch_output_types (IDL_MODULE (tree).definition_list, rinfo, ci);
340 for (sub = tree; sub; sub = IDL_LIST (sub).next) {
341 ch_output_types (IDL_LIST (sub).data, rinfo, ci);
346 ch_output_types (IDL_INTERFACE (tree).body, rinfo, ci);
354 ch_output_impl_struct_members(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
358 switch(IDL_NODE_TYPE(tree)) {
363 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
364 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
372 /* if(IDL_INTERFACE(tree).inheritance_spec) { */
373 /* InheritedOutputInfo ioi; */
374 /* ioi.of = ci->fh; */
375 /* ioi.realif = tree; */
376 /* IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi); */
379 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
382 cur = IDL_LIST(sub).data;
384 switch(IDL_NODE_TYPE(cur)) {
386 forb_idl_check_oneway_op (cur);
387 fprintf(ci->fh, " ");
388 forb_cbe_op_write_proto(ci->fh, cur, "", TRUE);
389 fprintf(ci->fh, ";\n");
391 /* case IDLN_ATTR_DCL: */
393 /* OIDL_Attr_Info *ai; */
394 /* IDL_tree curitem; */
396 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
397 /* ai = IDL_LIST(curitem).data->data; */
399 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE); */
400 /* fprintf(ci->fh, ";\n"); */
403 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE); */
404 /* fprintf(ci->fh, ";\n"); */
420 ch_output_impl_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
423 fullname = forb_cbe_get_typespec_str(tree);
424 fprintf(ci->fh, "struct forb_%s_impl {\n", fullname);
425 ch_output_impl_struct_members(tree, rinfo, ci);
426 fprintf(ci->fh, "};\n\n");
431 ch_output_interface(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
434 fullname = forb_cbe_get_typespec_str(tree);
435 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);
437 if ( tree->declspec & IDLF_DECLSPEC_PIDL ) {
438 /* PIDL interfaces are not normal CORBA Objects */
439 fprintf(ci->fh, "// PIDL: %s\n", fullname);
440 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", fullname, fullname); */
441 /* fprintf(ci->fh, "#ifndef TC_%s\n", fullname); */
442 /* fprintf(ci->fh, "# define TC_%s TC_CORBA_Object\n", fullname); */
443 /* fprintf(ci->fh, "#endif\n"); */
446 /* fprintf(ci->fh, "#define %s__freekids CORBA_Object__freekids\n", fullname); */
447 fprintf(ci->fh, "typedef forb_object %s;\n", fullname);
448 fprintf(ci->fh, "#define %s_serialize(codec, obj) forb_object_serialize((codec), (obj))\n", fullname);
449 fprintf(ci->fh, "#define %s_deserialize(codec, obj, orb) forb_object_deserialize((codec), (obj), (orb))\n", fullname);
450 /* fprintf(ci->fh, "extern CORBA_unsigned_long %s__classid;\n", fullname); */
452 ch_output_impl_struct(tree, rinfo, ci);
454 /* fprintf(ci->fh, "void forb_register_%s_interface(void);\n", fullname); */
455 fprintf(ci->fh, "%s forb_%s_new(forb_orb orb,\n"
456 " const struct forb_%s_impl *impl,\n"
457 " void *instance_data);\n\n",
458 fullname, fullname, fullname);
460 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
463 fprintf(ci->fh, "#endif\n\n");
468 ch_output_type_enum (IDL_tree tree,
469 OIDL_Run_Info *rinfo,
475 /* CORBA spec says to do
476 * typedef unsigned int enum_name;
477 * and then #defines for each enumerator.
478 * This works just as well and seems cleaner.
481 enumid = IDL_ns_ident_to_qstring (
482 IDL_IDENT_TO_NS (IDL_TYPE_ENUM (tree).ident), "_", 0);
483 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", enumid, enumid);
484 fprintf (ci->fh, "typedef enum {\n");
486 for (l = IDL_TYPE_ENUM (tree).enumerator_list; l; l = IDL_LIST (l).next) {
489 id = IDL_ns_ident_to_qstring (
490 IDL_IDENT_TO_NS (IDL_LIST (l).data), "_", 0);
492 fprintf (ci->fh, " %s%s\n", id, IDL_LIST (l).next ? "," : "");
497 fprintf (ci->fh, "} %s;\n", enumid);
499 /* ch_type_alloc_and_tc (tree, rinfo, ci, FALSE); */
500 fprintf (ci->fh, "#define %s_serialize(codec, val) CORBA_unsigned_long_serialize(codec, val)\n", enumid);
501 fprintf (ci->fh, "#define %s_deserialize(codec, val) CORBA_unsigned_long_deserialize(codec, val)\n", enumid);
503 fprintf (ci->fh, "#endif\n\n");
509 ch_output_type_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
513 ch_prep (IDL_TYPE_DCL (tree).type_spec, rinfo, ci);
515 for (l = IDL_TYPE_DCL (tree).dcls; l; l = IDL_LIST (l).next) {
518 IDL_tree ent = IDL_LIST (l).data;
520 switch (IDL_NODE_TYPE(ent)) {
522 ctmp = IDL_ns_ident_to_qstring (
523 IDL_IDENT_TO_NS (ent), "_", 0);
525 case IDLN_TYPE_ARRAY:
526 ctmp = IDL_ns_ident_to_qstring (
527 IDL_IDENT_TO_NS (IDL_TYPE_ARRAY (ent).ident), "_", 0);
530 g_assert_not_reached ();
534 fprintf (ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp);
535 fprintf (ci->fh, "typedef ");
536 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
538 switch (IDL_NODE_TYPE (ent)) {
540 fprintf (ci->fh, " %s;\n", ctmp);
541 fprintf (ci->fh, "#define %s_serialize(x,y) ", ctmp);
542 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
543 fprintf (ci->fh, "_serialize((x),(y))\n");
545 fprintf (ci->fh, "#define %s_deserialize(x,y) ", ctmp);
546 forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec);
547 fprintf (ci->fh, "_deserialize((x),(y))\n");
549 case IDLN_TYPE_ARRAY: {
552 fprintf (ci->fh, " %s", ctmp);
553 for (sub = IDL_TYPE_ARRAY (ent).size_list; sub; sub = IDL_LIST (sub).next)
554 fprintf (ci->fh, "[%" IDL_LL "d]",
555 IDL_INTEGER (IDL_LIST (sub).data).value);
557 fprintf (ci->fh, ";\n");
558 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s array);\n", ctmp, ctmp);
559 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s array);\n", ctmp, ctmp);
560 /* fprintf (ci->fh, "typedef "); */
561 /* forb_cbe_write_typespec (ci->fh, IDL_TYPE_DCL (tree).type_spec); */
562 /* fprintf (ci->fh, " %s_slice", ctmp); */
563 /* for (sub = IDL_LIST (IDL_TYPE_ARRAY (ent).size_list).next; */
564 /* sub; sub = IDL_LIST (sub).next) */
565 /* fprintf (ci->fh, "[%" IDL_LL "d]", IDL_INTEGER (IDL_LIST (sub).data).value); */
566 /* fprintf(ci->fh, ";\n"); */
573 /* ch_type_alloc_and_tc (ent, rinfo, ci, TRUE); */
574 fprintf (ci->fh, "#endif\n");
580 /* ch_output_native(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
583 /* IDL_tree id = IDL_NATIVE(tree).ident; */
584 /* ctmp = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(id), "_", 0); */
585 /* fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", ctmp, ctmp); */
586 /* fprintf(ci->fh, "typedef struct %s_type *%s;\n", ctmp, ctmp); */
587 /* /\* Dont even think about emitting a typecode. *\/ */
588 /* fprintf(ci->fh, "#endif\n"); */
593 ch_output_type_struct(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
596 IDL_tree cur, curmem;
598 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_STRUCT(tree).ident),
600 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
601 /* put typedef out first for recursive seq */
602 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
604 /* Scan for any nested decls */
605 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
607 ts = IDL_MEMBER(IDL_LIST(cur).data).type_spec;
608 ch_prep(ts, rinfo, ci);
611 fprintf(ci->fh, "struct %s_type {\n", id);
613 for(cur = IDL_TYPE_STRUCT(tree).member_list; cur; cur = IDL_LIST(cur).next) {
614 for(curmem = IDL_MEMBER(IDL_LIST(cur).data).dcls; curmem; curmem = IDL_LIST(curmem).next) {
615 ch_output_var(IDL_MEMBER(IDL_LIST(cur).data).type_spec, IDL_LIST(curmem).data, ci);
618 if(!IDL_TYPE_STRUCT(tree).member_list)
619 fprintf(ci->fh, "int dummy;\n");
620 fprintf(ci->fh, "};\n");
622 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", id, id);
623 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", id, id);
625 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
627 fprintf(ci->fh, "#endif\n\n");
634 ch_output_type_union(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
639 if (IDL_NODE_TYPE (IDL_TYPE_UNION (tree).switch_type_spec) == IDLN_TYPE_ENUM)
640 ch_output_type_enum (IDL_TYPE_UNION (tree).switch_type_spec, rinfo, ci);
642 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_TYPE_UNION(tree).ident), "_", 0);
643 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n", id, id);
644 fprintf(ci->fh, "typedef struct %s_type %s;\n", id, id);
646 /* Scan for any nested decls */
647 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
648 IDL_tree member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
649 ch_prep(IDL_MEMBER(member).type_spec, rinfo, ci);
652 fprintf(ci->fh, "struct %s_type {\n", id);
653 forb_cbe_write_typespec(ci->fh, IDL_TYPE_UNION(tree).switch_type_spec);
654 fprintf(ci->fh, " _d;\nunion {\n");
656 for(curitem = IDL_TYPE_UNION(tree).switch_body; curitem; curitem = IDL_LIST(curitem).next) {
659 member = IDL_CASE_STMT(IDL_LIST(curitem).data).element_spec;
660 ch_output_var(IDL_MEMBER(member).type_spec,
661 IDL_LIST(IDL_MEMBER(member).dcls).data,
665 fprintf(ci->fh, "} _u;\n};\n");
667 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
669 fprintf(ci->fh, "#endif\n");
675 ch_output_codefrag(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
679 for(list = IDL_CODEFRAG(tree).lines; list;
680 list = g_slist_next(list)) {
681 if(!strncmp(list->data,
682 "#pragma include_defs",
683 sizeof("#pragma include_defs")-1)) {
685 ctmp = ((char *)list->data) + sizeof("#pragma include_defs");
686 while(*ctmp && (isspace((int)*ctmp) || *ctmp == '"')) ctmp++;
688 while(*cte && !isspace((int)*cte) && *cte != '"') cte++;
690 fprintf(ci->fh, "#include <%s>\n", ctmp);
692 fprintf(ci->fh, "%s\n", (char *)list->data);
697 ch_output_const_dcl(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
703 ident = IDL_CONST_DCL (tree).ident;
704 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS (ident), "_", 0);
706 fprintf(ci->fh, "#ifndef %s\n", id);
707 fprintf(ci->fh, "#define %s ", id);
709 forb_cbe_write_const(ci->fh,
710 IDL_CONST_DCL(tree).const_exp);
712 typespec = forb_cbe_get_typespec (IDL_CONST_DCL(tree).const_type);
713 if (IDL_NODE_TYPE (typespec) == IDLN_TYPE_INTEGER &&
714 !IDL_TYPE_INTEGER (typespec).f_signed)
715 fprintf(ci->fh, "U");
717 fprintf(ci->fh, "\n");
718 fprintf(ci->fh, "#endif /* !%s */\n\n", id);
724 ch_prep_fixed(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
728 ctmp = forb_cbe_get_typespec_str(tree);
730 "typedef struct { CORBA_unsigned_short _digits; CORBA_short _scale; CORBA_char _value[%d]; } %s;\n",
731 (int) (IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value + 2)/2,
735 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
739 ch_prep_sequence(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
741 char *ctmp, *fullname, *fullname_def, *ctmp2;
743 gboolean separate_defs, fake_if;
744 IDL_tree fake_seq = NULL;
746 tts = forb_cbe_get_typespec(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
747 ctmp = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tree).simple_type_spec);
748 ctmp2 = forb_cbe_get_typespec_str(tts);
749 fake_if = (IDL_NODE_TYPE(tts) == IDLN_INTERFACE);
753 ctmp2 = g_strdup("CORBA_Object");
755 separate_defs = strcmp(ctmp, ctmp2);
756 fullname = forb_cbe_get_typespec_str(tree);
757 //printf("YYY %s\n", fullname);
762 //printf("XXXXXXXX Separate defs %s, %s\n", ctmp, ctmp2);
763 //forb_idl_print_node(tree, 2);
765 tts = IDL_type_object_new();
766 fake_seq = IDL_type_sequence_new(tts, NULL);
767 IDL_NODE_UP(fake_seq) = IDL_NODE_UP(tree);
768 ch_prep_sequence(fake_seq, rinfo, ci);
769 member_type = forb_cbe_type_is_builtin (tts) ?
770 ctmp2 + strlen ("CORBA_") : ctmp2;
771 fullname_def = g_strdup_printf("CORBA_sequence_%s", member_type);
774 IDL_TYPE_SEQUENCE(fake_seq).simple_type_spec = NULL;
777 fullname_def = g_strdup(fullname);
779 if(IDL_NODE_TYPE(IDL_TYPE_SEQUENCE(tree).simple_type_spec)
780 == IDLN_TYPE_SEQUENCE)
781 ch_prep_sequence(IDL_TYPE_SEQUENCE(tree).simple_type_spec, rinfo, ci);
783 /* NOTE: FORB_DECL_%s protects redef of everything (struct,TC,externs)
784 * while _%s_defined protects only the struct */
786 fprintf(ci->fh, "#if !defined(FORB_DECL_%s)\n#define FORB_DECL_%s 1\n",
788 /* if ( ci->do_impl_hack ) */
789 /* forb_cbe_id_define_hack(ci->fh, "FORB_IMPL", fullname, ci->c_base_name); */
793 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
795 if(!strcmp(ctmp, "CORBA_RepositoryId"))
796 fprintf(ci->fh, "/* CRACKHEADS */\n");
797 fprintf(ci->fh, "typedef %s\n %s;\n", fullname_def, fullname);
798 fprintf(ci->fh, "#endif\n");
799 /* ch_type_alloc_and_tc(tree, rinfo, ci, FALSE); */
800 /* fprintf(ci->fh, "#define %s__alloc %s__alloc\n", */
801 /* fullname, fullname_def); */
802 /* fprintf(ci->fh, "#define %s__freekids %s__freekids\n", */
803 /* fullname, fullname_def); */
804 fprintf(ci->fh, "#define CORBA_sequence_%s_allocbuf(l) %s_allocbuf(l)\n",
806 fprintf(ci->fh, "#define %s_serialize(x,y) %s_serialize((x),(y))\n", fullname, fullname_def);
808 fprintf(ci->fh, "#define %s_deserialize(x,y) %s_deserialize((x),(y))\n", fullname, fullname_def);
809 IDL_tree_free(fake_seq);
815 fprintf(ci->fh, "#if !defined(_%s_defined)\n#define _%s_defined 1\n",
817 fprintf(ci->fh, "typedef struct { CORBA_unsigned_long _maximum, _length; ");
818 forb_cbe_write_typespec(ci->fh, IDL_TYPE_SEQUENCE(tree).simple_type_spec);
819 fprintf(ci->fh, "* _buffer; CORBA_boolean _release; }\n ");
820 forb_cbe_write_typespec(ci->fh, tree);
821 fprintf(ci->fh, ";\n#endif\n");
823 fprintf(ci->fh, "CORBA_boolean %s_serialize(CDR_Codec *codec, const %s *ptr);\n", fullname, fullname);
824 fprintf(ci->fh, "CORBA_boolean %s_deserialize(CDR_Codec *codec, %s *ptr);\n", fullname, fullname);
825 /* ch_type_alloc_and_tc(tree, rinfo, ci, TRUE); */
827 /* tc = forb_cbe_get_typecode_name (forb_cbe_get_typespec (tree)); */
828 member_type = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tree).simple_type_spec) ?
829 ctmp + strlen ("CORBA_") : ctmp;
831 fprintf (ci->fh, "#define CORBA_sequence_%s_allocbuf(l) "
832 "((%s*)forb_malloc(sizeof(%s)*(l)))\n",
833 member_type, ctmp, ctmp);
838 fprintf(ci->fh, "#endif\n\n");
843 g_free(fullname_def);
847 void ch_prep (IDL_tree tree,
848 OIDL_Run_Info *rinfo,
851 switch (IDL_NODE_TYPE (tree)) {
852 case IDLN_TYPE_SEQUENCE:
853 ch_prep_sequence (tree, rinfo, ci);
855 case IDLN_TYPE_FIXED:
856 ch_prep_fixed (tree, rinfo, ci);
858 case IDLN_TYPE_STRUCT:
859 ch_output_type_struct (tree, rinfo, ci);
862 ch_output_type_enum (tree, rinfo, ci);
870 /* ch_type_alloc_and_tc(IDL_tree tree, OIDL_Run_Info *rinfo, */
871 /* OIDL_C_Info *ci, gboolean do_alloc) */
876 /* ctmp = forb_cbe_get_typespec_str(tree); */
878 /* if ( ci->do_impl_hack ) { */
879 /* fprintf(ci->fh, "#if !defined(TC_IMPL_TC_%s_0)\n", ctmp); */
880 /* forb_cbe_id_define_hack(ci->fh, "TC_IMPL_TC", ctmp, ci->c_base_name); */
883 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", ci->c_base_name); */
884 /* fprintf (ci->fh, "static\n"); */
885 /* fprintf (ci->fh, "#else\n"); */
886 /* fprintf (ci->fh, "extern\n"); */
887 /* fprintf (ci->fh, "#endif\n"); */
888 /* fprintf (ci->fh, "FORB2_MAYBE_CONST struct CORBA_TypeCode_struct TC_%s_struct;\n", ctmp); */
890 /* fprintf (ci->fh, "#define TC_%s ((CORBA_TypeCode)&TC_%s_struct)\n", ctmp, ctmp); */
891 /* if (ci->do_impl_hack) */
892 /* fprintf (ci->fh, "#endif\n"); */
897 /* tts = forb_cbe_get_typespec(tree); */
899 /* tc = forb_cbe_get_typecode_name (tts); */
901 /* fprintf (ci->fh, "#define %s__alloc() ((%s%s *)Forb_small_alloc (%s))\n", */
902 /* ctmp, ctmp, (IDL_NODE_TYPE(tree) == IDLN_TYPE_ARRAY)?"_slice":"", tc); */
904 /* fprintf (ci->fh, "#define %s__freekids(m,d) Forb_small_freekids (%s,(m),(d))\n", ctmp, tc); */
906 /* if ( IDL_NODE_TYPE(tts) == IDLN_TYPE_SEQUENCE ) */
908 /* char *member_type = forb_cbe_get_typespec_str(IDL_TYPE_SEQUENCE(tts).simple_type_spec); */
909 /* char *member_name = forb_cbe_type_is_builtin (IDL_TYPE_SEQUENCE (tts).simple_type_spec) ? */
910 /* member_type + strlen ("CORBA_") : member_type; */
912 /* fprintf (ci->fh, "#define %s_allocbuf(l) " */
913 /* "((%s*)Forb_small_allocbuf (%s, (l)))\n", */
914 /* ctmp, member_name, tc); */
916 /* g_free (member_type); */
925 /************************/
927 /* cbe_header_interface_print_vepv(IDL_tree node, FILE *of) */
929 /* char *id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(node).ident), */
931 /* fprintf(of, " POA_%s__epv *%s_epv;\n", id, id); */
937 /* ch_output_poa(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
939 /* if(!tree) return; */
941 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
944 /* switch(IDL_NODE_TYPE(tree)) { */
945 /* case IDLN_MODULE: */
946 /* ch_output_poa(IDL_MODULE(tree).definition_list, rinfo, ci); */
948 /* case IDLN_LIST: */
952 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
953 /* ch_output_poa(IDL_LIST(sub).data, rinfo, ci); */
957 /* case IDLN_INTERFACE: */
963 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
965 /* fprintf(ci->fh, "#ifndef _defined_POA_%s\n#define _defined_POA_%s 1\n", */
968 /* /\* First, do epv for this interface, then vepv, then servant *\/ */
969 /* fprintf(ci->fh, "typedef struct {\n"); */
970 /* fprintf(ci->fh, " void *_private;\n"); */
971 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
974 /* cur = IDL_LIST(sub).data; */
976 /* switch(IDL_NODE_TYPE(cur)) { */
977 /* case IDLN_OP_DCL: */
978 /* forb_cbe_op_write_proto(ci->fh, cur, "", TRUE); */
979 /* fprintf(ci->fh, ";\n"); */
981 /* case IDLN_ATTR_DCL: */
983 /* OIDL_Attr_Info *ai; */
984 /* IDL_tree curitem; */
986 /* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { */
987 /* ai = IDL_LIST(curitem).data->data; */
989 /* forb_cbe_op_write_proto(ci->fh, ai->op1, "", TRUE); */
990 /* fprintf(ci->fh, ";\n"); */
993 /* forb_cbe_op_write_proto(ci->fh, ai->op2, "", TRUE); */
994 /* fprintf(ci->fh, ";\n"); */
1004 /* fprintf(ci->fh, "} POA_%s__epv;\n", id); */
1006 /* fprintf(ci->fh, "typedef struct {\n"); */
1007 /* fprintf(ci->fh, " PortableServer_ServantBase__epv *_base_epv;\n"); */
1008 /* IDL_tree_traverse_parents(tree, (GFunc)cbe_header_interface_print_vepv, ci->fh); */
1009 /* fprintf(ci->fh, "} POA_%s__vepv;\n", id); */
1011 /* fprintf(ci->fh, "typedef struct {\n"); */
1012 /* fprintf(ci->fh, " void *_private;\n"); */
1013 /* fprintf(ci->fh, " POA_%s__vepv *vepv;\n", id); */
1014 /* fprintf(ci->fh, "} POA_%s;\n", id); */
1016 /* fprintf(ci->fh, */
1017 /* "extern void POA_%s__init(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1018 /* fprintf(ci->fh, */
1019 /* "extern void POA_%s__fini(PortableServer_Servant servant, CORBA_Environment *ev);\n", id); */
1021 /* fprintf(ci->fh, "#endif /\* _defined_POA_%s *\/\n", id); */
1031 /************************/
1035 } InheritedOutputInfo;
1036 static void ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi);
1039 ch_output_stub_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci)
1044 switch(IDL_NODE_TYPE(tree)) {
1046 ch_output_stub_protos(IDL_MODULE(tree).definition_list, rinfo, ci);
1052 for(sub = tree; sub; sub = IDL_LIST(sub).next) {
1053 ch_output_stub_protos(IDL_LIST(sub).data, rinfo, ci);
1057 case IDLN_INTERFACE:
1061 if(IDL_INTERFACE(tree).inheritance_spec) {
1062 InheritedOutputInfo ioi;
1065 IDL_tree_traverse_parents(IDL_INTERFACE(tree).inheritance_spec, (GFunc)ch_output_inherited_protos, &ioi);
1068 for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) {
1071 cur = IDL_LIST(sub).data;
1073 switch(IDL_NODE_TYPE(cur)) {
1075 forb_idl_check_oneway_op (cur);
1076 forb_cbe_op_write_proto(ci->fh, cur, "", FALSE);
1077 fprintf(ci->fh, ";\n");
1084 for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1085 ai = IDL_LIST(curitem).data->data;
1087 forb_cbe_op_write_proto(ci->fh, ai->op1, "", FALSE);
1088 fprintf(ci->fh, ";\n");
1091 forb_cbe_op_write_proto(ci->fh, ai->op2, "", FALSE);
1092 fprintf(ci->fh, ";\n");
1109 ch_output_inherited_protos(IDL_tree curif, InheritedOutputInfo *ioi)
1114 if(curif == ioi->realif)
1117 realid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(ioi->realif).ident), "_", 0);
1118 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(curif).ident), "_", 0);
1120 for(curitem = IDL_INTERFACE(curif).body; curitem; curitem = IDL_LIST(curitem).next) {
1121 IDL_tree curop = IDL_LIST(curitem).data;
1123 switch(IDL_NODE_TYPE(curop)) {
1125 fprintf(ioi->of, "#define %s_%s %s_%s\n",
1126 realid, IDL_IDENT(IDL_OP_DCL(curop).ident).str,
1127 id, IDL_IDENT(IDL_OP_DCL(curop).ident).str);
1133 /* We don't use OIDL_Attr_Info here because inherited ops may go back into trees that are output-inhibited
1134 and therefore don't have the OIDL_Attr_Info generated on them */
1136 for(curitem = IDL_ATTR_DCL(curop).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) {
1139 ident = IDL_LIST(curitem).data;
1141 fprintf(ioi->of, "#define %s__get_%s %s__get_%s\n",
1142 realid, IDL_IDENT(ident).str,
1143 id, IDL_IDENT(ident).str);
1145 if(!IDL_ATTR_DCL(curop).f_readonly)
1146 fprintf(ioi->of, "#define %s__set_%s %s__set_%s\n",
1147 realid, IDL_IDENT(ident).str,
1148 id, IDL_IDENT(ident).str);
1162 /* doskel(IDL_tree cur, OIDL_Run_Info *rinfo, char *ifid, OIDL_C_Info *ci) */
1166 /* id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_OP_DCL(cur).ident), "_", 0); */
1168 /* fprintf(ci->fh, "void _forb_skel_%s(" */
1169 /* "CDR_Codec *codec, %s *obj", */
1171 /* /\* forb_cbe_op_write_proto(ci->fh, cur, "_impl_", TRUE); *\/ */
1172 /* fprintf(ci->fh, ");\n"); */
1178 /* ch_output_skel_protos(IDL_tree tree, OIDL_Run_Info *rinfo, OIDL_C_Info *ci) */
1180 /* if(!tree) return; */
1182 /* if ( tree->declspec & IDLF_DECLSPEC_PIDL ) */
1185 /* switch(IDL_NODE_TYPE(tree)) { */
1186 /* case IDLN_MODULE: */
1187 /* ch_output_skel_protos(IDL_MODULE(tree).definition_list, rinfo, ci); */
1189 /* case IDLN_LIST: */
1193 /* for(sub = tree; sub; sub = IDL_LIST(sub).next) { */
1194 /* ch_output_skel_protos(IDL_LIST(sub).data, rinfo, ci); */
1198 /* case IDLN_INTERFACE: */
1203 /* ifid = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(IDL_INTERFACE(tree).ident), "_", 0); */
1205 /* for(sub = IDL_INTERFACE(tree).body; sub; sub = IDL_LIST(sub).next) { */
1208 /* cur = IDL_LIST(sub).data; */
1210 /* switch(IDL_NODE_TYPE(cur)) { */
1211 /* case IDLN_OP_DCL: */
1212 /* doskel(cur, rinfo, ifid, ci); */
1214 /* case IDLN_ATTR_DCL: */
1215 /* IDL_tree_warning(cur, IDL_WARNING1, "Attributes are not supperted\n"); */
1217 /* /\* OIDL_Attr_Info *ai = cur->data; *\/ */
1218 /* /\* IDL_tree curitem; *\/ */
1220 /* /\* for(curitem = IDL_ATTR_DCL(cur).simple_declarations; curitem; curitem = IDL_LIST(curitem).next) { *\/ */
1221 /* /\* ai = IDL_LIST(curitem).data->data; *\/ */
1223 /* /\* doskel(ai->op1, rinfo, ifid, ci); *\/ */
1224 /* /\* if(ai->op2) *\/ */
1225 /* /\* doskel(ai->op2, rinfo, ifid, ci); *\/ */
1242 /* ch_output_itypes (IDL_tree tree, OIDL_C_Info *ci) */
1244 /* static int num_methods = 0; */
1249 /* switch(IDL_NODE_TYPE(tree)) { */
1250 /* case IDLN_MODULE: */
1251 /* ch_output_itypes (IDL_MODULE(tree).definition_list, ci); */
1253 /* case IDLN_LIST: { */
1255 /* for (sub = tree; sub; sub = IDL_LIST(sub).next) */
1256 /* ch_output_itypes (IDL_LIST(sub).data, ci); */
1259 /* case IDLN_ATTR_DCL: { */
1260 /* OIDL_Attr_Info *ai = tree->data; */
1262 /* IDL_tree curitem; */
1264 /* for(curitem = IDL_ATTR_DCL(tree).simple_declarations; curitem; */
1265 /* curitem = IDL_LIST(curitem).next) { */
1266 /* ai = IDL_LIST(curitem).data->data; */
1268 /* ch_output_itypes (ai->op1, ci); */
1270 /* ch_output_itypes (ai->op2, ci); */
1275 /* case IDLN_INTERFACE: { */
1278 /* id = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS ( */
1279 /* IDL_INTERFACE (tree).ident), "_", 0); */
1281 /* ch_output_itypes (IDL_INTERFACE(tree).body, ci); */
1283 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1284 /* ci->c_base_name); */
1285 /* fprintf (ci->fh, "static \n"); */
1286 /* fprintf (ci->fh, "#else\n"); */
1287 /* fprintf (ci->fh, "extern \n"); */
1288 /* fprintf (ci->fh, "#endif\n"); */
1289 /* fprintf (ci->fh, "Forb_IInterface %s__iinterface;\n", id); */
1291 /* fprintf (ci->fh, "#define %s_IMETHODS_LEN %d\n", id, num_methods); */
1293 /* if (num_methods == 0) */
1294 /* fprintf (ci->fh, "#define %s__imethods (Forb_IMethod*) NULL\n", id); */
1296 /* fprintf (ci->fh, "#ifdef FORB_IDL_C_IMODULE_%s\n", */
1297 /* ci->c_base_name); */
1298 /* fprintf (ci->fh, "static \n"); */
1299 /* fprintf (ci->fh, "#else\n"); */
1300 /* fprintf (ci->fh, "extern \n"); */
1301 /* fprintf (ci->fh, "#endif\n"); */
1302 /* fprintf (ci->fh, "Forb_IMethod %s__imethods[%s_IMETHODS_LEN];\n", id, id); */
1306 /* num_methods = 0; */
1311 /* case IDLN_OP_DCL: */
1312 /* num_methods++; */