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