From 742687a86b3efdbf56c2ba7b0e1ea4d6ab564bd0 Mon Sep 17 00:00:00 2001 From: Lutz Kettner Date: Mon, 11 Sep 1995 19:37:20 +0000 Subject: [PATCH] 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. --- Packages/Manual_tools/format/cc_manual.sty | 100 ++++++++++++--------- Packages/Manual_tools/format/test.tex | 42 +++++---- 2 files changed, 84 insertions(+), 58 deletions(-) diff --git a/Packages/Manual_tools/format/cc_manual.sty b/Packages/Manual_tools/format/cc_manual.sty index 2e6466f3744..18274d67119 100644 --- a/Packages/Manual_tools/format/cc_manual.sty +++ b/Packages/Manual_tools/format/cc_manual.sty @@ -165,7 +165,7 @@ \begingroup\CCcatcode\creationvariableX} \def\creationvariableX #1{% - \gdef\var{$#1$} + \gdef\var{{\CCfont #1\CCendfont}} \gdef\purevar{#1} \endgroup} @@ -270,6 +270,7 @@ % | Predicates: % | % | isEmpty, isLetter, hasLeadingSpace, isOperator, isParenthesisOperator +% | isConversionOperator % | % | All predicates uses pattern matching of TeX. The original predicate uses % | 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. \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: @@ -388,17 +397,22 @@ \fi \def\CCextendedFormat{\ }% Switches ext. format OFF. \isOperator{#2 #3(#4)#5}\ifnum\CCbool=\CCtrue - \CCseparateOperator #2 #3\end% - \isParenthesisOperator{#2 #3(#4)#5}% + \isConversionOperator{#2 #3(#4)#5} \ifnum\CCbool=\CCtrue - \setbox\functioncallbox=\hbox{{\CCfont - \CCprintParOperator #1#2 #3(#4)#5\end}} + \CCprintConversionOperator #2 #3(#4)#5\end \else - \setbox\functioncallbox=\hbox{{\CCfont - \CCprintOperator #1#2 #3(#4)#5\end}} + \CCseparateOperator #2 #3\end% + \isParenthesisOperator{#2 #3(#4)#5}% + \ifnum\CCbool=\CCtrue + \setbox\functioncallbox=\hbox{{\CCfont + \CCprintParOperator #1#2 #3(#4)#5\end}} + \else + \setbox\functioncallbox=\hbox{{\CCfont + \CCprintOperator #1#2 #3(#4)#5\end}} + \fi \fi \else - \CCseparateFunction #2 #3::\end% + \CCseparateFunction{}#2 #3::\end% \setbox\functioncallbox=\hbox{{\CCfont \ifnum#1=0 \purevar.\fi \unhcopy\functionnamebox(% @@ -448,55 +462,45 @@ % Set the two boxes, returntype and functionname, for a function declaration. % The part of the declaration has to be terminated with "::\end". -\def\CCseparateFunction #1::#2\end{% - \isEmpty{#2}\ifnum\CCbool=\CCtrue - \CCseparateFunctionXX{}{}#1 .\end% +\def\CCseparateFunction #1#2::#3\end{% + \isEmpty{#3}\ifnum\CCbool=\CCtrue + \CCseparateFunctionXX{#1}#2 .\end% \else - \CCseparateFunctionX{#1}#2\end% + \CCseparateFunction{#1#2::}#3\end% \fi} -\def\CCseparateFunctionX #1#2::\end{% - \CCseparateFunctionXX{}{#2}#1 .\end} - % Set the two boxes, returntype and functionname, for a function declaration. % 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. % 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 3rd parameter is the next part of the type name. -% o The 4th and 5th parameter are the next part of the return type or -% the name, if #6 is empty. Then, the 4th parameter is the first +% o The 2nd parameter is the next part of the type name. +% o The 3rd and 4th parameter are the next part of the return type or +% the name, if #4 is empty. Then, the 3rd parameter is the first % 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". -\def\CCseparateFunctionXX #1#2#3 #4#5\end{% - \isEmpty{#5}\ifnum\CCbool=\CCtrue +% The part of the declaration has to be terminated with " .\end". +\def\CCseparateFunctionXX #1#2 #3#4\end{% + \isEmpty{#4}\ifnum\CCbool=\CCtrue \setbox\returntypebox=\hbox{{\CCfont \CCprintReturnType #1const.&.\end}}% - \def\xparams{#2}\ifx\xparams\empty - \setbox\functionnamebox=\hbox{{\CCfont - \CCprintTokens #3\end}}% - \else - \setbox\functionnamebox=\hbox{{\CCfont - \CCprintTokens #3::#2\end}}% - \fi + \setbox\functionnamebox=\hbox{{\CCfont + \CCprintTokens #2\end}}% \else \def\xparams{#1}\ifx\xparams\empty - \if#4&% - \CCseparateFunctionXX{#3#4}{#2}#5\end% - \else\if#4*% - \CCseparateFunctionXX{#3#4}{#2}#5\end% + \if#3&% + \CCseparateFunctionXX{#2#3}#4\end% + \else\if#3*% + \CCseparateFunctionXX{#2#3}#4\end% \else - \CCseparateFunctionXX{#3}{#2}#4#5\end% + \CCseparateFunctionXX{#2}#3#4\end% \fi\fi \else - \if#4&% - \CCseparateFunctionXX{#1 #3#4}{#2}#5\end% - \else\if#4*% - \CCseparateFunctionXX{#1 #3#4}{#2}#5\end% + \if#3&% + \CCseparateFunctionXX{#1 #2#3}#4\end% + \else\if#3*% + \CCseparateFunctionXX{#1 #2#3}#4\end% \else - \CCseparateFunctionXX{#1 #3}{#2}#4#5\end% + \CCseparateFunctionXX{#1 #2}#3#4\end% \fi\fi \fi \fi} @@ -578,6 +582,17 @@ \CCprintOperatorOne{#1}{}{#6}()\end \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. % 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. @@ -629,7 +644,7 @@ style, sorry. Go ahead, and I format it as a function}@ \ifnum#1=0 {\CCfont \purevar.}\fi - \CCprintTokens operator#4#5\end@ + \CCprintTokens operator #4#5\end@ (\isEmpty{#3}\ifnum\CCbool=\CCfalse \CCprintParamList{#3}\fi )@ @@ -642,8 +657,7 @@ @ o The third parameter contains the rest of the operator. @ The declaration ends with "\end". \gdef\CCprintOperatorTwo #1#2#3\end{@ - \def\xparams{#3}@ - \ifx\xparams\empty + \isEmpty{#3}\ifnum\CCbool=\CCtrue @ two character operations \ifcase\NParameters @ no parameter \or @ 1 parameter diff --git a/Packages/Manual_tools/format/test.tex b/Packages/Manual_tools/format/test.tex index 4ac21fe3f8a..5b03b4eee3b 100644 --- a/Packages/Manual_tools/format/test.tex +++ b/Packages/Manual_tools/format/test.tex @@ -103,12 +103,15 @@ with operators. See the following example: \CCstyle{ #define %^~ Return_Type > fct_foo( const X &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 -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 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 parsed from \TeX\ and the catcodes are all fixed before the catcode changing macro expands. @@ -124,12 +127,12 @@ name as it was originally written can be accessed using the \creation 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 \verb"\purevar" macro. 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. 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 @@ -220,10 +223,17 @@ future). An example: Operator declarations are formatted as like the operators are used. All operators that are allowed to be overloaded in \CC\ are handled. They are listed in the last section for completeness and -to check the layout. Type casting through an operator is currently -not supported. It will give an error message. If the error will be -ignored, the macro formats the operator as a method or function, -as it was declared. Sometimes, there is a choice between +to check the layout. + +Type casting through a conversion operator is the default behavior +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 declarations will produce the same formatting, as demonstrated with the next two declarations. @@ -232,7 +242,7 @@ with the next two declarations. operator+(Demo_Class p, Demo_Class q);}{Declaration via function.} \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 characters. See the following examples: @@ -263,12 +273,14 @@ style can handle such cases: \method{A operator0(Demo_Class q);}{} -For future extensions, the macro that separates the return type from -the function or method name recognizes the scope operator (, but -currently not in the usage as the global scope). An example: +CGAL will use {\tt typedef}'s and the scope operator to define types. +Here is an example for the scope operator within types. The scope +operator cannot be used within the function or method name. - \function{Demo_Class - Class_X :: foo(Demo_Class p, Demo_Class q);}{Declaration with scope.} + \threecolumns{5.8cm}{2.8cm} + \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 constants and macros, normal C variable declarations and constants,