Debian Codegraph @

lib/loc.mli

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (** {5 Basic types} *)
12
13 (** Information about a source file. *)
14 type source =
15 | InFile of { dirpath : string option; file : string }
16 | ToplevelInput
17
18 (** [Loc.t] represents a range of positions in a source file.
19 It is commonly used with ['a CAst.t]. *)
20 type t = {
21 fname : source; (** Filename or toplevel input. *)
22 line_nb : int; (** Start line number. *)
23 bol_pos : int; (** Position of the beginning of start line. *)
24 line_nb_last : int; (** End line number. *)
25 bol_pos_last : int; (** Position of the beginning of end line. *)
26 bp : int; (** Start position. *)
27 ep : int; (** End position. *)
28 }
29
30 (** {5 Location manipulation} *)
31
32 (** This is inherited from CAMPL4/5. *)
33
34 (** Create a location from a filename, a line number, a position of the
35 beginning of the line, a start and end position *)
36 val create : source -> int -> int -> int -> int -> t
37
38 (** Create a location corresponding to the beginning of the given source *)
39 val initial : source -> t
40
41 (** Return the start and end position of a location *)
42 val unloc : t -> int * int
43
44 (** Make a location out of its start and end position *)
45 val make_loc : int * int -> t
46
47 val merge : t -> t -> t
48
49 (** Merge locations, usually generating the largest possible span *)
50 val merge_opt : t option -> t option -> t option
51
52 (** [sub loc sh len] is the location [loc] shifted with [sh]
53 characters and with length [len]. The previous ending position
54 of the location is lost. *)
55 val sub : t -> int -> int -> t
56
57 (** [after loc sh len] is the location just after loc (starting at the
58 end position of [loc]) shifted with [sh] characters and of length [len]. *)
59 val after : t -> int -> int -> t
60
61 (** Answers [true] when the first location is more defined, or, when
62 both defined, included in the second one *)
63 val finer : t option -> t option -> bool
64
65 (** [shift_loc loc n p] shifts the beginning of location by [n] and
66 the end by [p]; it is assumed that the shifts do not change the
67 lines at which the location starts and ends *)
68 val shift_loc : int -> int -> t -> t
69
70 (** {5 Located exceptions} *)
71
72 (** Adding location to an exception *)
73 val add_loc : Exninfo.info -> t -> Exninfo.info
74
75 (** Retrieving the optional location of an exception *)
76 val get_loc : Exninfo.info -> t option
77
78 (** [raise loc e] is the same as [Pervasives.raise (add_loc e loc)]. *)
79 val raise : ?loc:t -> exn -> 'a
80
81 (** {5 Objects with location information } *)
82
83 type 'a located = t option * 'a
84
85 (** Embed a location in a type *)
86 val tag : ?loc:t -> 'a -> 'a located
87
88 (** Modify an object carrying a location *)
89 val map : ('a -> 'b) -> 'a located -> 'b located
90
91 (** Print for user consumption. *)
92 val pr : t -> Pp.t
93
94 (** {5 Location of the current command (if any) } *)
95
96 val get_current_command_loc : unit -> t option
97
98 val set_current_command_loc : t option -> unit