Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

lustrec / src / location.ml @ b38ffff3

History | View | Annotate | Download (2.57 KB)

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
type t = { loc_start: Lexing.position; loc_end: Lexing.position }
13
let dummy_loc = {loc_start=Lexing.dummy_pos; loc_end=Lexing.dummy_pos}
14

    
15
let input_name = ref ""
16

    
17
let curr lexbuf = {
18
  loc_start = lexbuf.Lexing.lex_start_p;
19
  loc_end = lexbuf.Lexing.lex_curr_p
20
}
21

    
22
let init lexbuf fname =
23
  lexbuf.Lexing.lex_curr_p <- {
24
    Lexing.pos_fname = fname;
25
    Lexing.pos_lnum = 1;
26
    Lexing.pos_bol = 0;
27
    Lexing.pos_cnum = 0;
28
  }
29
      
30
let symbol_rloc () = 
31
  {
32
    loc_start = Parsing.symbol_start_pos ();
33
    loc_end = Parsing.symbol_end_pos ()
34
  }
35
    
36

    
37
open Format
38

    
39
let print loc =
40
  let filename = loc.loc_start.Lexing.pos_fname in
41
  let line = loc.loc_start.Lexing.pos_lnum in
42
  let start_char =
43
    loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
44
  in
45
  let end_char =
46
    loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
47
  in
48
  let (start_char, end_char) =
49
    if start_char < 0 then (0,1) else (start_char, end_char)
50
  in
51
  print_string ("File \""^filename^"\", line ");
52
  print_int line;
53
  print_string ", characters ";
54
  print_int start_char;
55
  print_string "-";
56
  print_int end_char;
57
  print_string ":";
58
  print_newline ()
59

    
60

    
61
let pp_loc fmt loc =
62
  let filename = loc.loc_start.Lexing.pos_fname in
63
  let line = loc.loc_start.Lexing.pos_lnum in
64
  let start_char =
65
    loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
66
  in
67
  let end_char =
68
    loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
69
  in
70
  let (start_char, end_char) =
71
    if start_char < 0 then (0,1) else (start_char, end_char)
72
  in
73
  Format.fprintf fmt "File \"%s\", line %i, characters %i-%i:" filename line start_char end_char
74

    
75
let pp_c_loc fmt loc =
76
  let filename = loc.loc_start.Lexing.pos_fname in
77
  let line = loc.loc_start.Lexing.pos_lnum in
78
  Format.fprintf fmt "#line %i \"%s\"" line filename
79

    
80
(* Local Variables: *)
81
(* compile-command:"make -C .." *)
82
(* End: *)