1 /* "CodeWorker": a scripting language for parsing and generating text. 2 3 Copyright (C) 1996-1997, 1999-2003 C�dric Lemaire 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 To contact the author: codeworker@free.fr 20 */ 21 22 #ifdef WIN32 23 #pragma warning (disable : 4786) 24 #endif 25 26 #include "UtlException.h" 27 #include "ScpStream.h" 28 #include "CppCompilerEnvironment.h" 29 #include "CGRuntime.h" 30 31 #include "DtaScriptVariable.h" 32 #include "ExprScriptVariable.h" 33 #include "DtaBNFScript.h" 34 #include "BNFClause.h" 35 #include "DtaVisitor.h" 36 #include "BNFAndOrJunction.h" 37 38 namespace CodeWorker { BNFAndOrJunction(DtaBNFScript * pBNFScript,GrfBlock * pParent,bool bContinue)39 BNFAndOrJunction::BNFAndOrJunction(DtaBNFScript* pBNFScript, GrfBlock* pParent, bool bContinue) : _pBNFScript(pBNFScript), GrfBlock(pParent), _bContinue(bContinue), _pLeftMember(NULL) {} 40 ~BNFAndOrJunction()41 BNFAndOrJunction::~BNFAndOrJunction() { 42 delete _pLeftMember; 43 } 44 accept(DtaVisitor & visitor,DtaVisitorEnvironment & env)45 void BNFAndOrJunction::accept(DtaVisitor& visitor, DtaVisitorEnvironment& env) { 46 visitor.visitBNFAndOrJunction(*this, env); 47 } 48 isABNFCommand() const49 bool BNFAndOrJunction::isABNFCommand() const { return true; } 50 executeInternal(DtaScriptVariable & visibility)51 SEQUENCE_INTERRUPTION_LIST BNFAndOrJunction::executeInternal(DtaScriptVariable& visibility) { 52 int iLocation = CGRuntime::getInputLocation(); 53 int iImplicitCopyPosition = _pBNFScript->skipEmptyChars(visibility); 54 SEQUENCE_INTERRUPTION_LIST result = _pLeftMember->execute(visibility); 55 if (result != CONTINUE_INTERRUPTION) { 56 SEQUENCE_INTERRUPTION_LIST result2 = GrfBlock::executeInternal(visibility); 57 if ((result == BREAK_INTERRUPTION) && (result2 == BREAK_INTERRUPTION)) { 58 BNF_SYMBOL_HAS_FAILED 59 } else if (result2 != BREAK_INTERRUPTION) { 60 result = result2; 61 } 62 } 63 return result; 64 } 65 compileCpp(CppCompilerEnvironment & theCompilerEnvironment) const66 void BNFAndOrJunction::compileCpp(CppCompilerEnvironment& theCompilerEnvironment) const { 67 CPP_COMPILER_BNF_SYMBOL_BEGIN; 68 _pLeftMember->compileCpp(theCompilerEnvironment); 69 CW_BODY_INDENT << "bool _compilerClauseSuccess" << iCursor << " = _compilerClauseSuccess;";CW_BODY_ENDL; 70 GrfBlock::compileCppBNFSequence(theCompilerEnvironment); 71 CW_BODY_INDENT << "if (!_compilerClauseSuccess) {";CW_BODY_ENDL; 72 theCompilerEnvironment.incrementIndentation(); 73 CW_BODY_INDENT << "_compilerClauseSuccess = _compilerClauseSuccess" << iCursor << ";";CW_BODY_ENDL; 74 CW_BODY_INDENT << "if (!_compilerClauseSuccess) {";CW_BODY_ENDL; 75 CPP_COMPILER_BNF_SYMBOL_HAS_FAILED; 76 CW_BODY_INDENT << "}";CW_BODY_ENDL; 77 theCompilerEnvironment.decrementIndentation(); 78 CW_BODY_INDENT << "}";CW_BODY_ENDL; 79 } 80 toString() const81 std::string BNFAndOrJunction::toString() const { 82 std::string sText = _pLeftMember->toString() + " &| " + getCommands()[0]->toString(); 83 if (_bContinue) sText = "#continue " + sText; 84 return sText; 85 } 86 } 87