Files
mercury/tests/valid_seq/xmlreader_helper_1.m
Zoltan Somogyi 7f64f6eae3 Rename X's aux modules as X_helper_N in valid_seq.
Do this after renaming the main modules of tests that either

- had names that did not even attempt to describe what problem
  they were intended to test for, or
- had names that include either a "test_" prefix or a "_main" suffix.

This ended up renaming most of the modules in this directory. The reason
for this is that many tests' names had an "intermod_" or "nested_" prefix.
This was useful in the valid directory, where these tests originally were,
but it is not useful here, since these tests are in the valid_seq directory
to be executed sequentially *precisely because* they involve multiple modules.

The set of renames of main modules are is:

    func_int_bug_main               ->  func_int_bug
    intermod_bug_nested             ->  spurious_match
    intermod_char                   ->  char_escape_opt
    intermod_dcg_bug                ->  dcg_bug
    intermod_impure                 ->  call_impure_in_opt
    intermod_lambda                 ->  exported_lambda
    intermod_nested                 ->  to_submods_opt
    intermod_nested_module          ->  read_submod_opt
    intermod_nested_module_bug      ->  mode_from_int0_opt
    intermod_nested_uniq            ->  head_var_unify_uniq
    intermod_quote                  ->  opt_file_quote
    intermod_record                 ->  field_access_funcs
    intermod_test                   ->  overload_resolution
    intermod_type_spec              ->  type_spec_vars
    intermod_typeclass_exist        ->  typeclass_exist_opt
    intermod_typeclass              ->  typeclass_in_opt
    intermod_pragma_import          ->  foreign_proc_import
    intermod_ua_type_spec           ->  unused_args_type_spec
    intermod_user_equality_nested   ->  user_eq_pred_nested
    intermod_user_equality          ->  user_eq_pred_nonnested
    intermod_user_sharing           ->  sharing_in_opt
    module_a                        ->  indirect_import_two_paths
    module_b                        ->  indirect_import_one_path
    module_c                        ->  DELETED
    module_d                        ->  DELETED
    module_e                        ->  DELETED
    nested_module_bug               ->  nested_module_ambiguity
    nested_mod_type_bug             ->  type_exported_to_submods
    parsing_bug_main                ->  parsing_bug
    test_xmlreader                  ->  xmlreader

Each of the new main modules includes a note about its previous name.

The old files module_[bcd].m were each used by two or more tests,
definitely including module_a and module_b, and including
module_c and module_d for some of them. The module_c and module_d tests
did not test anything that module_b did not test, and the module_e test
did not test anything useful at all, which is why this diff deletes them.
The diff also ensures that the module_a and module_b tests, under their
new names, now used disjoint sets of helper modules.

Add a note to module_a, under its new name, indirect_import_two_paths,
that despite an original log message saying that it tests importing
the same module via both direct and indirect paths, there is no actual
indirect import of the module in question.
2023-09-10 15:54:13 +10:00

158 lines
3.8 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Binding to xmlReader by Daniel Veillard.
%
:- module xmlreader_helper_1.
:- interface.
:- import_module bool.
:- import_module io.
:- import_module maybe.
:- import_module string.
:- type xmlreader.
:- pred open_file(string::in, maybe(xmlreader)::uo, io::di, io::uo) is det.
:- pred close_reader(xmlreader::di, io::di, io::uo) is det.
:- type evt
---> node(
depth :: int,
nodetype :: int,
name :: string,
is_empty :: bool,
value :: maybe(string)
)
; error(int)
; eof.
:- pred read(evt::out, xmlreader::di, xmlreader::uo) is det.
:- implementation.
:- pragma foreign_decl(c, "
/*
#include <stdio.h>
#include <libxml/xmlreader.h>
*/
").
% The original code used this, but it breaks compiling this test
% with --intermodule-optimization since xmlTextReaderPtr is undefined.
%:- pragma foreign_type("C", xmlreader, "xmlTextReaderPtr",
% [can_pass_as_mercury_type]).
:- pragma foreign_type("C", xmlreader, "MR_Word",
[can_pass_as_mercury_type]).
:- initialise c_init_xml_reader/2.
:- pred c_init_xml_reader(io::di, io::uo) is det.
:- pragma foreign_proc(c,
c_init_xml_reader(IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
** this initialize the library and check potential ABI mismatches
** between the version it was compiled for and the actual shared
** library used.
LIBXML_TEST_VERSION
*/
LIBXML_TEST_VERSION = 1;
MR_update_io(IIO, OIO);
").
open_file(FN, MayReader, !IO) :-
c_open_file(FN, OK, Rdr, !IO),
(
OK = yes,
MayReader = unsafe_promise_unique(yes(Rdr))
;
OK = no,
MayReader = unsafe_promise_unique(no)
).
:- pred c_open_file(string::in, bool::out, xmlreader::out,
io::di, io::uo) is det.
:- pragma foreign_proc(c,
c_open_file(FN::in, OK::out, Rdr::out, IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Rdr = xmlReaderForFile(FN, NULL, 0);
*/
if (Rdr == NULL) {
OK = 0;
} else {
OK = 1;
}
MR_update_io(IIO, OIO);
").
:- pragma foreign_proc(c,
close_reader(Rdr::di, IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
xmlFreeTextReader(Rdr);
*/
MR_update_io(IIO, OIO);
").
read(Evt, !Rdr) :-
c_read(Ret, !Rdr),
( if Ret = 1 then
c_get(Depth, NodeType, Name, Empty, GotVal, Val, !Rdr),
( if GotVal = yes then
MayVal = yes(Val)
else
MayVal = no
),
Evt = node(Depth, NodeType, Name, Empty, MayVal)
else if Ret = 0 then
Evt = eof
else
Evt = error(Ret)
).
:- pred c_read(int::out, xmlreader::di, xmlreader::uo) is det.
:- pragma foreign_proc(c,
c_read(Ret::out, IRdr::di, ORdr::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Ret = xmlTextReaderRead(IRdr);
*/
ORdr = IRdr;
").
:- pred c_get(int::out, int::out, string::out, bool::out,
bool::out, string::out, xmlreader::di, xmlreader::uo) is det.
:- pragma foreign_proc(c,
c_get(Depth::out, NodeType::out, Name::out, Empty::out, GotVal::out,
Val::out, IRdr::di, ORdr::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Name = xmlTextReaderConstName(IRdr);
if (Name == NULL)
Name = BAD_CAST ""--"";
Val = xmlTextReaderConstValue(IRdr);
Depth = xmlTextReaderDepth(IRdr);
NodeType = xmlTextReaderNodeType(IRdr);
Empty = xmlTextReaderIsEmptyElement(IRdr);
GotVal = xmlTextReaderHasValue(IRdr);
ORdr = IRdr;
*/
").