1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include <cpp/prs_cpp.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <cosv/file.hxx>
34*cdf0e10cSrcweir #include <ary/ary.hxx>
35*cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx>
36*cdf0e10cSrcweir #include <autodoc/prs_docu.hxx>
37*cdf0e10cSrcweir #include <autodoc/filecoli.hxx>
38*cdf0e10cSrcweir #include <autodoc/x_parsing.hxx>
39*cdf0e10cSrcweir #include <tools/tkpchars.hxx>
40*cdf0e10cSrcweir #include <adc_cl.hxx>
41*cdf0e10cSrcweir #include "c_dealer.hxx"
42*cdf0e10cSrcweir #include "defdescr.hxx"
43*cdf0e10cSrcweir #include "tkp_cpp.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir // Helper function
47*cdf0e10cSrcweir static bool         Local_LoadFile(
48*cdf0e10cSrcweir                         CharacterSource &       o_rTextBuffer,
49*cdf0e10cSrcweir                         const String  &         i_rFullFilePath );
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace cpp
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // This class is used for the UDK as workaround for the missing
58*cdf0e10cSrcweir //   feature of parsing #define s.
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir class Udk_MacroMap
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir   public:
63*cdf0e10cSrcweir     typedef std::map< String , DefineDescription* > Data;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir                         Udk_MacroMap();
66*cdf0e10cSrcweir                         ~Udk_MacroMap();
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     const Data &        GetData() const         { return aData; }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir   private:
71*cdf0e10cSrcweir     Data                aData;
72*cdf0e10cSrcweir };
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir struct S_RunningData
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     CharacterSource	    aFileContent;
77*cdf0e10cSrcweir 	ary::cpp::Gate &    rCppGate;
78*cdf0e10cSrcweir     Udk_MacroMap        aMacros;
79*cdf0e10cSrcweir 	Distributor	        aDealer;
80*cdf0e10cSrcweir 	TokenParser_Cpp	    aTkp;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir                             S_RunningData(
83*cdf0e10cSrcweir                                 ary::Repository &   o_rRepository,
84*cdf0e10cSrcweir                                 const autodoc::DocumentationParser_Ifc &
85*cdf0e10cSrcweir                                                     i_rDocumentationInterpreter );
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir Cpluplus_Parser::Cpluplus_Parser()
92*cdf0e10cSrcweir //    : pRunningData
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir Cpluplus_Parser::~Cpluplus_Parser()
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir void
101*cdf0e10cSrcweir Cpluplus_Parser::Setup( ary::Repository &                        o_rRepository,
102*cdf0e10cSrcweir                         const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     pRunningData = new S_RunningData(o_rRepository, i_rDocumentationInterpreter);
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir void
108*cdf0e10cSrcweir Cpluplus_Parser::Run( const autodoc::FileCollector_Ifc &    i_rFiles )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	for ( autodoc::FileCollector_Ifc::const_iterator iter = i_rFiles.Begin();
111*cdf0e10cSrcweir 		  iter != i_rFiles.End();
112*cdf0e10cSrcweir 		  ++iter )
113*cdf0e10cSrcweir 	{
114*cdf0e10cSrcweir         csv::ploc::Path
115*cdf0e10cSrcweir             aFilePath(*iter);
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         try
118*cdf0e10cSrcweir         {
119*cdf0e10cSrcweir             if ( NOT Local_LoadFile(pRunningData->aFileContent, *iter) )
120*cdf0e10cSrcweir                 continue;
121*cdf0e10cSrcweir     		for ( pRunningData->aTkp.StartNewFile(aFilePath);
122*cdf0e10cSrcweir                   pRunningData->aTkp.HasMore();
123*cdf0e10cSrcweir                   pRunningData->aTkp.GetNextToken() )
124*cdf0e10cSrcweir                 ;
125*cdf0e10cSrcweir         }
126*cdf0e10cSrcweir         catch (autodoc::X_Parser_Ifc & rX_Parse)
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
129*cdf0e10cSrcweir                 Cerr() << rX_Parse << Endl();
130*cdf0e10cSrcweir         }
131*cdf0e10cSrcweir         catch (...)
132*cdf0e10cSrcweir         {
133*cdf0e10cSrcweir             if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
134*cdf0e10cSrcweir                 Cerr() << "Error:  Unknown exception." << Endl();
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir 	}   // end for (iter)
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir S_RunningData::S_RunningData( ary::Repository &                        o_rRepository,
140*cdf0e10cSrcweir                               const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
141*cdf0e10cSrcweir     :   aFileContent(),
142*cdf0e10cSrcweir         rCppGate( o_rRepository.Gate_Cpp() ),
143*cdf0e10cSrcweir         aMacros(),
144*cdf0e10cSrcweir         aDealer(o_rRepository.Gate_Cpp()),
145*cdf0e10cSrcweir         aTkp( * i_rDocumentationInterpreter.Create_DocuContext() )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     aDealer.AssignPartners( aFileContent,
148*cdf0e10cSrcweir                             aMacros.GetData() );
149*cdf0e10cSrcweir     aTkp.AssignPartners( aFileContent, aDealer );
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir Udk_MacroMap::Udk_MacroMap()
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     String  sSAL_CALL("SAL_CALL");
156*cdf0e10cSrcweir     String  sSAL_CALL_ELLIPSE("SAL_CALL_ELLIPSE");
157*cdf0e10cSrcweir     String  sSAL_NO_VTABLE("SAL_NO_VTABLE");
158*cdf0e10cSrcweir     String  sREGISTRY_CALLTYPE("REGISTRY_CALLTYPE");
159*cdf0e10cSrcweir     String  sSAL_THROW("SAL_THROW");
160*cdf0e10cSrcweir     String  sSAL_THROW_EXTERN_C("SAL_THROW_EXTERN_C");
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER_A("__DEF_COMPIMPLHELPER_A");
163*cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER_B("__DEF_COMPIMPLHELPER_B");
164*cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER("__DEF_COMPIMPLHELPER");
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     String  s__DEF_IMPLHELPER_PRE("__DEF_IMPLHELPER_PRE");
167*cdf0e10cSrcweir     String  s__IFC_WRITEOFFSET("__IFC_WRITEOFFSET");
168*cdf0e10cSrcweir     String  s__DEF_IMPLHELPER_POST("__DEF_IMPLHELPER_POST");
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     String  sSAL_EXCEPTION_DLLPUBLIC_EXPORT("SAL_EXCEPTION_DLLPUBLIC_EXPORT");
171*cdf0e10cSrcweir     String  sSAL_EXCEPTION_DLLPRIVATE("SAL_EXCEPTION_DLLPRIVATE");
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     StringVector aEmpty;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     StringVector aParamsSAL_THROW;
177*cdf0e10cSrcweir     aParamsSAL_THROW.push_back( String ("exc") );
178*cdf0e10cSrcweir     StringVector aDefSAL_THROW;
179*cdf0e10cSrcweir     aDefSAL_THROW.push_back( String ("throw") );
180*cdf0e10cSrcweir     aDefSAL_THROW.push_back( String ("exc") );
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     StringVector aCompImplHelperParams;
183*cdf0e10cSrcweir     aCompImplHelperParams.push_back(String ("N"));
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     // filling up the list
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir     aData[sSAL_CALL] = new DefineDescription(sSAL_CALL, aEmpty);
190*cdf0e10cSrcweir     aData[sSAL_CALL_ELLIPSE] = new DefineDescription(sSAL_CALL_ELLIPSE, aEmpty);
191*cdf0e10cSrcweir     aData[sSAL_NO_VTABLE] = new DefineDescription(sSAL_NO_VTABLE, aEmpty);
192*cdf0e10cSrcweir     aData[sREGISTRY_CALLTYPE] = new DefineDescription(sREGISTRY_CALLTYPE, aEmpty);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     aData[sSAL_THROW] = new DefineDescription(sSAL_THROW, aParamsSAL_THROW, aDefSAL_THROW);
195*cdf0e10cSrcweir     aData[sSAL_THROW_EXTERN_C] = new DefineDescription(sSAL_THROW_EXTERN_C, aEmpty, aEmpty);
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER_A]
198*cdf0e10cSrcweir         = new DefineDescription( s__DEF_COMPIMPLHELPER_A, aCompImplHelperParams, aEmpty);
199*cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER_B]
200*cdf0e10cSrcweir         = new DefineDescription(s__DEF_COMPIMPLHELPER_B, aCompImplHelperParams, aEmpty);
201*cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER]
202*cdf0e10cSrcweir         = new DefineDescription(s__DEF_COMPIMPLHELPER, aCompImplHelperParams, aEmpty);
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     aData[s__DEF_IMPLHELPER_PRE]
205*cdf0e10cSrcweir         = new DefineDescription(s__DEF_IMPLHELPER_PRE, aCompImplHelperParams, aEmpty);
206*cdf0e10cSrcweir     aData[s__IFC_WRITEOFFSET]
207*cdf0e10cSrcweir         = new DefineDescription(s__IFC_WRITEOFFSET, aCompImplHelperParams, aEmpty);
208*cdf0e10cSrcweir     aData[s__DEF_IMPLHELPER_POST]
209*cdf0e10cSrcweir         = new DefineDescription(s__DEF_IMPLHELPER_POST, aCompImplHelperParams, aEmpty);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     aData[sSAL_EXCEPTION_DLLPUBLIC_EXPORT]
212*cdf0e10cSrcweir         = new DefineDescription(sSAL_EXCEPTION_DLLPUBLIC_EXPORT, aEmpty);
213*cdf0e10cSrcweir     aData[sSAL_EXCEPTION_DLLPRIVATE]
214*cdf0e10cSrcweir         = new DefineDescription(sSAL_EXCEPTION_DLLPRIVATE, aEmpty);
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir Udk_MacroMap::~Udk_MacroMap()
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     for ( Data::iterator it = aData.begin(); it != aData.end(); ++it )
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir      	delete (*it).second;
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir } // namespace cpp
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir bool
231*cdf0e10cSrcweir Local_LoadFile( CharacterSource &       o_rTextBuffer,
232*cdf0e10cSrcweir                 const String  &         i_rFullFilePath )
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     Cout() << "Parse " << i_rFullFilePath << " ..." << Endl();
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 	csv::File aFile( i_rFullFilePath, csv::CFM_READ );
237*cdf0e10cSrcweir 	if (NOT aFile.open())
238*cdf0e10cSrcweir 	{
239*cdf0e10cSrcweir         Cerr() << "   could not be opened.\n" << Endl();
240*cdf0e10cSrcweir 		return false;
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir 	o_rTextBuffer.LoadText(aFile);
243*cdf0e10cSrcweir 	aFile.close();
244*cdf0e10cSrcweir     return true;
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 
249