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_loc = 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 init lexbuf fname =
|
37
|
* lexbuf.Lexing.lex_curr_p <- {
|
38
|
* Lexing.pos_fname = fname;
|
39
|
* Lexing.pos_lnum = 1;
|
40
|
* Lexing.pos_bol = 0;
|
41
|
* Lexing.pos_cnum = 0;
|
42
|
* } *)
|
43
|
|
44
|
let shift_pos pos1 pos2 =
|
45
|
(* Format.eprintf "Shift pos %s by pos %s@." pos1.Lexing.pos_fname pos2.Lexing.pos_fname;
|
46
|
* assert (pos1.Lexing.pos_fname = pos2.Lexing.pos_fname); *)
|
47
|
{
|
48
|
pos_fname = pos1.pos_fname;
|
49
|
pos_lnum = pos1.pos_lnum + pos2.pos_lnum - 1;
|
50
|
(* New try *)
|
51
|
(* pos_bol = pos2.pos_bol; *)
|
52
|
pos_bol = pos1.pos_bol + pos2.pos_bol;
|
53
|
pos_cnum =
|
54
|
pos1.pos_cnum + pos2.pos_cnum
|
55
|
(* pos_cnum = pos2.pos_cnum; *)
|
56
|
(* pos_bol = pos1.pos_bol + pos2.pos_bol; pos_cnum =if pos2.pos_lnum = 1
|
57
|
then pos1.pos_cnum + pos2.pos_cnum else pos2.pos_cnum *);
|
58
|
}
|
59
|
|
60
|
(* let print loc =
|
61
|
* let filename = loc.loc_start.pos_fname in
|
62
|
* let line = loc.loc_start.pos_lnum in
|
63
|
* let start_char =
|
64
|
* loc.loc_start.pos_cnum - loc.loc_start.pos_bol
|
65
|
* in
|
66
|
* let end_char =
|
67
|
* loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + start_char
|
68
|
* in
|
69
|
* let (start_char, end_char) =
|
70
|
* if start_char < 0 then (0,1) else (start_char, end_char)
|
71
|
* in
|
72
|
* print_string ("File \""^filename^"\", line ");
|
73
|
* print_int line;
|
74
|
* print_string ", characters ";
|
75
|
* print_int start_char;
|
76
|
* print_string "-";
|
77
|
* print_int end_char;
|
78
|
* print_string ":";
|
79
|
* print_newline () *)
|
80
|
|
81
|
let loc_line (s, _e) = s.pos_lnum
|
82
|
|
83
|
let pp_loc fmt loc =
|
84
|
if loc == dummy_loc then () else Format.fprintf fmt "%s" (Lex.range loc)
|
85
|
|
86
|
let pp_c_loc fmt (s, _e) =
|
87
|
let filename = s.pos_fname in
|
88
|
let line = s.pos_lnum in
|
89
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
90
|
|
91
|
let shift (_s1, e1) (s2, e2) = shift_pos e1 s2, shift_pos e1 e2
|
92
|
|
93
|
(* Local Variables: *)
|
94
|
(* compile-command:"make -C .." *)
|
95
|
(* End: *)
|