[Libguestfs] [PATCH libnbd 1/3] generator: Move location code from State_machine to Utils

Richard W.M. Jones rjones at redhat.com
Fri Dec 3 19:02:08 UTC 2021


Move the type [location] and the values [noloc], [string_of_location]
and [line_directive_of_location] to [Utils].  Straightforward code
motion, no change in functionality.
---
 generator/state_machine.ml  | 12 +++---------
 generator/state_machine.mli |  7 +------
 generator/utils.ml          |  7 +++++++
 generator/utils.mli         |  6 ++++++
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/generator/state_machine.ml b/generator/state_machine.ml
index d3edef4c9..3bc77f242 100644
--- a/generator/state_machine.ml
+++ b/generator/state_machine.ml
@@ -48,9 +48,6 @@ let string_of_external_event = function
   | CmdConnectSocket -> "CmdConnectSocket"
   | CmdIssue -> "CmdIssue"
 
-type location = string * int
-let noloc = ("", 0)
-
 type state = {
   name : string;
   comment : string;
@@ -61,7 +58,7 @@ and parsed_state = {
   prefix : string list;
   display_name : string;
   state_enum : string;
-  loc : location;
+  loc : Utils.location;
   code : string;
   internal_transitions : state list;
   events : (external_event * state) list;
@@ -69,7 +66,8 @@ and parsed_state = {
 
 let default_state = { name = ""; comment = ""; external_events = [];
                       parsed = { prefix = []; display_name = "";
-                                 state_enum = ""; loc = noloc; code = "";
+                                 state_enum = ""; loc = Utils.noloc;
+                                 code = "";
                                  internal_transitions = []; events = [] } }
 
 type state_machine = state_group list
@@ -878,7 +876,3 @@ and structured_reply_state_machine = [
     external_events = [];
   };
 ]
-
-let string_of_location (file, lineno) = sprintf "%s:%d" file lineno
-let line_directive_of_location (file, lineno) =
-  sprintf "#line %d \"%s\"" lineno file
diff --git a/generator/state_machine.mli b/generator/state_machine.mli
index 4e387e3ea..020225f84 100644
--- a/generator/state_machine.mli
+++ b/generator/state_machine.mli
@@ -80,11 +80,6 @@ type external_event =
 val all_external_events : external_event list
 val string_of_external_event : external_event -> string
 
-type location = string * int  (** source location: file, line number *)
-val noloc : location
-val string_of_location : location -> string
-val line_directive_of_location : location -> string
-
 type state = {
   (** The state name (without prefix).  If this has the special name
       "START" then it is the start state of the current group.  Each
@@ -117,7 +112,7 @@ and parsed_state = {
   state_enum : string;
 
   (** The C code implementing this state. *)
-  loc : location;
+  loc : Utils.location;
   code : string;
 
   (** Internal transitions, parsed out of the C code. *)
diff --git a/generator/utils.ml b/generator/utils.ml
index c326c0364..b8f394ce2 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -20,6 +20,9 @@
 open Printf
 open Unix
 
+type location = string * int
+let noloc = ("", 0)
+
 let failwithf fs = ksprintf failwith fs
 
 let rec filter_map f = function
@@ -190,6 +193,10 @@ let pr_wrap ?(maxcol = 76) c code =
       *)
      pr "%s" (String.concat "\n" rest)
 
+let string_of_location (file, lineno) = sprintf "%s:%d" file lineno
+let line_directive_of_location (file, lineno) =
+  sprintf "#line %d \"%s\"" lineno file
+
 type comment_style =
   | CStyle | CPlusPlusStyle | HashStyle | OCamlStyle | HaskellStyle
   | PODCommentStyle
diff --git a/generator/utils.mli b/generator/utils.mli
index b559baf76..c6ed61ce0 100644
--- a/generator/utils.mli
+++ b/generator/utils.mli
@@ -29,6 +29,8 @@ type comment_style =
 
 type chan = NoOutput | OutChannel of out_channel | Buffer of Buffer.t
 
+type location = string * int  (** source location: file, line number *)
+
 val failwithf : ('a, unit, string, 'b) format4 -> 'a
 
 val filter_map : ('a -> 'b option) -> 'a list -> 'b list
@@ -51,6 +53,10 @@ val output_to : string -> (unit -> 'a) -> unit
 val pr : ('a, unit, string, unit) format4 -> 'a
 val pr_wrap : ?maxcol:int -> char -> (unit -> 'a) -> unit
 
+val noloc : location
+val string_of_location : location -> string
+val line_directive_of_location : location -> string
+
 type cache_key = string
 type cache_value = string list
 val pod2text : cache_key -> cache_value
-- 
2.32.0




More information about the Libguestfs mailing list