Original in Russian: http://programmingmindstream.blogspot.ru/2015/08/blog-post_37.html
The previous series was here – Code generation. Extracting almost everything to external dictionaries.
Now we will extract the specific model and the specific templates to external dictionaries.
The following code stays untouched:
https://bitbucket.org/lulinalex/mindstream/src/eaf26043070bdd15485c631ba5e2f9b00bf882e2/Examples/Scripts/CodeGeneration/CodeGen69.ms.script?at=B284
The previous series was here – Code generation. Extracting almost everything to external dictionaries.
Now we will extract the specific model and the specific templates to external dictionaries.
The following code stays untouched:
https://bitbucket.org/lulinalex/mindstream/src/eaf26043070bdd15485c631ba5e2f9b00bf882e2/Examples/Scripts/CodeGeneration/CodeGen69.ms.script?at=B284
USES Documentation.ms.dict Object.ms.dict ; Test CodeGen %REMARK ' CodeGen - function to test functionality ' USES Concrete.ms.model // - loads the specific model ; USES CodeDump.ms.dict // - the CodeDump.ms.dict is loaded so we can “see” the DumpElement word ; this.method.addr DumpElement %REMARK ' - the CodeGen element and its contents are dumped in a standard output device. We only do it to debug what we’ve written. ' USES Generation.ms.dict // - in order to load CallGensList CommonLang.ms.tpl // - loads the specific templates of code generation ; help %REMARK ' The available axiomatic is output to a standard output device. We only do it to debug what we’ve written. ' ( Project1 Project2 Project3 ) %REMARK 'Full list of root elements (projects)' ( .dump .pas .c++ .h .script ) %REMARK 'Full list of generators' CallGensList %REMARK '- launches the list of generators on the model’s “root elements” list' ; // CodeGen CodeGen Next we will develop the templates of code generation as target languages. As for now, the templates of code generation as target languages look as follows: // CommonLang.ms.tpl // Code generation templates for “common languages” USES Documentation.ms.dict params.ms.dict NoStrangeSymbols.ms.dict arrays.ms.dict ElementsRTTI.ms.dict Generation.ms.dict string.ms.dict ; STRING FUNCTION CatSepIndent> ARRAY right aValues CatSep> cIndentChar aValues =: Result ; // CatSepIndent> elem_proc DumpAsIs %SUMMARY 'Printing procedure for model element content, recursively.' ; CatSepIndent> [ Self .Stereotypes .reverted> ==> .Name %REMARK 'Outputs the stereotype of the element, recursively' Self .Name %REMARK 'Outputs the element name' ] OutToFile 'Parents ' (+)? CatSepIndent> ( Self .Parents .reverted> .map> .Name ) ?OutToFile 'Inherited ' (+)? CatSepIndent> ( Self .Inherited .map> .Name ) ?OutToFile 'Implemented ' (+)? CatSepIndent> ( Self .Implements .map> .Name ) ?OutToFile Self .generate.children %REMARK 'Outputs the element’s children with the same generator' [ '; // ' Self .Name ] OutToFile %REMARK 'Outputs the closing bracket of the element' ; // DumpAsIs elem_generator dump %SUMMARY 'Output generator for of the model’s element’s dump.' ; %GEN_PROPERTY Name 'dump' %REMARK 'Generator name and file extension for target language. Later, we try to avoid coincidence' Self .DumpAsIs %REMARK 'For now, outputs “as it is” without transformation to target language' ; // dump elem_generator pas %SUMMARY 'Generator to output model elements on Pascal.' ; %GEN_PROPERTY Name 'pas' %REMARK 'Generator name and file extension for target language. Later, we try to avoid coincidence' Self .DumpAsIs %REMARK 'For now, outputs “as it is” without transformation to target language' ; // pas elem_generator script %SUMMARY 'Generator to output model elements to ms.script.' ; %GEN_PROPERTY Name 'ms.script' %REMARK 'Generator name and file extension for target language. Later, we try to avoid coincidence' Self .DumpAsIs %REMARK 'For now, outputs “as it is” without transformation to target language' ; // script elem_generator c++ %SUMMARY ' 'Generator to output model elements to c++. Later we will specially talk about *.h files. ' ; %GEN_PROPERTY Name 'cpp' %REMARK 'Generator name and file extension for target language. Later, we try to avoid coincidence' Self .DumpAsIs %REMARK 'For now, outputs “as it is” without transformation to target language' ; // c++ elem_generator h %SUMMARY ' 'Generator to output model elements to *.h. Later we will specially talk about *.h files. ' ; %GEN_PROPERTY Name 'h' %REMARK 'Generator name and file extension for target language. Later, we try to avoid coincidence' Self .DumpAsIs %REMARK 'For now, outputs “as it is” without transformation to target language' ; // h
Комментариев нет:
Отправить комментарий