Pa_type_conv: Preprocessing Module for Registering Type Conversions
set_conv_path_if_not_set loc
sets the path to the file/module being
converted for improved error messages.
get_conv_path ()
add_generator ?is_exn name gen
adds the code generator gen
,
which maps type or exception declarations to structure items, where
is_exn
specifies whether the declaration is an exception. Note that
the original type/exception declarations get added automatically in
any case.
false
add_generator_with_arg ?is_exn name entry generator
same as
add_generator
, but the generator may accept an argument, which is
parsed with entry
.
rm_generator ?is_exn name
removes the code generator named name
for types if is_exn
is false
, or exceptions otherwise.
false
add_sig_generator ?delayed ?is_exn name gen
adds the code generator gen
,
which maps type or exception declarations to signature items, where
is_exn
specifies whether the declaration is an exception. Note that the
original type/exception declarations get added automatically in any case. If
delayed
is set to true, the output of this generator is appended to the
signature in which it's defined
false
false
add_sig_generator_with_arg ?delayed ?is_exn name entry generator
same as
add_sig_generator
, but the generator may accept an argument,
which is parsed with entry
.
rm_sig_generator ?is_exn name
removes the signature code generator named
name
for types if is_exn
is false
, or exceptions otherwise.
false
Type of record field code generators
add_record_field_generator gen_name gen
adds the record field code
generator gen
with name gen_name
, which acts on the location
identifying the record field.
add_record_field_generator_with_arg name entry generator
same as
add_record_field_generator
, but the generator
takes an argument,
which is parsed with entry
. If None
is passed to the generator,
parsing of the argument failed, otherwise Some arg
will be passed,
where arg
is the successfully parsed argument.
rm_record_field_generator name
removes the record field code generator
named name
.
add_sig_set ?is_exn id ~set
adds the generator id
to the list
of generators for signatures.
This generator will behave as if is all the generators from set
had been given instead. Any duplicate arising from repeatedly
expanding such generators are removed.
If is_exn
, then it is a generator for exception declaration, or
else it is a generator for type declaration.
add_str_set ?is_exn id ~set
behaves exactly like
add_sig_set ?is_exn id ~set
but for structure items instead of
signatures items.
add_set ~kind ~is_exn id ~set
is a shorthand for doing multiple
calls to add_str_set
and add_sig_set
get_loc_err loc msg
generates a compile-time error message.
hash_variant str
str
.
expr_app_of_list l
takes list l
of expressions e1; e2; e3; ...
and returns the expression e1 e2 e3
. C.f.: Ast.exSem_of_list
.
tyArr_of_list l
takes list l
of types e1; e2; e3; ...
and
returns the type e1 -> e2 -> e3
. C.f.: Ast.exSem_of_list
.
paOr_of_list l
takes list l
of patterns p1; p2; p3; ...
and returns
the pattern p1 | p2 | p3 | ...
gensym ?prefix ()
generates a fresh variable name with prefix
.
When used with the default parameters, it will return: _x__001
,
_x__002
, _x__003
, ...
error tp ~fn ~msg
raises an error with msg
on type tp
occuring
in function fn
.
unknown_type tp fn
type tp
cannot be handled by function fn
.
ty_var_list_of_ctyp tp acc
accumulates a list of type parameters
contained in tp
into acc
as strings.
get_rev_id_path id acc
takes an identifier.
acc
.
ident_of_rev_path loc path
takes a location loc
and a reversed path
rev_path
to an identifier.
get_appl_path loc tp
abstract loc patts body
takes a location loc
, a pattern list
patts
, and an expression body
.
body
.
apply loc f_expr arg_exprs
takes a location loc
, an expression
f_expr
representing a function, and a list of argument expressions
arg_exprs
.
switch_tp_def ~alias ~sum ~record ~variants ~mani tp_def
takes a handler function for each kind of type definition and
applies the appropriate handler when tp_def
matches.
mk_expr_lst loc expr_list
takes a list of expressions.
mk_patt_lst _loc patt_list
takes a list of patterns.
get_tparam_id tp
tp
if it is a type parameter.
Failure
otherwise.
type_is_recursive ?short_circuit id tp
tp
with name id
refers to itself, assuming that it is not mutually recursive with
another type.
drop_variance_annotations tp
tp
.
find_record_default loc
loc
if defined.
delay_sig_item item
places item
at the end of the current signature
sig_ loc rec_ typedefs
rewrites the given type definition to make it either
recursive or non recursive.
For instance, the parser calls sig_ loc false (TyDcl (_, t, [], t, []))
when it
encouters type t = t
and calls sig_ loc true (TyDcl (_, t, [], t, []))
when it
encouters type nonrec t = t
in signatures.
str_ loc rec_ typedefs
does the same thing as sig_ loc rec_ typedefs
, except
that it returns a structure item instead of a signature item.