[Libguestfs] [PATCH 1/2] generator: Rename java_structs to camel_structs to better reflect their purpose

Matthew Booth mbooth at redhat.com
Mon Jan 9 10:16:34 UTC 2012


This map was originally included just for the java bindings, but is generally
useful to any binding which uses camel case by requirement or convention.
---
 generator/generator_haskell.ml  |    4 ++--
 generator/generator_java.ml     |   10 +++++-----
 generator/generator_main.ml     |    2 +-
 generator/generator_structs.ml  |   12 +++++-------
 generator/generator_structs.mli |    8 ++++----
 5 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/generator/generator_haskell.ml b/generator/generator_haskell.ml
index 29b260f..a57cfd8 100644
--- a/generator/generator_haskell.ml
+++ b/generator/generator_haskell.ml
@@ -239,10 +239,10 @@ and generate_haskell_prototype ~handle ?(hs = false) (ret, args, optargs) =
    | RString _ -> pr "%s" string
    | RStringList _ -> pr "[%s]" string
    | RStruct (_, typ) ->
-       let name = java_name_of_struct typ in
+       let name = camel_name_of_struct typ in
        pr "%s" name
    | RStructList (_, typ) ->
-       let name = java_name_of_struct typ in
+       let name = camel_name_of_struct typ in
        pr "[%s]" name
    | RHashtable _ -> pr "Hashtable"
    | RBufferOut _ -> pr "%s" string
diff --git a/generator/generator_java.ml b/generator/generator_java.ml
index 68972bc..69d5e24 100644
--- a/generator/generator_java.ml
+++ b/generator/generator_java.ml
@@ -219,10 +219,10 @@ and generate_java_prototype ?(public=false) ?(privat=false) ?(native=false)
    | RBufferOut _ -> pr "String ";
    | RStringList _ -> pr "String[] ";
    | RStruct (_, typ) ->
-       let name = java_name_of_struct typ in
+       let name = camel_name_of_struct typ in
        pr "%s " name;
    | RStructList (_, typ) ->
-       let name = java_name_of_struct typ in
+       let name = camel_name_of_struct typ in
        pr "%s[] " name;
    | RHashtable _ ->
        if not native then
@@ -657,11 +657,11 @@ Java_com_redhat_et_libguestfs_GuestFS__1close
            pr "  free (r);\n";
            pr "  return jr;\n"
        | RStruct (_, typ) ->
-           let jtyp = java_name_of_struct typ in
+           let jtyp = camel_name_of_struct typ in
            let cols = cols_of_struct typ in
            generate_java_struct_return typ jtyp cols
        | RStructList (_, typ) ->
-           let jtyp = java_name_of_struct typ in
+           let jtyp = camel_name_of_struct typ in
            let cols = cols_of_struct typ in
            generate_java_struct_list_return typ jtyp cols
        | RBufferOut _ ->
@@ -767,5 +767,5 @@ and generate_java_makefile_inc () =
   List.iter (
     fun (typ, jtyp) ->
         pr "\tcom/redhat/et/libguestfs/%s.java \\\n" jtyp;
-  ) java_structs;
+  ) camel_structs;
   pr "\tcom/redhat/et/libguestfs/GuestFS.java\n"
diff --git a/generator/generator_main.ml b/generator/generator_main.ml
index 7e4e4ed..53a0f29 100644
--- a/generator/generator_main.ml
+++ b/generator/generator_main.ml
@@ -124,7 +124,7 @@ Run it from the top source directory using the command
       let cols = cols_of_struct typ in
       let filename = sprintf "java/com/redhat/et/libguestfs/%s.java" jtyp in
       output_to filename (generate_java_struct jtyp cols);
-  ) java_structs;
+  ) camel_structs;
 
   output_to "java/Makefile.inc" generate_java_makefile_inc;
   output_to "java/com_redhat_et_libguestfs_GuestFS.c" generate_java_c;
diff --git a/generator/generator_structs.ml b/generator/generator_structs.ml
index 8fd12e4..83442d1 100644
--- a/generator/generator_structs.ml
+++ b/generator/generator_structs.ml
@@ -193,10 +193,8 @@ let structs = [
   ];
 ] (* end of structs *)
 
-(* Ugh, Java has to be different ..
- * These names are also used by the Haskell bindings.
- *)
-let java_structs = [
+(* For bindings which want camel case *)
+let camel_structs = [
   "int_bool", "IntBool";
   "lvm_pv", "PV";
   "lvm_vg", "VG";
@@ -211,11 +209,11 @@ let java_structs = [
   "application", "Application";
 ]
 
-let java_name_of_struct typ =
-  try List.assoc typ java_structs
+let camel_name_of_struct typ =
+  try List.assoc typ camel_structs
   with Not_found ->
     failwithf
-      "java_name_of_struct: no java_structs entry corresponding to %s" typ
+      "camel_name_of_struct: no camel_structs entry corresponding to %s" typ
 
 let cols_of_struct typ =
   try List.assoc typ structs
diff --git a/generator/generator_structs.mli b/generator/generator_structs.mli
index 66ae2ea..f47a9ad 100644
--- a/generator/generator_structs.mli
+++ b/generator/generator_structs.mli
@@ -26,8 +26,8 @@ type cols = (string * Generator_types.field) list
 val structs : (string * cols) list
 (** List of structures. *)
 
-val java_structs : (string * string) list
-(** Of course, Java has to be different from everyone else. *)
+val camel_structs : (string * string) list
+(** For bindings which want camel case struct names *)
 
 val lvm_pv_cols : cols
 val lvm_vg_cols : cols
@@ -36,8 +36,8 @@ val lvm_lv_cols : cols
     used to generate code for parsing the output of commands like
     [lvs].  One day replace this with liblvm API calls. *)
 
-val java_name_of_struct : string -> string
-(** Extract Java name of struct. *)
+val camel_name_of_struct : string -> string
+(** Camel case name of struct. *)
 
 val cols_of_struct : string -> cols
 (** Extract columns of a struct. *)
-- 
1.7.7.5




More information about the Libguestfs mailing list