[latex3-commits] [git/LaTeX3-latex3-latex3] debug: Minor simplifications to l3debug (e67a2fb48)
Bruno Le Floch
bruno at le-floch.fr
Mon Jun 24 00:44:29 CEST 2019
Repository : https://github.com/latex3/latex3
On branch : debug
Link : https://github.com/latex3/latex3/commit/e67a2fb48d40e9f981ca6b23cd18363ef35e7efc
>---------------------------------------------------------------
commit e67a2fb48d40e9f981ca6b23cd18363ef35e7efc
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Sun Jun 23 23:43:10 2019 +0100
Minor simplifications to l3debug
>---------------------------------------------------------------
e67a2fb48d40e9f981ca6b23cd18363ef35e7efc
l3kernel/l3debug.dtx | 305 ++++++++++++++++++++++++---------------------------
1 file changed, 143 insertions(+), 162 deletions(-)
diff --git a/l3kernel/l3debug.dtx b/l3kernel/l3debug.dtx
index ec71567be..aca660bc0 100644
--- a/l3kernel/l3debug.dtx
+++ b/l3kernel/l3debug.dtx
@@ -54,8 +54,7 @@
% \cs{__kernel_chk_var_local:N} \meta{var}
% \cs{__kernel_chk_var_global:N} \meta{var}
% \end{syntax}
-% Applies \cs{__kernel_chk_var_exist:N} \meta{var}, and assuming that is
-% true applies
+% Applies \cs{__kernel_chk_var_exist:N} \meta{var} as well as
% \cs{__kernel_chk_var_scope:NN} \meta{scope} \meta{var}, where
% \meta{scope} is |l| or~|g|.
% \end{function}
@@ -77,13 +76,30 @@
% different scopes a kernel error will result.
% \end{function}
%
-% \begin{function}{\__kernel_chk_var_exist:N}
+% \begin{function}
+% {
+% \__kernel_chk_cs_exist:N,
+% \__kernel_chk_cs_exist:c,
+% \__kernel_chk_var_exist:N
+% }
% \begin{syntax}
+% \cs{__kernel_chk_cs_exist:N} \meta{cs}
% \cs{__kernel_chk_var_exist:N} \meta{var}
% \end{syntax}
+% These functions are only created if debugging is enabled. They
+% check that their argument is defined according to the criteria for
+% \cs{cs_if_exist_p:N},
+% and if not raises a kernel-level error. Error messages are
+% different.
+% \end{function}
+%
+% \begin{function}[EXP]{\__kernel_chk_flag_exist:n}
+% \begin{syntax}
+% \cs{__kernel_chk_flag_exist:n} \Arg{flag}
+% \end{syntax}
% This function is only created if debugging is enabled. It checks
-% that \meta{var} is defined according to the criteria for
-% \cs{cs_if_exist_p:N}, and if not raises a kernel-level error.
+% that the \meta{flag} is defined according to the criterion for
+% \cs{flag_if_exist_p:n}, and if not raises a kernel-level error.
% \end{function}
%
% \begin{function}{\__kernel_debug_log:x}
@@ -128,7 +144,7 @@
\cs_set_protected:Npn \debug_off:n #1
{
\exp_args:No \clist_map_inline:nn { \tl_to_str:n {#1} }
- {
+ {
\cs_if_exist_use:cF { @@_ ##1 _off: }
{ \__kernel_msg_error:nnn { kernel } { debug } {##1} }
}
@@ -154,6 +170,7 @@
}
}
% \end{macrocode}
+% \end{macro}
%
% \begin{macro}{\debug_suspend:, \debug_resume:}
% \begin{macro}{\@@_suspended:T}
@@ -179,7 +196,7 @@
\cs_set_eq:NN \@@_suspended:T \use_none:n
}
}
-\cs_new:Npn \@@_suspended:T #1 { }
+\cs_new_eq:NN \@@_suspended:T \use_none:n
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -210,7 +227,7 @@
\cs_new_protected:Npn \__kernel_chk_var_exist:N #1 { }
\cs_new_protected:Npn \__kernel_chk_cs_exist:N #1 { }
\cs_generate_variant:Nn \__kernel_chk_cs_exist:N { c }
-\cs_new_protected:Npn \__kernel_chk_flag_exist:n #1 { }
+\cs_new:Npn \__kernel_chk_flag_exist:n #1 { }
\cs_new_protected:Npn \__kernel_chk_var_local:N #1 { }
\cs_new_protected:Npn \__kernel_chk_var_global:N #1 { }
\cs_new_protected:Npn \__kernel_chk_var_scope:NN #1#2 { }
@@ -236,6 +253,7 @@
}
\cs_set:Npn \__kernel_chk_flag_exist:n ##1
{
+ \@@_suspended:T \use_none:nnn
\flag_if_exist:nF {##1}
{
\__kernel_msg_expandable_error:nnn
@@ -327,12 +345,8 @@
% \begin{macro}{\@@_log-functions_on:, \@@_log-functions_off:}
% \begin{macro}{\__kernel_debug_log:x}
% These two functions (corresponding to the \pkg{expl3} option
-% \texttt{log-functions}) control whether \cs{__kernel_debug_log:x} writes to the
-% log file or not. Since \cs{iow_log:x} does not yet have its final
-% definition we do not use \cs{cs_set_eq:NN} (not defined yet anyway).
-% Once everything is defined, turn logging on or off depending on what
-% option was given. When debugging is not enabled, simply produce an
-% error.
+% \texttt{log-functions}) control whether \cs{__kernel_debug_log:x}
+% writes to the log file or not. By default, logging is off.
% \begin{macrocode}
\cs_new_protected:cpn { @@_log-functions_on: }
{
@@ -341,7 +355,7 @@
}
\cs_new_protected:cpn { @@_log-functions_off: }
{ \cs_set_protected:Npn \__kernel_debug_log:x { \use_none:n } }
-\use:c { @@_log-functions_off: }
+\cs_new_protected:Npn \__kernel_debug_log:x { \use_none:n }
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -381,7 +395,7 @@
}
\cs_new_protected:cpn { @@_check-expressions_off: }
{ \cs_set:Npn \__kernel_chk_expr:nNnN ##1##2##3##4 {##1} }
-\use:c { @@_check-expressions_off: }
+\cs_new:Npn \__kernel_chk_expr:nNnN #1#2#3#4 {#1}
\cs_new:Npn \@@_chk_expr_aux:nNnN #1#2#3#4
{
\tl_if_empty:oF
@@ -404,7 +418,8 @@
% \begin{macro}{\@@_deprecation_on:, \@@_deprecation_off:}
% Some commands were more recently deprecated and not yet removed;
% only make these into errors if the user requests it. This relies on
-% two token lists, filled up in \pkg{l3deprecation}.
+% two token lists, filled up in \pkg{l3deprecation} by calls to
+% \cs{__kernel_deprecation_code:nn}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_deprecation_on:
{ \g_@@_deprecation_on_tl }
@@ -420,12 +435,12 @@
% \end{macrocode}
% \end{variable}
%
-% \begin{macro}{\@@_patch:Nnn}
-% Simple patching by adding material at the start and end of functions
-% is straight-forward as we know the catcode set up. The approach is
-% essentially that in \pkg{etoolbox}. Notice the need to worry about spaces:
-% those are otherwise lost as normally in \pkg{expl3} code they would be
-% |~|.
+% \begin{macro}{\__kernel_patch:nnn}
+% Simple patching by adding material at the start and end of (a
+% collection of) functions is straight-forward as we know the catcode
+% set up. The approach is essentially that in \pkg{etoolbox}. Notice
+% the need to worry about spaces: those are otherwise lost as normally
+% in \pkg{expl3} code they would be~|~|.
% \begin{macrocode}
\group_begin:
\cs_set_protected:Npn \__kernel_patch:nnn
@@ -438,20 +453,17 @@
{
\char_set_catcode_parameter:N \#
\char_set_catcode_space:N \ %
+ \tex_endlinechar:D -1 \scan_stop:
\tl_map_inline:nn {#3}
{
- \use:x
+ \exp_args:Nx \tex_scantokens:D
{
- \tex_endlinechar:D -1 \scan_stop:
- \exp_not:N \tex_scantokens:D
+ \tex_global:D \cs_prefix_spec:N ##1 \tex_def:D \exp_not:N ##1
+ \cs_argument_spec:N ##1
{
- \tex_global:D \cs_prefix_spec:N ##1 \tex_def:D \exp_not:N ##1
- \cs_argument_spec:N ##1
- {
- \tl_to_str:n {#1}
- \cs_replacement_spec:N ##1
- \tl_to_str:n {#2}
- }
+ \tl_to_str:n {#1}
+ \cs_replacement_spec:N ##1
+ \tl_to_str:n {#2}
}
}
}
@@ -461,7 +473,9 @@
% \end{macro}
%
% Patching the second argument to ensure it exists. This happens before
-% we alter |#1| so the ordering is correct.
+% we alter |#1| so the ordering is correct. For many variable types
+% such as \texttt{int} a low-level error occurs when |#2| is unknown, so
+% adding a check is not needed.
% \begin{macrocode}
\__kernel_patch:nnn
{ \__kernel_chk_var_exist:N #2 }
@@ -473,8 +487,12 @@
\clist_gset_eq:NN
\fp_set_eq:NN
\fp_gset_eq:NN
+ \prop_set_eq:NN
+ \prop_gset_eq:NN
\seq_set_eq:NN
\seq_gset_eq:NN
+ \str_set_eq:NN
+ \str_gset_eq:NN
\tl_set_eq:NN
\tl_gset_eq:NN
}
@@ -489,25 +507,31 @@
}
{ }
{
+ \clist_concat:NNN
+ \clist_gconcat:NNN
+ \seq_concat:NNN
+ \seq_gconcat:NNN
+ \str_concat:NNN
+ \str_gconcat:NNN
\tl_concat:NNN
\tl_gconcat:NNN
}
% \end{macrocode}
%
-% Patching where the first argument to a function needs scope-checking:
-% either local or global (so two lists).
+% Patching where the first argument to a function needs scope-checking:
+% either local or global (so two lists).
% \begin{macrocode}
\__kernel_patch:nnn
{ \__kernel_chk_var_local:N #1 }
{ }
{
+ \bool_set:Nn
\bool_set_eq:NN
\bool_set_true:N
\bool_set_false:N
\box_set_eq:NN
\box_set_eq_drop:NN
\box_set_to_last:N
- \bool_set:Nn
\clist_set_eq:NN
\dim_zero:N
\dim_set:Nn
@@ -564,13 +588,13 @@
{ \__kernel_chk_var_global:N #1 }
{ }
{
+ \bool_gset:Nn
\bool_gset_eq:NN
\bool_gset_true:N
\bool_gset_false:N
\box_gset_eq:NN
\box_gset_eq_drop:NN
\box_gset_to_last:N
- \bool_gset:Nn
\clist_gset_eq:NN
\dim_gset_eq:NN
\dim_gzero:N
@@ -642,7 +666,7 @@
}
% \end{macrocode}
%
-% Flag functions.
+% Flag functions.
% \begin{macrocode}
\__kernel_patch:nnn
{ \__kernel_chk_flag_exist:n {#1} }
@@ -654,6 +678,7 @@
\flag_if_raised_p:n
\flag_height:n
\flag_raise_if_clear:n
+ \flag_clear:n
}
% \end{macrocode}
%
@@ -664,10 +689,6 @@
{ }
{ \cs_generate_variant:Nn }
\__kernel_patch:nnn
- { \exp_args:Nc \__kernel_chk_var_exist:N { flag~#1 } }
- { }
- { \flag_clear:n }
- \__kernel_patch:nnn
{ \__kernel_chk_var_scope:NN g #1 }
{ }
{ \intarray_new:Nn }
@@ -679,14 +700,20 @@
{ \__kernel_chk_var_scope:NN s #1 }
{ }
{ \scan_new:N }
-
% \end{macrocode}
%
+% Patch various internal commands to log definitions of functions.
+% First, a kernel internal. Then internals from the \pkg{cs},
+% \pkg{keys} and \pkg{msg} modules.
% \begin{macrocode}
+ \__kernel_patch:nnn
+ { }
+ {
+ \__kernel_debug_log:x
+ { Defining~\token_to_str:N #1~ \msg_line_context: }
+ }
+ { \__kernel_chk_if_free_cs:N }
%<@@=cs>
-% \end{macrocode}
-% Internal functions from \pkg{cs} module.
-% \begin{macrocode}
\__kernel_patch:nnn
{
\cs_if_free:NF #4
@@ -700,13 +727,7 @@
}
{ }
{ \@@_generate_variant:wwNN }
-% \end{macrocode}
-%
-% \begin{macrocode}
%<@@=keys>
-% \end{macrocode}
-% Internal functions from \pkg{keys} module.
-% \begin{macrocode}
\__kernel_patch:nnn
{
\cs_if_exist:cF { \c_@@_code_root_tl #1 }
@@ -714,13 +735,7 @@
}
{ }
{ \@@_cmd_set:nn }
-% \end{macrocode}
-%
-% \begin{macrocode}
%<@@=msg>
-% \end{macrocode}
-% Internal functions from \pkg{msg} module.
-% \begin{macrocode}
\__kernel_patch:nnn
{ }
{
@@ -834,18 +849,6 @@
{ \@@_replacement:n }
% \end{macrocode}
%
-% Internal to the kernel itself.
-%
-% \begin{macrocode}
- \__kernel_patch:nnn
- { }
- {
- \__kernel_debug_log:x
- { Defining~\token_to_str:N #1~ \msg_line_context: }
- }
- { \__kernel_chk_if_free_cs:N }
-% \end{macrocode}
-%
% \begin{macrocode}
\group_end:
% \end{macrocode}
@@ -854,8 +857,8 @@
%<@@=debug>
% \end{macrocode}
%
-% Patching arguments is a bit more involved: we do these one-at-a-time
-% basis. Basic idea is the same, using a |#| token that is a string.
+% Patching arguments is a bit more involved: we do these one at a time.
+% The basic idea is the same, using a |#| token that is a string.
% \begin{macrocode}
\group_begin:
\cs_set_protected:Npn \__kernel_patch:Nn #1
@@ -866,22 +869,14 @@
}
\cs_set_protected:Npn \__kernel_patch_aux:Nn #1#2
{
- \exp_after:wN \__kernel_patch_aux:nN \exp_after:wN
- { #1 #2 } #1
- }
- \cs_set_protected:Npn \__kernel_patch_aux:nN #1#2
- {
- \use:x
- {
- \group_end:
- \exp_not:N \tex_scantokens:D
- {
- \tex_endlinechar:D -1 \scan_stop:
- \tex_global:D \cs_prefix_spec:N #2 \tex_def:D \exp_not:N #2
- \cs_argument_spec:N #2
- { \tl_to_str:n {#1} }
- }
- }
+ \tex_endlinechar:D -1 \scan_stop:
+ \exp_args:Nx \tex_scantokens:D
+ {
+ \tex_global:D \cs_prefix_spec:N #1 \tex_def:D \exp_not:N #1
+ \cs_argument_spec:N #1
+ { \exp_args:No \tl_to_str:n { #1 #2 } }
+ }
+ \group_end:
}
% \end{macrocode}
%
@@ -892,21 +887,18 @@
% \begin{macrocode}
\cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
{
- \tl_map_inline:nn {#1}
- {
- \use:x
+ \tl_map_inline:nn {#1}
+ {
+ \exp_args:NNx \__kernel_patch:Nn ##1
{
- \__kernel_patch:Nn \exp_not:N ##1
- {
- { \c_hash_str 1 }
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
- \exp_not:n {#2}
- \exp_not:N ##1
- }
- }
+ { \c_hash_str 1 }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
+ \exp_not:n {#2}
+ \exp_not:N ##1
+ }
}
- }
+ }
}
%<@@=dim>
\__kernel_patch_eval:nn
@@ -961,20 +953,17 @@
% \begin{macrocode}
\cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
{
- \tl_map_inline:nn {#1}
- {
- \use:x
+ \tl_map_inline:nn {#1}
+ {
+ \exp_args:NNx \__kernel_patch:Nn ##1
{
- \__kernel_patch:Nn \exp_not:N ##1
- {
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
- \exp_not:n {#2}
- \exp_not:N ##1
- }
- }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
+ \exp_not:n {#2}
+ \exp_not:N ##1
+ }
}
- }
+ }
}
%<@@=box>
\__kernel_patch_eval:nn
@@ -1012,25 +1001,22 @@
{ \tex_muexpr:D { \tex_mutoglue:D } }
\cs_set_protected:Npn \__kernel_patch_eval:nn #1#2
{
- \tl_map_inline:nn {#1}
- {
- \use:x
+ \tl_map_inline:nn {#1}
+ {
+ \exp_args:NNx \__kernel_patch:Nn ##1
{
- \__kernel_patch:Nn \exp_not:N ##1
- {
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
- \exp_not:n {#2}
- \exp_not:N ##1
- }
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
- \exp_not:n {#2}
- \exp_not:N ##1
- }
- }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
+ \exp_not:n {#2}
+ \exp_not:N ##1
+ }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 2 }
+ \exp_not:n {#2}
+ \exp_not:N ##1
+ }
}
- }
+ }
}
%<@@=dim>
\__kernel_patch_eval:nn
@@ -1054,26 +1040,23 @@
% \begin{macrocode}
\cs_set_protected:Npn \__kernel_patch_cond:nn #1#2
{
- \clist_map_inline:nn { :nNnT , :nNnF , :nNnTF , _p:nNn }
- {
- \use:x
+ \clist_map_inline:nn { :nNnT , :nNnF , :nNnTF , _p:nNn }
+ {
+ \exp_args:Ncx \__kernel_patch:Nn { #1 ##1 }
{
- \__kernel_patch:Nn \exp_not:c { #1 ##1 }
- {
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
- \exp_not:n {#2}
- \exp_not:c { #1 ##1 }
- }
- { \c_hash_str 2 }
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 3 }
- \exp_not:n {#2}
- \exp_not:c { #1 ##1 }
- }
- }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
+ \exp_not:n {#2}
+ \exp_not:c { #1 ##1 }
+ }
+ { \c_hash_str 2 }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 3 }
+ \exp_not:n {#2}
+ \exp_not:c { #1 ##1 }
+ }
}
- }
+ }
}
%<@@=dim>
\__kernel_patch_cond:nn { dim_compare } { \@@_eval:w { } }
@@ -1081,20 +1064,17 @@
\__kernel_patch_cond:nn { int_compare } { \@@_eval:w { } }
\cs_set_protected:Npn \__kernel_patch_cond:nn #1#2
{
- \clist_map_inline:nn { :nT , :nF , :nTF , _p:n }
- {
- \use:x
+ \clist_map_inline:nn { :nT , :nF , :nTF , _p:n }
+ {
+ \exp_args:Ncx \__kernel_patch:Nn { #1 ##1 }
{
- \__kernel_patch:Nn \exp_not:c { #1 ##1 }
- {
- {
- \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
- \exp_not:n {#2}
- \exp_not:c { #1 ##1 }
- }
- }
+ {
+ \exp_not:N \__kernel_chk_expr:nNnN { \c_hash_str 1 }
+ \exp_not:n {#2}
+ \exp_not:c { #1 ##1 }
+ }
}
- }
+ }
}
%<@@=int>
\__kernel_patch_cond:nn { int_if_even } { \@@_eval:w { } }
@@ -1177,7 +1157,8 @@
{
The~functions~'\iow_char:N\\debug_on:n'~and~
'\iow_char:N\\debug_off:n'~only~accept~the~arguments~
- 'check-declarations',~'deprecation',~'log-functions',~not~'#1'.
+ 'all',~'check-declarations',~'check-expressions',~
+ 'deprecation',~'log-functions',~not~'#1'.
}
\__kernel_msg_new:nnn { kernel } { expr } { '#2'~in~#1 }
\__kernel_msg_new:nnnn { kernel } { local-global }
More information about the latex3-commits
mailing list