diff options
author | Adrian Thurston <thurston@colm.net> | 2019-12-27 11:52:41 +0200 |
---|---|---|
committer | Adrian Thurston <thurston@colm.net> | 2019-12-27 11:52:41 +0200 |
commit | ba0569b4a80459e7d05f63115c89073eb9637537 (patch) | |
tree | 73738236d6d9554a92b45ca2ff8434a438b47475 /colm/exports.cc | |
parent | 7595234119adcda6e060fef31b3424589bf634df (diff) | |
download | colm-ba0569b4a80459e7d05f63115c89073eb9637537.tar.gz |
Created a common superclass for the export classes
Every class representing Colm types has a program and tree pointer and some
common functions. Moving this out allows us to pass the common base to the
repeat iterator and eliminate the first argument to the iterator.
Diffstat (limited to 'colm/exports.cc')
-rw-r--r-- | colm/exports.cc | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/colm/exports.cc b/colm/exports.cc index cc040d57..58482ad1 100644 --- a/colm/exports.cc +++ b/colm/exports.cc @@ -64,26 +64,6 @@ void Compiler::generateExports() "#include <string>\n" "\n"; - out << - "inline void appendString( colm_print_args *args, const char *data, int length )\n" - "{\n" - " std::string *str = (std::string*)args->arg;\n" - " *str += std::string( data, length );\n" - "}\n" - "\n"; - - out << - "inline std::string printTreeStr( colm_program *prg, colm_tree *tree, bool trim )\n" - "{\n" - " std::string str;\n" - " struct indent_impl indent = { -1, 0 };\n" - " colm_print_args printArgs = { &str, 1, 0, trim, &indent, &appendString, \n" - " &colm_print_null, &colm_print_term_tree, &colm_print_null };\n" - " colm_print_tree_args( prg, colm_vm_root(prg), &printArgs, tree );\n" - " return str;\n" - "}\n" - "\n"; - /* Declare. */ for ( LelList::Iter lel = langEls; lel.lte(); lel++ ) { if ( lel->isEOF ) @@ -102,25 +82,18 @@ void Compiler::generateExports() openNameSpace( out, lel->nspace ); out << "struct " << lel->fullName << "\n"; + out << " : public ExportTree\n"; out << "{\n"; out << " static const int ID = " << lel->id << ";\n"; - out << " std::string text() { return printTreeStr( __prg, __tree, true ); }\n"; - out << " colm_location *loc() { return colm_find_location( __prg, __tree ); }\n"; - out << " std::string text_notrim() { return printTreeStr( __prg, __tree, false ); }\n"; - out << " std::string text_ws() { return printTreeStr( __prg, __tree, false ); }\n"; - out << " colm_data *data() { return __tree->tokdata; }\n"; - out << " operator colm_tree *() { return __tree; }\n"; - out << " colm_program *__prg;\n"; - out << " colm_tree *__tree;\n"; if ( mainReturnUT != 0 && mainReturnUT->langEl == lel ) { out << " " << lel->fullName << - "( colm_program *prg ) : __prg(prg), __tree(returnVal(prg)) {\n"; + "( colm_program *prg ) : ExportTree( prg, returnVal(prg) ) {\n"; out << " }\n"; } out << " " << lel->fullName << - "( colm_program *prg, colm_tree *tree ) : __prg(prg), __tree(tree) {\n"; + "( colm_program *prg, colm_tree *tree ) : ExportTree( prg, tree ) {\n"; out << "}\n"; |