Parameter lists are now correct separated.

Matching const ... & pairs are eliminated from parameters.
A leading classname is eliminated from a parameter.
This commit is contained in:
Lutz Kettner 1995-08-10 14:12:08 +00:00
parent 4f52196c78
commit cab523f0f8
1 changed files with 135 additions and 46 deletions

View File

@ -5,8 +5,10 @@
% $Date$ % $Date$
% ---------------------------------------- % ----------------------------------------
% \tracingmacros=1 \tracingmacros=1
\newcount\spaceflag \newcount\nestinglevel % counts nesting levels of template parameters
\newcount\xnestinglevel % counts nesting levels of template parameters
\newcount\spaceflag % result, weather a parameter starts with a space
% These macros allow the characterwise parsing of an argument, where normally % These macros allow the characterwise parsing of an argument, where normally
% the spaces are ignored. % the spaces are ignored.
@ -21,7 +23,7 @@
\def\xxparams{#1}\def\xxxparams{#2#3}\ifx\xxparams\xxxparams\spaceflag=0 \def\xxparams{#1}\def\xxxparams{#2#3}\ifx\xxparams\xxxparams\spaceflag=0
\else\spaceflag=1 \fi} \else\spaceflag=1 \fi}
\def\testAndCopySpace #1{% \def\testAndCopySpace #1{%
\compareAndCopySpace{#1}#1\end} \def\qparams{#1}\ifx\qparams\empty\else\compareAndCopySpace{#1}#1\end\fi}
\def\compareAndCopySpace #1#2#3\end{% \def\compareAndCopySpace #1#2#3\end{%
\def\xxparams{#1}\def\xxxparams{#2#3}\ifx\xxparams\xxxparams\else\ \fi} \def\xxparams{#1}\def\xxxparams{#2#3}\ifx\xxparams\xxxparams\else\ \fi}
@ -48,7 +50,7 @@
\label{#1}} \label{#1}}
\def\creationvariable #1{\creation #1} \def\creationvariable #1{\creation #1}
\def\threecolumns #1 #2 {\typewidth=#1 % compare to setopdims \def\threecolumns #1#2{\typewidth=#1 % compare to setopdims
\callwidth=#2 \callwidth=#2
\descriptwidth=\textwidth \descriptwidth=\textwidth
\advance\descriptwidth-\typewidth \advance\descriptwidth-\typewidth
@ -90,60 +92,131 @@
% Print one parameter in C++ style (including spaces). % Print one parameter in C++ style (including spaces).
\def\CCstyle #1{{\em \CCprintTokens #1 ;\/}} \def\CCstyle #1{{\em \CCprintTokens #1 ;\/}}
% Print a parameter where "const ...&" pairs are eliminated. Strips a
% leading type that equals the \classname. It is a three step process:
% 1. strip all in front of a "<" character.
% 2. extract the leading token without any space in it to decide,
% weather the type given is a templated type or not.
% 3. Compare the leading token with \classname
% 4. If true, strip the possible following template parameter.
% The parameter has to be delimited with "<>;".
% Ignore leading spaces.
\def\CCprintOwnClassParameter #1#2<#3#4;{%
\if>#3%
\CCprintOwnClassX #1#2 ;% no template case
\else
\CCprintOwnClassXX{#1#2}<#3#4;% template case ?
\fi}
\def\CCprintOwnClassX #1 #2;{% check for \classname
\def\xparams{#1}\ifx\xparams\pureclassname
\CCprintTokens #2;%
\else
\CCprintTokens #1 #2;%
\fi}
\def\CCprintOwnClassXX #1#2<>;{% strip the unneccessary <> from the end
\CCprintOwnClassXXX {#2}#1 ;}
\def\CCprintOwnClassXXX #1#2 #3;{%
% check \classname in the possible template case
% #1 is the parameter tail starting with the template params
% #2 is the leading class name
% #3 is inbetween and should be empty
\def\qqparams{#3}\ifx\qqparams\empty
\def\xparams{#2}\ifx\xparams\pureclassname
\xnestinglevel=0
\CCprintOwnClassXXXX #1;% strip the template parameters
\else
\CCprintTokens #2#1 ;% nothing stripped
\fi
\else
\errhelp{The allowed syntax is: name< params...}%
\errmessage{Confusing class name with a space before
the template parameters.}%
\fi}
\def\CCprintOwnClassXXXX #1#2;{% strip a leading template parameter
\if<#1\advance\xnestinglevel by1 \fi
\if>#1\advance\xnestinglevel by-1 \fi
\ifnum\xnestinglevel=0
\CCprintTokens #2 ;%
\let\xnext=\relax
\else
\def\xparams{#2}%
\ifx\xparams\empty
\errhelp{Look for mismatching angles.}%
\errmessage{Mismatching angles in template
parameter list.}%
\fi
\def\xbody{\CCprintOwnClassXXXX #2;}%
\let\xnext=\xbody
\fi
\xnext}
% Print a C++ function or method parameter. Strips a matching
% "const ...&" pair.
% The parameter has to be delimited with "const.&.;".
\def\CCprintParameter #1const#2#3&#4#5;{%
\if.#2\CCprintOwnClassParameter #1<>;%
\else
\if&#2\CCprintParameter #1#3&#4#5;%
\else
\CCprintParameter #1#2#3 #4#5;%
\fi
\fi}
% Print a C++ parameter list (separated with commatas). The output formats % Print a C++ parameter list (separated with commatas). The output formats
% with a space in front of the parameter text. % with a space between commata and the parameter text.
\def\CCprintParamList #1{%
\nestinglevel=0
\CCprintParamListX{}#1;}
% Support function:
% o The first parameter accumulates the so far parsed first parameter. % o The first parameter accumulates the so far parsed first parameter.
% o The second parameter contains the current nesting level. Start with 0. % o The second parameter contains the next character.
% o The third parameter contains the next character. % o The third parameter contains the rest.
% o The fourth parameter contains the rest.
% The parsing process iterates characterwise. % The parsing process iterates characterwise.
% The parameter list has to be terminated with ";". % The parameter list has to be terminated with ";".
\newcount\nestinglevel \def\CCprintParamListX #1#2#3;{%
\def\CCprintParamList #1#2#3#4;{% \testSpace{#3}%
\def\xxparams{#4}% \if<#2\advance\nestinglevel by1 \fi
\nestinglevel=#2% \if>#2\advance\nestinglevel by-1 \fi
% \edef\spaceflag{\testSpace{#4}}% \if,#2%
\testSpace{#4}% \ifnum\nestinglevel=0
\if<#3\advance\nestinglevel by1\fi \CCprintParameter #1const.&.;,\ %
\if>#3\advance\nestinglevel by-1\fi \def\xxbody{\CCprintParamListX{}#3;}%
\if,#3% \else\ifnum\nestinglevel<0
\ifnum\nestinglevel=0%
\CCprintTokens #1 ;,\ %
\def\xxbody{\CCprintParamList{}{0}#4;}%
\else\ifnum\nestinglevel<0%
\def\errhelp{Look for unbalanced angles in \def\errhelp{Look for unbalanced angles in
template types in the C++ parameter list.}% template types in the C++ parameter list.}%
\errmessage{Unbalanced angles detected.}% \errmessage{Unbalanced angles detected.}%
\def\xxbody{\CCprintParamList{}{0}#4;}% \def\xxbody{\CCprintParamListX{}#3;}%
\else% comma within template parameter detected \else% comma within template parameter detected
\ifnum\spaceflag=1 \ifnum\spaceflag=1
\def\xxbody{\CCprintParamList \def\xxbody{\CCprintParamListX
{#1#3 }{\nestinglevel}#4;}% {#1#2 }#3;}%
\else \else
\def\xxbody{\CCprintParamList \def\xxbody{\CCprintParamListX
{#1#3}{\nestinglevel}#4;}% {#1#2}#3;}%
\fi \fi
\fi \fi
\fi \fi
\else\ifx\xxparams\empty% \else\def\xxparams{#3}\ifx\xxparams\empty%
\ifnum\nestinglevel=0% \ifnum\nestinglevel=0
\CCprintTokens #1#3 ;% \CCprintParameter #1#2const.&.;%
\else\def\errhelp{Look for unbalanced angles in \else\def\errhelp{Look for unbalanced angles in
template types in the C++ parameter list.}% template types in the C++ parameter list.}%
\errmessage{Unbalanced angles detected.}% \errmessage{Unbalanced angles detected.}%
\fi \fi
\def\xxbody{\CCprintParamList{}{0}#4;}% \def\xxbody{\CCprintParamListX{}#3;}%
\else \else
\ifnum\spaceflag=1 \ifnum\spaceflag=1
\def\xxbody{\CCprintParamList \def\xxbody{\CCprintParamListX
{#1#3 }{\nestinglevel}#4;}% {#1#2 }#3;}%
\else \else
\def\xxbody{\CCprintParamList \def\xxbody{\CCprintParamListX
{#1#3}{\nestinglevel}#4;}% {#1#2}#3;}%
\fi \fi
\fi \fi
\fi \fi
\ifx\xxparams\empty\let\xxnext=\relax \def\xxparams{#3}\ifx\xxparams\empty\let\xxnext=\relax
\else\let\xxnext=\xxbody\fi \else\let\xxnext=\xxbody\fi
\xxnext} \xxnext}
@ -152,9 +225,9 @@
\def\params{#2}\ifx\params\empty% \def\params{#2}\ifx\params\empty%
\mbox{\classtemplatename\ \ \var;}% \mbox{\classtemplatename\ \ \var;}%
\else\mbox{\classtemplatename \else\mbox{\classtemplatename
\ \ \var{\em (\CCprintParamList{}{0}#2;);}}% \ \ \var{\em (\CCprintParamList{#2});}}%
\fi\par } \fi\par }
\def\constructor #1 #2 {% \def\constructor #1#2{%
\constructorcall #1 \par \constructorcall #1 \par
\hspace*{1cm}\hfill \hspace*{1cm}\hfill
\parbox[t]{\createtextwidth}{\sloppy #2}\par \parbox[t]{\createtextwidth}{\sloppy #2}\par
@ -173,26 +246,42 @@
\ifx\params\empty \CCprintSingleToken #1;% \ifx\params\empty \CCprintSingleToken #1;%
\else\extractname #2;\fi} \else\extractname #2;\fi}
\def\methodcall #1 #2(#3)#4; #5; {% % Formats a method or a function call.
% o The first parameter contains a 0 for a method call, a 1 for a function.
% o The second parameter contains the beginning of the type declaration.
% o The third parameter contains the rest of the type and the function name.
% o The fourth parameter contains the parameter list (maybe empty).
% o The fifth parameter contains the optional const specifier for methods.
% The declaration has to be terminated with ";;\end" where the first ";"
% has to be from the original call notation. The sixth parameter is there
% to check for this ";".
\def\functioncall #1#2 #3(#4)#5;#6\end{%
\def\xparam{#6}\ifx\xparam\empty\def\errhelp{A method
or function declaration has to end with a ";".}%
\errmessage{Missing ";" at the end of the
declaration. Go ahead, I've inserted one.}%
\fi
\parbox[t]{\typewidth}{\sloppy \parbox[t]{\typewidth}{\sloppy
{\em \extracttype {#1}#2 ;}} {\em \extracttype {#2}#3 ;}}
\setbox0=\hbox{\mbox{ \setbox0=\hbox{\mbox{
#5{\em \extractname #2 ;% \ifnum#1=0 \var.\fi{\em \extractname #3 ;%
(\def\params{#3}\ifx\params\empty\else% (\def\params{#4}\ifx\params\empty\else%
\CCprintParamList{}{0}#3;\fi)} \CCprintParamList{#4}\fi)}
}} }}
\ifdim\wd0>\callwidth \ifdim\wd0>\callwidth
\parbox[t]{\callwidthl}{\box0}\hfill\par \parbox[t]{\callwidthl}{\box0}\hfill\par
\hspace*{1cm}\hfill \hspace*{1cm}\hfill
\else\parbox[t]{\callwidth}{\box0}\hfill \else\parbox[t]{\callwidth}{\box0}\hfill
\fi} \fi}
\def\method #1 #2 {\smallskip \def\method #1#2{%
\methodcall #1; \var.; \smallskip
\functioncall{0}#1;\end
\parbox[t]{\descriptwidth}{\sloppy #2}\hfill\par \parbox[t]{\descriptwidth}{\sloppy #2}\hfill\par
\smallskip} \smallskip}
\def\function #1 #2 {\smallskip \def\function #1#2{%
\methodcall #1; ; \smallskip
\functioncall{1}#1;\end
\parbox[t]{\descriptwidth}{\sloppy #2}\hfill\par \parbox[t]{\descriptwidth}{\sloppy #2}\hfill\par
\smallskip} \smallskip}