1 #include "config.h"
2 
3 #include "orbit-idl-c-backend.h"
4 
5 #include <string.h>
6 
7 static void
cs_output_stub(IDL_tree tree,OIDL_C_Info * ci,int * idx)8 cs_output_stub (IDL_tree     tree,
9 		OIDL_C_Info *ci,
10 		int         *idx)
11 {
12 	FILE     *of = ci->fh;
13 	char     *iface_id;
14 	char     *opname;
15 	gboolean  has_retval, has_args;
16 
17 	g_return_if_fail (idx != NULL);
18 
19 	iface_id = IDL_ns_ident_to_qstring (
20 			IDL_IDENT_TO_NS (IDL_INTERFACE (
21 				IDL_get_parent_node (tree, IDLN_INTERFACE, NULL)
22 					).ident), "_", 0);
23 	opname = IDL_ns_ident_to_qstring (IDL_IDENT_TO_NS (IDL_OP_DCL (tree).ident), "_", 0);
24 
25 	has_retval = IDL_OP_DCL (tree).op_type_spec != NULL;
26 	has_args   = IDL_OP_DCL (tree).parameter_dcls != NULL;
27 
28 	orbit_cbe_op_write_proto (of, tree, "", FALSE);
29 
30 	fprintf (of, "{\n");
31 
32 	if (has_retval) {
33 		orbit_cbe_write_param_typespec (of, tree);
34 		fprintf (of, " " ORBIT_RETVAL_VAR_NAME ";\n");
35 	}
36 #if 0
37 	fprintf (ci->fh, "POA_%s__epv *%s;\n", iface_id, ORBIT_EPV_VAR_NAME);
38 	fprintf (ci->fh, "gpointer _ORBIT_servant;\n");
39 
40 	/* in-proc part */
41 	fprintf (ci->fh, "if ((%s = ORBit_c_stub_invoke\n", ORBIT_EPV_VAR_NAME);
42 	fprintf (ci->fh, "		(_obj, %s__classid, &_ORBIT_servant,\n", iface_id);
43 	fprintf (ci->fh, "               G_STRUCT_OFFSET (POA_%s__epv, %s)))) {\n",
44 		 iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
45 
46 	fprintf (ci->fh, "if (ORBit_small_flags & ORBIT_SMALL_FAST_LOCALS && \n");
47 	fprintf (ci->fh, "    ORBIT_STUB_IsBypass (_obj, %s__classid) && \n", iface_id);
48 	fprintf (ci->fh, "    (%s = (POA_%s__epv*) ORBIT_STUB_GetEpv (_obj, %s__classid))->%s) {\n",
49 		 ORBIT_EPV_VAR_NAME, iface_id, iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
50 
51 	fprintf (ci->fh, "ORBIT_STUB_PreCall (_obj);\n");
52 
53 	fprintf (ci->fh, "%s%s->%s (_ORBIT_servant, ",
54 		 IDL_OP_DCL (tree).op_type_spec? ORBIT_RETVAL_VAR_NAME " = ":"",
55 		 ORBIT_EPV_VAR_NAME,
56 		 IDL_IDENT (IDL_OP_DCL (tree).ident).str);
57 
58 	for (node = IDL_OP_DCL (tree).parameter_dcls; node; node = IDL_LIST (node).next)
59 		fprintf (ci->fh, "%s, ",
60 			 IDL_IDENT (IDL_PARAM_DCL (IDL_LIST (node).data).simple_declarator).str);
61 
62 	if (IDL_OP_DCL (tree).context_expr)
63 		fprintf (ci->fh, "_ctx, ");
64 
65 	fprintf (ci->fh, "ev);\n");
66 
67 	fprintf (ci->fh, "ORBit_stub_post_invoke (_obj, %s);\n", ORBIT_EPV_VAR_NAME);
68 
69 	fprintf (of, " } else { /* remote marshal */\n");
70 #endif
71 
72 	/* remote invocation part */
73 	if (has_args)
74 		orbit_cbe_flatten_args (tree, of, "_args");
75 
76 	fprintf (of, "ORBit_c_stub_invoke (_obj, "
77 		 "&%s__iinterface.methods, %d, ", iface_id, *idx);
78 
79 	if (has_retval)
80 		fprintf (of, "&_ORBIT_retval, ");
81 	else
82 		fprintf (of, "NULL, ");
83 
84 	if (has_args)
85 		fprintf (of, "_args, ");
86 	else
87 		fprintf (of, "NULL, ");
88 
89 	if (IDL_OP_DCL (tree).context_expr)
90 		fprintf (ci->fh, "_ctx, ");
91 	else
92 		fprintf (ci->fh, "NULL, ");
93 
94 	fprintf (of, "ev, ");
95 
96 	fprintf (of, "%s__classid, G_STRUCT_OFFSET (POA_%s__epv, %s),\n",
97 		 iface_id, iface_id, IDL_IDENT (IDL_OP_DCL (tree).ident).str);
98 	fprintf (of, "(ORBitSmallSkeleton) _ORBIT_skel_small_%s);\n\n", opname);
99 
100 	if (has_retval)
101 		fprintf (of, "return " ORBIT_RETVAL_VAR_NAME ";\n");
102 
103 	fprintf (of, "}\n");
104 
105 	g_free (iface_id);
106 
107 	(*idx)++;
108 }
109 
110 static void
cs_output_stubs(IDL_tree tree,OIDL_C_Info * ci,int * idx)111 cs_output_stubs (IDL_tree     tree,
112 		 OIDL_C_Info *ci,
113 		 int         *idx)
114 {
115 	if (!tree)
116 		return;
117 
118 	switch (IDL_NODE_TYPE (tree)) {
119 	case IDLN_MODULE:
120 		cs_output_stubs (IDL_MODULE (tree).definition_list, ci, idx);
121 		break;
122 	case IDLN_LIST: {
123 		IDL_tree sub;
124 
125 		for (sub = tree; sub; sub = IDL_LIST (sub).next)
126 			cs_output_stubs (IDL_LIST (sub).data, ci, idx);
127 		break;
128 		}
129 	case IDLN_ATTR_DCL: {
130 		IDL_tree node;
131 
132 		for (node = IDL_ATTR_DCL (tree).simple_declarations; node; node = IDL_LIST (node).next) {
133 			OIDL_Attr_Info *ai;
134 
135 			ai = IDL_LIST (node).data->data;
136 
137 			cs_output_stubs (ai->op1, ci, idx);
138 
139 			if (ai->op2)
140 				cs_output_stubs (ai->op2, ci, idx);
141 		}
142 		break;
143 		}
144 	case IDLN_INTERFACE: {
145 		int real_idx = 0;
146 
147 		cs_output_stubs (IDL_INTERFACE (tree).body, ci, &real_idx);
148 		break;
149 		}
150 	case IDLN_OP_DCL:
151 		cs_output_stub (tree, ci, idx);
152 		break;
153 	default:
154 		break;
155 	}
156 }
157 
158 void
orbit_idl_output_c_stubs(IDL_tree tree,OIDL_Run_Info * rinfo,OIDL_C_Info * ci)159 orbit_idl_output_c_stubs (IDL_tree       tree,
160 			  OIDL_Run_Info *rinfo,
161 			  OIDL_C_Info   *ci)
162 {
163 	fprintf (ci->fh, OIDL_C_WARNING);
164 	fprintf (ci->fh, "#include <string.h>\n");
165 	fprintf (ci->fh, "#define ORBIT2_STUBS_API\n");
166 	fprintf (ci->fh, "#include \"%s.h\"\n\n", ci->base_name);
167 
168 	cs_output_stubs (tree, ci, NULL);
169 }
170