diff options
Diffstat (limited to 'xsde/cxx/parser/generator.cxx')
-rw-r--r-- | xsde/cxx/parser/generator.cxx | 130 |
1 files changed, 62 insertions, 68 deletions
diff --git a/xsde/cxx/parser/generator.cxx b/xsde/cxx/parser/generator.cxx index 8f91f6b..22e1669 100644 --- a/xsde/cxx/parser/generator.cxx +++ b/xsde/cxx/parser/generator.cxx @@ -3,6 +3,22 @@ // copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <iostream> + +#include <boost/filesystem/fstream.hpp> + +#include <cult/containers/set.hxx> +#include <cult/containers/vector.hxx> + +#include <cutl/compiler/code-stream.hxx> +#include <cutl/compiler/cxx-indenter.hxx> +#include <cutl/compiler/sloc-counter.hxx> + +#include <backend-elements/regex.hxx> +#include <backend-elements/indentation/clip.hxx> + +#include <xsd-frontend/semantic-graph.hxx> + #include <type-map/lexer.hxx> #include <type-map/parser.hxx> @@ -27,20 +43,6 @@ #include <cxx/parser/attribute-validation-source.hxx> #include <cxx/parser/characters-validation-source.hxx> -#include <xsd-frontend/semantic-graph.hxx> - -#include <backend-elements/regex.hxx> -#include <backend-elements/indentation/cxx.hxx> -#include <backend-elements/indentation/sloc.hxx> -#include <backend-elements/indentation/clip.hxx> - -#include <cult/containers/set.hxx> -#include <cult/containers/vector.hxx> - -#include <boost/filesystem/fstream.hpp> - -#include <iostream> - #include <usage.hxx> #include "../../../libxsde/xsde/cxx/version.hxx" @@ -1180,12 +1182,18 @@ namespace CXX open (epilogue, name); } - // SLOC counter. // - UnsignedLong sloc (0); + UnsignedLong sloc_total (0); Boolean show_sloc (ops.value<CLI::show_sloc> ()); + typedef + compiler::ostream_filter<compiler::cxx_indenter, wchar_t> + ind_filter; + + typedef + compiler::ostream_filter<compiler::sloc_counter, wchar_t> + sloc_filter; // // @@ -1199,14 +1207,13 @@ namespace CXX if (guard_prefix) guard_prefix += '_'; - // HXX // { Context ctx ( hxx, schema, file_path, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); - Indentation::Clip<Indentation::SLOC, WideChar> hxx_sloc (hxx); + sloc_filter sloc (hxx); String guard (guard_expr.merge (guard_prefix + hxx_name)); guard = ctx.escape (guard); // Make it a C++ id. @@ -1431,23 +1438,21 @@ namespace CXX << "// End prologue." << endl << endl; + // Generate. + // { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> hxx_clip (hxx); + ind_filter ind (hxx); // We don't want to indent prologues/epilogues. - // Generate. - // if (!generate_xml_schema) generate_parser_forward (ctx); generate_parser_header (ctx, generate_xml_schema); - - if (inline_) - hxx << "#include " << ctx.process_include_path (ixx_name) << endl - << endl; } + if (inline_) + hxx << "#include " << ctx.process_include_path (ixx_name) << endl + << endl; + // Copy epilogue. // hxx << "// Begin epilogue." << endl @@ -1467,12 +1472,11 @@ namespace CXX hxx << "#endif // " << guard << endl; if (show_sloc) - wcerr << hxx_path << ": " << hxx_sloc.buffer ().count () << endl; + wcerr << hxx_path << ": " << sloc.stream ().count () << endl; - sloc += hxx_sloc.buffer ().count (); + sloc_total += sloc.stream ().count (); } - // IXX // if (inline_) @@ -1480,8 +1484,7 @@ namespace CXX Context ctx ( ixx, schema, file_path, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); - Indentation::Clip<Indentation::SLOC, WideChar> ixx_sloc (ixx); - + sloc_filter sloc (ixx); // Copy prologue. // @@ -1496,14 +1499,10 @@ namespace CXX << "// End prologue." << endl << endl; + // Generate. + // { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> ixx_clip (ixx); - - - // Generate. - // + ind_filter ind (ixx); // We don't want to indent prologues/epilogues. generate_parser_inline (ctx); } @@ -1521,9 +1520,9 @@ namespace CXX << endl; if (show_sloc) - wcerr << ixx_path << ": " << ixx_sloc.buffer ().count () << endl; + wcerr << ixx_path << ": " << sloc.stream ().count () << endl; - sloc += ixx_sloc.buffer ().count (); + sloc_total += sloc.stream ().count (); } @@ -1534,7 +1533,7 @@ namespace CXX Context ctx ( cxx, schema, file_path, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); - Indentation::Clip<Indentation::SLOC, WideChar> cxx_sloc (cxx); + sloc_filter sloc (cxx); // Copy prologue. // @@ -1549,14 +1548,14 @@ namespace CXX << "// End prologue." << endl << endl; - { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> cxx_clip (cxx); - - cxx << "#include " << ctx.process_include_path (hxx_name) << endl + cxx << "#include " << ctx.process_include_path (hxx_name) << endl << endl; + // Generate. + // + { + ind_filter ind (cxx); // We don't want to indent prologues/epilogues. + if (!inline_) generate_parser_inline (ctx); @@ -1584,9 +1583,9 @@ namespace CXX << endl; if (show_sloc) - wcerr << cxx_path << ": " << cxx_sloc.buffer ().count () << endl; + wcerr << cxx_path << ": " << sloc.stream ().count () << endl; - sloc += cxx_sloc.buffer ().count (); + sloc_total += sloc.stream ().count (); } // HXX impl @@ -1604,14 +1603,11 @@ namespace CXX << "#define " << guard << endl << endl; - { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> clip (hxx_impl); - - hxx_impl << "#include " << ctx.process_include_path (hxx_name) - << endl << endl; + hxx_impl << "#include " << ctx.process_include_path (hxx_name) + << endl << endl; + { + ind_filter ind (hxx_impl); generate_impl_header (ctx); } @@ -1625,14 +1621,13 @@ namespace CXX Context ctx (cxx_impl, schema, file_path, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> clip (cxx_impl); - cxx_impl << "#include " << ctx.process_include_path (hxx_impl_name) << endl << endl; - generate_impl_source (ctx); + { + ind_filter ind (cxx_impl); + generate_impl_source (ctx); + } } // CXX driver @@ -1642,17 +1637,16 @@ namespace CXX Context ctx (cxx_driver, schema, file_path, ops, &hxx_expr, &ixx_expr, &hxx_impl_expr); - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> clip (cxx_driver); - cxx_driver << "#include " << ctx.process_include_path (hxx_impl_name) << endl << endl; - generate_driver_source (ctx); + { + ind_filter ind (cxx_driver); + generate_driver_source (ctx); + } } - return sloc; + return sloc_total; } catch (UnrepresentableCharacter const& e) { |