3 #include "orte-idl-c-backend.h"
8 orte_cbe_get_typecode_name (IDL_tree tree)
11 return g_strdup ("TC_FIXME");
13 return g_strconcat ("TC_", orte_cbe_get_typespec_str (tree), NULL);
17 orte_cbe_type_is_builtin(IDL_tree tree)
20 switch(IDL_NODE_TYPE(tree)) {
30 g_error("Strange type for being a builtin");
34 case IDLN_WIDE_STRING:
41 case IDLN_TYPE_INTEGER:
44 case IDLN_TYPE_WIDE_CHAR:
45 case IDLN_TYPE_STRING:
46 case IDLN_TYPE_WIDE_STRING:
47 case IDLN_TYPE_BOOLEAN:
50 case IDLN_TYPE_OBJECT:
51 case IDLN_TYPE_TYPECODE:
61 case IDLN_TYPE_SEQUENCE:
63 case IDLN_TYPE_STRUCT:
67 case IDLN_FORWARD_DCL:
77 Gets the "type" of {tree} as known in C.
78 The return value was alloc'd via g_malloc, and must be g_free'd.
81 orte_cbe_get_typespec_str(IDL_tree tree)
84 GString *tmpstr = NULL;
87 return g_strdup("void");
90 switch(IDL_NODE_TYPE(tree)) {
92 return orte_cbe_get_typespec_str(IDL_MEMBER(tree).type_spec);
98 switch(IDL_TYPE_FLOAT(tree).f_type) {
99 case IDL_FLOAT_TYPE_FLOAT:
100 retval = "CORBA_float";
102 case IDL_FLOAT_TYPE_DOUBLE:
103 retval = "CORBA_double";
105 case IDL_FLOAT_TYPE_LONGDOUBLE:
106 retval = "CORBA_long_double";
110 case IDLN_TYPE_FIXED:
111 return g_strdup_printf( "CORBA_fixed_%" IDL_LL "d_%" IDL_LL "d",
112 IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value,
113 IDL_INTEGER(IDL_TYPE_FIXED(tree).integer_lit).value);
115 case IDLN_TYPE_INTEGER:
116 tmpstr = g_string_new(NULL);
117 g_string_append(tmpstr, "CORBA_");
118 if(!IDL_TYPE_INTEGER(tree).f_signed)
119 g_string_append(tmpstr, "unsigned_");
121 switch(IDL_TYPE_INTEGER(tree).f_type) {
122 case IDL_INTEGER_TYPE_SHORT:
123 g_string_append(tmpstr, "short");
125 case IDL_INTEGER_TYPE_LONGLONG:
126 g_string_append(tmpstr, "long_");
128 case IDL_INTEGER_TYPE_LONG:
129 g_string_append(tmpstr, "long");
133 case IDLN_TYPE_STRING:
134 retval = "CORBA_string"; /* this is non-standard! */
136 case IDLN_TYPE_OCTET:
137 retval = "CORBA_octet";
139 case IDLN_TYPE_WIDE_STRING:
140 retval = "CORBA_wstring"; /* this is non-standard! */
143 retval = "CORBA_char";
145 case IDLN_TYPE_WIDE_CHAR:
146 retval = "CORBA_wchar";
148 case IDLN_TYPE_BOOLEAN:
149 retval = "CORBA_boolean";
151 case IDLN_TYPE_STRUCT:
152 return orte_cbe_get_typespec_str(IDL_TYPE_STRUCT(tree).ident);
153 case IDLN_EXCEPT_DCL:
154 return orte_cbe_get_typespec_str(IDL_EXCEPT_DCL(tree).ident);
155 case IDLN_TYPE_ARRAY:
156 return orte_cbe_get_typespec_str(IDL_TYPE_ARRAY(tree).ident);
157 case IDLN_TYPE_UNION:
158 return orte_cbe_get_typespec_str(IDL_TYPE_UNION(tree).ident);
160 return orte_cbe_get_typespec_str(IDL_TYPE_ENUM(tree).ident);
162 return IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0);
164 return orte_cbe_get_typespec_str(IDL_PARAM_DCL(tree).param_type_spec);
165 case IDLN_TYPE_SEQUENCE:
167 IDL_tree subtype = IDL_TYPE_SEQUENCE(tree).simple_type_spec;
169 ctmp = orte_cbe_get_typespec_str(subtype);
170 /* We should have built-in alias to make this next line not needed */
171 base = orte_cbe_type_is_builtin(subtype)
172 ? ctmp + strlen("CORBA_") : ctmp;
173 retval = g_strdup_printf( "CORBA_sequence_%s", base);
181 case IDLN_FORWARD_DCL:
183 return orte_cbe_get_typespec_str(IDL_INTERFACE(tree).ident);
184 case IDLN_TYPE_OBJECT:
185 retval = "CORBA_Object";
187 case IDLN_TYPE_TYPECODE:
188 retval = "CORBA_TypeCode";
191 g_error("We were asked to get a typename for a %s",
192 IDL_tree_type_names[IDL_NODE_TYPE(tree)]);
197 return g_strdup (retval);
199 return g_string_free (tmpstr, FALSE);
203 orte_cbe_write_typespec(FILE *of, IDL_tree tree)
205 char *name = orte_cbe_get_typespec_str(tree);
210 /* Writes the value of the constant in 'tree' to file handle 'of' */
212 orte_cbe_get_const(IDL_tree tree)
214 char *opc = NULL, *retval, *ctmp;
215 GString *tmpstr = g_string_new(NULL);
217 switch(IDL_NODE_TYPE(tree)) {
219 g_string_printf(tmpstr, "%s", IDL_BOOLEAN(tree).value?"CORBA_TRUE":"CORBA_FALSE");
222 g_string_printf(tmpstr, "'%s'", IDL_CHAR(tree).value);
225 g_string_printf(tmpstr, "%f", IDL_FLOAT(tree).value);
228 g_string_printf(tmpstr, "%" IDL_LL "d", IDL_INTEGER(tree).value);
231 g_string_printf(tmpstr, "\"%s\"", IDL_STRING(tree).value);
234 g_string_printf(tmpstr, "L'%ls'", IDL_WIDE_CHAR(tree).value);
236 case IDLN_WIDE_STRING:
237 g_string_printf(tmpstr, "L\"%ls\"", IDL_WIDE_STRING(tree).value);
240 g_string_printf(tmpstr, "(");
241 ctmp = orte_cbe_get_const(IDL_BINOP(tree).left);
242 g_string_append(tmpstr, ctmp);
244 switch(IDL_BINOP(tree).op) {
276 g_string_append_printf(tmpstr, " %s ", opc);
277 ctmp = orte_cbe_get_const(IDL_BINOP(tree).right);
278 g_string_append_printf(tmpstr, "%s)", ctmp);
282 switch(IDL_UNARYOP(tree).op) {
283 case IDL_UNARYOP_PLUS: opc = "+"; break;
284 case IDL_UNARYOP_MINUS: opc = "-"; break;
285 case IDL_UNARYOP_COMPLEMENT: opc = "~"; break;
287 ctmp = orte_cbe_get_const(IDL_UNARYOP(tree).operand);
288 g_string_printf(tmpstr, "%s%s", opc, ctmp);
294 id = IDL_ns_ident_to_qstring(IDL_IDENT_TO_NS(tree), "_", 0);
295 g_string_printf(tmpstr, "%s", id);
300 g_error("We were asked to print a constant for %s", IDL_tree_type_names[tree->_type]);
304 retval = tmpstr->str;
306 g_string_free(tmpstr, FALSE);
312 orte_cbe_write_const(FILE *of, IDL_tree tree)
316 ctmp = orte_cbe_get_const(tree);
317 fprintf(of, "%s", ctmp);
321 /* This is the WORST HACK in the WORLD, really truly, but the C preprocessor doesn't allow us to use
322 strings, so we have to work around it by using individual characters. */
324 orte_cbe_id_define_hack(FILE *fh, const char *def_prefix, const char *def_name, const char *def_value)
327 n = strlen(def_value);
328 for(i = 0; i < n; i++)
329 fprintf(fh, "#define %s_%s_%d '%c'\n", def_prefix, def_name, i, def_value[i]);