13 #ifndef FAUDES_CODEGENERATOR_H
14 #define FAUDES_CODEGENERATOR_H
16 #include "libfaudes.h"
20 using namespace faudes;
23 #define FCG_VERB0(msg) { if(mVerbLevel>=0) *pErrStream << msg << std::endl; }
24 #define FCG_VERB1(msg) { if(mVerbLevel>=1) *pErrStream << msg << std::endl; }
25 #define FCG_VERB2(msg) { if(mVerbLevel>=2) *pErrStream << msg << std::endl; }
26 #define FCG_ERR(msg) { *pErrStream << msg << std::endl; throw Exception("CodeGenerator()","internal error", 500); }
29 #ifndef COMPILEDES_VERSION
30 #define COMPILEDES_VERSION "3.0x"
116 enum OutSink { CONSOLE, FILE, STRING };
147 virtual void Clear(
void);
156 virtual void Name(
const std::string& rName) { mName=rName;};
164 virtual const std::string&
Name(
void)
const {
return mName;};
170 virtual void Compile(
void);
176 static std::string VersionString(
void);
203 Idx Size(
void)
const;
219 void Insert(
const std::string& file);
231 void Insert(
const TimedGenerator& rGen);
234 const TimedGenerator& At(
int i)
const {
return mGenerators.at(i); };
237 typedef std::vector<TimedGenerator>::const_iterator Iterator;
275 Idx
EventIndex(
const std::string& rName)
const {
return mAlphabet.Index(rName); };
286 std::string
EventName(Idx index)
const {
return mAlphabet.SymbolicName(index); };
370 virtual int EventTargetIdx(Idx idx);
373 virtual int EventTargetIdx(
const std::string& ev);
376 int EventBitAddress(Idx idx);
379 Idx EventFaudesIdx(
int idx);
382 std::vector<bool> EventBitMask(Idx idx);
385 std::vector<bool> EventBitMask(
const EventSet& eset);
388 int EventBitMaskSize(
void);
394 word_t WordFromBitVector(
const std::vector<bool>& vect,
int wordindex);
397 std::vector< word_t > WordVectorFromBitVector(
const std::vector<bool>& vect);
447 const std::vector<int>& TransitionVector(
size_t git);
450 virtual int StateTargetIdx(
size_t git, Idx idx);
453 virtual Idx StateFaudesIdx(
size_t git,
int idx);
469 std::string mAddress;
561 if(!(mTimerStops==other.
mTimerStops))
return false;
617 virtual void Generate(
void);
628 void Verbose(
int level, std::ostream* altout=0);
647 virtual void OutputMode(
const std::string& mode) {mOutMode=mode;};
672 virtual std::ostream& Output(
void);
686 const std::string& OutputString(
void);
696 void OutputString(
const std::string& strbuf);
712 virtual void MuteMode(
char mode);
721 virtual void MuteCond(
char mode);
724 virtual void LineFeed(
int lines=1);
727 virtual std::string LineCount(
void);
730 virtual void IndentInc();
733 virtual void IndentDec();
736 virtual void Comment(
const std::string& text);
742 virtual void XmlTextEscape(
bool on);
745 virtual void XmlCdataEscape(
bool on);
748 virtual void MuteComments(
bool on);
751 virtual void MuteVspace(
bool on);
794 static void Register(
const std::string& type,
CodeGenerator* (*newcg)(
void));
802 static std::vector< std::string > Registry(
void);
827 #define FAUDES_REGISTERCODEGENERATOR(ftype,ctype) static CodeGenerator::Registration<ctype> gRegister(ftype)
894 std::map<std::string, LineAddress>
mLines;
897 std::map<std::string, FlagExpression>
mFlags;
900 std::map<std::string, TimerConfiguration>
mTimers;
930 virtual void DoCompile(
void);
933 virtual void DoGenerate(
void) = 0;
953 virtual void DoRead(TokenReader& rTr,
const std::string& rLabel=
"",
const Type* pContext=0);
975 virtual void DoWrite(TokenWriter& rTw,
const std::string& rLabel=
"",
const Type* pContext=0)
const;
987 virtual void DoReadTargetConfiguration(TokenReader& rTr);
998 virtual void DoWriteTargetConfiguration(TokenWriter& rTw)
const;
1003 static std::map< std::string, CodeGenerator* (*)(void) >* mpsRegistry;
1006 void DoReadGenerators(TokenReader& rTr);
1009 void DoWriteGenerators(TokenWriter& rTw)
const;
1013 class cgp_streambuf :
public std::streambuf {
1016 cgp_streambuf(std::string mode);
1027 void MuteVspace(
bool on);
1028 void XmlTextEscape(
bool on);
1029 void XmlCdataEscape(
bool on);
1032 const std::string& Buffer();
1039 virtual int_type overflow (int_type c);
1041 std::string mBuffer;
1042 std::ostream* pOutStream;
1043 std::ofstream* mpFOutStream;
1044 std::stringstream* mpSOutStream;
1057 cgp_streambuf* pOutBuffer;