Files
mercury/trace/mercury_trace_browse.h
Zoltan Somogyi 31ad9a21e1 Allow terms to be dumped as docs in mdb.
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.
2022-08-25 16:39:50 +10:00

130 lines
4.9 KiB
C

// vim: ts=4 sw=4 expandtab ft=c
// Copyright (C) 1998-2002, 2004-2006 The University of Melbourne.
// Copyright (C) 2017-2018 The Mercury team.
// This file is distributed under the terms specified in COPYING.LIB.
// mercury_trace_browse.h
//
// Defines the interface of the term browser and the interactive query
// facility for the internal and external debuggers.
#ifndef MERCURY_TRACE_BROWSE_H
#define MERCURY_TRACE_BROWSE_H
#include "mercury_conf.h" // for MR_USE_EXTERNAL_DEBUGGER
#include "mercury_types.h" // for MR_Word, MR_String
#include "mercury_std.h" // for MR_bool
#include "mercury_tags.h" // for MR_DEFINE_MERCURY_ENUM_CONST
#include <stdio.h> // for FILE
// Convert a term (expressed either as a typeinfo/value pair or as a univ)
// or a synthetic term to a browser term.
extern MR_Word MR_type_value_to_browser_term(MR_TypeInfo type_info,
MR_Word value);
extern MR_Word MR_univ_to_browser_term(MR_Word univ);
extern MR_Word MR_synthetic_to_browser_term(const char *functor,
MR_Word arg_list, MR_bool is_func);
// Save the given browser term to the named file.
extern void MR_trace_save_term(const char *filename,
MR_Word browser_term);
extern void MR_trace_save_term_xml(const char *filename,
MR_Word browser_term);
extern void MR_trace_save_term_doc(const char *filename,
MR_Word browser_term);
// The constants defined by the following enums must correspond with the
// values in the representation of browse_caller_type and portray_format in
// browser/browser_info.m, so that it is possible to cast to/from MR_Word
// in order to interface with Mercury code.
typedef enum {
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_CALLER_PRINT),
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_CALLER_BROWSE),
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_CALLER_PRINT_ALL)
} MR_BrowseCallerType;
typedef enum {
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_FLAT),
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_RAW_PRETTY),
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_VERBOSE),
MR_DEFINE_MERCURY_ENUM_CONST(MR_BROWSE_FORMAT_PRETTY)
} MR_BrowseFormat;
// This value must be different from any of the MR_BROWSE_FORMAT_* values.
#define MR_BROWSE_DEFAULT_FORMAT -1
// If *str represents a value of type MR_BrowseFormat, set *format to that
// value.
extern MR_bool MR_trace_is_portray_format(const char *str,
MR_BrowseFormat *format);
// Interactively browse a term.
extern void MR_trace_browse(MR_Word type_info, MR_Word value,
MR_BrowseFormat format);
extern void MR_trace_browse_goal(MR_ConstString name, MR_Word arg_list,
MR_Word is_func, MR_BrowseFormat format);
#ifdef MR_USE_EXTERNAL_DEBUGGER
extern void MR_trace_browse_external(MR_Word type_info, MR_Word value,
MR_BrowseCallerType caller, MR_BrowseFormat format);
#endif
// Browse a term using a web browser.
extern void MR_trace_save_and_invoke_web_browser(MR_Word browser_term);
// Display a term non-interactively.
extern void MR_trace_print(MR_Word type_info, MR_Word value,
MR_BrowseCallerType caller, MR_BrowseFormat format);
extern void MR_trace_print_goal(MR_ConstString name, MR_Word arg_list,
MR_Word is_func, MR_BrowseCallerType caller,
MR_BrowseFormat format);
// Print all the browser parameters in the form of the mdb commands required to
// recreate this state.
extern void MR_trace_print_all_browser_params(FILE *fp);
// Invoke an interactive query.
// The constants defined by the following enum must correspond with the
// values in the representation of query_type in browser/interactive.m, so
// that it is possible to cast to/from MR_Word in order to interface with
// Mercury code.
typedef enum {
MR_DEFINE_MERCURY_ENUM_CONST(MR_NORMAL_QUERY),
MR_DEFINE_MERCURY_ENUM_CONST(MR_CC_QUERY),
MR_DEFINE_MERCURY_ENUM_CONST(MR_IO_QUERY)
} MR_QueryType;
extern void MR_trace_query(MR_QueryType type, const char *options,
int num_imports, /* const */ char *imports[]);
#ifdef MR_USE_EXTERNAL_DEBUGGER
extern void MR_trace_query_external(MR_QueryType type,
MR_String options, int num_imports,
MR_Word imports_list);
#endif
// Points to the state of the interactive term browser that should persist
// between browsing sessions, like the format settings.
extern MR_Word MR_trace_browser_persistent_state;
extern MR_TypeInfo MR_trace_browser_persistent_state_type;
// Initializes the interactive term browser persistent state, or does nothing
// if it has already been initialized.
extern void MR_trace_browse_ensure_init(void);
#endif // MERCURY_TRACE_BROWSE_H