Initial snarf.
[shack.git] / arch / mir / util / mir_pos.ml
blob9c21707cfa27554e924d268ffc3f982ba6c39611
1 (*
2 * Normal MIR exceptions.
4 * ----------------------------------------------------------------
6 * @begin[license]
7 * Copyright (C) 2001 Jason Hickey, Caltech
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Author: Jason Hickey
24 * @email{jyh@cs.caltech.edu}
25 * @end[license]
27 open Format
29 open Debug
30 open Symbol
31 open Location
33 open Fir_print
34 open Fir_state
36 open Mir
37 open Mir_ds
38 open Mir_exn
39 open Mir_print
42 * Location of exception.
44 type item =
45 Exp of exp
46 | Atom of atom
47 | AtomClass of atom_class
48 | Symbol of var
49 | String of string
51 type pos = item Position.pos
54 * FIR exception.
56 exception MirException of pos * mir_error
58 (************************************************************************
59 * UTILITIES
60 ************************************************************************)
63 * Get the source location for an exception.
65 let string_loc = bogus_loc "<Mir_pos>"
67 let rec loc_of_value x =
68 match x with
69 Exp e ->
70 loc_of_exp e
71 | Atom _
72 | AtomClass _
73 | Symbol _
74 | String _ ->
75 string_loc
78 * Print debugging info.
80 let rec pp_print_value buf x =
81 match x with
82 Exp e ->
83 pp_print_expr_size (exn_expr_size ()) buf e
85 | Atom a ->
86 pp_print_atom buf a
88 | AtomClass ac ->
89 pp_print_atom_class buf ac
91 | Symbol v ->
92 pp_print_symbol buf v
94 | String s ->
95 pp_print_string buf s
97 (************************************************************************
98 * CONSTRUCTION
99 ************************************************************************)
101 module type PosSig =
103 val loc_pos : loc -> pos
105 val exp_pos : exp -> pos
106 val var_exp_pos : var -> pos
107 val string_exp_pos : string -> pos
108 val string_pos : string -> pos -> pos
109 val pos_pos : pos -> pos -> pos
110 val int_pos : int -> pos -> pos
111 val var_pos : var -> pos -> pos
112 val atom_pos : atom -> pos -> pos
113 val atom_class_pos : atom_class -> pos -> pos
115 val del_pos : (formatter -> unit) -> loc -> pos
116 val del_exp_pos : (formatter -> unit) -> pos -> pos
118 (* Utilities *)
119 val loc_of_pos : pos -> loc
120 val pp_print_pos : formatter -> pos -> unit
123 module type NameSig =
125 val name : string
128 module MakePos (Name : NameSig) : PosSig =
129 struct
130 module Name' =
131 struct
132 type t = item
134 let name = Name.name
136 let loc_of_value = loc_of_value
137 let pp_print_value = pp_print_value
140 module Pos = Position.MakePos (Name')
142 include Pos
144 let exp_pos e = base_pos (Exp e)
145 let atom_pos a pos = cons_pos (Atom a) pos
146 let atom_class_pos ac pos = cons_pos (AtomClass ac) pos
147 let var_exp_pos v = base_pos (Symbol v)
148 let string_exp_pos s = base_pos (String s)
149 let var_pos = symbol_pos
153 * @docoff
155 * -*-
156 * Local Variables:
157 * Caml-master: "compile"
158 * End:
159 * -*-