author | Michael Krelin <hacker@klever.net> | 2005-01-29 21:21:05 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-01-29 21:21:05 (UTC) |
commit | ce1f37aae46ea95020d7b865f7a80e8abdfad0d8 (patch) (side-by-side diff) | |
tree | 4964383ab8cd7e6d8ea821f1a615d1bbcf98dad8 /lib/sitecing_enflesher.ll | |
parent | 3c75c860fc1ad5b3f5185e23ec6f438dd2528958 (diff) | |
download | sitecing-ce1f37aae46ea95020d7b865f7a80e8abdfad0d8.zip sitecing-ce1f37aae46ea95020d7b865f7a80e8abdfad0d8.tar.gz sitecing-ce1f37aae46ea95020d7b865f7a80e8abdfad0d8.tar.bz2 |
initial commit into repository0.0
-rw-r--r-- | lib/sitecing_enflesher.ll | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/lib/sitecing_enflesher.ll b/lib/sitecing_enflesher.ll new file mode 100644 index 0000000..5f631d7 --- a/dev/null +++ b/lib/sitecing_enflesher.ll @@ -0,0 +1,202 @@ +%{ +#include <iostream> +#include <fstream> +#include <cassert> +#include <stdexcept> +using namespace std; +#include "sitecing/sitecing_exception.h" +using namespace sitecing; +#define sitecing_enflesher_flexlexer_once +#include "sitecing/sitecing_enflesher.h" +#include "sitecing/sitecing_parser.h" +#undef yyFlexLexer +#define yyFlexLexer sitecing_enflesherFlexLexer +%} +%option 8bit c++ verbose noyywrap yyclass="sitecing_enflesher" yylineno prefix="sitecing_enflesher" stack debug + +ID [A-Za-z_][A-Za-z0-9_]* + +%% + +^\%\%\#[^\n]+\n { + string line = yytext; + line.erase(0,3); + line.erase(line.length()-1); + outs.flush(); + outs.close(); + outs.clear(); + outs.open((parser.output_basename+line).c_str(),ios::trunc); + if(!outs.good()) + throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); + anchor(); + anchoraged = true; +} +^\%\%[^\n]+\n { + string line = yytext; + line.erase(0,2); + line.erase(line.length()-1); + outs.flush(); + outs.close(); + outs.clear(); + outs.open((parser.output_basename+line).c_str(),ios::trunc); + if(!outs.good()) + throw preprocessor_error(CODEPOINT,"failed to write preprocessor output"); + anchoraged = false; +} + +\<\%component_basename\%\> outs << parser.component_basename; anchor_time = true; +\<\%impl\%\> outs << parser.impl; anchor_time = true; +\<\%member_functions:impl\%\> { + for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) { + outs << i->type << " " << parser.class_name << "::"; + if(i->name.empty()) { + outs << parser.class_name << "()"; + bool first = true; + for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { + if(i->initializer.empty()) + continue; + if(first) { + outs << ":"; + first=false; + }else{ + outs << ","; + } + if(i->bComponent) { + outs << i->name << "(NULL)"; + }else { + outs << i->name << "(" << i->initializer << ")"; + } + } + }else if(i->name == "~") + outs << "~" << parser.class_name << "()"; + else + outs << i->name << i->args; + outs << "{\n" << i->body << "\n}\n"; + } + anchor_time = true; +} +\<\%class_name\%\> outs << parser.class_name; anchor_time = true; +\<\%baseclass_header\%\> outs << parser.base_header; anchor_time = true; +\<\%decl\%\> outs << parser.decl; anchor_time = true; +\<\%baseclass_name\%\> outs << parser.base_class; anchor_time = true; +\<\%member_variables:decl\%\> { + for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { + if(i->bComponent) { + if(i->type.empty()) { + i->type = parser.factory.get_classname(i->initializer); + } + if(i->bTypeOnly) { + outs << "typedef " << i->type << " " << i->name << ";\n"; + }else{ + outs << "typedef " << i->type << " __type_" << i->name << ";\nsitecing::so_component __soc_" << i->name << ";\n__type_" << i->name << " *" << i->name << ";\n"; + } + }else{ + outs << i->type << " " << i->name << ";\n"; + } + } + anchor_time = true; +} +\<\%member_functions:decl\%\> { + for(sitecing_parser::member_functions_t::const_iterator i=parser.member_functions.begin();i!=parser.member_functions.end();i++) { + (i->name.empty()?outs:outs << "virtual ") + << i->type << " "; + if(i->name.empty()) { + outs << parser.class_name << "()"; + }else if(i->name == "~") + outs << "~" << parser.class_name << "()"; + else + outs << i->name << i->args; + outs << ";\n"; + } + anchor_time = true; +} +\<\%imports:list\%\> { + for(sitecing_parser::member_variables_t::const_iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { + if(i->bComponent) + outs << i->initializer << endl; + } + anchor_time = true; +} +\<\%imports:includes\%\> { + for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { + if(i->bComponent) + outs << "\n#include \"" << i->initializer << ".h\"\n"; + } + anchor_time = true; +} +\<\%imports:import\%\> { + for(sitecing_parser::member_variables_t::iterator i=parser.member_variables.begin();i!=parser.member_variables.end();i++) { + if(!i->bComponent) + continue; + if(i->bTypeOnly) + continue; + outs << "__soc_" << i->name << "=__SCIF->ss->fetch(\"" << i->initializer << "\",__SCIF); " << i->name << "=static_cast<__type_" << i->name << "*>(__soc_" << i->name << ".ac->__the_most_derived_this());\n"; + } + anchor_time = true; +} + +\<\%base_component\%\> { + // TODO: + anchor_time = true; +} + +\<\%ancestors:includes\%\> { + for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { + outs << "#include \"" << i->path << ".h\"\n"; + } + anchor_time = true; +} +\<\%ancestors:component_list\%\> { + for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { + outs << i->path << "\n"; + } + anchor_time = true; +} +\<\%ancestors:base_clause_part\%\> { + for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { + outs << ", virtual public " << parser.factory.get_classname(i->path); + } +} +\<\%ancestors:typedefs\%\> { + for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { + outs << "typedef class " << parser.factory.get_classname(i->path) << " " << i->name << ";\n"; + } + anchor_time = true; +} +\<\%ancestors:import\%\> { + for(sitecing_parser::ancestor_classes_t::const_iterator i=parser.ancestor_classes.begin();i!=parser.ancestor_classes.end();++i) { + outs << i->name << "::__do_imports();\n"; + } + anchor_time = true; +} + +\n { + if(anchor_time) + anchor(); + ECHO; +} +. ECHO; + +%% + +void sitecing_enflesher::LexerOutput(const char *buf,int size) { + outs.write(buf,size); +} + +void sitecing_enflesher::enflesh() { + ifstream ifs(parser.skeleton.c_str()); + if(!ifs.good()) + throw preprocessor_error(CODEPOINT,"failed to open skeleton file"); + switch_streams(&ifs,NULL); + yylex(); +} + +void sitecing_enflesher::anchor() { + if(!anchoraged) + return; + outs << "\n#line " << lineno() << " \"" << parser.skeleton << "\"\n"; + anchor_time = false; +} +/* + * vim:set ft=lex: + */ |