1 /* "CodeWorker": a scripting language for parsing and generating text. 2 3 Copyright (C) 1996-1997, 1999-2002 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 "DtaScriptVariable.h" 28 #include "ExprScriptVariable.h" 29 #include "ScpStream.h" 30 #include "CppCompilerEnvironment.h" 31 #include "GrfReference.h" 32 33 namespace CodeWorker { ~GrfReference()34 GrfReference::~GrfReference() { 35 if (_pVariable != NULL) delete _pVariable; 36 if (_pReference != NULL) delete _pReference; 37 } 38 executeInternal(DtaScriptVariable & visibility)39 SEQUENCE_INTERRUPTION_LIST GrfReference::executeInternal(DtaScriptVariable& visibility) { 40 DtaScriptVariable* pVariable = visibility.getVariableForReferenceAssignment(*_pVariable); 41 DtaScriptVariable* pReference = visibility.getExistingVariable(*_pReference); 42 if (pReference == NULL) { 43 std::string sCompleteName = pVariable->getCompleteName(); 44 std::string sExpression = _pReference->toString(); 45 throw UtlException("runtime error: can't refer to a variable that doesn't exist, see 'ref " + sCompleteName + " = " + sExpression + ";'"); 46 } 47 if (pVariable != pReference) pVariable->setValue(pReference); 48 return NO_INTERRUPTION; 49 } 50 compileCpp(CppCompilerEnvironment & theCompilerEnvironment) const51 void GrfReference::compileCpp(CppCompilerEnvironment& theCompilerEnvironment) const { 52 CW_BODY_INDENT; 53 _pVariable->compileCppForSet(theCompilerEnvironment); 54 CW_BODY_STREAM << ".setReference("; 55 _pReference->compileCpp(theCompilerEnvironment); 56 CW_BODY_STREAM << ");"; 57 CW_BODY_ENDL; 58 } 59 } 60