1 |
a2d97a3e
|
ploc
|
(********************************************************************)
|
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 |
22fe1c93
|
ploc
|
|
12 |
|
|
type t = { loc_start: Lexing.position; loc_end: Lexing.position }
|
13 |
ef34b4ae
|
xthirioux
|
|
14 |
|
|
type filename = string
|
15 |
|
|
|
16 |
22fe1c93
|
ploc
|
let dummy_loc = {loc_start=Lexing.dummy_pos; loc_end=Lexing.dummy_pos}
|
17 |
|
|
|
18 |
ef34b4ae
|
xthirioux
|
let set_input, get_input, get_module =
|
19 |
|
|
let input_name : filename ref = ref "__UNINITIALIZED__" in
|
20 |
|
|
let module_name : filename ref = ref "__UNINITIALIZED__" in
|
21 |
|
|
(fun name -> input_name := name; module_name := Filename.chop_extension name),
|
22 |
|
|
(fun () -> !input_name),
|
23 |
|
|
(fun () -> !module_name)
|
24 |
22fe1c93
|
ploc
|
|
25 |
|
|
let curr lexbuf = {
|
26 |
|
|
loc_start = lexbuf.Lexing.lex_start_p;
|
27 |
|
|
loc_end = lexbuf.Lexing.lex_curr_p
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
let init lexbuf fname =
|
31 |
|
|
lexbuf.Lexing.lex_curr_p <- {
|
32 |
|
|
Lexing.pos_fname = fname;
|
33 |
|
|
Lexing.pos_lnum = 1;
|
34 |
|
|
Lexing.pos_bol = 0;
|
35 |
|
|
Lexing.pos_cnum = 0;
|
36 |
|
|
}
|
37 |
04a63d25
|
xthirioux
|
|
38 |
|
|
let shift_pos pos1 pos2 =
|
39 |
|
|
assert (pos1.Lexing.pos_fname = pos2.Lexing.pos_fname);
|
40 |
|
|
{Lexing.pos_fname = pos1.Lexing.pos_fname;
|
41 |
|
|
Lexing.pos_lnum = pos1.Lexing.pos_lnum + pos2.Lexing.pos_lnum;
|
42 |
|
|
Lexing.pos_bol = pos1.Lexing.pos_bol + pos2.Lexing.pos_bol;
|
43 |
|
|
Lexing.pos_cnum =if pos2.Lexing.pos_lnum = 1 then pos1.Lexing.pos_cnum + pos2.Lexing.pos_cnum else pos2.Lexing.pos_cnum
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
let shift loc1 loc2 =
|
47 |
|
|
{loc_start = shift_pos loc1.loc_start loc2.loc_start;
|
48 |
|
|
loc_end = shift_pos loc1.loc_start loc2.loc_end
|
49 |
|
|
}
|
50 |
|
|
|
51 |
3826f8cb
|
ploc
|
let symbol_rloc () =
|
52 |
|
|
{
|
53 |
|
|
loc_start = Parsing.symbol_start_pos ();
|
54 |
|
|
loc_end = Parsing.symbol_end_pos ()
|
55 |
|
|
}
|
56 |
|
|
|
57 |
22fe1c93
|
ploc
|
|
58 |
|
|
open Format
|
59 |
|
|
|
60 |
|
|
let print loc =
|
61 |
|
|
let filename = loc.loc_start.Lexing.pos_fname in
|
62 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
63 |
|
|
let start_char =
|
64 |
|
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
65 |
|
|
in
|
66 |
|
|
let end_char =
|
67 |
|
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.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 |
|
|
|
82 |
|
|
let pp_loc fmt loc =
|
83 |
ec433d69
|
xthirioux
|
if loc == dummy_loc then () else
|
84 |
22fe1c93
|
ploc
|
let filename = loc.loc_start.Lexing.pos_fname in
|
85 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
86 |
|
|
let start_char =
|
87 |
|
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
88 |
|
|
in
|
89 |
|
|
let end_char =
|
90 |
|
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
|
91 |
|
|
in
|
92 |
|
|
let (start_char, end_char) =
|
93 |
|
|
if start_char < 0 then (0,1) else (start_char, end_char)
|
94 |
|
|
in
|
95 |
|
|
Format.fprintf fmt "File \"%s\", line %i, characters %i-%i:" filename line start_char end_char
|
96 |
|
|
|
97 |
|
|
let pp_c_loc fmt loc =
|
98 |
|
|
let filename = loc.loc_start.Lexing.pos_fname in
|
99 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
100 |
|
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
101 |
|
|
|
102 |
|
|
(* Local Variables: *)
|
103 |
|
|
(* compile-command:"make -C .." *)
|
104 |
|
|
(* End: *)
|