178bc99aaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 378bc99aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 478bc99aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 578bc99aaSAndrew Rist * distributed with this work for additional information 678bc99aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 778bc99aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 878bc99aaSAndrew Rist * "License"); you may not use this file except in compliance 978bc99aaSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1178bc99aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1378bc99aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 1478bc99aaSAndrew Rist * software distributed under the License is distributed on an 1578bc99aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1678bc99aaSAndrew Rist * KIND, either express or implied. See the License for the 1778bc99aaSAndrew Rist * specific language governing permissions and limitations 1878bc99aaSAndrew Rist * under the License. 19cdf0e10cSrcweir * 2078bc99aaSAndrew 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 59*b32aa359SDamjan Jovanovic Udk_MacroMap(const ::std::vector<String>& ignoreDefines); 60cdf0e10cSrcweir ~Udk_MacroMap(); 61cdf0e10cSrcweir 62cdf0e10cSrcweir 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 & 79*b32aa359SDamjan Jovanovic i_rDocumentationInterpreter, 80*b32aa359SDamjan Jovanovic const ::std::vector<String> & 81*b32aa359SDamjan Jovanovic ignoreDefines ); 82cdf0e10cSrcweir }; 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir Cpluplus_Parser::Cpluplus_Parser() 88cdf0e10cSrcweir // : pRunningData 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir Cpluplus_Parser::~Cpluplus_Parser() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir void 97cdf0e10cSrcweir Cpluplus_Parser::Setup( ary::Repository & o_rRepository, 98*b32aa359SDamjan Jovanovic const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter, 99*b32aa359SDamjan Jovanovic const ::std::vector<String> & ignoreDefines ) 100cdf0e10cSrcweir { 101*b32aa359SDamjan Jovanovic pRunningData = new S_RunningData(o_rRepository, i_rDocumentationInterpreter, ignoreDefines); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir void 105cdf0e10cSrcweir Cpluplus_Parser::Run( const autodoc::FileCollector_Ifc & i_rFiles ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir for ( autodoc::FileCollector_Ifc::const_iterator iter = i_rFiles.Begin(); 108cdf0e10cSrcweir iter != i_rFiles.End(); 109cdf0e10cSrcweir ++iter ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir csv::ploc::Path 112cdf0e10cSrcweir aFilePath(*iter); 113cdf0e10cSrcweir 114cdf0e10cSrcweir try 115cdf0e10cSrcweir { 116cdf0e10cSrcweir if ( NOT Local_LoadFile(pRunningData->aFileContent, *iter) ) 117cdf0e10cSrcweir continue; 118cdf0e10cSrcweir for ( pRunningData->aTkp.StartNewFile(aFilePath); 119cdf0e10cSrcweir pRunningData->aTkp.HasMore(); 120cdf0e10cSrcweir pRunningData->aTkp.GetNextToken() ) 121cdf0e10cSrcweir ; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch (autodoc::X_Parser_Ifc & rX_Parse) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if ( DEBUG_ShowStoring() OR DEBUG_ShowText() ) 126cdf0e10cSrcweir Cerr() << rX_Parse << Endl(); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir catch (...) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir if ( DEBUG_ShowStoring() OR DEBUG_ShowText() ) 131cdf0e10cSrcweir Cerr() << "Error: Unknown exception." << Endl(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } // end for (iter) 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir S_RunningData::S_RunningData( ary::Repository & o_rRepository, 137*b32aa359SDamjan Jovanovic const autodoc::DocumentationParser_Ifc & i_rDocumentationInterpreter, 138*b32aa359SDamjan Jovanovic const ::std::vector<String> & ignoreDefines ) 139cdf0e10cSrcweir : aFileContent(), 140cdf0e10cSrcweir rCppGate( o_rRepository.Gate_Cpp() ), 141*b32aa359SDamjan Jovanovic aMacros( ignoreDefines ), 142cdf0e10cSrcweir aDealer(o_rRepository.Gate_Cpp()), 143cdf0e10cSrcweir aTkp( * i_rDocumentationInterpreter.Create_DocuContext() ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir aDealer.AssignPartners( aFileContent, 146cdf0e10cSrcweir aMacros.GetData() ); 147cdf0e10cSrcweir aTkp.AssignPartners( aFileContent, aDealer ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151*b32aa359SDamjan Jovanovic Udk_MacroMap::Udk_MacroMap( const ::std::vector<String> & ignoreDefines ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir String sSAL_CALL("SAL_CALL"); 154cdf0e10cSrcweir String sSAL_CALL_ELLIPSE("SAL_CALL_ELLIPSE"); 155cdf0e10cSrcweir String sSAL_NO_VTABLE("SAL_NO_VTABLE"); 156cdf0e10cSrcweir String sREGISTRY_CALLTYPE("REGISTRY_CALLTYPE"); 157cdf0e10cSrcweir String sSAL_THROW("SAL_THROW"); 158cdf0e10cSrcweir String sSAL_THROW_EXTERN_C("SAL_THROW_EXTERN_C"); 159cdf0e10cSrcweir 160cdf0e10cSrcweir String s__DEF_COMPIMPLHELPER_A("__DEF_COMPIMPLHELPER_A"); 161cdf0e10cSrcweir String s__DEF_COMPIMPLHELPER_B("__DEF_COMPIMPLHELPER_B"); 162cdf0e10cSrcweir String s__DEF_COMPIMPLHELPER("__DEF_COMPIMPLHELPER"); 163cdf0e10cSrcweir 164cdf0e10cSrcweir String s__DEF_IMPLHELPER_PRE("__DEF_IMPLHELPER_PRE"); 165cdf0e10cSrcweir String s__IFC_WRITEOFFSET("__IFC_WRITEOFFSET"); 166cdf0e10cSrcweir String s__DEF_IMPLHELPER_POST("__DEF_IMPLHELPER_POST"); 167cdf0e10cSrcweir 168cdf0e10cSrcweir String sSAL_EXCEPTION_DLLPUBLIC_EXPORT("SAL_EXCEPTION_DLLPUBLIC_EXPORT"); 169cdf0e10cSrcweir String sSAL_EXCEPTION_DLLPRIVATE("SAL_EXCEPTION_DLLPRIVATE"); 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir StringVector aEmpty; 173cdf0e10cSrcweir 174cdf0e10cSrcweir StringVector aParamsSAL_THROW; 175cdf0e10cSrcweir aParamsSAL_THROW.push_back( String ("exc") ); 176cdf0e10cSrcweir StringVector aDefSAL_THROW; 177cdf0e10cSrcweir aDefSAL_THROW.push_back( String ("throw") ); 178cdf0e10cSrcweir aDefSAL_THROW.push_back( String ("exc") ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir StringVector aCompImplHelperParams; 181cdf0e10cSrcweir aCompImplHelperParams.push_back(String ("N")); 182cdf0e10cSrcweir 183cdf0e10cSrcweir 184cdf0e10cSrcweir // filling up the list 185cdf0e10cSrcweir 186cdf0e10cSrcweir 187cdf0e10cSrcweir aData[sSAL_CALL] = new DefineDescription(sSAL_CALL, aEmpty); 188cdf0e10cSrcweir aData[sSAL_CALL_ELLIPSE] = new DefineDescription(sSAL_CALL_ELLIPSE, aEmpty); 189cdf0e10cSrcweir aData[sSAL_NO_VTABLE] = new DefineDescription(sSAL_NO_VTABLE, aEmpty); 190cdf0e10cSrcweir aData[sREGISTRY_CALLTYPE] = new DefineDescription(sREGISTRY_CALLTYPE, aEmpty); 191cdf0e10cSrcweir 192cdf0e10cSrcweir aData[sSAL_THROW] = new DefineDescription(sSAL_THROW, aParamsSAL_THROW, aDefSAL_THROW); 193cdf0e10cSrcweir aData[sSAL_THROW_EXTERN_C] = new DefineDescription(sSAL_THROW_EXTERN_C, aEmpty, aEmpty); 194cdf0e10cSrcweir 195cdf0e10cSrcweir aData[s__DEF_COMPIMPLHELPER_A] 196cdf0e10cSrcweir = new DefineDescription( s__DEF_COMPIMPLHELPER_A, aCompImplHelperParams, aEmpty); 197cdf0e10cSrcweir aData[s__DEF_COMPIMPLHELPER_B] 198cdf0e10cSrcweir = new DefineDescription(s__DEF_COMPIMPLHELPER_B, aCompImplHelperParams, aEmpty); 199cdf0e10cSrcweir aData[s__DEF_COMPIMPLHELPER] 200cdf0e10cSrcweir = new DefineDescription(s__DEF_COMPIMPLHELPER, aCompImplHelperParams, aEmpty); 201cdf0e10cSrcweir 202cdf0e10cSrcweir aData[s__DEF_IMPLHELPER_PRE] 203cdf0e10cSrcweir = new DefineDescription(s__DEF_IMPLHELPER_PRE, aCompImplHelperParams, aEmpty); 204cdf0e10cSrcweir aData[s__IFC_WRITEOFFSET] 205cdf0e10cSrcweir = new DefineDescription(s__IFC_WRITEOFFSET, aCompImplHelperParams, aEmpty); 206cdf0e10cSrcweir aData[s__DEF_IMPLHELPER_POST] 207cdf0e10cSrcweir = new DefineDescription(s__DEF_IMPLHELPER_POST, aCompImplHelperParams, aEmpty); 208cdf0e10cSrcweir 209cdf0e10cSrcweir aData[sSAL_EXCEPTION_DLLPUBLIC_EXPORT] 210cdf0e10cSrcweir = new DefineDescription(sSAL_EXCEPTION_DLLPUBLIC_EXPORT, aEmpty); 211cdf0e10cSrcweir aData[sSAL_EXCEPTION_DLLPRIVATE] 212cdf0e10cSrcweir = new DefineDescription(sSAL_EXCEPTION_DLLPRIVATE, aEmpty); 213*b32aa359SDamjan Jovanovic 214*b32aa359SDamjan Jovanovic for (size_t index = 0; index != ignoreDefines.size(); ++index) 215*b32aa359SDamjan Jovanovic aData[ignoreDefines[index]] = new DefineDescription(ignoreDefines[index], aEmpty); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir Udk_MacroMap::~Udk_MacroMap() 219cdf0e10cSrcweir { 220cdf0e10cSrcweir for ( Data::iterator it = aData.begin(); it != aData.end(); ++it ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir delete (*it).second; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir 227cdf0e10cSrcweir 228cdf0e10cSrcweir } // namespace cpp 229cdf0e10cSrcweir 230cdf0e10cSrcweir 231cdf0e10cSrcweir bool 232cdf0e10cSrcweir Local_LoadFile( CharacterSource & o_rTextBuffer, 233cdf0e10cSrcweir const String & i_rFullFilePath ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir Cout() << "Parse " << i_rFullFilePath << " ..." << Endl(); 236cdf0e10cSrcweir 237cdf0e10cSrcweir csv::File aFile( i_rFullFilePath, csv::CFM_READ ); 238cdf0e10cSrcweir if (NOT aFile.open()) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir Cerr() << " could not be opened.\n" << Endl(); 241cdf0e10cSrcweir return false; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir o_rTextBuffer.LoadText(aFile); 244cdf0e10cSrcweir aFile.close(); 245cdf0e10cSrcweir return true; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250