diff options
| author | Maxime Dénès | 2017-09-15 10:42:13 +0200 |
|---|---|---|
| committer | Maxime Dénès | 2017-09-15 10:42:13 +0200 |
| commit | 9e6b192adcaadcdb1935a68f39ce5ea877562188 (patch) | |
| tree | c0b66a5665b1068c694466e8c64ec57c748530fb /lib | |
| parent | d6d7a12eb49c997dd83298477e216349fad74c7f (diff) | |
| parent | 7f816f00fed5ee7c7e94bd5f02a88880cdfa96aa (diff) | |
Merge PR #1051: Using an algebraic type for distinguishing toplevel input from location in file
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/loc.ml | 13 | ||||
| -rw-r--r-- | lib/loc.mli | 8 |
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/loc.ml b/lib/loc.ml index 9f036d90f9..06da13d44f 100644 --- a/lib/loc.ml +++ b/lib/loc.ml @@ -8,8 +8,12 @@ (* Locations management *) +type source = + | InFile of string + | ToplevelInput + type t = { - fname : string; (** filename *) + fname : source; (** filename or toplevel input *) line_nb : int; (** start line number *) bol_pos : int; (** position of the beginning of start line *) line_nb_last : int; (** end line number *) @@ -23,10 +27,15 @@ let create fname line_nb bol_pos bp ep = { line_nb_last = line_nb; bol_pos_last = bol_pos; bp = bp; ep = ep; } let make_loc (bp, ep) = { - fname = ""; line_nb = -1; bol_pos = 0; line_nb_last = -1; bol_pos_last = 0; + fname = ToplevelInput; line_nb = -1; bol_pos = 0; line_nb_last = -1; bol_pos_last = 0; bp = bp; ep = ep; } +let mergeable loc1 loc2 = + loc1.fname = loc2.fname + let merge loc1 loc2 = + if not (mergeable loc1 loc2) then + failwith "Trying to merge unmergeable locations."; if loc1.bp < loc2.bp then if loc1.ep < loc2.ep then { fname = loc1.fname; diff --git a/lib/loc.mli b/lib/loc.mli index 1fbaae8368..d4061e0446 100644 --- a/lib/loc.mli +++ b/lib/loc.mli @@ -8,8 +8,12 @@ (** {5 Basic types} *) +type source = + | InFile of string + | ToplevelInput + type t = { - fname : string; (** filename *) + fname : source; (** filename or toplevel input *) line_nb : int; (** start line number *) bol_pos : int; (** position of the beginning of start line *) line_nb_last : int; (** end line number *) @@ -22,7 +26,7 @@ type t = { (** This is inherited from CAMPL4/5. *) -val create : string -> int -> int -> int -> int -> t +val create : source -> int -> int -> int -> int -> t (** Create a location from a filename, a line number, a position of the beginning of the line, a start and end position *) |
