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 _DtaProject_h_ 23 #define _DtaProject_h_ 24 25 #include <map> 26 27 #include "ExprScriptFunction.h" 28 #include "DtaScriptVariable.h" 29 30 namespace CodeWorker { 31 class ScpStream; 32 class UtlTimer; 33 34 class DtaScript; 35 class GrfReadonlyHook; 36 class GrfWritefileHook; 37 class CppParsingTree_value; 38 39 class DtaBNFScript; 40 class DtaPatternScript; 41 class DtaCustomTagsHandler; // private class 42 43 class DtaGlobalVariableData; 44 45 class DtaProject : public DtaScriptVariable { 46 public: 47 enum TEXT_MODE { BINARY_MODE, DOS_MODE, UNIX_MODE }; 48 49 private: 50 DtaScript* _pScript; 51 std::string _sVersion; 52 bool _bVerbose; 53 std::string _sTargetLanguage; 54 mutable DtaBNFScript* _pCommonAlienParser; 55 mutable DtaBNFScript* _pBNFAlienParser; 56 mutable DtaBNFScript* _pTemplateAlienParser; 57 mutable DtaBNFScript* _pTranslationAlienParser; 58 std::string _sCodeWorkerHome; 59 std::map<std::string, DtaGlobalVariableData*> _mapOfGlobalVariables; 60 61 std::string _sMarkupKey; 62 std::string _sMarkupValue; 63 std::string _sWorkingPath; 64 std::map<std::string, std::string> _mapOfDefinedTargets; 65 std::string _sCommentBegin; 66 std::string _sCommentEnd; 67 std::string _sGenerationHeader; 68 std::map<std::string, int> _mapOfWarnings; 69 UtlTimer* _pDelayTimer; 70 double _dLastDelay; 71 GrfReadonlyHook* _pReadonlyHook; 72 GrfWritefileHook* _pWritefileHook; 73 bool _bSpeed; 74 TEXT_MODE _iTextMode; 75 std::map<std::string, DtaCustomTagsHandler*> _mapOfGenerationTagsHandlers; 76 std::string _sCurrentGenerationTagsHandler; 77 std::map<std::string, std::set<std::string> > _mapOfCapturedOutputFiles; 78 std::map<std::string, std::set<std::string> > _mapOfCapturedInputFiles; 79 std::string sFinalInfoOutputFilename_; 80 int iFinalInfoFlag_; 81 std::set<std::string> noWarnings_; 82 std::string sRemoteDebugHost_; 83 int iRemoteDebugPort_; 84 85 static DtaProject* _pInstance; 86 static std::list<DtaProject*> _stackOfProjects; 87 88 public: 89 enum FINAL_INFO_TYPE { 90 FINAL_INFO_GENERATED_FILES = 1, FINAL_INFO_PARSED_FILES = 2, 91 FINAL_INFO_TEMPLATE_COVERAGE = 4, FINAL_INFO_PARSE_COVERAGE = 8, 92 FINAL_INFO_TEMPLATE_COVERAGE_FOR_EVERYBODY = 16, FINAL_INFO_PARSE_COVERAGE_FOR_EVERYBODY = 32 93 }; 94 95 public: 96 DtaProject(); 97 ~DtaProject(); 98 99 void reset(); 100 existInstance()101 inline static bool existInstance() { return (_pInstance != NULL); } getInstance()102 inline static DtaProject& getInstance() { return *_pInstance; } 103 static DtaProject& createRootInstance(); 104 getScript()105 inline DtaScript* getScript() const { return _pScript; } setScript(DtaScript * pScript)106 inline void setScript(DtaScript* pScript) { _pScript = pScript; } getVersion()107 inline const std::string& getVersion() const { return _sVersion; } setVersion(const std::string & sVersion)108 inline void setVersion(const std::string& sVersion) { _sVersion = sVersion; } getVerbose()109 inline bool getVerbose() const { return _bVerbose; } setVerbose(bool bVerbose)110 inline void setVerbose(bool bVerbose) { _bVerbose = bVerbose; } getCodeWorkerHome()111 inline const std::string& getCodeWorkerHome() const { return _sCodeWorkerHome; } 112 void setCodeWorkerHome(const std::string& sPath); getMarkupKey()113 inline const std::string& getMarkupKey() const { return _sMarkupKey; } setMarkupKey(const std::string & sMarkupKey)114 inline void setMarkupKey(const std::string& sMarkupKey) { _sMarkupKey = sMarkupKey; } getMarkupValue()115 inline const std::string& getMarkupValue() const { return _sMarkupValue; } setMarkupValue(const std::string & sMarkupValue)116 inline void setMarkupValue(const std::string& sMarkupValue) { _sMarkupValue = sMarkupValue; } getWorkingPath()117 inline const std::string& getWorkingPath() const { return _sWorkingPath; } setWorkingPath(const std::string & sWorkingPath)118 inline void setWorkingPath(const std::string& sWorkingPath) { _sWorkingPath = sWorkingPath; } 119 const std::string& getDefineTarget(const std::string& sTarget) const; 120 void setDefineTarget(const std::string& sTarget, const std::string& sValue); setMapOfDefinedTargets(const std::map<std::string,std::string> & mapOfDefinedTargets)121 inline void setMapOfDefinedTargets(const std::map<std::string, std::string>& mapOfDefinedTargets) { _mapOfDefinedTargets = mapOfDefinedTargets; } getCommentBegin()122 inline const std::string& getCommentBegin() const { return _sCommentBegin; } setCommentBegin(const std::string & sCommentBegin)123 inline void setCommentBegin(const std::string& sCommentBegin) { _sCommentBegin = sCommentBegin; } getCommentEnd()124 inline const std::string& getCommentEnd() const { return _sCommentEnd; } setCommentEnd(const std::string & sCommentEnd)125 inline void setCommentEnd(const std::string& sCommentEnd) { _sCommentEnd = sCommentEnd; } getGenerationHeader()126 inline const std::string& getGenerationHeader() const { return _sGenerationHeader; } setGenerationHeader(const std::string & sGenerationHeader)127 inline void setGenerationHeader(const std::string& sGenerationHeader) { _sGenerationHeader = sGenerationHeader; } getDelayTimer()128 inline UtlTimer* getDelayTimer() const { return _pDelayTimer; } setDelayTimer(UtlTimer * pTimer)129 inline void setDelayTimer(UtlTimer* pTimer) { _pDelayTimer = pTimer; } 130 double getLastDelay() const; setLastDelay(double dDelay)131 inline void setLastDelay(double dDelay) { _dLastDelay = dDelay; } getReadonlyHook()132 inline GrfReadonlyHook* getReadonlyHook() const { return _pReadonlyHook; } setReadonlyHook(GrfReadonlyHook * pReadonlyHook)133 inline void setReadonlyHook(GrfReadonlyHook* pReadonlyHook) { _pReadonlyHook = pReadonlyHook; } getWritefileHook()134 inline GrfWritefileHook* getWritefileHook() const { return _pWritefileHook; } setWritefileHook(GrfWritefileHook * pWritefileHook)135 inline void setWritefileHook(GrfWritefileHook* pWritefileHook) { _pWritefileHook = pWritefileHook; } getSpeed()136 inline bool getSpeed() const { return _bSpeed; } setSpeed(bool bSpeed)137 inline void setSpeed(bool bSpeed) { _bSpeed = bSpeed; } getTextMode()138 inline TEXT_MODE getTextMode() const { return _iTextMode; } 139 void setTextMode(TEXT_MODE iTextMode); noWarning(const std::string & sWarningType)140 inline bool noWarning(const std::string& sWarningType) const { return noWarnings_.find(sWarningType) != noWarnings_.end(); } addNoWarning(const std::string & sWarningType)141 inline void addNoWarning(const std::string& sWarningType) { noWarnings_.insert(sWarningType); } getCapturedOutputFiles()142 inline const std::map<std::string, std::set<std::string> >& getCapturedOutputFiles() const { return _mapOfCapturedOutputFiles; } getCapturedInputFiles()143 inline const std::map<std::string, std::set<std::string> >& getCapturedInputFiles() const { return _mapOfCapturedInputFiles; } 144 void setFinalInfo(const std::string& sOutputFilename, int iFlag); getFinalInfoOutputFilename()145 inline const std::string& getFinalInfoOutputFilename() const { return sFinalInfoOutputFilename_; } getFinalInfoFlag()146 inline int getFinalInfoFlag() const { return iFinalInfoFlag_; } 147 void setRemoteDebug(const std::string& sHost, int iPort); getRemoteDebugHost()148 inline const std::string& getRemoteDebugHost() const { return sRemoteDebugHost_; } getRemoteDebugPort()149 inline int getRemoteDebugPort() const { return iRemoteDebugPort_; } 150 getTargetLanguage()151 inline const std::string& getTargetLanguage() const { return _sTargetLanguage; } hasTargetLanguage()152 inline bool hasTargetLanguage() const { return !_sTargetLanguage.empty(); } setTargetLanguage(const std::string & sTargetLanguage)153 inline void setTargetLanguage(const std::string& sTargetLanguage) { _sTargetLanguage = sTargetLanguage; } 154 static std::string getTargetScriptFilename(const std::string& sTargetLanguage, const std::string& sScriptShortFilename); 155 DtaBNFScript* getCommonAlienParser() const; 156 DtaBNFScript* getBNFAlienParser() const; 157 DtaBNFScript* getTemplateAlienParser() const; 158 DtaBNFScript* getTranslationAlienParser() const; 159 160 DtaScriptVariable* getGlobalVariable(const std::string& sName) const; 161 EXPRESSION_TYPE getGlobalVariableType(const std::string& sName) const; 162 DtaScriptVariable* setGlobalVariable(const std::string& sName, EXPRESSION_TYPE variableType = NODE_EXPRTYPE); 163 void setGlobalVariableType(const std::string& sName, EXPRESSION_TYPE variableType); 164 165 void copyCommon(const DtaProject& project); 166 std::string getTraceStack(ScpStream& script) const; 167 void traceEngine() const; 168 169 void prepareExecution(); 170 int addWarning(const std::string& sWarning); 171 bool isScriptVersionOlderThan(int* tiVersion) const; 172 173 bool addGenerationTagsHandler(const std::string& sKey, DtaBNFScript* pReader, DtaPatternScript* pWriter); 174 bool removeGenerationTagsHandler(const std::string& sKey); 175 bool existGenerationTagsHandler(const std::string& sKey) const; 176 bool selectGenerationTagsHandler(const std::string& sKey); 177 bool getGenerationTagsHandler(const std::string& sKey, DtaBNFScript*& pReader, DtaPatternScript*& pWriter) const; getCurrentGenerationTagsHandler()178 inline const std::string& getCurrentGenerationTagsHandler() const { return _sCurrentGenerationTagsHandler; } 179 180 void captureOutputFile(const char* tcOutputFile, const char* tcTemplateScript); 181 void captureInputFile(const char* tcInputFile, const char* tcBNFScript); 182 }; 183 } 184 185 #endif 186