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
|
|
14
|
module Lex = MenhirLib.LexerUtil
|
15
|
|
16
|
type t = position * position
|
17
|
|
18
|
type filename = string
|
19
|
|
20
|
let dummy_loc = dummy_pos, dummy_pos
|
21
|
|
22
|
let set_input, get_input, get_module =
|
23
|
let input_name : filename ref = ref "__UNINITIALIZED__" in
|
24
|
let module_name : filename ref = ref "__UNINITIALIZED__" in
|
25
|
(fun name -> input_name := name; module_name := Filename.chop_extension name),
|
26
|
(fun () -> !input_name),
|
27
|
(fun () -> !module_name)
|
28
|
|
29
|
let curr lexbuf =
|
30
|
lexbuf.lex_start_p, lexbuf.lex_curr_p
|
31
|
|
32
|
let filename_of_loc (s, _) =
|
33
|
s.pos_fname
|
34
|
|
35
|
let filename_of_lexbuf lexbuf =
|
36
|
lexbuf.lex_start_p.pos_fname
|
37
|
|
38
|
(* let init lexbuf fname =
|
39
|
* lexbuf.Lexing.lex_curr_p <- {
|
40
|
* Lexing.pos_fname = fname;
|
41
|
* Lexing.pos_lnum = 1;
|
42
|
* Lexing.pos_bol = 0;
|
43
|
* Lexing.pos_cnum = 0;
|
44
|
* } *)
|
45
|
|
46
|
let shift_pos pos1 pos2 =
|
47
|
(* Format.eprintf "Shift pos %s by pos %s@." pos1.Lexing.pos_fname pos2.Lexing.pos_fname;
|
48
|
* assert (pos1.Lexing.pos_fname = pos2.Lexing.pos_fname); *)
|
49
|
{
|
50
|
pos_fname = pos1.pos_fname;
|
51
|
pos_lnum = pos1.pos_lnum + pos2.pos_lnum - 1;
|
52
|
|
53
|
(* New try *)
|
54
|
(* pos_bol = pos2.pos_bol; *)
|
55
|
pos_bol = pos1.pos_bol + pos2.pos_bol;
|
56
|
pos_cnum = pos1.pos_cnum + pos2.pos_cnum
|
57
|
(* pos_cnum = pos2.pos_cnum; *)
|
58
|
(*
|
59
|
pos_bol = pos1.pos_bol + pos2.pos_bol;
|
60
|
pos_cnum =if pos2.pos_lnum = 1 then pos1.pos_cnum + pos2.pos_cnum else pos2.pos_cnum
|
61
|
*)
|
62
|
}
|
63
|
|
64
|
|
65
|
(* let print loc =
|
66
|
* let filename = loc.loc_start.pos_fname in
|
67
|
* let line = loc.loc_start.pos_lnum in
|
68
|
* let start_char =
|
69
|
* loc.loc_start.pos_cnum - loc.loc_start.pos_bol
|
70
|
* in
|
71
|
* let end_char =
|
72
|
* loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + start_char
|
73
|
* in
|
74
|
* let (start_char, end_char) =
|
75
|
* if start_char < 0 then (0,1) else (start_char, end_char)
|
76
|
* in
|
77
|
* print_string ("File \""^filename^"\", line ");
|
78
|
* print_int line;
|
79
|
* print_string ", characters ";
|
80
|
* print_int start_char;
|
81
|
* print_string "-";
|
82
|
* print_int end_char;
|
83
|
* print_string ":";
|
84
|
* print_newline () *)
|
85
|
|
86
|
let loc_line (s, _e) = s.pos_lnum
|
87
|
|
88
|
let pp_loc fmt loc =
|
89
|
if loc == dummy_loc then
|
90
|
()
|
91
|
else
|
92
|
Format.fprintf fmt "%s" (Lex.range loc)
|
93
|
|
94
|
let pp_c_loc fmt (s, _e) =
|
95
|
let filename = s.pos_fname in
|
96
|
let line = s.pos_lnum in
|
97
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
98
|
|
99
|
let shift (_s1, e1) (s2, e2) =
|
100
|
shift_pos e1 s2,
|
101
|
shift_pos e1 e2
|
102
|
|
103
|
(* Local Variables: *)
|
104
|
(* compile-command:"make -C .." *)
|
105
|
(* End: *)
|