From 1d945c0e2e93172a371daf0e514e2986af32440a Mon Sep 17 00:00:00 2001 From: Nicolas Berthier Date: Tue, 19 Sep 2023 08:52:45 +0200 Subject: [PATCH] Improve representation and hash of virtual limits in source overlay module --- src/lsp/cobol_preproc/src_overlay.ml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lsp/cobol_preproc/src_overlay.ml b/src/lsp/cobol_preproc/src_overlay.ml index e073ff002..7b40a317a 100644 --- a/src/lsp/cobol_preproc/src_overlay.ml +++ b/src/lsp/cobol_preproc/src_overlay.ml @@ -33,19 +33,20 @@ module Limit = struct type t = limit let make_virtual: unit -> t = - let id = ref 0 in + let id = ref (-1) in (* Actually start at -2 (-1 is used in Lexing.dummy) *) fun () -> decr id; - Lexing.{ dummy_pos with pos_lnum = !id } + Lexing.{ dummy_pos with pos_cnum = !id } - let is_virtual: t -> bool = - fun l -> l.Lexing.pos_lnum < 0 + let is_virtual (l: t) : bool = + l.pos_cnum < (-1) + + let equal (l1: t) (l2: t) = + l1.pos_cnum == l2.pos_cnum && + l1.pos_fname = l2.pos_fname + + let hash (l: limit) = l.pos_cnum - (* Structural equality is required below, to deal with cases where we - construct the limits of a token several times, for instance at the - beginning of recovery. *) - let equal = (=) - let hash = Hashtbl.hash end (** Weak hashtable where keys are overlay limits (internal) *)