diff options
author | Norbert Preining <norbert@preining.info> | 2024-02-01 03:00:51 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2024-02-01 03:00:51 +0000 |
commit | a494a509f3f4a13a450c898488155f7aa5353bd3 (patch) | |
tree | ab11a3116dfe36f273b0eefe1a7abb556253a9c8 /support/splint/examples/ld/ldunion.sty | |
parent | 79e1bbc1ad6b308aa2074540b2afd43b6a72ce03 (diff) |
CTAN sync 202402010300
Diffstat (limited to 'support/splint/examples/ld/ldunion.sty')
-rw-r--r-- | support/splint/examples/ld/ldunion.sty | 242 |
1 files changed, 142 insertions, 100 deletions
diff --git a/support/splint/examples/ld/ldunion.sty b/support/splint/examples/ld/ldunion.sty index 710d4e1725..c59cd601e0 100644 --- a/support/splint/examples/ld/ldunion.sty +++ b/support/splint/examples/ld/ldunion.sty @@ -1,4 +1,4 @@ -% Copyright 2012-2020, Alexander Shibakov +% Copyright 2012-2024, Alexander Shibakov % This file is part of SPLinT % % SPLinT is free software: you can redistribute it and/or modify @@ -19,9 +19,9 @@ % of TeX tokens; sptr is a pointer to the stash stream, fptr is a pointer to the format stream \def\yyuniontag{\ldunion} -\def\parserstrictnamespace{ld-parser-strict} -\def\parserprototypesnamespace{ld-parser-strict:headers} -\def\parserdebugnamespace{ld-parser-debug} +\def\parserstrictnamespace{ld-parser-strict} % expands to an error message +\def\parserprototypesnamespace{ld-parser-strict:headers} % the parameter strings +\def\parserdebugnamespace{ld-parser-debug} % control sequences are \let...=\relax for debugging \def\ldunion{\currentyyunionnamespace} \def\currentyyunionnamespace{ld-generic} @@ -34,11 +34,12 @@ % ld commands +\defp\ldor{} % item separator :: \ldor, is only needed here for debugging (in the ld-parser-debug namespace) \defp\ldregexp#1{} % name pattern :: \ldregexp{{name}{name11}{fptr}{sptr}} \defp\ldregop#1{} % name pattern :: \ldregop{name} \defp\ldspace{} % space separator :: \ldspace -\defp\ldattributes#1{} % attributes :: \ldattributes{name} -\defp\ldattributesneg#1{} % complemented attributes :: \ldattributesneg{name} +\defp\ldattrstring#1#2#3#4{} % attributes string :: \ldattrstring{name}{name11}{fptr}{sptr} +\defp\ldattrstringneg#1#2#3#4{} % complemented attributes string :: \ldattrstring{name}{name11}{fptr}{sptr} \defp\ldfilename#1{} % file name :: \ldfilename{name} \defp\ldcommandseparator#1#2#3#4{} % command separator :: \ldcommandseparator{fptr}{sptr}{prev command}{next command} \defp\ldassignment#1#2#3{} % assignment :: \ldassignment{lhs}{op}{rhs} @@ -59,20 +60,38 @@ \defp\ldsectionseparator#1#2{} % section separator :: \ldsectionseparator{fptr}{sptr} \defp\ldtype#1{} % section type :: \ldtype{type} \defp\ldstatement#1{} % statement :: \ldstatement{statement} +\defp\ldfreestmt#1{} % statement in a section :: \ldfreestmt{\ldstatement{statement}} \defp\ldsecspec#1{} % section spec :: \ldsecspec{section spec} \defp\ldinsertcweb#1#2#3#4{} % insert accumulated \CWEB\ material :: \ldinsertcweb % {fptr}{sptr}{command}{parsed segment} : never defined \defp\ldnamedsection#1#2#3#4#5#6#7{} % named section :: \ldnamedsection{name} - % {{expression}{type}}{at} + % {expression}{type}}{at} % {{}{}{}:alignment} % {constraint}{statements} % {{}{}{}{}:placement} +\defp\ldoverlay#1#2#3#4#5#6{} % overlay section list :: \ldoverlay{expression}{crossrefs}{at}{subalign} + % {sections} + % {{memspec}{memspec_at}{phdr}{fill}} +\defp\ldoverlaysection#1#2#3#4{} % overlay section :: \ldoverlaysection{name}{statements}{phdr}{fill} \defp\ldsectionstash#1#2{} % sections spec stash :: \ldsectionstash{fptr}{sptr} -\savecslist{ld-parser-prototypes}\ldunion +\savecslist{ld-parser-prototypes}\ldunion % these consume parameters and expand to nothing \input ldint.sty +\def\ldidxdomain{L} + +\let\writeldidxentry\writeidxentry % mix the \ld\ index with the +\let\writeldidxhentry\writeidxhentry % \bison\ index for now + +\def\writeldidxhentry#1{% + \indxe\gindex{{\secno}{{}{\hostparsernamespace}}{\ldidxdomain}{\headeridxrank}#1}% +} + +\def\writeldidxentry#1{% + \indxe\gindex{{\secno}{{}{\hostparsernamespace}}{\ldidxdomain}{\termidxrank}#1}% +} + \def\bigbracedel{\delimiter"4266308} \newtoks\lddisplay @@ -116,6 +135,10 @@ \edef\next{\toksc{\gidxentry{\termttstring}{#2}{}{\ntt #2}}}\next } +\def\ldextractattrs#1#2#3#4{% + \edef\next{\toksc{{\ntt #2}}}\next +} + \def\ldextractmemname#1#2#3#4{% {% \expandafter\let\expandafter\tosmallparser\csname to\stripbrackets\cwebclinknamespace parser\endcsname @@ -134,7 +157,6 @@ % \separatorswitcheq and \separatorswitchneq in yyunion.sty \defc\ldcommandseparator{% - \restorecs{table-render}{\strm}% \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax \yyifsamestring{#3}{#4}{}{\appendrnx\lddisplay{\medskip}}% \else @@ -197,16 +219,16 @@ \def\ldreg@xp#1#2#3#4{% \expandafter\ifx\csname ldvarname[#2]\endcsname\relax {% - \let\termindex\writeidxentry + \let\termindex\writeldidxentry \let\hostparsernamespace\cwebclinknamespace% process the variable names as in \CWEB - \edef\next{\toksc{\gidxentry{\termttstring}{#1}{}}}\next\the\toksc + \edef\next{\toksc{\gidxentry{\termttstring}{#1}{}}}\next \hbox{\ntt@#1}% \expandafter }\the\toksc \else \yyifsamestring{#2}{.}{% special . name {% - \let\termindex\writeidxentry + \let\termindex\writeldidxentry \let\hostparsernamespace\cwebclinknamespace% for consistency \edef\next{\toksc{\gidxentry{\termexception}{.origin&}{.}}}\next \hbox{\csname\prettynamecs\hostparsernamespace{.origin&}\endcsname{}}% @@ -214,14 +236,14 @@ }\the\toksc }{% {% - \let\termindex\writeidxentry + \let\termindex\writeldidxentry \let\hostparsernamespace\cwebclinknamespace% process the variable names as in \CWEB \edef\next{\toksc{\gidxentry{\termhostidstring}{#1}{}}}\next \hbox{% \expandafter\let\expandafter\tosmallparser\csname to\stripbrackets\cwebclinknamespace parser\endcsname \let\optstrextra\optstrextraesc \nameproc{#2}\with\parsebin - \it\the\toksa + \\{\the\toksa}% }% \expandafter }\the\toksc @@ -259,27 +281,34 @@ \defc\ldmemoryspec{% \toksb{\hfil&}% - \let\termindex\writeidxhentry + \let\termindex\writeldidxhentry \ldextractmemname#1\concat\toksb\toksc \let\termindex\eatone \appendrnx\toksb{&}% - \toksc{}#2\concat\toksb\toksc - \toksc{}#3\concat\toksb\toksc + \toksc{}#2\appendrnx\toksc{&}\concat\toksb\toksc% attributes + \toksc{}#3\appendrnx\toksc{&}\concat\toksb\toksc \toksc{}#4\concat\toksb\toksc \concat\toksa\toksb \toksb{\cr}\concat\toksa\toksb } -\defc\ldattributes{% - \ldextractname#1\appendrnx\toksc{&}% +\defc\ldattrstring{% + \appendrnx\toksc{{\ntt@ #2}}% +} + +\defc\ldattrstringneg{% + \appendrnx\toksc{\hbox{$\neg$}{\ntt@ #2}}% +} + +\defc\ldspace{% } \defc\ldlengthspec{% - \toksc{#1}% + \toksc{$#1$}% } \defc\ldoriginspec{% - \toksc{#1&}% + \toksc{#1}% } \defc\ldinclude{% @@ -290,15 +319,7 @@ \concat\toksa\toksc } -\defc\ldmemspecseparator{% TODO: remove after testing is complete - \restorecs{table-render}{\strm}% - \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax - \else - \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% - \edef\next{\toksc{&\noexpand\multispan4\toksa{}\the\yystashlocal - \noexpand\ldmakestashbox{\cdotfill}\noexpand\quad\cr}}\next\concat\toksa\toksc - \fi -} +% TODO: change the code to use linked lists \defc\ldmemspecseparator{% \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax @@ -309,16 +330,6 @@ } \defc\ldmemspecstash{% - \restorecs{table-render}{\strm}% - \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax - \else - \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% - \edef\next{\toksc{&\noexpand\multispan4\toksa{}\the\yystashlocal - \noexpand\ldmakestashbox{\cdotfill}\noexpand\quad\cr}}\next\concat\toksa\toksc - \fi -} - -\defc\ldmemspecstash{% \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax \else \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% @@ -370,7 +381,7 @@ \else \toksb\expandafter{&}% section header \advance\tempca\m@ne - \ldextractitem\tempca{#6}% expression + \ldextractitem\tempca{#6}% next statement \advance\tempca\@ne \yytoksempty\toksc{% \ldextractfill#7% @@ -382,7 +393,7 @@ \fi \fillextractedtrue }{% - \toksc\expandafter{\expandafter\qquad\expandafter$\the\toksc{}$}% + \toksc\expandafter{\expandafter\qquad\the\toksc{}}% }% \concat\toksb\toksc \appendrnx\toksb{&}% @@ -407,7 +418,60 @@ \repeat } -\def\ldextractitem#1#2{% + +% named section :: \ldnamedsection{name} + % {{bind?}{expression}{block?}{expression}{type}}{at} + % {{}{}{}:alignment} + % {constraint}{statements} + % {{memspec}{memspec_at}{phdr}{fill}} + +\defc\ldoverlay{% overlay sections :: \ldoverlay{expression}{crossrefs}{at}{subalign} + % {sections} + % {{memspec}{memspec_at}{phdr}{fill}} + \yystringempty{#1}{\tokse{}}{\tokse{ $#1$}}% + \yystringempty{#2}{\toksf{}}{\toksf{{ \ttl noxrefs}}}% + \yystringempty{#3}{\toksg{}\toksc{}}{\toksg{{\ttl at} $#3$}\toksc{ }}% + \yystringempty{#4}{\toksh{}}{\toksh\expandafter{\expandafter{\the\tokc\ttl subalign} $#4$}}% + \appendr\toksa{&\hskip-1em\noexpand\ttl overlay\the\tokse\the\toksf&&\the\toksg\the\toksh}% + \ldwrapoverlay#6% + \appendr\toksa{&\the\toksc&\cr}% + #5% + \ldoverlayfill#6% + \yytoksempty\toksd{}{\appendr\toksa{&\the\toksd&&&&&\cr}}% attach the fill at the end + \appendr\toksa{&\hskip-1em{\ttl overlay end}&&&&&\cr}% +} + +\defc\ldoverlaysection{% overlay section :: \ldoverlaysection{name}{statements}{phdr}{fill} + \ldnamedsection{#1}% + {{}{}{}{}{}}{}% + {{}{}{}}% + {}{#2}% + {{}{}{#3}{#4}}% +} + +\def\ldwrapoverlay#1#2#3#4{% puts memspec... in \toksc and fill in \toksd + \toksc{}% + \yystringempty{#1}{% any > ? + }{% + \ldextractname#1% + \toksd{{\ttl in }}% + \concatl\toksd\toksc + }% + \yystringempty{#2}{% any AT > ? + }{% + \yytoksempty\toksc{\toksc{{\ttl as }}}{\appendrnx\toksc{ {\ttl as }}}% + \toksd=\toksc + \ldextractname#2% + \concat\toksd\toksc + \toksc=\toksd + }% +} + +\def\ldoverlayfill#1#2#3#4{% + \ld@xtractfill{#4}% +} + +\def\ldextractitem#1#2{% #1 is a counter, #2 is a list separated by \ldor \yystringempty{#2}{% \toksc{}% }{% @@ -463,18 +527,23 @@ } \def\ldextractfill#1#2#3#4{% + \toksc{}% \yystringempty{#4}{% - \toksc{}% \fillextractedtrue }{% \iffillextracted - \toksc{}% \else - \toksc={\qquad{\ttl fill }$#4$}% + \ld@xtractfill{#4}% + \appendr\toksc{\noexpand\qquad{\noexpand\ttl fill }$\the\toksd$}% \fi }% } +\def\ld@xtractfill#1{% #1 must be \ldfill{expression} +\toksf{#1}% + \toksd\expandafter{#1}% +} + \def\ldpushpheaders#1#2#3#4{% \ldextractitem\tempcc{#3}% \advance\tempcc\@ne @@ -491,11 +560,10 @@ \toksd{\hbox{\ttl #1}}% } -\defc\ldstatement{{#1}} % the braces form the group for a \toks assignment - -\let\ldsecspec\ldstatement +\defc\ldstatement{{\let\ldrlap\relax\let\ldintfont\ntt@$#1$}} % the braces form the group for a \toks assignment +\defc\ldfreestmt{\toksb\expandafter{#1}\appendr\toksa{&\the\toksb\cr}} -\defc\ldsectionseparator{\toksc{&\multispan5\cdotfill\quad\cr}\concat\toksa\toksc} +\defc\ldsecspec{{$#1$}} \def\ldboxstash#1{% \ifchecktrim\errmessage{stash contents: \the\toksa}\fi @@ -506,16 +574,6 @@ \def\ldmakestashbox#1{\cleanstash\stripstash\ldboxstash{#1}} \defc\ldsectionseparator{% - \restorecs{table-render}{\strm}% - \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax - \else - \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% - \edef\next{\toksc{&\noexpand\multispan5\toksa{}\the\yystashlocal - \noexpand\ldmakestashbox{\cdotfill}\noexpand\quad\cr}}\next\concat\toksa\toksc - \fi -} - -\defc\ldsectionseparator{% \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax \else \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% @@ -524,17 +582,6 @@ } \defc\ldsectionstash{% - \restorecs{table-render}{\strm}% - \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax - \else - \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% - \edef\next{\toksc{\sections@header&\noexpand\multispan5\toksa{}\the\yystashlocal - \noexpand\ldmakestashbox{\cdotfill}\noexpand\quad\cr}}\next\concat\toksa\toksc - \def\sections@header{}% - \fi -} - -\defc\ldsectionstash{% \expandafter\ifx\csname ldstashentry[#2]\endcsname\relax \else \expandafter\expandafter\expandafter\yystashlocal\expandafter\expandafter\expandafter{\csname ldstashentry[#2]\endcsname}% @@ -546,7 +593,12 @@ \restorecs{ld-display}{\ldregexp\ldassignment\ldfill\ldinsertcweb\ldentry} \toyyunion{ld-parser:sections} -% preprocessing macros: collecing stash and marking variables +% preprocessing macros: collecting stash and marking variables +% currently these macros do not get inside expressions to extract +% variable names, consequently if the variable is used before it +% appears in an assignment, it will not be displayed properly +% (is this even legal in linker scripts?) although the index will +% show it correctly \restorecslist{ld-parser-prototypes}\ldunion \restorecs{ld-parser-strict}{\insertcweb} @@ -557,7 +609,8 @@ \readstash{#2}% \setbox0 \vbox{\toksa\expandafter{\the\yystashlocal}\cleanstash\stripstash\the\toksa}% \ifdim\ht0=\z@ - \expandafter\let\csname ldstashentry[#2]\endcsname\relax + \expandafter\let\csname ldstashentry[#2]\endcsname\relax % this is redundant but we may change \relax to + % something else later \else \expandafter\edef\csname ldstashentry[#2]\endcsname{\the\yystashlocal}% \fi @@ -575,6 +628,12 @@ \defc\ldsections{#1} % ld sections :: \ldsections{sections} +\defc\ldoverlay{% overlay section :: \ldoverlay{expression}{crossrefs}{at}{subalign} + % {sections} + % {{memspec}{memspec_at}{phdr}{fill}} + #3#5% +} % TODO: add handling of subalign, memmspec, and memspec_at + \defc\ldsectionseparator{% \readstash{#2}% \setbox0 \vbox{\toksa\expandafter{\the\yystashlocal}\cleanstash\stripstash\the\toksa}% @@ -606,37 +665,20 @@ } % command separator :: \ldcommandseparator{fptr}{sptr}{prev command}{next command} \defc\ldstatement{#1} - +\defc\ldfreestmt{#1} +\defc\ldassignment{#1} +\defc\ldprovide{#1} +\defc\ldentry{#1} +\let\ldhidden\ldprovide +\let\ldprovidehid\ldprovide \defc\ldnamedsection{\let\ldor\empty#6} -\defc\ldassignment{% - {% - \let\ldregexp\markldname - #1% - }{\errmessage{Not an \\ldregexp!}}% -} -\defc\ldprovide{% - {% - \let\ldregexp\markldname - #1% - }{\errmessage{Not an \\ldregexp!}}% -} - -\defc\ldentry{% - {% - \let\ldregexp\markldname - #1% - }{\errmessage{Not an \\ldregexp!}}% +\defc\ldregexp{% + \ldr@gexprestash#1% } -\def\markldname#1{% - \markldn@me#1% +\def\ldr@gexprestash#1#2#3#4{ + \expandafter\def\csname ldvarname[#2]\endcsname{\errmessage{Not an \\ldregexp!, maybe change the parser namespace?}}% } -\def\markldn@me#1#2#3#4{% - \aftergroup\def\expandafter\aftergroup\csname ldvarname[#2]\endcsname -} - -\let\ldhidden\ldprovide -\let\ldprovidehid\ldprovide \toyyunion{ld-parser:restash} |