1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <precomp.h> 29*cdf0e10cSrcweir #include "c_rcode.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir // NOT FULLY DECLARED SERVICES 33*cdf0e10cSrcweir #include <ary/cpp/c_gate.hxx> 34*cdf0e10cSrcweir #include <ary/cpp/c_namesp.hxx> 35*cdf0e10cSrcweir // #include <ary/cpp/c_groups.hxx> 36*cdf0e10cSrcweir #include <ary/loc/locp_le.hxx> 37*cdf0e10cSrcweir #include "cpp_pe.hxx" 38*cdf0e10cSrcweir #include <adc_cl.hxx> 39*cdf0e10cSrcweir #include <x_parse.hxx> 40*cdf0e10cSrcweir #include "pe_file.hxx" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir const uintt C_nNO_TRY = uintt(-1); 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir namespace cpp { 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir CodeExplorer::CodeExplorer( ary::cpp::Gate & io_rAryGate ) 49*cdf0e10cSrcweir : aGlobalParseContext(io_rAryGate), 50*cdf0e10cSrcweir // aEnvironments, 51*cdf0e10cSrcweir pPE_File(0), 52*cdf0e10cSrcweir pGate(&io_rAryGate), 53*cdf0e10cSrcweir dpCurToken(0) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir pPE_File = new PE_File( aGlobalParseContext ); 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir CodeExplorer::~CodeExplorer() 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir void 63*cdf0e10cSrcweir CodeExplorer::StartNewFile() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir csv::erase_container(aEnvironments); 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir aEnvironments.push_back( pPE_File.MutablePtr() ); 68*cdf0e10cSrcweir pPE_File->Enter(push); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void 72*cdf0e10cSrcweir CodeExplorer::Process_Token( DYN cpp::Token & let_drToken ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir if (DEBUG_ShowTokens()) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir Cout() << let_drToken.Text() << Endl(); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir dpCurToken = &let_drToken; 79*cdf0e10cSrcweir aGlobalParseContext.ResetResult(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir do { 82*cdf0e10cSrcweir CurToken().Trigger( CurEnv() ); 83*cdf0e10cSrcweir AcknowledgeResult(); 84*cdf0e10cSrcweir } while ( dpCurToken ); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir void 88*cdf0e10cSrcweir CodeExplorer::AcknowledgeResult() 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir if (CurResult().eDone == done) 91*cdf0e10cSrcweir dpCurToken = 0; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir switch ( CurResult().eStackAction ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir case stay: 96*cdf0e10cSrcweir break; 97*cdf0e10cSrcweir case push: 98*cdf0e10cSrcweir CurEnv().Leave(push); 99*cdf0e10cSrcweir aEnvironments.push_back( &PushEnv() ); 100*cdf0e10cSrcweir PushEnv().Enter(push); 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir case pop_success: 103*cdf0e10cSrcweir CurEnv().Leave(pop_success); 104*cdf0e10cSrcweir aEnvironments.pop_back(); 105*cdf0e10cSrcweir CurEnv().Enter(pop_success); 106*cdf0e10cSrcweir break; 107*cdf0e10cSrcweir case pop_failure: 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir Cpp_PE * pRecover = 0; 110*cdf0e10cSrcweir do { 111*cdf0e10cSrcweir CurEnv().Leave(pop_failure); 112*cdf0e10cSrcweir aEnvironments.pop_back(); 113*cdf0e10cSrcweir if ( aEnvironments.empty() ) 114*cdf0e10cSrcweir break; 115*cdf0e10cSrcweir pRecover = CurEnv().Handle_ChildFailure(); 116*cdf0e10cSrcweir } while ( pRecover == 0 ); 117*cdf0e10cSrcweir if ( pRecover != 0 ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir aEnvironments.push_back(pRecover); 120*cdf0e10cSrcweir pRecover->Enter(push); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir else 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir throw X_Parser( X_Parser::x_UnexpectedToken, CurToken().Text(), aGlobalParseContext.CurFileName(), aGlobalParseContext.LineCount() ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir } break; 127*cdf0e10cSrcweir default: 128*cdf0e10cSrcweir csv_assert(false); 129*cdf0e10cSrcweir } // end switch(CurResult().eStackAction) 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir const Token & 133*cdf0e10cSrcweir CodeExplorer::CurToken() const 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir csv_assert(dpCurToken); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir return *dpCurToken; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir Cpp_PE & 141*cdf0e10cSrcweir CodeExplorer::CurEnv() const 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir csv_assert(aEnvironments.size() > 0); 144*cdf0e10cSrcweir csv_assert(aEnvironments.back() != 0); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir return *aEnvironments.back(); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir Cpp_PE & 150*cdf0e10cSrcweir CodeExplorer::PushEnv() const 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir TokenProcessing_Result & rCurResult = const_cast< TokenProcessing_Result& >(aGlobalParseContext.CurResult()); 153*cdf0e10cSrcweir Cpp_PE * ret = dynamic_cast< Cpp_PE* >(rCurResult.pEnv2Push); 154*cdf0e10cSrcweir csv_assert( ret != 0 ); 155*cdf0e10cSrcweir return *ret; 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir } // namespace cpp 161*cdf0e10cSrcweir 162