Skip to content
This repository
Newer
Older
100644 73 lines (55 sloc) 2.078 kb
fccc6851 »
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (* CF mli *)
19
20 type filename = string
21 type line_number = int
22
23 let private_filename = ref ( "<unnamed file>" : filename )
24 let private_line_number = ref ( (-1) : line_number )
25
26 (* The last directive is set by BslRegisterLib,
27 so that the parser can make some context check *)
28 let private_last_directive = ref None
29 let set_last_directive directive = private_last_directive := Some directive
30 let get_last_directive () = !private_last_directive
31
32 let make_pos () = FilePos.make_pos_from_line !private_filename !private_line_number
33
34 let pp_citation fmt () =
35 let pos = make_pos () in
36 if FilePos.is_empty pos then
37 Format.fprintf fmt "File \"%s\", line %d@\n" !private_filename !private_line_number
38 else
39 FilePos.citation fmt pos
40
41 let warning fmt =
42 OManager.warning ~wclass:WarningClass.bsl_register ("@\n%a"^^fmt) pp_citation ()
43
44 let error fmt =
45 OManager.printf "%a" pp_citation () ;
46 OManager.error fmt
47
48 module TypeVar =
49 struct
50 let tbl = Hashtbl.create 10
51
52 let var name =
53 try Hashtbl.find tbl name with
54 | Not_found ->
55 let typevar = BslTypes.TypeVar.next ~name () in
56 Hashtbl.add tbl name typevar;
57 typevar
58
59 let fresh () =
60 BslTypes.TypeVar.next ()
61
62 let reset () =
63 Hashtbl.clear tbl
64 end
65
66 let init_file ~filename =
67 private_last_directive := None;
68 private_filename := filename
69
70 let init_line ~line_number =
71 TypeVar.reset ();
72 private_line_number := line_number
Something went wrong with that request. Please try again.