merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / cpp / cx_c_pp.cxx
blob93014b2b1c917d817a5eb9000ffc67ad896aa8d9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cx_c_pp.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "cx_c_pp.hxx"
36 // NOT FULLY DECLARED SERVICES
37 #include "c_dealer.hxx"
38 #include <tokens/parseinc.hxx>
39 #include <x_parse.hxx>
40 #include "all_toks.hxx"
43 namespace cpp
46 Context_Preprocessor::Context_Preprocessor( TkpContext & i_rFollowUpContext )
47 : Cx_Base(&i_rFollowUpContext),
48 pContext_Parent(&i_rFollowUpContext),
49 pContext_PP_MacroParams( 0 ),
50 pContext_PP_Definition( new Context_PP_Definition(i_rFollowUpContext) )
52 pContext_PP_MacroParams = new Context_PP_MacroParams(*pContext_PP_Definition);
55 void
56 Context_Preprocessor::ReadCharChain( CharacterSource & io_rText )
58 jumpOverWhite( io_rText );
59 jumpToWhite( io_rText );
60 const char * sPP_Keyword = io_rText.CutToken();
61 if ( strcmp(sPP_Keyword, "define") == 0 )
62 ReadDefine(io_rText);
63 else
64 ReadDefault(io_rText);
67 void
68 Context_Preprocessor::AssignDealer( Distributor & o_rDealer )
70 Cx_Base::AssignDealer(o_rDealer);
71 pContext_PP_MacroParams->AssignDealer(o_rDealer);
72 pContext_PP_Definition->AssignDealer(o_rDealer);
75 void
76 Context_Preprocessor::ReadDefault( CharacterSource & io_rText )
78 int o_rCount_BackslashedLineBreaks = 0;
79 jumpToEol(io_rText,o_rCount_BackslashedLineBreaks);
80 for ( ; o_rCount_BackslashedLineBreaks > 0; --o_rCount_BackslashedLineBreaks )
81 Dealer().Deal_Eol();
83 if (io_rText.CurChar() != NULCH)
84 jumpOverEol(io_rText);
85 io_rText.CutToken();
86 Dealer().Deal_Eol();
87 SetNewToken(0);
88 SetFollowUpContext( pContext_Parent );
91 void
92 Context_Preprocessor::ReadDefine( CharacterSource & io_rText )
94 jumpOverWhite( io_rText );
95 io_rText.CutToken();
97 char cNext = '\0';
98 for ( cNext = io_rText.CurChar();
99 static_cast<UINT8>(cNext) > 32 AND cNext != '(';
100 cNext = io_rText.MoveOn() )
103 bool bMacro = cNext == '(';
105 if ( NOT bMacro )
107 SetNewToken( new Tok_DefineName(io_rText.CutToken()) );
108 SetFollowUpContext( pContext_PP_Definition.Ptr() );
110 else
112 SetNewToken( new Tok_MacroName(io_rText.CutToken()) );
113 io_rText.MoveOn();
114 io_rText.CutToken();
115 SetFollowUpContext( pContext_PP_MacroParams.Ptr() );
120 Context_PP_MacroParams::Context_PP_MacroParams( Cx_Base & i_rFollowUpContext )
121 : Cx_Base(&i_rFollowUpContext),
122 pContext_PP_Definition(&i_rFollowUpContext)
126 void
127 Context_PP_MacroParams::ReadCharChain( CharacterSource & io_rText )
129 uintt nLen;
131 jumpOverWhite( io_rText );
132 // KORR_FUTURE Handling line breaks within macro parameters:
133 char cSeparator = jumpTo( io_rText, ',', ')' );
134 csv_assert( cSeparator != 0 );
136 static char cBuf[500];
137 // KORR_FUTURE, make it still safer, here:
138 strcpy( cBuf, io_rText.CutToken() ); // SAFE STRCPY (#100211# - checked)
139 for ( nLen = strlen(cBuf);
140 nLen > 0 AND cBuf[nLen-1] < 33;
141 --nLen )
143 cBuf[nLen] = '\0';
144 SetNewToken( new Tok_MacroParameter(cBuf) );
146 io_rText.MoveOn();
147 io_rText.CutToken();
148 if ( cSeparator == ',')
149 SetFollowUpContext( this );
150 else // Must be ')'
151 SetFollowUpContext( pContext_PP_Definition );
154 Context_PP_Definition::Context_PP_Definition( TkpContext & i_rFollowUpContext )
155 : Cx_Base(&i_rFollowUpContext),
156 pContext_Parent(&i_rFollowUpContext)
160 void
161 Context_PP_Definition::ReadCharChain( CharacterSource & io_rText )
163 int o_rCount_BackslashedLineBreaks = 0;
164 jumpToEol(io_rText,o_rCount_BackslashedLineBreaks);
165 for ( ; o_rCount_BackslashedLineBreaks > 0; --o_rCount_BackslashedLineBreaks )
166 Dealer().Deal_Eol();
167 SetNewToken( new Tok_PreProDefinition(io_rText.CutToken()) );
168 if (io_rText.CurChar() != NULCH)
169 jumpOverEol(io_rText);
170 Dealer().Deal_Eol();
174 } // namespace cpp