Skip to content

Commit

Permalink
Check local/global assignments to int/dim/skip/muskip/box (see #410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Le Floch committed Nov 29, 2017
1 parent 03ca82e commit 815ad41
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 239 deletions.
69 changes: 44 additions & 25 deletions l3kernel/l3basics.dtx
Expand Up @@ -1339,6 +1339,16 @@
% counterpart.
% \end{function}
%
% \begin{function}
% {\__debug_patch_args:nnnNNpn, \__debug_patch_conditional_args:nnnNNpnn}
% \begin{syntax}
% \cs{__debug_patch_args:nnnNNpn} \Arg{before} \Arg{after} \Arg{arguments}
% \meta{definition} \meta{function} \meta{parameters} \Arg{code}
% \end{syntax}
% A combination of \cs{__debug_patch:nnNNpn} and
% \cs{__debug_patch_args:nNNpn}.
% \end{function}
%
% \begin{function}{\__kernel_register_show:N, \__kernel_register_show:c}
% \begin{syntax}
% \cs{__kernel_register_show:N} \meta{register}
Expand Down Expand Up @@ -2135,7 +2145,7 @@
% \begin{macro}[int]
% {\@@_patch:nnNNpn, \@@_patch_conditional:nNNpnn}
% \begin{macro}[aux]
% {\@@_patch_aux:nnNNnn, \@@_patch_aux:nNNnnn}
% {\@@_patch_aux:nnnn, \@@_patch_auxii:nnnn}
% When debugging is not enabled, \cs{@@_patch:nnNNpn} and
% \cs{@@_patch_conditional:nNNpnn} throw the patch away.
% Otherwise they can be followed by \cs{cs_new:Npn} (or similar), and
Expand All @@ -2146,13 +2156,13 @@
\@@:TF
{
\cs_set_protected:Npn \@@_patch:nnNNpn #1#2#3#4#5#
{ \@@_patch_aux:nnNNnn {#1} {#2} #3 #4 {#5} }
{ \@@_patch_aux:nnnn {#1} {#2} { #3 #4 #5 } }
\cs_set_protected:Npn \@@_patch_conditional:nNNpnn #1#2#3#4#
{ \@@_patch_aux:nNNnnn {#1} #2 #3 {#4} }
\cs_set_protected:Npn \@@_patch_aux:nnNNnn #1#2#3#4#5#6
{ #3 #4 #5 { #1 #6 #2 } }
\cs_set_protected:Npn \@@_patch_aux:nNNnnn #1#2#3#4#5#6
{ #2 #3 #4 {#5} { #1 #6 } }
{ \@@_patch_auxii:nnnn {#1} { #2 #3 #4 } }
\cs_set_protected:Npn \@@_patch_aux:nnnn #1#2#3#4
{ #3 { #1 #4 #2 } }
\cs_set_protected:Npn \@@_patch_auxii:nnnn #1#2#3#4
{ #2 {#3} { #1 #4 } }
}
{
\cs_set_protected:Npn \@@_patch:nnNNpn #1#2 { }
Expand All @@ -2164,46 +2174,55 @@
%
% \begin{macro}[int]
% {\@@_patch_args:nNNpn, \@@_patch_conditional_args:nNNpnn}
% \begin{macro}[int]
% {\@@_patch_args:nnnNNpn, \@@_patch_conditional_args:nnnNNpnn}
% \begin{macro}[aux]
% {
% \@@_tmp:w,
% \@@_patch_args_aux:nNNnn,
% \@@_patch_args_aux:nNNnnn
% \@@_patch_args_aux:nnnNNnn,
% \@@_patch_args_aux:nnnNNnnn,
% \@@_patch_args_aux:nnnn
% }
% See \cs{@@_patch:nnNNpn}. The first argument is something like
% |{#1}{(#2)}|. Define a temporary macro using the \meta{parameters}
% and \meta{code} of the definition that follows, then expand that
% temporary macro in front of the first argument to obtain new
% \meta{code}. Then perform the definition as if that new \meta{code}
% was directly typed in the file. To make it easy to expand in the
% definition, treat it as a \enquote{pre}-code to an empty definition.
% was directly typed in the file.
% \begin{macrocode}
\cs_set_protected:Npn \@@_patch_args:nNNpn
{ \@@_patch_args:nnnNNpn { } { } }
\cs_set_protected:Npn \@@_patch_conditional_args:nNNpnn
{ \@@_patch_conditional_args:nnnNNpnn { } { } }
\@@:TF
{
\cs_set_protected:Npn \@@_patch_args:nNNpn #1#2#3#4#
{ \@@_patch_args_aux:nNNnn {#1} #2 #3 {#4} }
\cs_set_protected:Npn \@@_patch_conditional_args:nNNpnn #1#2#3#4#
{ \@@_patch_args_aux:nNNnnn {#1} #2 #3 {#4} }
\cs_set_protected:Npn \@@_patch_args_aux:nNNnn #1#2#3#4#5
\cs_set_protected:Npn \@@_patch_args:nnnNNpn #1#2#3#4#5#6#
{ \@@_patch_args_aux:nnnNNnn {#1} {#2} {#3} #4 #5 {#6} }
\cs_set_protected:Npn \@@_patch_conditional_args:nnnNNpnn #1#2#3#4#5#6#
{ \@@_patch_args_aux:nnnNNnnn {#1} {#2} {#3} #4 #5 {#6} }
\cs_set_protected:Npn \@@_patch_args_aux:nnnNNnn #1#2#3#4#5#6#7
{
\cs_set:Npn \@@_tmp:w #4 {#5}
\exp_after:wN \@@_patch_aux:nnNNnn \exp_after:wN
{ \@@_tmp:w #1 } { } #2 #3 {#4} { }
\cs_set:Npn \@@_tmp:w #6 {#7}
\exp_after:wN \@@_patch_args_aux:nnnn \exp_after:wN
{ \@@_tmp:w #3 } { #4 #5 #6 } {#1} {#2}
}
\cs_set_protected:Npn \@@_patch_args_aux:nNNnnn #1#2#3#4#5#6
\cs_set_protected:Npn \@@_patch_args_aux:nnnNNnnn #1#2#3#4#5#6#7#8
{
\cs_set:Npn \@@_tmp:w #4 {#6}
\exp_after:wN \@@_patch_aux:nNNnnn \exp_after:wN
{ \@@_tmp:w #1 } #2 #3 {#4} {#5} { }
\cs_set:Npn \@@_tmp:w #6 {#8}
\exp_after:wN \@@_patch_args_aux:nnnn \exp_after:wN
{ \@@_tmp:w #3 } { #4 #5 #6 {#7} } {#1} {#2}
}
\cs_set_protected:Npn \@@_patch_args_aux:nnnn #1#2#3#4
{ #2 { #3 #1 #4 } }
}
{
\cs_set_protected:Npn \@@_patch_args:nNNpn #1 { }
\cs_set_protected:Npn \@@_patch_conditional_args:nNNpnn #1 { }
\cs_set_protected:Npn \@@_patch_args:nnnNNpn #1#2#3 { }
\cs_set_protected:Npn \@@_patch_conditional_args:nnnNNpnn #1#2#3 { }
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \subsection{Conditional processing and definitions}
%
Expand Down
135 changes: 108 additions & 27 deletions l3kernel/l3box.dtx
Expand Up @@ -901,10 +901,12 @@
% \testfile*
% Assigning the contents of a box to be another box.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \box_set_eq:NN #1#2
{ \tex_setbox:D #1 \tex_copy:D #2 }
\cs_new_protected:Npn \box_gset_eq:NN
{ \tex_global:D \box_set_eq:NN }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \box_gset_eq:NN #1#2
{ \tex_global:D \tex_setbox:D #1 \tex_copy:D #2 }
\cs_generate_variant:Nn \box_set_eq:NN { c , Nc , cc }
\cs_generate_variant:Nn \box_gset_eq:NN { c , Nc , cc }
% \end{macrocode}
Expand All @@ -926,10 +928,12 @@
% Assigning the contents of a box to be another box.
% This clears the second box globally (that's how \TeX{} does it).
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \box_set_eq_clear:NN #1#2
{ \tex_setbox:D #1 \tex_box:D #2 }
\cs_new_protected:Npn \box_gset_eq_clear:NN
{ \tex_global:D \box_set_eq_clear:NN }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \box_gset_eq_clear:NN #1#2
{ \tex_global:D \tex_setbox:D #1 \tex_box:D #2 }
\cs_generate_variant:Nn \box_set_eq_clear:NN { c , Nc , cc }
\cs_generate_variant:Nn \box_gset_eq_clear:NN { c , Nc , cc }
% \end{macrocode}
Expand Down Expand Up @@ -1087,10 +1091,12 @@
% \testfile*
% Set a box to the previous box.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \box_set_to_last:N #1
{ \tex_setbox:D #1 \tex_lastbox:D }
\cs_new_protected:Npn \box_gset_to_last:N
{ \tex_global:D \box_set_to_last:N }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \box_gset_to_last:N #1
{ \tex_global:D \tex_setbox:D #1 \tex_lastbox:D }
\cs_generate_variant:Nn \box_set_to_last:N { c }
\cs_generate_variant:Nn \box_gset_to_last:N { c }
% \end{macrocode}
Expand Down Expand Up @@ -1205,9 +1211,12 @@
% \begin{macro}{\hbox_gset:Nn, \hbox_gset:cn}
% \testfile*
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \hbox_set:Nn #1#2
{ \tex_setbox:D #1 \tex_hbox:D { \group_begin: #2 \group_end: } }
\cs_new_protected:Npn \hbox_gset:Nn { \tex_global:D \hbox_set:Nn }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \hbox_gset:Nn #1#2
{ \tex_global:D \tex_setbox:D #1 \tex_hbox:D { \group_begin: #2 \group_end: } }
\cs_generate_variant:Nn \hbox_set:Nn { c }
\cs_generate_variant:Nn \hbox_gset:Nn { c }
% \end{macrocode}
Expand All @@ -1220,14 +1229,25 @@
% Storing material in a horizontal box with a specified width.
% Again, put the dimension expression in parentheses when debugging.
% \begin{macrocode}
\__debug_patch_args:nNNpn { {#1} { (#2) } {#3} }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_local:N #1 }
{ }
{ {#1} { (#2) } {#3} }
\cs_new_protected:Npn \hbox_set_to_wd:Nnn #1#2#3
{
\tex_setbox:D #1 \tex_hbox:D to \__dim_eval:w #2 \__dim_eval_end:
{ \group_begin: #3 \group_end: }
}
\cs_new_protected:Npn \hbox_gset_to_wd:Nnn
{ \tex_global:D \hbox_set_to_wd:Nnn }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_global:N #1 }
{ }
{ {#1} { (#2) } {#3} }
\cs_new_protected:Npn \hbox_gset_to_wd:Nnn #1#2#3
{
\tex_global:D \tex_setbox:D #1 \tex_hbox:D
to \__dim_eval:w #2 \__dim_eval_end:
{ \group_begin: #3 \group_end: }
}
\cs_generate_variant:Nn \hbox_set_to_wd:Nnn { c }
\cs_generate_variant:Nn \hbox_gset_to_wd:Nnn { c }
% \end{macrocode}
Expand All @@ -1241,14 +1261,20 @@
% Storing material in a horizontal box. This type is useful in
% environment definitions.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \hbox_set:Nw #1
{
\tex_setbox:D #1 \tex_hbox:D
\c_group_begin_token
\group_begin:
}
\cs_new_protected:Npn \hbox_gset:Nw
{ \tex_global:D \hbox_set:Nw }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \hbox_gset:Nw #1
{
\tex_global:D \tex_setbox:D #1 \tex_hbox:D
\c_group_begin_token
\group_begin:
}
\cs_generate_variant:Nn \hbox_set:Nw { c }
\cs_generate_variant:Nn \hbox_gset:Nw { c }
\cs_new_protected:Npn \hbox_set_end:
Expand All @@ -1266,15 +1292,27 @@
% \begin{macro}{\hbox_gset_to_wd:Nnw, \hbox_gset_to_wd:cnw}
% Combining the above ideas.
% \begin{macrocode}
\__debug_patch_args:nNNpn { {#1} { (#2) } }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_local:N #1 }
{ }
{ {#1} { (#2) } }
\cs_new_protected:Npn \hbox_set_to_wd:Nnw #1#2
{
\tex_setbox:D #1 \tex_hbox:D to \__dim_eval:w #2 \__dim_eval_end:
\c_group_begin_token
\group_begin:
}
\cs_new_protected:Npn \hbox_gset_to_wd:Nnw
{ \tex_global:D \hbox_set_to_wd:Nnw }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_global:N #1 }
{ }
{ {#1} { (#2) } }
\cs_new_protected:Npn \hbox_gset_to_wd:Nnw #1#2
{
\tex_global:D \tex_setbox:D #1 \tex_hbox:D
to \__dim_eval:w #2 \__dim_eval_end:
\c_group_begin_token
\group_begin:
}
\cs_generate_variant:Nn \hbox_set_to_wd:Nnw { c }
\cs_generate_variant:Nn \hbox_gset_to_wd:Nnw { c }
% \end{macrocode}
Expand Down Expand Up @@ -1367,12 +1405,18 @@
% \testfile*
% Storing material in a vertical box with a natural height.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \vbox_set:Nn #1#2
{
\tex_setbox:D #1 \tex_vbox:D
{ \group_begin: #2 \par \group_end: }
}
\cs_new_protected:Npn \vbox_gset:Nn { \tex_global:D \vbox_set:Nn }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \vbox_gset:Nn #1#2
{
\tex_global:D \tex_setbox:D #1 \tex_vbox:D
{ \group_begin: #2 \par \group_end: }
}
\cs_generate_variant:Nn \vbox_set:Nn { c }
\cs_generate_variant:Nn \vbox_gset:Nn { c }
% \end{macrocode}
Expand All @@ -1385,13 +1429,18 @@
% Storing material in a vertical box with a natural height and reference
% point at the baseline of the first object in the box.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \vbox_set_top:Nn #1#2
{
\tex_setbox:D #1 \tex_vtop:D
{ \group_begin: #2 \par \group_end: }
}
\cs_new_protected:Npn \vbox_gset_top:Nn
{ \tex_global:D \vbox_set_top:Nn }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \vbox_gset_top:Nn #1#2
{
\tex_global:D \tex_setbox:D #1 \tex_vtop:D
{ \group_begin: #2 \par \group_end: }
}
\cs_generate_variant:Nn \vbox_set_top:Nn { c }
\cs_generate_variant:Nn \vbox_gset_top:Nn { c }
% \end{macrocode}
Expand All @@ -1403,14 +1452,25 @@
% \testfile*
% Storing material in a vertical box with a specified height.
% \begin{macrocode}
\__debug_patch_args:nNNpn { {#1} { (#2) } {#3} }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_local:N #1 }
{ }
{ {#1} { (#2) } {#3} }
\cs_new_protected:Npn \vbox_set_to_ht:Nnn #1#2#3
{
\tex_setbox:D #1 \tex_vbox:D to \__dim_eval:w #2 \__dim_eval_end:
{ \group_begin: #3 \par \group_end: }
}
\cs_new_protected:Npn \vbox_gset_to_ht:Nnn
{ \tex_global:D \vbox_set_to_ht:Nnn }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_global:N #1 }
{ }
{ {#1} { (#2) } {#3} }
\cs_new_protected:Npn \vbox_gset_to_ht:Nnn #1#2#3
{
\tex_global:D \tex_setbox:D #1 \tex_vbox:D
to \__dim_eval:w #2 \__dim_eval_end:
{ \group_begin: #3 \par \group_end: }
}
\cs_generate_variant:Nn \vbox_set_to_ht:Nnn { c }
\cs_generate_variant:Nn \vbox_gset_to_ht:Nnn { c }
% \end{macrocode}
Expand All @@ -1424,14 +1484,20 @@
% Storing material in a vertical box. This type is useful in
% environment definitions.
% \begin{macrocode}
\__debug_patch:nnNNpn { \__debug_chk_var_local:N #1 } { }
\cs_new_protected:Npn \vbox_set:Nw #1
{
\tex_setbox:D #1 \tex_vbox:D
\c_group_begin_token
\group_begin:
}
\cs_new_protected:Npn \vbox_gset:Nw
{ \tex_global:D \vbox_set:Nw }
\__debug_patch:nnNNpn { \__debug_chk_var_global:N #1 } { }
\cs_new_protected:Npn \vbox_gset:Nw #1
{
\tex_global:D \tex_setbox:D #1 \tex_vbox:D
\c_group_begin_token
\group_begin:
}
\cs_generate_variant:Nn \vbox_set:Nw { c }
\cs_generate_variant:Nn \vbox_gset:Nw { c }
\cs_new_protected:Npn \vbox_set_end:
Expand All @@ -1450,15 +1516,27 @@
% \begin{macro}{\vbox_gset_to_ht:Nnw, \vbox_gset_to_ht:cnw}
% A combination of the above ideas.
% \begin{macrocode}
\__debug_patch_args:nNNpn { {#1} { (#2) } }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_local:N #1 }
{ }
{ {#1} { (#2) } }
\cs_new_protected:Npn \vbox_set_to_ht:Nnw #1#2
{
\tex_setbox:D #1 \tex_vbox:D to \__dim_eval:w #2 \__dim_eval_end:
\c_group_begin_token
\group_begin:
}
\cs_new_protected:Npn \vbox_gset_to_ht:Nnw
{ \tex_global:D \vbox_set_to_ht:Nnw }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_global:N #1 }
{ }
{ {#1} { (#2) } }
\cs_new_protected:Npn \vbox_gset_to_ht:Nnw #1#2
{
\tex_global:D \tex_setbox:D #1 \tex_vbox:D
to \__dim_eval:w #2 \__dim_eval_end:
\c_group_begin_token
\group_begin:
}
\cs_generate_variant:Nn \vbox_set_to_ht:Nnw { c }
\cs_generate_variant:Nn \vbox_gset_to_ht:Nnw { c }
% \end{macrocode}
Expand All @@ -1482,7 +1560,10 @@
% \testfile*
% Splitting a vertical box in two.
% \begin{macrocode}
\__debug_patch_args:nNNpn { {#1} {#2} { (#3) } }
\__debug_patch_args:nnnNNpn
{ \__debug_chk_var_local:N #1 }
{ }
{ {#1} {#2} { (#3) } }
\cs_new_protected:Npn \vbox_set_split_to_ht:NNn #1#2#3
{ \tex_setbox:D #1 \tex_vsplit:D #2 to \__dim_eval:w #3 \__dim_eval_end: }
% \end{macrocode}
Expand Down

0 comments on commit 815ad41

Please sign in to comment.