Project

General

Profile

Download (2.88 KB) Statistics
| Branch: | Tag: | Revision:
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
  loc_start = Parsing.symbol_start_pos ();
43
  loc_end = Parsing.symbol_end_pos ()
44
}
45

    
46
open Format
47

    
48
let print loc =
49
  let filename = loc.loc_start.Lexing.pos_fname in
50
  let line = loc.loc_start.Lexing.pos_lnum in
51
  let start_char =
52
    loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
53
  in
54
  let end_char =
55
    loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
56
  in
57
  let (start_char, end_char) =
58
    if start_char < 0 then (0,1) else (start_char, end_char)
59
  in
60
  print_string ("File \""^filename^"\", line ");
61
  print_int line;
62
  print_string ", characters ";
63
  print_int start_char;
64
  print_string "-";
65
  print_int end_char;
66
  print_string ":";
67
  print_newline ()
68

    
69

    
70
let pp_loc fmt loc =
71
  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: *)
(28-28/46)