1*78bc99aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*78bc99aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*78bc99aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*78bc99aaSAndrew Rist  * distributed with this work for additional information
6*78bc99aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*78bc99aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*78bc99aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*78bc99aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*78bc99aaSAndrew Rist  *
11*78bc99aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*78bc99aaSAndrew Rist  *
13*78bc99aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*78bc99aaSAndrew Rist  * software distributed under the License is distributed on an
15*78bc99aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*78bc99aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*78bc99aaSAndrew Rist  * specific language governing permissions and limitations
18*78bc99aaSAndrew Rist  * under the License.
19*78bc99aaSAndrew Rist  *
20*78bc99aaSAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir #include <precomp.h>
23cdf0e10cSrcweir #include <cpp/prs_cpp.hxx>
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
27cdf0e10cSrcweir #include <cosv/file.hxx>
28cdf0e10cSrcweir #include <ary/ary.hxx>
29cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx>
30cdf0e10cSrcweir #include <autodoc/prs_docu.hxx>
31cdf0e10cSrcweir #include <autodoc/filecoli.hxx>
32cdf0e10cSrcweir #include <autodoc/x_parsing.hxx>
33cdf0e10cSrcweir #include <tools/tkpchars.hxx>
34cdf0e10cSrcweir #include <adc_cl.hxx>
35cdf0e10cSrcweir #include "c_dealer.hxx"
36cdf0e10cSrcweir #include "defdescr.hxx"
37cdf0e10cSrcweir #include "tkp_cpp.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // Helper function
41cdf0e10cSrcweir static bool         Local_LoadFile(
42cdf0e10cSrcweir                         CharacterSource &       o_rTextBuffer,
43cdf0e10cSrcweir                         const String  &         i_rFullFilePath );
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace cpp
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // This class is used for the UDK as workaround for the missing
52cdf0e10cSrcweir //   feature of parsing #define s.
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class Udk_MacroMap
55cdf0e10cSrcweir {
56cdf0e10cSrcweir   public:
57cdf0e10cSrcweir     typedef std::map< String , DefineDescription* > Data;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir                         Udk_MacroMap();
60cdf0e10cSrcweir                         ~Udk_MacroMap();
61cdf0e10cSrcweir 
GetData() const62cdf0e10cSrcweir     const Data &        GetData() const         { return aData; }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir   private:
65cdf0e10cSrcweir     Data                aData;
66cdf0e10cSrcweir };
67cdf0e10cSrcweir 
68cdf0e10cSrcweir struct S_RunningData
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     CharacterSource	    aFileContent;
71cdf0e10cSrcweir 	ary::cpp::Gate &    rCppGate;
72cdf0e10cSrcweir     Udk_MacroMap        aMacros;
73cdf0e10cSrcweir 	Distributor	        aDealer;
74cdf0e10cSrcweir 	TokenParser_Cpp	    aTkp;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir                             S_RunningData(
77cdf0e10cSrcweir                                 ary::Repository &   o_rRepository,
78cdf0e10cSrcweir                                 const autodoc::DocumentationParser_Ifc &
79cdf0e10cSrcweir                                                     i_rDocumentationInterpreter );
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
Cpluplus_Parser()85cdf0e10cSrcweir Cpluplus_Parser::Cpluplus_Parser()
86cdf0e10cSrcweir //    : pRunningData
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
~Cpluplus_Parser()90cdf0e10cSrcweir Cpluplus_Parser::~Cpluplus_Parser()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir void
Setup(ary::Repository & o_rRepository,const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter)95cdf0e10cSrcweir Cpluplus_Parser::Setup( ary::Repository &                        o_rRepository,
96cdf0e10cSrcweir                         const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     pRunningData = new S_RunningData(o_rRepository, i_rDocumentationInterpreter);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir void
Run(const autodoc::FileCollector_Ifc & i_rFiles)102cdf0e10cSrcweir Cpluplus_Parser::Run( const autodoc::FileCollector_Ifc &    i_rFiles )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	for ( autodoc::FileCollector_Ifc::const_iterator iter = i_rFiles.Begin();
105cdf0e10cSrcweir 		  iter != i_rFiles.End();
106cdf0e10cSrcweir 		  ++iter )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir         csv::ploc::Path
109cdf0e10cSrcweir             aFilePath(*iter);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         try
112cdf0e10cSrcweir         {
113cdf0e10cSrcweir             if ( NOT Local_LoadFile(pRunningData->aFileContent, *iter) )
114cdf0e10cSrcweir                 continue;
115cdf0e10cSrcweir     		for ( pRunningData->aTkp.StartNewFile(aFilePath);
116cdf0e10cSrcweir                   pRunningData->aTkp.HasMore();
117cdf0e10cSrcweir                   pRunningData->aTkp.GetNextToken() )
118cdf0e10cSrcweir                 ;
119cdf0e10cSrcweir         }
120cdf0e10cSrcweir         catch (autodoc::X_Parser_Ifc & rX_Parse)
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
123cdf0e10cSrcweir                 Cerr() << rX_Parse << Endl();
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir         catch (...)
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir             if ( DEBUG_ShowStoring() OR DEBUG_ShowText() )
128cdf0e10cSrcweir                 Cerr() << "Error:  Unknown exception." << Endl();
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir 	}   // end for (iter)
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
S_RunningData(ary::Repository & o_rRepository,const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter)133cdf0e10cSrcweir S_RunningData::S_RunningData( ary::Repository &                        o_rRepository,
134cdf0e10cSrcweir                               const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter )
135cdf0e10cSrcweir     :   aFileContent(),
136cdf0e10cSrcweir         rCppGate( o_rRepository.Gate_Cpp() ),
137cdf0e10cSrcweir         aMacros(),
138cdf0e10cSrcweir         aDealer(o_rRepository.Gate_Cpp()),
139cdf0e10cSrcweir         aTkp( * i_rDocumentationInterpreter.Create_DocuContext() )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     aDealer.AssignPartners( aFileContent,
142cdf0e10cSrcweir                             aMacros.GetData() );
143cdf0e10cSrcweir     aTkp.AssignPartners( aFileContent, aDealer );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
Udk_MacroMap()147cdf0e10cSrcweir Udk_MacroMap::Udk_MacroMap()
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     String  sSAL_CALL("SAL_CALL");
150cdf0e10cSrcweir     String  sSAL_CALL_ELLIPSE("SAL_CALL_ELLIPSE");
151cdf0e10cSrcweir     String  sSAL_NO_VTABLE("SAL_NO_VTABLE");
152cdf0e10cSrcweir     String  sREGISTRY_CALLTYPE("REGISTRY_CALLTYPE");
153cdf0e10cSrcweir     String  sSAL_THROW("SAL_THROW");
154cdf0e10cSrcweir     String  sSAL_THROW_EXTERN_C("SAL_THROW_EXTERN_C");
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER_A("__DEF_COMPIMPLHELPER_A");
157cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER_B("__DEF_COMPIMPLHELPER_B");
158cdf0e10cSrcweir     String  s__DEF_COMPIMPLHELPER("__DEF_COMPIMPLHELPER");
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     String  s__DEF_IMPLHELPER_PRE("__DEF_IMPLHELPER_PRE");
161cdf0e10cSrcweir     String  s__IFC_WRITEOFFSET("__IFC_WRITEOFFSET");
162cdf0e10cSrcweir     String  s__DEF_IMPLHELPER_POST("__DEF_IMPLHELPER_POST");
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     String  sSAL_EXCEPTION_DLLPUBLIC_EXPORT("SAL_EXCEPTION_DLLPUBLIC_EXPORT");
165cdf0e10cSrcweir     String  sSAL_EXCEPTION_DLLPRIVATE("SAL_EXCEPTION_DLLPRIVATE");
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     StringVector aEmpty;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     StringVector aParamsSAL_THROW;
171cdf0e10cSrcweir     aParamsSAL_THROW.push_back( String ("exc") );
172cdf0e10cSrcweir     StringVector aDefSAL_THROW;
173cdf0e10cSrcweir     aDefSAL_THROW.push_back( String ("throw") );
174cdf0e10cSrcweir     aDefSAL_THROW.push_back( String ("exc") );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     StringVector aCompImplHelperParams;
177cdf0e10cSrcweir     aCompImplHelperParams.push_back(String ("N"));
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     // filling up the list
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     aData[sSAL_CALL] = new DefineDescription(sSAL_CALL, aEmpty);
184cdf0e10cSrcweir     aData[sSAL_CALL_ELLIPSE] = new DefineDescription(sSAL_CALL_ELLIPSE, aEmpty);
185cdf0e10cSrcweir     aData[sSAL_NO_VTABLE] = new DefineDescription(sSAL_NO_VTABLE, aEmpty);
186cdf0e10cSrcweir     aData[sREGISTRY_CALLTYPE] = new DefineDescription(sREGISTRY_CALLTYPE, aEmpty);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     aData[sSAL_THROW] = new DefineDescription(sSAL_THROW, aParamsSAL_THROW, aDefSAL_THROW);
189cdf0e10cSrcweir     aData[sSAL_THROW_EXTERN_C] = new DefineDescription(sSAL_THROW_EXTERN_C, aEmpty, aEmpty);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER_A]
192cdf0e10cSrcweir         = new DefineDescription( s__DEF_COMPIMPLHELPER_A, aCompImplHelperParams, aEmpty);
193cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER_B]
194cdf0e10cSrcweir         = new DefineDescription(s__DEF_COMPIMPLHELPER_B, aCompImplHelperParams, aEmpty);
195cdf0e10cSrcweir     aData[s__DEF_COMPIMPLHELPER]
196cdf0e10cSrcweir         = new DefineDescription(s__DEF_COMPIMPLHELPER, aCompImplHelperParams, aEmpty);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     aData[s__DEF_IMPLHELPER_PRE]
199cdf0e10cSrcweir         = new DefineDescription(s__DEF_IMPLHELPER_PRE, aCompImplHelperParams, aEmpty);
200cdf0e10cSrcweir     aData[s__IFC_WRITEOFFSET]
201cdf0e10cSrcweir         = new DefineDescription(s__IFC_WRITEOFFSET, aCompImplHelperParams, aEmpty);
202cdf0e10cSrcweir     aData[s__DEF_IMPLHELPER_POST]
203cdf0e10cSrcweir         = new DefineDescription(s__DEF_IMPLHELPER_POST, aCompImplHelperParams, aEmpty);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     aData[sSAL_EXCEPTION_DLLPUBLIC_EXPORT]
206cdf0e10cSrcweir         = new DefineDescription(sSAL_EXCEPTION_DLLPUBLIC_EXPORT, aEmpty);
207cdf0e10cSrcweir     aData[sSAL_EXCEPTION_DLLPRIVATE]
208cdf0e10cSrcweir         = new DefineDescription(sSAL_EXCEPTION_DLLPRIVATE, aEmpty);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
~Udk_MacroMap()211cdf0e10cSrcweir Udk_MacroMap::~Udk_MacroMap()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     for ( Data::iterator it = aData.begin(); it != aData.end(); ++it )
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir      	delete (*it).second;
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir } // namespace cpp
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 
224cdf0e10cSrcweir bool
Local_LoadFile(CharacterSource & o_rTextBuffer,const String & i_rFullFilePath)225cdf0e10cSrcweir Local_LoadFile( CharacterSource &       o_rTextBuffer,
226cdf0e10cSrcweir                 const String  &         i_rFullFilePath )
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     Cout() << "Parse " << i_rFullFilePath << " ..." << Endl();
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	csv::File aFile( i_rFullFilePath, csv::CFM_READ );
231cdf0e10cSrcweir 	if (NOT aFile.open())
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir         Cerr() << "   could not be opened.\n" << Endl();
234cdf0e10cSrcweir 		return false;
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 	o_rTextBuffer.LoadText(aFile);
237cdf0e10cSrcweir 	aFile.close();
238cdf0e10cSrcweir     return true;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243