2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
49 (* Dump an OCaml value into a printable string.
50 * By Richard W.M. Jones (rich@annexia.org).
51 * dumper.ml 1.2 2005/02/06 12:38:21 rich Exp
59 string_of_int
(magic r
: int)
61 let rec get_fields acc
= function
63 | n
-> let n = n-1 in get_fields (field r
n :: acc
) n
67 if (magic r
: int) = 0 then true (* [] *)
70 let s = size r
and t
= tag r
in
71 if t
= 0 && s = 2 then is_list (field r
1) (* h :: t *)
77 else let h = field r
0 and t
= get_list (field r
1) in h :: t
80 (* XXX In future, print the address of value 'r'. Not possible in
81 * pure OCaml at the moment.
86 let s = size r
and t
= tag r
in
88 (* From the tag, determine the type of block. *)
89 if is_list r
then ( (* List. *)
90 let fields = get_list r
in
91 "[" ^
String.concat
"; " (List.map
dump fields) ^
"]"
93 else if t
= 0 then ( (* Tuple, array, record. *)
94 let fields = get_fields [] s in
95 "(" ^
String.concat
", " (List.map
dump fields) ^
")"
98 (* Note that [lazy_tag .. forward_tag] are < no_scan_tag. Not
99 * clear if very large constructed values could have the same
101 else if t
= lazy_tag
then opaque "lazy"
102 else if t
= closure_tag
then opaque "closure"
103 else if t
= object_tag
then ( (* Object. *)
104 let fields = get_fields [] s in
105 let clasz, id
, slots
=
106 match fields with h::h'
::t
-> h, h'
, t
| _
-> assert false in
107 (* No information on decoding the class (first field). So just print
108 * out the ID and the slots.
110 "Object #" ^
dump id ^
111 " (" ^
String.concat
", " (List.map
dump slots
) ^
")"
113 else if t
= infix_tag
then opaque "infix"
114 else if t
= forward_tag
then opaque "forward"
116 else if t
< no_scan_tag
then ( (* Constructed value. *)
117 let fields = get_fields [] s in
118 "Tag" ^ string_of_int t ^
119 " (" ^
String.concat
", " (List.map
dump fields) ^
")"
121 else if t
= string_tag
then (
122 "\"" ^
String.escaped
(magic r
: string) ^
"\""
124 else if t
= double_tag
then (
125 string_of_float
(magic r
: float)
127 else if t
= abstract_tag
then opaque "abstract"
128 else if t
= custom_tag
then opaque "custom"
129 else if t
= final_tag
then opaque "final"
130 else failwith
("dump: impossible tag (" ^ string_of_int t ^
")")
133 let dump v
= dump (repr v
)