merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / cpp / prs_cpp.cxx
blob306169aa43250c436619254caa84202b0f3f7bf4
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: prs_cpp.cxx,v $
10 * $Revision: 1.7 $
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 <cpp/prs_cpp.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <cosv/file.hxx>
37 #include <ary/ary.hxx>
38 #include <ary/cpp/c_gate.hxx>
39 #include <autodoc/prs_docu.hxx>
40 #include <autodoc/filecoli.hxx>
41 #include <autodoc/x_parsing.hxx>
42 #include <tools/tkpchars.hxx>
43 #include <adc_cl.hxx>
44 #include "c_dealer.hxx"
45 #include "defdescr.hxx"
46 #include "tkp_cpp.hxx"
49 // Helper function
50 static bool Local_LoadFile(
51 CharacterSource & o_rTextBuffer,
52 const String & i_rFullFilePath );
57 namespace cpp
60 // This class is used for the UDK as workaround for the missing
61 // feature of parsing #define s.
63 class Udk_MacroMap
65 public:
66 typedef std::map< String , DefineDescription* > Data;
68 Udk_MacroMap();
69 ~Udk_MacroMap();
71 const Data & GetData() const { return aData; }
73 private:
74 Data aData;
77 struct S_RunningData
79 CharacterSource aFileContent;
80 ary::cpp::Gate & rCppGate;
81 Udk_MacroMap aMacros;
82 Distributor aDealer;
83 TokenParser_Cpp aTkp;
85 S_RunningData(
86 ary::Repository & o_rRepository,
87 const autodoc::DocumentationParser_Ifc &
88 i_rDocumentationInterpreter );
94 Cpluplus_Parser::Cpluplus_Parser()
95 // : pRunningData
99 Cpluplus_Parser::~Cpluplus_Parser()
103 void
104 Cpluplus_Parser::Setup( ary::Repository & o_rRepository,
105 const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
107 pRunningData = new S_RunningData(o_rRepository, i_rDocumentationInterpreter);
110 void
111 Cpluplus_Parser::Run( const autodoc::FileCollector_Ifc & i_rFiles )
113 for ( autodoc::FileCollector_Ifc::const_iterator iter = i_rFiles.Begin();
114 iter != i_rFiles.End();
115 ++iter )
117 csv::ploc::Path
118 aFilePath(*iter);
122 if ( NOT Local_LoadFile(pRunningData->aFileContent, *iter) )
123 continue;
124 for ( pRunningData->aTkp.StartNewFile(aFilePath);
125 pRunningData->aTkp.HasMore();
126 pRunningData->aTkp.GetNextToken() )
129 catch (autodoc::X_Parser_Ifc & rX_Parse)
131 if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
132 Cerr() << rX_Parse << Endl();
134 catch (...)
136 if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
137 Cerr() << "Error: Unknown exception." << Endl();
139 } // end for (iter)
142 S_RunningData::S_RunningData( ary::Repository & o_rRepository,
143 const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
144 : aFileContent(),
145 rCppGate( o_rRepository.Gate_Cpp() ),
146 aMacros(),
147 aDealer(o_rRepository.Gate_Cpp()),
148 aTkp( * i_rDocumentationInterpreter.Create_DocuContext() )
150 aDealer.AssignPartners( aFileContent,
151 aMacros.GetData() );
152 aTkp.AssignPartners( aFileContent, aDealer );
156 Udk_MacroMap::Udk_MacroMap()
158 String sSAL_CALL("SAL_CALL");
159 String sSAL_CALL_ELLIPSE("SAL_CALL_ELLIPSE");
160 String sSAL_NO_VTABLE("SAL_NO_VTABLE");
161 String sREGISTRY_CALLTYPE("REGISTRY_CALLTYPE");
162 String sSAL_THROW("SAL_THROW");
163 String sSAL_THROW_EXTERN_C("SAL_THROW_EXTERN_C");
165 String s__DEF_COMPIMPLHELPER_A("__DEF_COMPIMPLHELPER_A");
166 String s__DEF_COMPIMPLHELPER_B("__DEF_COMPIMPLHELPER_B");
167 String s__DEF_COMPIMPLHELPER("__DEF_COMPIMPLHELPER");
169 String s__DEF_IMPLHELPER_PRE("__DEF_IMPLHELPER_PRE");
170 String s__IFC_WRITEOFFSET("__IFC_WRITEOFFSET");
171 String s__DEF_IMPLHELPER_POST("__DEF_IMPLHELPER_POST");
173 String sSAL_EXCEPTION_DLLPUBLIC_EXPORT("SAL_EXCEPTION_DLLPUBLIC_EXPORT");
174 String sSAL_EXCEPTION_DLLPRIVATE("SAL_EXCEPTION_DLLPRIVATE");
177 StringVector aEmpty;
179 StringVector aParamsSAL_THROW;
180 aParamsSAL_THROW.push_back( String ("exc") );
181 StringVector aDefSAL_THROW;
182 aDefSAL_THROW.push_back( String ("throw") );
183 aDefSAL_THROW.push_back( String ("exc") );
185 StringVector aCompImplHelperParams;
186 aCompImplHelperParams.push_back(String ("N"));
189 // filling up the list
192 aData[sSAL_CALL] = new DefineDescription(sSAL_CALL, aEmpty);
193 aData[sSAL_CALL_ELLIPSE] = new DefineDescription(sSAL_CALL_ELLIPSE, aEmpty);
194 aData[sSAL_NO_VTABLE] = new DefineDescription(sSAL_NO_VTABLE, aEmpty);
195 aData[sREGISTRY_CALLTYPE] = new DefineDescription(sREGISTRY_CALLTYPE, aEmpty);
197 aData[sSAL_THROW] = new DefineDescription(sSAL_THROW, aParamsSAL_THROW, aDefSAL_THROW);
198 aData[sSAL_THROW_EXTERN_C] = new DefineDescription(sSAL_THROW_EXTERN_C, aEmpty, aEmpty);
200 aData[s__DEF_COMPIMPLHELPER_A]
201 = new DefineDescription( s__DEF_COMPIMPLHELPER_A, aCompImplHelperParams, aEmpty);
202 aData[s__DEF_COMPIMPLHELPER_B]
203 = new DefineDescription(s__DEF_COMPIMPLHELPER_B, aCompImplHelperParams, aEmpty);
204 aData[s__DEF_COMPIMPLHELPER]
205 = new DefineDescription(s__DEF_COMPIMPLHELPER, aCompImplHelperParams, aEmpty);
207 aData[s__DEF_IMPLHELPER_PRE]
208 = new DefineDescription(s__DEF_IMPLHELPER_PRE, aCompImplHelperParams, aEmpty);
209 aData[s__IFC_WRITEOFFSET]
210 = new DefineDescription(s__IFC_WRITEOFFSET, aCompImplHelperParams, aEmpty);
211 aData[s__DEF_IMPLHELPER_POST]
212 = new DefineDescription(s__DEF_IMPLHELPER_POST, aCompImplHelperParams, aEmpty);
214 aData[sSAL_EXCEPTION_DLLPUBLIC_EXPORT]
215 = new DefineDescription(sSAL_EXCEPTION_DLLPUBLIC_EXPORT, aEmpty);
216 aData[sSAL_EXCEPTION_DLLPRIVATE]
217 = new DefineDescription(sSAL_EXCEPTION_DLLPRIVATE, aEmpty);
220 Udk_MacroMap::~Udk_MacroMap()
222 for ( Data::iterator it = aData.begin(); it != aData.end(); ++it )
224 delete (*it).second;
230 } // namespace cpp
233 bool
234 Local_LoadFile( CharacterSource & o_rTextBuffer,
235 const String & i_rFullFilePath )
237 Cout() << "Parse " << i_rFullFilePath << " ..." << Endl();
239 csv::File aFile( i_rFullFilePath, csv::CFM_READ );
240 if (NOT aFile.open())
242 Cerr() << " could not be opened.\n" << Endl();
243 return false;
245 o_rTextBuffer.LoadText(aFile);
246 aFile.close();
247 return true;