1
|
(* ----------------------------------------------------------------------------
|
2
|
* SchedMCore - A MultiCore Scheduling Framework
|
3
|
* Copyright (C) 2009-2011, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE
|
4
|
*
|
5
|
* This file is part of Prelude
|
6
|
*
|
7
|
* Prelude is free software; you can redistribute it and/or
|
8
|
* modify it under the terms of the GNU Lesser General Public License
|
9
|
* as published by the Free Software Foundation ; either version 2 of
|
10
|
* the License, or (at your option) any later version.
|
11
|
*
|
12
|
* Prelude is distributed in the hope that it will be useful, but
|
13
|
* WITHOUT ANY WARRANTY ; without even the implied warranty of
|
14
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
15
|
* Lesser General Public License for more details.
|
16
|
*
|
17
|
* You should have received a copy of the GNU Lesser General Public
|
18
|
* License along with this program ; if not, write to the Free Software
|
19
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
20
|
* USA
|
21
|
*---------------------------------------------------------------------------- *)
|
22
|
|
23
|
type t = { loc_start: Lexing.position; loc_end: Lexing.position }
|
24
|
let dummy_loc = {loc_start=Lexing.dummy_pos; loc_end=Lexing.dummy_pos}
|
25
|
|
26
|
let input_name = ref ""
|
27
|
|
28
|
let curr lexbuf = {
|
29
|
loc_start = lexbuf.Lexing.lex_start_p;
|
30
|
loc_end = lexbuf.Lexing.lex_curr_p
|
31
|
}
|
32
|
|
33
|
let init lexbuf fname =
|
34
|
lexbuf.Lexing.lex_curr_p <- {
|
35
|
Lexing.pos_fname = fname;
|
36
|
Lexing.pos_lnum = 1;
|
37
|
Lexing.pos_bol = 0;
|
38
|
Lexing.pos_cnum = 0;
|
39
|
}
|
40
|
|
41
|
let symbol_rloc () =
|
42
|
{
|
43
|
loc_start = Parsing.symbol_start_pos ();
|
44
|
loc_end = Parsing.symbol_end_pos ()
|
45
|
}
|
46
|
|
47
|
|
48
|
open Format
|
49
|
|
50
|
let print loc =
|
51
|
let filename = loc.loc_start.Lexing.pos_fname in
|
52
|
let line = loc.loc_start.Lexing.pos_lnum in
|
53
|
let start_char =
|
54
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
55
|
in
|
56
|
let end_char =
|
57
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
|
58
|
in
|
59
|
let (start_char, end_char) =
|
60
|
if start_char < 0 then (0,1) else (start_char, end_char)
|
61
|
in
|
62
|
print_string ("File \""^filename^"\", line ");
|
63
|
print_int line;
|
64
|
print_string ", characters ";
|
65
|
print_int start_char;
|
66
|
print_string "-";
|
67
|
print_int end_char;
|
68
|
print_string ":";
|
69
|
print_newline ()
|
70
|
|
71
|
|
72
|
let pp_loc fmt loc =
|
73
|
let filename = loc.loc_start.Lexing.pos_fname in
|
74
|
let line = loc.loc_start.Lexing.pos_lnum in
|
75
|
let start_char =
|
76
|
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
|
77
|
in
|
78
|
let end_char =
|
79
|
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
|
80
|
in
|
81
|
let (start_char, end_char) =
|
82
|
if start_char < 0 then (0,1) else (start_char, end_char)
|
83
|
in
|
84
|
Format.fprintf fmt "File \"%s\", line %i, characters %i-%i:" filename line start_char end_char
|
85
|
|
86
|
let pp_c_loc fmt loc =
|
87
|
let filename = loc.loc_start.Lexing.pos_fname in
|
88
|
let line = loc.loc_start.Lexing.pos_lnum in
|
89
|
Format.fprintf fmt "#line %i \"%s\"" line filename
|
90
|
|
91
|
(* Local Variables: *)
|
92
|
(* compile-command:"make -C .." *)
|
93
|
(* End: *)
|