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