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 #ifndef _GrfCommand_h_ 23 #define _GrfCommand_h_ 24 25 namespace CodeWorker { 26 class ScpStream; 27 28 class UtlException; 29 class DtaScriptVariable; 30 class GrfExecutionContext; 31 class GrfCommand; 32 class GrfBlock; 33 class CppCompilerEnvironment; 34 class UtlTimer; 35 36 class DtaVisitor; 37 class DtaVisitorEnvironment; 38 39 #ifndef SEQUENCE_INTERRUPTION_DECLARATION 40 #define SEQUENCE_INTERRUPTION_DECLARATION 41 enum SEQUENCE_INTERRUPTION_LIST { NO_INTERRUPTION, CONTINUE_INTERRUPTION, RETURN_INTERRUPTION, BREAK_INTERRUPTION, EXIT_INTERRUPTION, THROW_INTERRUPTION }; 42 #endif 43 44 typedef void (*APPLY_ON_COMMAND_FUNCTION)(GrfCommand*); 45 46 class GrfCommand { 47 private: 48 static GrfExecutionContext* _pExecutionContext; 49 50 GrfBlock* _pParent; 51 52 private: 53 // These attributes are used only by subclasses of 'GrfExecutionContext' 54 unsigned int _iCounter; 55 UtlTimer* _pTimer; 56 57 friend class GrfExecutionContext; 58 59 protected: 60 const char* _sParsingFilePtr; 61 int _iFileLocation; 62 friend class GrfScriptBlock; 63 64 public: 65 GrfCommand(GrfBlock* pParent = NULL); 66 virtual ~GrfCommand(); 67 68 virtual void accept(DtaVisitor& visitor, DtaVisitorEnvironment& env); 69 70 virtual const char* getFunctionName() const; 71 virtual bool isAPredefinedFunction() const; 72 virtual bool isABNFCommand() const; 73 setParent(GrfBlock * pBlock)74 inline void setParent(GrfBlock* pBlock) { _pParent = pBlock; } getParent()75 inline GrfBlock* getParent() const { return _pParent; } getCurrentExecutionContext()76 static inline GrfExecutionContext* getCurrentExecutionContext() { return _pExecutionContext; } 77 78 virtual void applyRecursively(APPLY_ON_COMMAND_FUNCTION apply); 79 80 void setParsingInformation(const char* sName, ScpStream& stream); 81 82 virtual SEQUENCE_INTERRUPTION_LIST execute(DtaScriptVariable& visibility); 83 84 virtual std::string toString() const; 85 virtual void compileCpp(CppCompilerEnvironment& theCompilerEnvironment) const; 86 87 protected: setCurrentExecutionContext(GrfExecutionContext * pContext)88 static inline void setCurrentExecutionContext(GrfExecutionContext* pContext) { _pExecutionContext = pContext; } 89 90 virtual void callBeforeExecutionCBK(DtaScriptVariable& visibility); 91 virtual void callRecursiveBeforeExecutionCBK(GrfExecutionContext* pContext, DtaScriptVariable& visibility); 92 virtual void callAfterExecutionCBK(DtaScriptVariable& visibility); 93 virtual void callAfterExceptionCBK(DtaScriptVariable& visibility, UtlException& exception); 94 virtual SEQUENCE_INTERRUPTION_LIST executeInternal(DtaScriptVariable& visibility) = 0; 95 96 private: clearCounter()97 inline void clearCounter() { _iCounter = 0; } 98 void clearTimer(); 99 void startTimer(); 100 void stopTimer(); 101 long getTimeInMillis() const; 102 103 friend class GrfQuantifyExecution; 104 }; 105 } 106 107 #endif 108