]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - forb-idl/forb-idl-c-utils.c
Fixed warnings on printf() on 64 bit systems
[frescor/forb.git] / forb-idl / forb-idl-c-utils.c
index c2ef95d91c362373166612fb36c8f4879d41eb8f..3d8aee64d3b5e2c2ebfd8aad71cf821f074e0f9e 100644 (file)
@@ -3,6 +3,90 @@
 #include "forb-idl-c-backend.h"
 
 #include <string.h>
+#include <inttypes.h>
+
+/** 
+ * 
+ * 
+ * @param of 
+ * @param ts Type spec.
+ * @param name decl
+ * @param use_name use identifier from name 
+ * @param var_prefix prefix for identifier taken from name
+ * @param serialization 
+ */
+void
+forb_cbe_write_ser_var(FILE *of, IDL_tree ts, IDL_tree name,
+                      bool use_name,
+                      char *var_prefix,
+                      enum forb_ser serialization)
+{
+       int indent = 0, i;
+       GString *id = g_string_new("");
+       char *serialize = (serialization == SERIALIZE) ? "serialize" : "deserialize";
+       gboolean use_ampersand = TRUE;
+
+       switch(IDL_NODE_TYPE(name)) {
+       case IDLN_IDENT:
+               fprintf(of, "  ");
+               if (use_name)
+                       g_string_assign(id, IDL_IDENT(name).str);
+               
+               if (IDL_NODE_TYPE(forb_cbe_get_typespec(ts)) == IDLN_TYPE_ARRAY)
+                 use_ampersand = FALSE;
+
+/*             printf("%s%s:\n", var_prefix, use_name ? id->str:""); */
+/*             forb_idl_print_node(forb_cbe_get_typespec(ts), 2); */
+       
+               break;
+       case IDLN_TYPE_ARRAY:
+       {
+               IDL_tree curitem;
+               char var;
+               if (use_name)
+                       g_string_assign(id, IDL_IDENT(IDL_TYPE_ARRAY(name).ident).str);
+
+               var = 'i';
+               fprintf(of, "  {\n    CORBA_unsigned_long ");
+               for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
+                       fprintf(of, "%c", var);
+                       if (IDL_LIST(curitem).next)
+                               fprintf(of, ", ");
+                       g_string_append_printf(id, "[%c]", var);
+                       var++;
+               }
+               fprintf(of, ";\n");
+
+               var = 'i';
+               for(curitem = IDL_TYPE_ARRAY(name).size_list; curitem; curitem = IDL_LIST(curitem).next) {
+                       indent++;
+                       for (i=0; i<indent+1; i++)
+                               fprintf(of, "  ");
+                       fprintf(of, "for (%c=0; %c<%" PRId64 "; %c++) \n",
+                               var, var, IDL_INTEGER(IDL_LIST(curitem).data).value, var);
+                       var++;
+               }
+
+
+               for (i=0; i<indent+2; i++)
+                       fprintf(of, "  ");
+
+       }
+       break;
+       default:
+               g_error("Weird varname - %s", IDL_tree_type_names[IDL_NODE_TYPE(name)]);
+               break;
+       }
+       fprintf(of, "if (!");
+       forb_cbe_write_typespec(of, ts);
+       fprintf(of, "_%s(codec, %s%s%s)) goto ser_exception;\n",
+               serialize, use_ampersand ? "&":"", var_prefix, id->str);
+       if (indent)
+               fprintf(of, "  }\n");
+
+       g_string_free(id, TRUE);
+}
+
 
 char *
 forb_cbe_get_typecode_name (IDL_tree tree)
@@ -16,12 +100,11 @@ forb_cbe_get_typecode_name (IDL_tree tree)
 gboolean
 forb_cbe_type_is_builtin(IDL_tree tree)
 { 
-  return FALSE;
+/*   return FALSE; */
   switch(IDL_NODE_TYPE(tree)) {
   case IDLN_LIST:
   case IDLN_GENTREE:
   case IDLN_MEMBER:
-  case IDLN_NATIVE:
   case IDLN_CASE_STMT:
   case IDLN_MODULE:
   case IDLN_BINOP:
@@ -50,6 +133,7 @@ forb_cbe_type_is_builtin(IDL_tree tree)
   case IDLN_TYPE_OBJECT:
   case IDLN_TYPE_TYPECODE:
   case IDLN_TYPE_ENUM:
+  case IDLN_TYPE_SEQUENCE:
     return TRUE;
     break;
   case IDLN_TYPE_DCL:
@@ -58,13 +142,13 @@ forb_cbe_type_is_builtin(IDL_tree tree)
   case IDLN_OP_DCL:
   case IDLN_PARAM_DCL:
   case IDLN_TYPE_FIXED:
-  case IDLN_TYPE_SEQUENCE:
   case IDLN_TYPE_ARRAY:
   case IDLN_TYPE_STRUCT:
   case IDLN_TYPE_UNION:
   case IDLN_IDENT:
   case IDLN_INTERFACE:
   case IDLN_FORWARD_DCL:
+  case IDLN_NATIVE:
   default:
     return FALSE;
     break;
@@ -108,7 +192,7 @@ forb_cbe_get_typespec_str(IDL_tree tree)
     }
     break;
   case IDLN_TYPE_FIXED:
-    return g_strdup_printf( "CORBA_fixed_%" IDL_LL "d_%" IDL_LL "d",
+    return g_strdup_printf( "CORBA_fixed_%" PRId64 "_%" PRId64 "",
                     IDL_INTEGER(IDL_TYPE_FIXED(tree).positive_int_const).value,
                     IDL_INTEGER(IDL_TYPE_FIXED(tree).integer_lit).value);
     break;
@@ -176,7 +260,7 @@ forb_cbe_get_typespec_str(IDL_tree tree)
     }
     break;
   case IDLN_NATIVE:
-    retval = "gpointer";
+    retval = forb_cbe_get_typespec_str(IDL_NATIVE(tree).ident);
     break;
   case IDLN_FORWARD_DCL:
   case IDLN_INTERFACE:
@@ -304,7 +388,7 @@ forb_cbe_op_write_proto (FILE       *of,
                        IDL_get_parent_node (op, IDLN_INTERFACE, NULL)).ident), "_", 0);
 
        if (for_epv)
-               fprintf (of, " (*%s%s)", nom_prefix ? nom_prefix : "",
+               fprintf (of, "\t(*%s%s)", nom_prefix ? nom_prefix : "",
                         IDL_IDENT(IDL_OP_DCL(op).ident).str);
        else 
                fprintf (of, " %s%s_%s", nom_prefix ? nom_prefix : "",
@@ -312,9 +396,9 @@ forb_cbe_op_write_proto (FILE       *of,
 
        fprintf (of, "(");
 
-       if (for_epv)
-               fprintf (of, "PortableServer_Servant _servant, ");
-       else
+/*     if (for_epv) */
+/*             fprintf (of, "PortableServer_Servant _servant, "); */
+/*     else */
                fprintf (of, "%s _obj, ", id);
 
        g_free (id);
@@ -351,7 +435,7 @@ forb_cbe_get_const(IDL_tree tree)
     g_string_printf(tmpstr, "%f", IDL_FLOAT(tree).value);
     break;
   case IDLN_INTEGER:
-    g_string_printf(tmpstr, "%" IDL_LL "d", IDL_INTEGER(tree).value);
+    g_string_printf(tmpstr, "%" PRId64 "", IDL_INTEGER(tree).value);
     break;
   case IDLN_STRING:
     g_string_printf(tmpstr, "\"%s\"", IDL_STRING(tree).value);