diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:25:44 +0200 |
commit | 8286ac511144e4f17d34eac9affb97e50646344a (patch) | |
tree | f1af7320d7b6be6be059216d0ad08ac7b4f73fd0 /xsd/xsd/cxx/parser/generator.cxx | |
parent | a15cf65c44d5c224169c32ef5495b68c758134b7 (diff) |
Imported Upstream version 4.0.0upstream/4.0.0
Diffstat (limited to 'xsd/xsd/cxx/parser/generator.cxx')
-rw-r--r-- | xsd/xsd/cxx/parser/generator.cxx | 890 |
1 files changed, 201 insertions, 689 deletions
diff --git a/xsd/xsd/cxx/parser/generator.cxx b/xsd/xsd/cxx/parser/generator.cxx index b3aee76..e17986b 100644 --- a/xsd/xsd/cxx/parser/generator.cxx +++ b/xsd/xsd/cxx/parser/generator.cxx @@ -1,8 +1,19 @@ // file : xsd/cxx/parser/generator.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <algorithm> +#include <iostream> +#include <fstream> + +#include <cutl/re.hxx> + +#include <cutl/compiler/code-stream.hxx> +#include <cutl/compiler/cxx-indenter.hxx> +#include <cutl/compiler/sloc-counter.hxx> + +#include <xsd-frontend/semantic-graph.hxx> + #include <type-map/lexer.hxx> #include <type-map/parser.hxx> #include <type-map/type-map.hxx> @@ -28,49 +39,28 @@ #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 <cxx/parser/options.hxx> #include "../../../libxsd/xsd/cxx/version.hxx" using std::endl; using std::wcerr; +using std::wcout; using namespace XSDFrontend::SemanticGraph; // // -typedef -boost::filesystem::wifstream -WideInputFileStream; - -typedef -boost::filesystem::wofstream -WideOutputFileStream; - -typedef -boost::filesystem::ifstream -NarrowInputFileStream; +typedef std::wifstream WideInputFileStream; +typedef std::wofstream WideOutputFileStream; +typedef std::ifstream NarrowInputFileStream; namespace CXX { namespace { - Char const copyright_gpl[] = - "// Copyright (C) 2005-2010 Code Synthesis Tools CC\n" + char const copyright_gpl[] = + "// Copyright (c) 2005-2014 Code Synthesis Tools CC\n" "//\n" "// This program was generated by CodeSynthesis XSD, an XML Schema to\n" "// C++ data binding compiler.\n" @@ -103,8 +93,8 @@ namespace CXX "// in the accompanying FLOSSE file.\n" "//\n\n"; - Char const copyright_proprietary[] = - "// Copyright (C) 2005-2010 Code Synthesis Tools CC\n" + char const copyright_proprietary[] = + "// Copyright (c) 2005-2014 Code Synthesis Tools CC\n" "//\n" "// This program was generated by CodeSynthesis XSD, an XML Schema\n" "// to C++ data binding compiler, in the Proprietary License mode.\n" @@ -113,7 +103,7 @@ namespace CXX "// conditions.\n" "//\n\n"; - Char const copyright_impl[] = + char const copyright_impl[] = "// Not copyrighted - public domain.\n" "//\n" "// This sample parser implementation was generated by CodeSynthesis XSD,\n" @@ -122,442 +112,24 @@ namespace CXX "//\n\n"; } - namespace Parser - { - namespace CLI - { - extern Key type_map = "type-map"; - extern Key char_type = "char-type"; - extern Key char_encoding = "char-encoding"; - extern Key output_dir = "output-dir"; - extern Key xml_parser = "xml-parser"; - extern Key generate_inline = "generate-inline"; - extern Key generate_validation = "generate-validation"; - extern Key suppress_validation = "suppress-validation"; - extern Key generate_polymorphic = "generate-polymorphic"; - extern Key generate_noop_impl = "generate-noop-impl"; - extern Key generate_print_impl = "generate-print-impl"; - extern Key generate_test_driver = "generate-test-driver"; - extern Key force_overwrite = "force-overwrite"; - extern Key root_element_first = "root-element-first"; - extern Key root_element_last = "root-element-last"; - extern Key root_element = "root-element"; - extern Key generate_xml_schema = "generate-xml-schema"; - extern Key extern_xml_schema = "extern-xml-schema"; - extern Key skel_type_suffix = "skel-type-suffix"; - extern Key skel_file_suffix = "skel-file-suffix"; - extern Key impl_type_suffix = "impl-type-suffix"; - extern Key impl_file_suffix = "impl-file-suffix"; - extern Key namespace_map = "namespace-map"; - extern Key namespace_regex = "namespace-regex"; - extern Key namespace_regex_trace = "namespace-regex-trace"; - extern Key reserved_name = "reserved-name"; - extern Key include_with_brackets = "include-with-brackets"; - extern Key include_prefix = "include-prefix"; - extern Key include_regex = "include-regex"; - extern Key include_regex_trace = "include-regex-trace"; - extern Key guard_prefix = "guard-prefix"; - extern Key hxx_suffix = "hxx-suffix"; - extern Key ixx_suffix = "ixx-suffix"; - extern Key cxx_suffix = "cxx-suffix"; - extern Key hxx_regex = "hxx-regex"; - extern Key ixx_regex = "ixx-regex"; - extern Key cxx_regex = "cxx-regex"; - extern Key hxx_prologue = "hxx-prologue"; - extern Key ixx_prologue = "ixx-prologue"; - extern Key cxx_prologue = "cxx-prologue"; - extern Key prologue = "prologue"; - extern Key hxx_epilogue = "hxx-epilogue"; - extern Key ixx_epilogue = "ixx-epilogue"; - extern Key cxx_epilogue = "cxx-epilogue"; - extern Key epilogue = "epilogue"; - extern Key hxx_prologue_file = "hxx-prologue-file"; - extern Key ixx_prologue_file = "ixx-prologue-file"; - extern Key cxx_prologue_file = "cxx-prologue-file"; - extern Key prologue_file = "prologue-file"; - extern Key hxx_epilogue_file = "hxx-epilogue-file"; - extern Key ixx_epilogue_file = "ixx-epilogue-file"; - extern Key cxx_epilogue_file = "cxx-epilogue-file"; - extern Key epilogue_file = "epilogue-file"; - extern Key export_symbol = "export-symbol"; - extern Key export_maps = "export-maps"; - extern Key import_maps = "import-maps"; - extern Key show_anonymous = "show-anonymous"; - extern Key show_sloc = "show-sloc"; - extern Key proprietary_license = "proprietary-license"; - } - } - - Void Parser::Generator:: + void Parser::Generator:: usage () { - std::wostream& e (wcerr); - ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); - - e << "--type-map <mapfile>" << endl - << " Read XML Schema to C++ type mapping information\n" - << " from <mapfile>. Repeat this option to specify\n" - << " several type maps. Type maps are considered in\n" - << " order of appearance and the first match is used." - << endl; - - e << "--char-type <type>" << endl - << " Use <type> as the base character type. Valid\n" - << " values are 'char' (default) and 'wchar_t'." - << endl; - - e << "--char-encoding <enc>" << endl - << " Specify the character encoding that should be used\n" - << " in the object model. Valid values for the 'char'\n" - << " character type are 'utf8' (default), 'iso8859-1',\n" - << " 'lcp', and 'custom'. For the 'wchar_t' character\n" - << " type the only valid value is 'auto'." - << endl; - - e << "--output-dir <dir>" << endl - << " Write generated files to <dir> instead of current\n" - << " directory." - << endl; - - e << "--xml-parser <parser>" << endl - << " Use <parser> as the underlying XML parser. Valid\n" - << " values are 'xerces' (default) and 'expat'." - << endl; - - e << "--generate-inline" << endl - << " Generate certain functions inline." - << endl; - - e << "--generate-validation" << endl - << " Generate validation code." - << endl; - - e << "--suppress-validation" << endl - << " Suppress the generation of validation code." - << endl; - - e << "--generate-polymorphic" << endl - << " Generate polymorphism-aware code. Specify this\n" - << " option if you use substitution groups or xsi:type." - << endl; - - e << "--generate-noop-impl" << endl - << " Generate a sample parser implementation that\n" - << " does nothing (no operation)." - << endl; - - e << "--generate-print-impl" << endl - << " Generate a sample parser implementation that\n" - << " prints the XML data to STDOUT." - << endl; - - e << "--generate-test-driver" << endl - << " Generate a test driver for the sample parser\n" - << " implementation." - << endl; - - e << "--force-overwrite" << endl - << " Force overwriting of the existing implementation\n" - << " and test driver files." - << endl; - - e << "--root-element-first" << endl - << " Indicate that the first global element is the\n" - << " document root." - << endl; - - e << "--root-element-last" << endl - << " Indicate that the last global element is the\n" - << " document root." - << endl; - - e << "--root-element <element>" << endl - << " Indicate that <element> is the document root." - << endl; - - e << "--generate-xml-schema" << endl - << " Generate a C++ header file as if the schema being\n" - << " compiled defines the XML Schema namespace." - << endl; - - e << "--extern-xml-schema <file>" << endl - << " Generate code as if the XML Schema namespace was\n" - << " defined in <file> and xsd:included in the schema\n" - << " being compiled." - << endl; - - e << "--skel-type-suffix <suffix>" << endl - << " Use <suffix> instead of the default '_pskel' to\n" - << " construct the names of generated parser skeletons." - << endl; - - e << "--skel-file-suffix <suffix>" << endl - << " Use <suffix> instead of the default '-pskel' to\n" - << " construct the names of generated parser skeleton\n" - << " files." - << endl; - - e << "--impl-type-suffix <suffix>" << endl - << " Use <suffix> instead of the default '_pimpl' to\n" - << " construct the names of parser implementations for\n" - << " the built-in XML Schema types and sample parser\n" - << " implementations." - << endl; - - e << "--impl-file-suffix <suffix>" << endl - << " Use <suffix> instead of the default '-pimpl' to\n" - << " construct the names of generated sample parser\n" - << " implementation files." - << endl; - - e << "--namespace-map <xns>=<cns>" << endl - << " Map XML Schema namespace <xns> to C++ namespace\n" - << " <cns>. Repeat this option to specify mapping for\n" - << " more than one XML Schema namespace." - << endl; - - e << "--namespace-regex <regex>" << endl - << " Add <regex> to the list of regular expressions\n" - << " used to translate XML Schema namespace names to\n" - << " C++ namespace names." - << endl; - - e << "--namespace-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --namespace-regex option." - << endl; - - e << "--reserved-name <name>" << endl - << " Add <name> to the list of names that should not\n" - << " be used as identifiers. The name can optionally\n" - << " be followed by '=' and the replacement name that\n" - << " should be used instead." - << endl; - - e << "--include-with-brackets" << endl - << " Use angle brackets (<>) instead of quotes (\"\") in\n" - << " generated #include directives." - << endl; - - e << "--include-prefix <prefix>" << endl - << " Add <prefix> to generated #include directive\n" - << " paths." - << endl; - - e << "--include-regex <regex>" << endl - << " Add <regex> to the list of regular expressions\n" - << " used to transform #include directive paths." - << endl; - - e << "--include-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --include-regex option." - << endl; - - e << "--guard-prefix <prefix>" << endl - << " Add <prefix> to generated header inclusion guards." - << endl; - - e << "--hxx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.hxx' to\n" - << " construct the name of the header file." - << endl; - - e << "--ixx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.ixx' to\n" - << " construct the name of the inline file." - << endl; - - e << "--cxx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.cxx' to\n" - << " construct the name of the source file." - << endl; - - e << "--hxx-regex <regex>" << endl - << " Use <regex> to construct the name of the header\n" - << " file." - << endl; - - e << "--ixx-regex <regex>" << endl - << " Use <regex> to construct the name of the inline\n" - << " file." - << endl; - - e << "--cxx-regex <regex>" << endl - << " Use <regex> to construct the name of the source\n" - << " file." - << endl; - - - // Prologues. - // - e << "--hxx-prologue <text>" << endl - << " Insert <text> at the beginning of the header file." - << endl; - - e << "--ixx-prologue <text>" << endl - << " Insert <text> at the beginning of the inline file." - << endl; - - e << "--cxx-prologue <text>" << endl - << " Insert <text> at the beginning of the source file." - << endl; - - e << "--prologue <text>" << endl - << " Insert <text> at the beginning of each generated\n" - << " file for which there is no file-specific prologue." - << endl; - - - // Epilogues. - // - e << "--hxx-epilogue <text>" << endl - << " Insert <text> at the end of the header file." - << endl; - - e << "--ixx-epilogue <text>" << endl - << " Insert <text> at the end of the inline file." - << endl; - - e << "--cxx-epilogue <text>" << endl - << " Insert <text> at the end of the source file." - << endl; - - e << "--epilogue <text>" << endl - << " Insert <text> at the end of each generated file\n" - << " for which there is no file-specific epilogue." - << endl; - - - // Prologue files. - // - e << "--hxx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the header file." - << endl; - - e << "--ixx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the inline file." - << endl; - - e << "--cxx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the source file." - << endl; - - e << "--prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of each generated file for which there is no file-\n" - << " specific prologue file." - << endl; - - - // Epilogue files. - // - e << "--hxx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the header file." - << endl; - - e << "--ixx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the inline file." - << endl; - - e << "--cxx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the source file." - << endl; - - e << "--epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " each generated file for which there is no file-\n" - << " specific epilogue file." - << endl; - - - // Misc. - // - e << "--custom-literals <file>" << endl - << " Load custom XML string to C++ literal mappings\n" - << " from <file>." - << endl; - - e << "--export-symbol <symbol>" << endl - << " Export symbol for Win32 DLL export/import control." - << endl; - - e << "--export-maps" << endl - << " Export polymorphism support maps from Win32 DLL." - << endl; - - e << "--import-maps" << endl - << " Import polymorphism support maps from Win32 DLL." - << endl; - - e << "--show-anonymous" << endl - << " Show elements and attributes that are of anonymous\n" - << " types." - << endl; - - e << "--show-sloc" << endl - << " Show the number of generated physical source lines\n" - << " of code (SLOC)." - << endl; - - e << "--sloc-limit <num>" << endl - << " Check that the number of generated physical source\n" - << " lines of code (SLOC) does not exceed <num>." - << endl; - - e << "--options-file <file>" << endl - << " Read additional options from <file>. Each option\n" - << " should appear on a separate line optionally\n" - << " followed by space and an argument." - << endl; - - e << "--proprietary-license" << endl - << " Indicate that the generated code is licensed under\n" - << " a proprietary license instead of the GPL." - << endl; + CXX::Parser::options::print_usage (wcout); + CXX::options::print_usage (wcout); } - Parser::CLI::OptionsSpec Parser::Generator:: - options_spec () - { - CLI::OptionsSpec spec; - - spec.option<CLI::char_type> ().default_value ("char"); - spec.option<CLI::xml_parser> ().default_value ("xerces"); - - spec.option<CLI::skel_file_suffix> ().default_value ("-pskel"); - spec.option<CLI::skel_type_suffix> ().default_value ("_pskel"); - spec.option<CLI::impl_file_suffix> ().default_value ("-pimpl"); - spec.option<CLI::impl_type_suffix> ().default_value ("_pimpl"); - - spec.option<CLI::hxx_suffix> ().default_value (".hxx"); - spec.option<CLI::ixx_suffix> ().default_value (".ixx"); - spec.option<CLI::cxx_suffix> ().default_value (".cxx"); - - return spec; - } - - namespace { template <typename S> - Void + void open (S& ifs, NarrowString const& path) { try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path fs_path (path, boost::filesystem::native); -#else - Path fs_path (path.c_str()); -#endif - ifs.open (fs_path, std::ios_base::in | std::ios_base::binary); + Path fs_path (path); + ifs.open (fs_path.string ().c_str (), + std::ios_base::in | std::ios_base::binary); if (!ifs.is_open ()) { @@ -576,7 +148,7 @@ namespace CXX } } - Void + void append (WideOutputFileStream& os, NarrowString const& path, WideInputFileStream& default_is) @@ -596,16 +168,15 @@ namespace CXX } } - Void + void append (WideOutputFileStream& os, - Cult::Containers::Vector<NarrowString> const& primary, - Cult::Containers::Vector<NarrowString> const& def) + NarrowStrings const& primary, + NarrowStrings const& def) { - Cult::Containers::Vector<NarrowString> const& v ( - primary.empty () ? def : primary); + NarrowStrings const& v (primary.empty () ? def : primary); - for (Containers::Vector<NarrowString>::ConstIterator - i (v.begin ()), e (v.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (v.begin ()), e (v.end ()); + i != e; ++i) { os << i->c_str () << endl; } @@ -613,25 +184,24 @@ namespace CXX } - UnsignedLong Parser::Generator:: - generate (Parser::CLI::Options const& ops, + size_t Parser::Generator:: + generate (Parser::options const& ops, Schema& schema, Path const& file_path, - Boolean fpt, + bool fpt, StringLiteralMap const& string_literal_map, - Boolean gen_driver, + bool gen_driver, const WarningSet& disabled_warnings, FileList& file_list, AutoUnlinks& unlinks) { using std::ios_base; - namespace Indentation = BackendElements::Indentation; - typedef BackendElements::Regex::Expression<Char> Regex; + typedef cutl::re::regexsub Regex; try { - Boolean generate_xml_schema (ops.value<CLI::generate_xml_schema> ()); + bool generate_xml_schema (ops.generate_xml_schema ()); // We could be compiling several schemas at once in which case // handling of the --generate-xml-schema option gets tricky: we @@ -640,23 +210,19 @@ namespace CXX // if (generate_xml_schema) { - if (NarrowString name = ops.value<CLI::extern_xml_schema> ()) + if (NarrowString name = ops.extern_xml_schema ()) { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - if (file_path.native_file_string () != name) -#else if (file_path.string () != name) -#endif generate_xml_schema = false; } } - Boolean impl (!generate_xml_schema && - (ops.value<CLI::generate_noop_impl> () || - ops.value<CLI::generate_print_impl> ())); + bool impl (!generate_xml_schema && + (ops.generate_noop_impl () || + ops.generate_print_impl ())); - Boolean driver (gen_driver && !generate_xml_schema && - ops.value<CLI::generate_test_driver> ()); + bool driver (gen_driver && !generate_xml_schema && + ops.generate_test_driver ()); // Evaluate the graph for possibility of generating something useful. // @@ -674,9 +240,9 @@ namespace CXX proc.process (ops, schema, file_path, string_literal_map); } - Boolean validation ((ops.value<CLI::xml_parser> () == "expat" || - ops.value<CLI::generate_validation> ()) && - !ops.value<CLI::suppress_validation> ()); + bool validation ((ops.xml_parser () == "expat" || + ops.generate_validation ()) && + !ops.suppress_validation ()); // Compute state machine info. // @@ -691,11 +257,11 @@ namespace CXX TypeMap::Namespaces type_map; { using namespace TypeMap; - typedef Containers::Vector<NarrowString> Files; - Files const& files (ops.value<CLI::type_map> ()); + NarrowStrings const& files (ops.type_map ()); - for (Files::ConstIterator f (files.begin ()); f != files.end (); ++f ) + for (NarrowStrings::const_iterator f (files.begin ()); + f != files.end (); ++f ) { NarrowInputFileStream ifs; open (ifs, *f); @@ -712,7 +278,7 @@ namespace CXX // String-based types. // - String char_type (ops.value<CLI::char_type> ()); + String char_type (ops.char_type ()); String string_type; if (char_type == L"char") @@ -723,12 +289,14 @@ namespace CXX string_type = L"::std::basic_string< " + char_type + L" >"; String xns; + String auto_ptr; { Context ctx (std::wcerr, schema, file_path, ops, 0, 0, 0, 0); xns = ctx.xs_ns_name (); + auto_ptr = ctx.auto_ptr; } - String buffer (L"::std::auto_ptr< " + xns + L"::buffer >"); + String buffer (auto_ptr + L"< " + xns + L"::buffer >"); TypeMap::Namespace xsd ("http://www\\.w3\\.org/2001/XMLSchema"); xsd.types_push_back ("string", string_type); @@ -800,7 +368,7 @@ namespace CXX type_map.push_back (xsd); - // Everyhting else maps to void. + // Everything else maps to void. // TypeMap::Namespace rest (".*"); rest.types_push_back (".*", "void", "void"); @@ -816,39 +384,33 @@ namespace CXX // // - Boolean inline_ (ops.value<CLI::generate_inline> () && - !generate_xml_schema); - - Boolean source (!generate_xml_schema); + bool inline_ (ops.generate_inline () && !generate_xml_schema); + bool source (!generate_xml_schema); // Generate code. // -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - NarrowString name (file_path.leaf ()); -#else - NarrowString name (file_path.filename().string()); -#endif - NarrowString skel_suffix (ops.value <CLI::skel_file_suffix> ()); - NarrowString impl_suffix (ops.value <CLI::impl_file_suffix> ()); - - NarrowString hxx_suffix (ops.value <CLI::hxx_suffix> ()); - NarrowString ixx_suffix (ops.value <CLI::ixx_suffix> ()); - NarrowString cxx_suffix (ops.value <CLI::cxx_suffix> ()); + NarrowString name (file_path.leaf ().string ()); + NarrowString skel_suffix (ops.skel_file_suffix ()); + NarrowString impl_suffix (ops.impl_file_suffix ()); + + NarrowString hxx_suffix (ops.hxx_suffix ()); + NarrowString ixx_suffix (ops.ixx_suffix ()); + NarrowString cxx_suffix (ops.cxx_suffix ()); Regex hxx_expr ( - ops.value <CLI::hxx_regex> ().empty () + ops.hxx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + skel_suffix + hxx_suffix + "#" - : ops.value <CLI::hxx_regex> ()); + : ops.hxx_regex ()); Regex ixx_expr ( - ops.value <CLI::ixx_regex> ().empty () + ops.ixx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + skel_suffix + ixx_suffix + "#" - : ops.value <CLI::ixx_regex> ()); + : ops.ixx_regex ()); Regex cxx_expr ( - ops.value <CLI::cxx_regex> ().empty () + ops.cxx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + skel_suffix + cxx_suffix + "#" - : ops.value <CLI::cxx_regex> ()); + : ops.cxx_regex ()); Regex hxx_impl_expr; @@ -870,7 +432,7 @@ namespace CXX if (!hxx_expr.match (name)) { wcerr << "error: header expression '" << - hxx_expr.pattern () << "' does not match '" << + hxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -878,7 +440,7 @@ namespace CXX if (inline_ && !ixx_expr.match (name)) { wcerr << "error: inline expression '" << - ixx_expr.pattern () << "' does not match '" << + ixx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -886,7 +448,7 @@ namespace CXX if (source && !cxx_expr.match (name)) { wcerr << "error: source expression '" << - cxx_expr.pattern () << "' does not match '" << + cxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -896,7 +458,7 @@ namespace CXX if (!hxx_impl_expr.match (name)) { wcerr << "error: implementation header expression '" << - hxx_impl_expr.pattern () << "' does not match '" << + hxx_impl_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -904,7 +466,7 @@ namespace CXX if (!cxx_impl_expr.match (name)) { wcerr << "error: implementation source expression '" << - cxx_impl_expr.pattern () << "' does not match '" << + cxx_impl_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -912,15 +474,15 @@ namespace CXX if (!cxx_driver_expr.match (name)) { wcerr << "error: driver source expression '" << - cxx_driver_expr.pattern () << "' does not match '" << + cxx_driver_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } } - NarrowString hxx_name (hxx_expr.merge (name)); - NarrowString ixx_name (inline_ ? ixx_expr.merge (name) : NarrowString ()); - NarrowString cxx_name (source ? cxx_expr.merge (name) : NarrowString ()); + NarrowString hxx_name (hxx_expr.replace (name)); + NarrowString ixx_name (inline_ ? ixx_expr.replace (name) : NarrowString ()); + NarrowString cxx_name (source ? cxx_expr.replace (name) : NarrowString ()); NarrowString hxx_impl_name; NarrowString cxx_impl_name; @@ -928,20 +490,14 @@ namespace CXX if (impl || driver) { - hxx_impl_name = hxx_impl_expr.merge (name); - cxx_impl_name = cxx_impl_expr.merge (name); - cxx_driver_name = cxx_driver_expr.merge (name); + hxx_impl_name = hxx_impl_expr.replace (name); + cxx_impl_name = cxx_impl_expr.replace (name); + cxx_driver_name = cxx_driver_expr.replace (name); } -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path hxx_path (hxx_name, boost::filesystem::native); - Path ixx_path (ixx_name, boost::filesystem::native); - Path cxx_path (cxx_name, boost::filesystem::native); -#else - Path hxx_path (hxx_name.c_str()); - Path ixx_path (ixx_name.c_str()); - Path cxx_path (cxx_name.c_str()); -#endif + Path hxx_path (hxx_name); + Path ixx_path (ixx_name); + Path cxx_path (cxx_name); Path hxx_impl_path; Path cxx_impl_path; @@ -949,28 +505,18 @@ namespace CXX if (impl || driver) { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - hxx_impl_path = Path (hxx_impl_name, boost::filesystem::native); - cxx_impl_path = Path (cxx_impl_name, boost::filesystem::native); - cxx_driver_path = Path (cxx_driver_name, boost::filesystem::native); -#else - hxx_impl_path = Path (hxx_impl_name.c_str()); - cxx_impl_path = Path (cxx_impl_name.c_str()); - cxx_driver_path = Path (cxx_driver_name.c_str()); -#endif + hxx_impl_path = Path (hxx_impl_name); + cxx_impl_path = Path (cxx_impl_name); + cxx_driver_path = Path (cxx_driver_name); } Path out_dir; - if (NarrowString dir = ops.value<CLI::output_dir> ()) + if (NarrowString dir = ops.output_dir ()) { try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - out_dir = Path (dir, boost::filesystem::native); -#else - out_dir = Path (dir.c_str()); -#endif + out_dir = Path (dir); } catch (InvalidPath const&) { @@ -985,7 +531,7 @@ namespace CXX // unless the user added the directory so that we propagate this // to the output files. // - Path fpt_dir (file_path.branch_path ()); + Path fpt_dir (file_path.directory ()); if (!fpt_dir.empty ()) out_dir /= fpt_dir; @@ -1014,9 +560,10 @@ namespace CXX if (impl) { - if (!ops.value<CLI::force_overwrite> ()) + if (!ops.force_overwrite ()) { - WideInputFileStream tmp (hxx_impl_path, ios_base::in); + WideInputFileStream tmp ( + hxx_impl_path.string ().c_str (), ios_base::in); if (tmp.is_open ()) { @@ -1028,7 +575,7 @@ namespace CXX tmp.close (); } - hxx_impl.open (hxx_impl_path, ios_base::out); + hxx_impl.open (hxx_impl_path.string ().c_str (), ios_base::out); if (!hxx_impl.is_open ()) { @@ -1038,15 +585,12 @@ namespace CXX } unlinks.add (hxx_impl_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (hxx_impl_path.native_file_string ()); -#else file_list.push_back (hxx_impl_path.string ()); -#endif - if (!ops.value<CLI::force_overwrite> ()) + if (!ops.force_overwrite ()) { - WideInputFileStream tmp (cxx_impl_path, ios_base::in); + WideInputFileStream tmp ( + cxx_impl_path.string ().c_str (), ios_base::in); if (tmp.is_open ()) { @@ -1058,7 +602,7 @@ namespace CXX tmp.close (); } - cxx_impl.open (cxx_impl_path, ios_base::out); + cxx_impl.open (cxx_impl_path.string ().c_str (), ios_base::out); if (!cxx_impl.is_open ()) { @@ -1068,18 +612,15 @@ namespace CXX } unlinks.add (cxx_impl_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (cxx_impl_path.native_file_string ()); -#else file_list.push_back (cxx_impl_path.string ()); -#endif } if (driver) { - if (!ops.value<CLI::force_overwrite> ()) + if (!ops.force_overwrite ()) { - WideInputFileStream tmp (cxx_driver_path, ios_base::in); + WideInputFileStream tmp ( + cxx_driver_path.string ().c_str (), ios_base::in); if (tmp.is_open ()) { @@ -1091,7 +632,7 @@ namespace CXX tmp.close (); } - cxx_driver.open (cxx_driver_path, ios_base::out); + cxx_driver.open (cxx_driver_path.string ().c_str (), ios_base::out); if (!cxx_driver.is_open ()) { @@ -1101,16 +642,12 @@ namespace CXX } unlinks.add (cxx_driver_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (cxx_driver_path.native_file_string ()); -#else file_list.push_back (cxx_driver_path.string ()); -#endif } // Open the skel files. // - WideOutputFileStream hxx (hxx_path, ios_base::out); + WideOutputFileStream hxx (hxx_path.string ().c_str (), ios_base::out); WideOutputFileStream ixx; WideOutputFileStream cxx; @@ -1121,15 +658,11 @@ namespace CXX } unlinks.add (hxx_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (hxx_path.native_file_string ()); -#else file_list.push_back (hxx_path.string ()); -#endif if (inline_) { - ixx.open (ixx_path, ios_base::out); + ixx.open (ixx_path.string ().c_str (), ios_base::out); if (!ixx.is_open ()) { @@ -1138,17 +671,13 @@ namespace CXX } unlinks.add (ixx_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (ixx_path.native_file_string ()); -#else file_list.push_back (ixx_path.string ()); -#endif } if (source) { - cxx.open (cxx_path, ios_base::out); + cxx.open (cxx_path.string ().c_str (), ios_base::out); if (!cxx.is_open ()) { @@ -1157,19 +686,13 @@ namespace CXX } unlinks.add (cxx_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (cxx_path.native_file_string ()); -#else file_list.push_back (cxx_path.string ()); -#endif } // Print copyright and license. // - Char const* copyright ( - ops.value<CLI::proprietary_license> () - ? copyright_proprietary - : copyright_gpl); + char const* copyright ( + ops.proprietary_license () ? copyright_proprietary : copyright_gpl); hxx << copyright; @@ -1192,7 +715,7 @@ namespace CXX // WideInputFileStream prologue; { - NarrowString name (ops.value<CLI::prologue_file> ()); + NarrowString name (ops.prologue_file ()); if (name) open (prologue, name); @@ -1202,7 +725,7 @@ namespace CXX // WideInputFileStream epilogue; { - NarrowString name (ops.value<CLI::epilogue_file> ()); + NarrowString name (ops.epilogue_file ()); if (name) open (epilogue, name); @@ -1210,21 +733,25 @@ namespace CXX // SLOC counter. // - UnsignedLong sloc (0); - Boolean show_sloc (ops.value<CLI::show_sloc> ()); + size_t sloc_total (0); + bool show_sloc (ops.show_sloc ()); + + typedef + compiler::ostream_filter<compiler::cxx_indenter, wchar_t> + ind_filter; + + typedef + compiler::ostream_filter<compiler::sloc_counter, wchar_t> + sloc_filter; // // Regex guard_expr ("/([a-z])([A-Z])/$1_$2/"); // Split words. - NarrowString guard_prefix (ops.value<CLI::guard_prefix> ()); + NarrowString guard_prefix (ops.guard_prefix ()); if (!guard_prefix) -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - guard_prefix = file_path.branch_path ().native_directory_string (); -#else - guard_prefix = file_path.branch_path ().string (); -#endif + guard_prefix = file_path.directory ().string (); if (guard_prefix) guard_prefix += '_'; @@ -1241,9 +768,9 @@ namespace CXX &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)); + String guard (guard_expr.replace (guard_prefix + hxx_name)); guard = ctx.escape (guard); // Make it a C++ id. std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1251,14 +778,21 @@ namespace CXX << "#define " << guard << endl << endl; + if (ctx.std >= cxx_version::cxx11) + { + hxx << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl + << endl; + } + // Copy prologue. // hxx << "// Begin prologue." << endl << "//" << endl; - append ( - hxx, ops.value<CLI::hxx_prologue> (), ops.value<CLI::prologue> ()); - append (hxx, ops.value<CLI::hxx_prologue_file> (), prologue); + append (hxx, ops.hxx_prologue (), ops.prologue ()); + append (hxx, ops.hxx_prologue_file (), prologue); hxx << "//" << endl << "// End prologue." << endl @@ -1273,38 +807,33 @@ namespace CXX << "#endif" << endl << endl; - { - hxx << "#include <xsd/cxx/pre.hxx>" << endl - << endl; - - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> hxx_clip (hxx); + hxx << "#include <xsd/cxx/pre.hxx>" << endl + << endl; + // Generate. + // + { + 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; - if (inline_) - hxx << "#include " << ctx.process_include_path (ixx_name) << endl; - - hxx << "#include <xsd/cxx/post.hxx>" << endl - << endl; - } + hxx << "#include <xsd/cxx/post.hxx>" << endl + << endl; // Copy epilogue. // hxx << "// Begin epilogue." << endl << "//" << endl; - append (hxx, ops.value<CLI::hxx_epilogue_file> (), epilogue); - append ( - hxx, ops.value<CLI::hxx_epilogue> (), ops.value<CLI::epilogue> ()); + append (hxx, ops.hxx_epilogue_file (), epilogue); + append (hxx, ops.hxx_epilogue (), ops.epilogue ()); hxx << "//" << endl << "// End epilogue." << endl @@ -1313,12 +842,9 @@ 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 (); } @@ -1335,30 +861,24 @@ namespace CXX &ixx_expr, &hxx_impl_expr); - Indentation::Clip<Indentation::SLOC, WideChar> ixx_sloc (ixx); - + sloc_filter sloc (ixx); // Copy prologue. // ixx << "// Begin prologue." << endl << "//" << endl; - append ( - ixx, ops.value<CLI::ixx_prologue> (), ops.value<CLI::prologue> ()); - append (ixx, ops.value<CLI::ixx_prologue_file> (), prologue); + append (ixx, ops.ixx_prologue (), ops.prologue ()); + append (ixx, ops.ixx_prologue_file (), prologue); ixx << "//" << endl << "// 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); } @@ -1367,21 +887,17 @@ namespace CXX ixx << "// Begin epilogue." << endl << "//" << endl; - append (ixx, ops.value<CLI::ixx_epilogue_file> (), epilogue); - append ( - ixx, ops.value<CLI::ixx_epilogue> (), ops.value<CLI::epilogue> ()); + append (ixx, ops.ixx_epilogue_file (), epilogue); + append (ixx, ops.ixx_epilogue (), ops.epilogue ()); ixx << "//" << endl << "// End epilogue." << endl << 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 (); } @@ -1398,28 +914,30 @@ namespace CXX &ixx_expr, &hxx_impl_expr); - Indentation::Clip<Indentation::SLOC, WideChar> cxx_sloc (cxx); + sloc_filter sloc (cxx); // Copy prologue. // cxx << "// Begin prologue." << endl << "//" << endl; - append ( - cxx, ops.value<CLI::cxx_prologue> (), ops.value<CLI::prologue> ()); - append (cxx, ops.value<CLI::cxx_prologue_file> (), prologue); + append (cxx, ops.cxx_prologue (), ops.prologue ()); + append (cxx, ops.cxx_prologue_file (), prologue); cxx << "//" << endl << "// End prologue." << endl << endl; - { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> cxx_clip (cxx); + cxx << "#include <xsd/cxx/pre.hxx>" << endl + << endl; - cxx << "#include " << ctx.process_include_path (hxx_name) << endl - << 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); @@ -1434,26 +952,25 @@ namespace CXX } } + cxx << "#include <xsd/cxx/post.hxx>" << endl + << endl; + // Copy epilogue. // cxx << "// Begin epilogue." << endl << "//" << endl; - append (cxx, ops.value<CLI::cxx_epilogue_file> (), epilogue); - append ( - cxx, ops.value<CLI::cxx_epilogue> (), ops.value<CLI::epilogue> ()); + append (cxx, ops.cxx_epilogue_file (), epilogue); + append (cxx, ops.cxx_epilogue (), ops.epilogue ()); cxx << "//" << endl << "// End epilogue." << endl << 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 @@ -1469,7 +986,7 @@ namespace CXX &ixx_expr, &hxx_impl_expr); - String guard (guard_expr.merge (guard_prefix + hxx_impl_name)); + String guard (guard_expr.replace (guard_prefix + hxx_impl_name)); guard = ctx.escape (guard); // Make it a C++ id. std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1477,14 +994,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); } @@ -1504,14 +1018,13 @@ namespace CXX &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 @@ -1527,17 +1040,16 @@ namespace CXX &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) { @@ -1569,18 +1081,18 @@ namespace CXX throw Failed (); } - catch (BackendElements::Regex::Format<Char> const& e) + catch (cutl::re::format const& e) { wcerr << "error: invalid regex: '" << - e.expression ().c_str () << "': " << + e.regex ().c_str () << "': " << e.description ().c_str () << endl; throw Failed (); } - catch (BackendElements::Regex::Format<WideChar> const& e) + catch (cutl::re::wformat const& e) { wcerr << "error: invalid regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } |