00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _MPCL_TEXT_CODEGEN_PATTERN_BASED_CODE_GENERATOR__
00027 #define _MPCL_TEXT_CODEGEN_PATTERN_BASED_CODE_GENERATOR__
00028
00029 #include "../../io/streamable.hh"
00030 #include "../../io/streamable_map.hh"
00031 #include "../string.hh"
00032 #include "clause_body_string.hh"
00033 #include "defs.hh"
00034 #include "instruction_body.hh"
00035 #include "instruction_tag_string.hh"
00036
00037
00039 namespace mpcl
00040 {
00041
00043 namespace text
00044 {
00045
00047 namespace codegen
00048 {
00049
00050 using io::IStreamable;
00051 using io::TStreamableMap;
00052
00070 class TPatternBasedCodeGenerator: public IStreamable<>
00071 {
00072
00073 private:
00074
00076 typedef
00077 TStreamableMap<TInstructionTagString, TInstructionBody>
00078 TInstructionMap;
00079
00081 TInstructionMap tInstructionMap;
00082
00084 TStringToVariableMap tVariableMap;
00085
00087 TString yCdmlPath;
00088
00090 TString yDescription;
00091
00093 TString yInherit;
00094
00096 TString yPublic;
00097
00099 TString ySystem;
00100
00102 TString yTarget;
00103
00104
00105 public:
00106
00107
00108
00109
00110
00119 TPatternBasedCodeGenerator ( const TString& rkySOURCE_CDML_FILE ,
00120 const TString& rkyCDML_PATH );
00121
00123 TPatternBasedCodeGenerator (void) :
00124 IStreamable<> () ,
00125 tInstructionMap () ,
00126 tVariableMap () ,
00127 yCdmlPath () ,
00128 yDescription () ,
00129 yInherit () ,
00130 yPublic () ,
00131 ySystem () ,
00132 yTarget ()
00133 {
00134 initConstants();
00135 }
00136
00138 void clear (void);
00139
00141 void clearCode (void);
00142
00148 void compile (void);
00149
00155 void loadFrom (const TString& rkySOURCE_CDML_FILE);
00156
00160 void preprocessVariables (void);
00161
00166 void setDescription (const char* pkcSOURCE_DESCRIPTION);
00167
00174 void setCdmlPath (const TString& rkyCDML_PATH);
00175
00176
00177 protected:
00178
00179
00180
00181
00182
00184 void initConstants (void) const;
00185
00193 void inheritFrom (const TString& rkySOURCE_CDML_FILE);
00194
00199 void read (std::basic_istream<char_type, traits_type>& rtSOURCE_STREAM);
00200
00201
00202 public:
00203
00204
00205
00206
00207
00213 const TStringToVariableMap& variables (void) const;
00214
00215 const TClauseBodyString& codePatternFor ( const char* pkcINSTRUCTION_NAME ,
00216 const char* pkcCLAUSE_NAME ) const;
00217
00218 TInstructionBody& instruction (const char* pkcINSTRUCTION_NAME);
00219
00220 const TInstructionBody& instruction (const char* pkcINSTRUCTION_NAME) const;
00221
00227 bool existsVariable (const char* pkcVARIABLE_NAME) const;
00228
00229 bool existsClause (const char* pkcINSTRUCTION_NAME, const char* pkcCLAUSE_NAME) const;
00230
00238 const TInstructionBody& operator [] (const char* pkcINSTRUCTION_NAME) const
00239 {
00240 return instruction (pkcINSTRUCTION_NAME);
00241 }
00242
00250 TInstructionBody& operator [] (const char* pkcINSTRUCTION_NAME)
00251 {
00252 return instruction (pkcINSTRUCTION_NAME);
00253 }
00254
00255
00256 protected:
00257
00258
00259
00260
00261
00266 void write (std::basic_ostream<char_type, traits_type>& rtTARGET_OSTREAM) const;
00267
00268 };
00269
00270 }
00271
00272 }
00273
00274 }
00275
00276
00277 #endif // not _MPCL_TEXT_CODEGEN_PATTERN_BASED_CODE_GENERATOR__