Conversion operator is handled now. The scope operator is now allowed in the

return type, but no longer in the function or method name.
Two character operators are now allowed to have a space before the
opening parantheses.
The \var macro uses now the \CCfont macro for formatting.
This commit is contained in:
Lutz Kettner 1995-09-11 19:37:20 +00:00
parent 0f4958ac10
commit 742687a86b
2 changed files with 84 additions and 58 deletions

View File

@ -165,7 +165,7 @@
\begingroup\CCcatcode\creationvariableX} \begingroup\CCcatcode\creationvariableX}
\def\creationvariableX #1{% \def\creationvariableX #1{%
\gdef\var{$#1$} \gdef\var{{\CCfont #1\CCendfont}}
\gdef\purevar{#1} \gdef\purevar{#1}
\endgroup} \endgroup}
@ -270,6 +270,7 @@
% | Predicates: % | Predicates:
% | % |
% | isEmpty, isLetter, hasLeadingSpace, isOperator, isParenthesisOperator % | isEmpty, isLetter, hasLeadingSpace, isOperator, isParenthesisOperator
% | isConversionOperator
% | % |
% | All predicates uses pattern matching of TeX. The original predicate uses % | All predicates uses pattern matching of TeX. The original predicate uses
% | a single parameter that should be in braces like in LaTeX. Internally, % | a single parameter that should be in braces like in LaTeX. Internally,
@ -348,6 +349,14 @@
% if and only if #6 is non empty, we have the () operator. % if and only if #6 is non empty, we have the () operator.
\isEmpty{#6}\CCinvert} \isEmpty{#6}\CCinvert}
% This macro gets a complete C++ declaration for an operator and has to
% decide weather it is the conversion operator declaration or not.
\def\isConversionOperator #1{%
\isConversionOperatorX #1\end}
\def\isConversionOperatorX #1operator#2\end{%
% if and only if #1 is empty, we have the conversion operator.
\isEmpty{#1}}
% +-------------------------------------------------------------------------- % +--------------------------------------------------------------------------
% | Toplevel declaration formatting: % | Toplevel declaration formatting:
@ -388,6 +397,10 @@
\fi \fi
\def\CCextendedFormat{\ }% Switches ext. format OFF. \def\CCextendedFormat{\ }% Switches ext. format OFF.
\isOperator{#2 #3(#4)#5}\ifnum\CCbool=\CCtrue \isOperator{#2 #3(#4)#5}\ifnum\CCbool=\CCtrue
\isConversionOperator{#2 #3(#4)#5}
\ifnum\CCbool=\CCtrue
\CCprintConversionOperator #2 #3(#4)#5\end
\else
\CCseparateOperator #2 #3\end% \CCseparateOperator #2 #3\end%
\isParenthesisOperator{#2 #3(#4)#5}% \isParenthesisOperator{#2 #3(#4)#5}%
\ifnum\CCbool=\CCtrue \ifnum\CCbool=\CCtrue
@ -397,8 +410,9 @@
\setbox\functioncallbox=\hbox{{\CCfont \setbox\functioncallbox=\hbox{{\CCfont
\CCprintOperator #1#2 #3(#4)#5\end}} \CCprintOperator #1#2 #3(#4)#5\end}}
\fi \fi
\fi
\else \else
\CCseparateFunction #2 #3::\end% \CCseparateFunction{}#2 #3::\end%
\setbox\functioncallbox=\hbox{{\CCfont \setbox\functioncallbox=\hbox{{\CCfont
\ifnum#1=0 \purevar.\fi \ifnum#1=0 \purevar.\fi
\unhcopy\functionnamebox(% \unhcopy\functionnamebox(%
@ -448,55 +462,45 @@
% Set the two boxes, returntype and functionname, for a function declaration. % Set the two boxes, returntype and functionname, for a function declaration.
% The part of the declaration has to be terminated with "::\end". % The part of the declaration has to be terminated with "::\end".
\def\CCseparateFunction #1::#2\end{% \def\CCseparateFunction #1#2::#3\end{%
\isEmpty{#2}\ifnum\CCbool=\CCtrue \isEmpty{#3}\ifnum\CCbool=\CCtrue
\CCseparateFunctionXX{}{}#1 .\end% \CCseparateFunctionXX{#1}#2 .\end%
\else \else
\CCseparateFunctionX{#1}#2\end% \CCseparateFunction{#1#2::}#3\end%
\fi} \fi}
\def\CCseparateFunctionX #1#2::\end{%
\CCseparateFunctionXX{}{#2}#1 .\end}
% Set the two boxes, returntype and functionname, for a function declaration. % Set the two boxes, returntype and functionname, for a function declaration.
% This macro scans through the token list space by space. If the operators % This macro scans through the token list space by space. If the operators
% & or * occurs on the right side, they are shifted to the left. % & or * occurs on the right side, they are shifted to the left.
% o The 1st parameter is the first part of the type. % o The 1st parameter is the first part of the type.
% o The 2nd parameter is the last part of the function name. % o The 2nd parameter is the next part of the type name.
% o The 3rd parameter is the next part of the type name. % o The 3rd and 4th parameter are the next part of the return type or
% o The 4th and 5th parameter are the next part of the return type or % the name, if #4 is empty. Then, the 3rd parameter is the first
% the name, if #6 is empty. Then, the 4th parameter is the first
% character of it. % character of it.
% o The 6th parameter is the rest of the type and name. % The part of the declaration has to be terminated with " .\end".
% The part of the declaration has to be terminated with " \end". \def\CCseparateFunctionXX #1#2 #3#4\end{%
\def\CCseparateFunctionXX #1#2#3 #4#5\end{% \isEmpty{#4}\ifnum\CCbool=\CCtrue
\isEmpty{#5}\ifnum\CCbool=\CCtrue
\setbox\returntypebox=\hbox{{\CCfont \setbox\returntypebox=\hbox{{\CCfont
\CCprintReturnType #1const.&.\end}}% \CCprintReturnType #1const.&.\end}}%
\def\xparams{#2}\ifx\xparams\empty
\setbox\functionnamebox=\hbox{{\CCfont \setbox\functionnamebox=\hbox{{\CCfont
\CCprintTokens #3\end}}% \CCprintTokens #2\end}}%
\else
\setbox\functionnamebox=\hbox{{\CCfont
\CCprintTokens #3::#2\end}}%
\fi
\else \else
\def\xparams{#1}\ifx\xparams\empty \def\xparams{#1}\ifx\xparams\empty
\if#4&% \if#3&%
\CCseparateFunctionXX{#3#4}{#2}#5\end% \CCseparateFunctionXX{#2#3}#4\end%
\else\if#4*% \else\if#3*%
\CCseparateFunctionXX{#3#4}{#2}#5\end% \CCseparateFunctionXX{#2#3}#4\end%
\else \else
\CCseparateFunctionXX{#3}{#2}#4#5\end% \CCseparateFunctionXX{#2}#3#4\end%
\fi\fi \fi\fi
\else \else
\if#4&% \if#3&%
\CCseparateFunctionXX{#1 #3#4}{#2}#5\end% \CCseparateFunctionXX{#1 #2#3}#4\end%
\else\if#4*% \else\if#3*%
\CCseparateFunctionXX{#1 #3#4}{#2}#5\end% \CCseparateFunctionXX{#1 #2#3}#4\end%
\else \else
\CCseparateFunctionXX{#1 #3}{#2}#4#5\end% \CCseparateFunctionXX{#1 #2}#3#4\end%
\fi\fi \fi\fi
\fi \fi
\fi} \fi}
@ -578,6 +582,17 @@
\CCprintOperatorOne{#1}{}{#6}()\end \CCprintOperatorOne{#1}{}{#6}()\end
\fi} \fi}
% Formats a conversion operator.
% Uses the returntypebox and the functioncallbox.
% The declaration ends with "\end".
\def\CCprintConversionOperator #1operator #2(#3)#4\end{%
\setbox\returntypebox=\hbox{{\CCfont
\CCprintTokens #2\end}}
\setbox\functioncallbox=\hbox{{\CCfont
\CCprintTokens #2(\purevar)\end}}
}
% An operator is detected and can be printed. % An operator is detected and can be printed.
% o The first parameter contains a 0 for a method call, a 1 for a function. % o The first parameter contains a 0 for a method call, a 1 for a function.
% o The second parameter contains the \purevar if it is a method. % o The second parameter contains the \purevar if it is a method.
@ -629,7 +644,7 @@
style, sorry. Go ahead, and I format it as style, sorry. Go ahead, and I format it as
a function}@ a function}@
\ifnum#1=0 {\CCfont \purevar.}\fi \ifnum#1=0 {\CCfont \purevar.}\fi
\CCprintTokens operator#4#5\end@ \CCprintTokens operator #4#5\end@
(\isEmpty{#3}\ifnum\CCbool=\CCfalse (\isEmpty{#3}\ifnum\CCbool=\CCfalse
\CCprintParamList{#3}\fi \CCprintParamList{#3}\fi
)@ )@
@ -642,8 +657,7 @@
@ o The third parameter contains the rest of the operator. @ o The third parameter contains the rest of the operator.
@ The declaration ends with "\end". @ The declaration ends with "\end".
\gdef\CCprintOperatorTwo #1#2#3\end{@ \gdef\CCprintOperatorTwo #1#2#3\end{@
\def\xparams{#3}@ \isEmpty{#3}\ifnum\CCbool=\CCtrue
\ifx\xparams\empty
@ two character operations @ two character operations
\ifcase\NParameters @ no parameter \ifcase\NParameters @ no parameter
\or @ 1 parameter \or @ 1 parameter

View File

@ -103,12 +103,15 @@ with operators. See the following example:
\CCstyle{ \CCstyle{
#define %^~ Return_Type<Template_Param, X<Y> > fct_foo( const X<Y> &a);} #define %^~ Return_Type<Template_Param, X<Y> > fct_foo( const X<Y> &a);}
To achieve this behaviour with \TeX\, the \verb"\catcode" values of This example is created using the {\verb+\CC+}{\tt style} macro
that formats its single parameter in this style.
To achieve this behavior with \TeX\, the \verb"\catcode" values of
some characters has to be changed. So within the \CC\ code some characters has to be changed. So within the \CC\ code
things like comments with ``\%'' sign wont work. Several macros read a things like comments with ``\%'' sign will not work. Several macros read a
second parameter with a \TeX\ comment to the declaration. The catcodes second parameter with a \TeX\ comment to the declaration. The catcodes
are restored just before this second parameter. A sad sideeffect is are restored just before this second parameter. A sad sideeffect is
that these changed catcodes wont apply if these macros are invoced that these changed catcodes will not apply if these macros are invoked
within other macros. In that case, the argument text was just once within other macros. In that case, the argument text was just once
parsed from \TeX\ and the catcodes are all fixed before the catcode parsed from \TeX\ and the catcodes are all fixed before the catcode
changing macro expands. changing macro expands.
@ -124,12 +127,12 @@ name as it was originally written can be accessed using the
\creation \creation
The constructors create a variable \var\ of the class. The The constructors create a variable \var\ of the class. The
\verb"\creationvariable{"\ldots\verb"}" macro sets the name for the \verb"\"\verb"creationvariable{"\ldots\verb"}" macro sets the name for the
future use. It can be accessed with the \verb"\var" or future use. It can be accessed with the \verb"\var" or
\verb"\purevar" macro. \verb"\purevar" macro.
The constructors are written using the The constructors are written using the
\verb"\constructor{"\ldots\verb"}{"\ldots\verb"}" macro. The first \verb"\"\verb"constructor{"\ldots\verb"}{"\ldots\verb"}" macro. The first
parameter contains the \CC\ declaration, the second parameter the comments. parameter contains the \CC\ declaration, the second parameter the comments.
The declaration is written in the normal \CC\ fashion, as shown at the end The declaration is written in the normal \CC\ fashion, as shown at the end
of the comment. The style formats them as if they are used of the comment. The style formats them as if they are used
@ -220,10 +223,17 @@ future). An example:
Operator declarations are formatted as like the operators are Operator declarations are formatted as like the operators are
used. All operators that are allowed to be overloaded in \CC\ are used. All operators that are allowed to be overloaded in \CC\ are
handled. They are listed in the last section for completeness and handled. They are listed in the last section for completeness and
to check the layout. Type casting through an operator is currently to check the layout.
not supported. It will give an error message. If the error will be
ignored, the macro formats the operator as a method or function, Type casting through a conversion operator is the default behavior
as it was declared. Sometimes, there is a choice between for the formatting routine if the return type before the {\tt
operator} keyword is empty.
\function{ operator int () const;}{Conversion operator.}
\function{operator A< FT>() const;}{Conversion operator.}
Sometimes, there is a choice between
implementing an operator as a method or as a function. Both implementing an operator as a method or as a function. Both
declarations will produce the same formatting, as demonstrated declarations will produce the same formatting, as demonstrated
with the next two declarations. with the next two declarations.
@ -232,7 +242,7 @@ with the next two declarations.
operator+(Demo_Class p, Demo_Class q);}{Declaration via function.} operator+(Demo_Class p, Demo_Class q);}{Declaration via function.}
\method{Demo_Class \method{Demo_Class
operator-(Demo_Class q);}{Declaration via method.} operator+(Demo_Class q);}{Declaration via method.}
There is some laziness allowed in placing spaces around the operator There is some laziness allowed in placing spaces around the operator
characters. See the following examples: characters. See the following examples:
@ -263,12 +273,14 @@ style can handle such cases:
\method{A operator0(Demo_Class q);}{} \method{A operator0(Demo_Class q);}{}
For future extensions, the macro that separates the return type from CGAL will use {\tt typedef}'s and the scope operator to define types.
the function or method name recognizes the scope operator (, but Here is an example for the scope operator within types. The scope
currently not in the usage as the global scope). An example: operator cannot be used within the function or method name.
\function{Demo_Class \threecolumns{5.8cm}{2.8cm}
Class_X :: foo(Demo_Class p, Demo_Class q);}{Declaration with scope.} \function{Demo_Class::Nested_Class
foo(Demo_Class::Nested_Class p, Demo_Class q);}{
Declaration with scope.}
Other features should be incorporated. These are: Preprocessor Other features should be incorporated. These are: Preprocessor
constants and macros, normal C variable declarations and constants, constants and macros, normal C variable declarations and constants,