1
|
(********************************************************************)
|
2
|
(* *)
|
3
|
(* The LustreC compiler toolset / The LustreC Development Team *)
|
4
|
(* Copyright 2012 - -- ONERA - CNRS - INPT *)
|
5
|
(* *)
|
6
|
(* LustreC is free software, distributed WITHOUT ANY WARRANTY *)
|
7
|
(* under the terms of the GNU Lesser General Public License *)
|
8
|
(* version 2.1. *)
|
9
|
(* *)
|
10
|
(********************************************************************)
|
11
|
|
12
|
open Lexing
|
13
|
module Lex = MenhirLib.LexerUtil
|
14
|
|
15
|
type t = position * position
|
16
|
|
17
|
type filename = string
|
18
|
|
19
|
let dummy = dummy_pos, dummy_pos
|
20
|
|
21
|
let set_input, get_input, get_module =
|
22
|
let input_name : filename ref = ref "__UNINITIALIZED__" in
|
23
|
let module_name : filename ref = ref "__UNINITIALIZED__" in
|
24
|
( (fun name ->
|
25
|
input_name := name;
|
26
|
module_name := Filename.chop_extension name),
|
27
|
(fun () -> !input_name),
|
28
|
fun () -> !module_name )
|
29
|
|
30
|
let curr lexbuf = lexbuf.lex_start_p, lexbuf.lex_curr_p
|
31
|
|
32
|
let filename_of_loc (s, _) = s.pos_fname
|
33
|
|
34
|
let filename_of_lexbuf lexbuf = lexbuf.lex_start_p.pos_fname
|
35
|
|
36
|
let shift_pos pos1 pos2 =
|
37
|
(* Format.eprintf "Shift pos %s by pos %s@." pos1.Lexing.pos_fname pos2.Lexing.pos_fname;
|
38
|
* assert (pos1.Lexing.pos_fname = pos2.Lexing.pos_fname); *)
|
39
|
{
|
40
|
pos_fname = pos1.pos_fname;
|
41
|
pos_lnum = pos1.pos_lnum + pos2.pos_lnum - 1;
|
42
|
(* New try *)
|
43
|
(* pos_bol = pos2.pos_bol; *)
|
44
|
pos_bol = pos1.pos_bol + pos2.pos_bol;
|
45
|
pos_cnum =
|
46
|
pos1.pos_cnum + pos2.pos_cnum
|
47
|
(* pos_cnum = pos2.pos_cnum; *)
|
48
|
(* pos_bol = pos1.pos_bol + pos2.pos_bol; pos_cnum =if pos2.pos_lnum = 1
|
49
|
then pos1.pos_cnum + pos2.pos_cnum else pos2.pos_cnum *);
|
50
|
}
|
51
|
|
52
|
let loc_line (s, _e) = s.pos_lnum
|
53
|
|
54
|
let pp fmt loc =
|
55
|
if loc = dummy then () else Format.fprintf fmt "%s" (Lex.range loc)
|
56
|
|
57
|
let pp_c fmt (s, _e) =
|
58
|
let filename = s.pos_fname in
|
59
|
let line = s.pos_lnum in
|
60
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
61
|
|
62
|
let shift (_s1, e1) (s2, e2) = shift_pos e1 s2, shift_pos e1 e2
|
63
|
|
64
|
(* Local Variables: *)
|
65
|
(* compile-command:"make -C .." *)
|
66
|
(* End: *)
|