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(); 60 ~Udk_MacroMap(); 61 62 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 }; 81 82 83 84 85 Cpluplus_Parser::Cpluplus_Parser() 86 // : pRunningData 87 { 88 } 89 90 Cpluplus_Parser::~Cpluplus_Parser() 91 { 92 } 93 94 void 95 Cpluplus_Parser::Setup( ary::Repository & o_rRepository, 96 const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter ) 97 { 98 pRunningData = new S_RunningData(o_rRepository, i_rDocumentationInterpreter); 99 } 100 101 void 102 Cpluplus_Parser::Run( const autodoc::FileCollector_Ifc & i_rFiles ) 103 { 104 for ( autodoc::FileCollector_Ifc::const_iterator iter = i_rFiles.Begin(); 105 iter != i_rFiles.End(); 106 ++iter ) 107 { 108 csv::ploc::Path 109 aFilePath(*iter); 110 111 try 112 { 113 if ( NOT Local_LoadFile(pRunningData->aFileContent, *iter) ) 114 continue; 115 for ( pRunningData->aTkp.StartNewFile(aFilePath); 116 pRunningData->aTkp.HasMore(); 117 pRunningData->aTkp.GetNextToken() ) 118 ; 119 } 120 catch (autodoc::X_Parser_Ifc & rX_Parse) 121 { 122 if ( DEBUG_ShowStoring() OR DEBUG_ShowText() ) 123 Cerr() << rX_Parse << Endl(); 124 } 125 catch (...) 126 { 127 if ( DEBUG_ShowStoring() OR DEBUG_ShowText() ) 128 Cerr() << "Error: Unknown exception." << Endl(); 129 } 130 } // end for (iter) 131 } 132 133 S_RunningData::S_RunningData( ary::Repository & o_rRepository, 134 const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter ) 135 : aFileContent(), 136 rCppGate( o_rRepository.Gate_Cpp() ), 137 aMacros(), 138 aDealer(o_rRepository.Gate_Cpp()), 139 aTkp( * i_rDocumentationInterpreter.Create_DocuContext() ) 140 { 141 aDealer.AssignPartners( aFileContent, 142 aMacros.GetData() ); 143 aTkp.AssignPartners( aFileContent, aDealer ); 144 } 145 146 147 Udk_MacroMap::Udk_MacroMap() 148 { 149 String sSAL_CALL("SAL_CALL"); 150 String sSAL_CALL_ELLIPSE("SAL_CALL_ELLIPSE"); 151 String sSAL_NO_VTABLE("SAL_NO_VTABLE"); 152 String sREGISTRY_CALLTYPE("REGISTRY_CALLTYPE"); 153 String sSAL_THROW("SAL_THROW"); 154 String sSAL_THROW_EXTERN_C("SAL_THROW_EXTERN_C"); 155 156 String s__DEF_COMPIMPLHELPER_A("__DEF_COMPIMPLHELPER_A"); 157 String s__DEF_COMPIMPLHELPER_B("__DEF_COMPIMPLHELPER_B"); 158 String s__DEF_COMPIMPLHELPER("__DEF_COMPIMPLHELPER"); 159 160 String s__DEF_IMPLHELPER_PRE("__DEF_IMPLHELPER_PRE"); 161 String s__IFC_WRITEOFFSET("__IFC_WRITEOFFSET"); 162 String s__DEF_IMPLHELPER_POST("__DEF_IMPLHELPER_POST"); 163 164 String sSAL_EXCEPTION_DLLPUBLIC_EXPORT("SAL_EXCEPTION_DLLPUBLIC_EXPORT"); 165 String sSAL_EXCEPTION_DLLPRIVATE("SAL_EXCEPTION_DLLPRIVATE"); 166 167 168 StringVector aEmpty; 169 170 StringVector aParamsSAL_THROW; 171 aParamsSAL_THROW.push_back( String ("exc") ); 172 StringVector aDefSAL_THROW; 173 aDefSAL_THROW.push_back( String ("throw") ); 174 aDefSAL_THROW.push_back( String ("exc") ); 175 176 StringVector aCompImplHelperParams; 177 aCompImplHelperParams.push_back(String ("N")); 178 179 180 // filling up the list 181 182 183 aData[sSAL_CALL] = new DefineDescription(sSAL_CALL, aEmpty); 184 aData[sSAL_CALL_ELLIPSE] = new DefineDescription(sSAL_CALL_ELLIPSE, aEmpty); 185 aData[sSAL_NO_VTABLE] = new DefineDescription(sSAL_NO_VTABLE, aEmpty); 186 aData[sREGISTRY_CALLTYPE] = new DefineDescription(sREGISTRY_CALLTYPE, aEmpty); 187 188 aData[sSAL_THROW] = new DefineDescription(sSAL_THROW, aParamsSAL_THROW, aDefSAL_THROW); 189 aData[sSAL_THROW_EXTERN_C] = new DefineDescription(sSAL_THROW_EXTERN_C, aEmpty, aEmpty); 190 191 aData[s__DEF_COMPIMPLHELPER_A] 192 = new DefineDescription( s__DEF_COMPIMPLHELPER_A, aCompImplHelperParams, aEmpty); 193 aData[s__DEF_COMPIMPLHELPER_B] 194 = new DefineDescription(s__DEF_COMPIMPLHELPER_B, aCompImplHelperParams, aEmpty); 195 aData[s__DEF_COMPIMPLHELPER] 196 = new DefineDescription(s__DEF_COMPIMPLHELPER, aCompImplHelperParams, aEmpty); 197 198 aData[s__DEF_IMPLHELPER_PRE] 199 = new DefineDescription(s__DEF_IMPLHELPER_PRE, aCompImplHelperParams, aEmpty); 200 aData[s__IFC_WRITEOFFSET] 201 = new DefineDescription(s__IFC_WRITEOFFSET, aCompImplHelperParams, aEmpty); 202 aData[s__DEF_IMPLHELPER_POST] 203 = new DefineDescription(s__DEF_IMPLHELPER_POST, aCompImplHelperParams, aEmpty); 204 205 aData[sSAL_EXCEPTION_DLLPUBLIC_EXPORT] 206 = new DefineDescription(sSAL_EXCEPTION_DLLPUBLIC_EXPORT, aEmpty); 207 aData[sSAL_EXCEPTION_DLLPRIVATE] 208 = new DefineDescription(sSAL_EXCEPTION_DLLPRIVATE, aEmpty); 209 } 210 211 Udk_MacroMap::~Udk_MacroMap() 212 { 213 for ( Data::iterator it = aData.begin(); it != aData.end(); ++it ) 214 { 215 delete (*it).second; 216 } 217 } 218 219 220 221 } // namespace cpp 222 223 224 bool 225 Local_LoadFile( CharacterSource & o_rTextBuffer, 226 const String & i_rFullFilePath ) 227 { 228 Cout() << "Parse " << i_rFullFilePath << " ..." << Endl(); 229 230 csv::File aFile( i_rFullFilePath, csv::CFM_READ ); 231 if (NOT aFile.open()) 232 { 233 Cerr() << " could not be opened.\n" << Endl(); 234 return false; 235 } 236 o_rTextBuffer.LoadText(aFile); 237 aFile.close(); 238 return true; 239 } 240 241 242 243