1 |
e2068500
|
Temesghen Kahsai
|
(********************************************************************)
|
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 |
|
|
type t = { loc_start: Lexing.position; loc_end: Lexing.position }
|
13 |
|
|
|
14 |
|
|
type filename = string
|
15 |
|
|
|
16 |
|
|
let dummy_loc = {loc_start=Lexing.dummy_pos; loc_end=Lexing.dummy_pos}
|
17 |
|
|
|
18 |
|
|
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 |
|
|
|
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 |
|
|
|
38 |
|
|
let symbol_rloc () =
|
39 |
|
|
{
|
40 |
|
|
loc_start = Parsing.symbol_start_pos ();
|
41 |
|
|
loc_end = Parsing.symbol_end_pos ()
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
open Format
|
46 |
|
|
|
47 |
|
|
let print loc =
|
48 |
|
|
let filename = loc.loc_start.Lexing.pos_fname in
|
49 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
50 |
|
|
let start_char =
|
51 |
|
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
52 |
|
|
in
|
53 |
|
|
let end_char =
|
54 |
|
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
|
55 |
|
|
in
|
56 |
|
|
let (start_char, end_char) =
|
57 |
|
|
if start_char < 0 then (0,1) else (start_char, end_char)
|
58 |
|
|
in
|
59 |
|
|
print_string ("File \""^filename^"\", line ");
|
60 |
|
|
print_int line;
|
61 |
|
|
print_string ", characters ";
|
62 |
|
|
print_int start_char;
|
63 |
|
|
print_string "-";
|
64 |
|
|
print_int end_char;
|
65 |
|
|
print_string ":";
|
66 |
|
|
print_newline ()
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
let pp_loc fmt loc =
|
70 |
d50b0dc0
|
Temesghen Kahsai
|
if loc == dummy_loc then () else
|
71 |
e2068500
|
Temesghen Kahsai
|
let filename = loc.loc_start.Lexing.pos_fname in
|
72 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
73 |
|
|
let start_char =
|
74 |
|
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
75 |
|
|
in
|
76 |
|
|
let end_char =
|
77 |
|
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
|
78 |
|
|
in
|
79 |
|
|
let (start_char, end_char) =
|
80 |
|
|
if start_char < 0 then (0,1) else (start_char, end_char)
|
81 |
|
|
in
|
82 |
|
|
Format.fprintf fmt "File \"%s\", line %i, characters %i-%i:" filename line start_char end_char
|
83 |
|
|
|
84 |
|
|
let pp_c_loc fmt loc =
|
85 |
|
|
let filename = loc.loc_start.Lexing.pos_fname in
|
86 |
|
|
let line = loc.loc_start.Lexing.pos_lnum in
|
87 |
|
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
88 |
|
|
|
89 |
|
|
(* Local Variables: *)
|
90 |
|
|
(* compile-command:"make -C .." *)
|
91 |
|
|
(* End: *)
|