mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 02:43:40 +00:00
The usual mdb "dump" command puts every function symbol on its own line.
This guarantees that we generate any line that is too long to be displayed
on terminals, but it also generates output that is too stretched out
vertically for its structure to be readily apparent. Dumping the term
as a doc allows pretty_printer.m to put as many function symbols on a line
as would fit, without exceeding the maximum line length.
browser/browse.m:
Add save_term_to_file_doc, a way to save a (possibly synthetic)
browser term in a file, using an interface that works the same way
the predicate that saves browser terms as XML.
Inline a predicate at its only call site. Improve variable names.
trace/mercury_trace_browse.[ch]:
Add MR_trace_save_term_as_doc, as an interface function between
save_term_to_file_doc and the code of mercury_trace_cmd_browsing.c.
trace/mercury_trace_cmd_browsing.c:
Add support for a new -p/--prettyprint flag to the mdb "dump" command,
which asks for the given term to be dumped as a pretty_printer doc.
doc/user_guide.texi:
NEWS:
Document the new option.
library/pretty_printer.m:
NEWS:
Rename write_as_doc to write_doc_formatted, and fix its argument type.
tests/debugger/browser_test.inp:
Dump a term that we already dumped with "dump" with "dump -x" and
"dump -p" as well.
tests/debugger/browser_test.m:
Put the code to remove the files we are going to dump to
and then later to print the files we have dumped to into separate
predicates. This keeps most (but not all) line numbers unchanged
even though we now dump to more files.
tests/debugger/browser_test.exp3:
Update this file to account both for the extra output from the just-added
dump commands, and for the changes in line numbers.
134 lines
3.1 KiB
Mathematica
134 lines
3.1 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
% The .exp file is for ???.
|
|
% The .exp2 file is for ???.
|
|
% The .exp3 file is for asm_fast.gc and asm_fast.gc.debug.
|
|
|
|
:- module browser_test.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
:- import_module io.file.
|
|
:- import_module list.
|
|
|
|
:- type big
|
|
---> big(big, int, big)
|
|
; small
|
|
; seq(int, list(big), int).
|
|
|
|
main(!IO) :-
|
|
% In case we have these files lying around.
|
|
remove_dump_files(!IO),
|
|
big_data(Data),
|
|
io.print(Data, !IO),
|
|
io.write_string(".\n", !IO),
|
|
list_data(List),
|
|
io.print(List, !IO),
|
|
io.write_string(".\n", !IO),
|
|
print_dump_files(!IO),
|
|
% Clean up after the test.
|
|
remove_dump_files(!IO),
|
|
a_func(Data) = Data2,
|
|
io.write(Data2, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred big_data(big::out) is det.
|
|
|
|
big_data(Data) :-
|
|
Data = big(
|
|
big(
|
|
big(
|
|
small,
|
|
1,
|
|
small
|
|
),
|
|
2,
|
|
small
|
|
),
|
|
3,
|
|
big(
|
|
big(
|
|
small,
|
|
4,
|
|
big(
|
|
small,
|
|
5,
|
|
small
|
|
)
|
|
),
|
|
6,
|
|
small
|
|
)
|
|
).
|
|
|
|
:- pred list_data(big::out) is det.
|
|
|
|
list_data(Data) :-
|
|
Element1 = big(
|
|
big(
|
|
small,
|
|
1,
|
|
small
|
|
),
|
|
2,
|
|
small
|
|
),
|
|
Element2 = small,
|
|
Element3 = big(
|
|
small,
|
|
4,
|
|
big(
|
|
small,
|
|
5,
|
|
small
|
|
)
|
|
),
|
|
Data = seq(1, [Element1, Element2, Element3], 5).
|
|
|
|
:- pred print_file(string::in, io::di, io::uo) is det.
|
|
|
|
print_file(FileName, !IO) :-
|
|
io.open_input(FileName, OpenRes, !IO),
|
|
(
|
|
OpenRes = ok(Stream),
|
|
io.read_file_as_string(Stream, ReadRes, !IO),
|
|
(
|
|
ReadRes = ok(Contents),
|
|
io.write_string(FileName, !IO),
|
|
io.write_string(":\n", !IO),
|
|
io.write_string(Contents, !IO),
|
|
io.write_string("\n", !IO)
|
|
;
|
|
ReadRes = error(_, _),
|
|
io.write_string("read failed\n", !IO)
|
|
)
|
|
;
|
|
OpenRes = error(_),
|
|
io.write_string("open failed\n", !IO)
|
|
).
|
|
|
|
:- func a_func(big) = big.
|
|
|
|
a_func(_) = Big :-
|
|
big_data(Big).
|
|
|
|
:- pred remove_dump_files(io::di, io::uo) is det.
|
|
|
|
remove_dump_files(!IO) :-
|
|
io.file.remove_file("browser_test.save.1", _, !IO),
|
|
io.file.remove_file("browser_test.save.2", _, !IO),
|
|
io.file.remove_file("browser_test.save.3", _, !IO),
|
|
io.file.remove_file("browser_test.save.4", _, !IO).
|
|
|
|
:- pred print_dump_files(io::di, io::uo) is det.
|
|
|
|
print_dump_files(!IO) :-
|
|
print_file("browser_test.save.1", !IO),
|
|
print_file("browser_test.save.2", !IO),
|
|
print_file("browser_test.save.3", !IO),
|
|
print_file("browser_test.save.4", !IO).
|