diff options
Diffstat (limited to 'xsd/xsd/xsd.cxx')
-rw-r--r-- | xsd/xsd/xsd.cxx | 681 |
1 files changed, 201 insertions, 480 deletions
diff --git a/xsd/xsd/xsd.cxx b/xsd/xsd/xsd.cxx index 2e2f6ce..f333d76 100644 --- a/xsd/xsd/xsd.cxx +++ b/xsd/xsd/xsd.cxx @@ -1,20 +1,17 @@ // file : xsd/xsd.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 <cult/types.hxx> - -#include <cult/trace/log.hxx> +#include <map> +#include <vector> +#include <memory> // std::auto_ptr +#include <cstddef> // std::size_t +#include <iostream> +#include <fstream> -#include <cult/containers/map.hxx> -#include <cult/containers/vector.hxx> +#include <xercesc/util/PlatformUtils.hpp> -#include <cult/cli/exceptions.hxx> -#include <cult/cli/file-arguments.hxx> -#include <cult/cli/options.hxx> -#include <cult/cli/options-spec.hxx> -#include <cult/cli/options-parser.hxx> +#include <cutl/re.hxx> #include <xsd-frontend/parser.hxx> #include <xsd-frontend/transformations/anonymous.hxx> @@ -23,8 +20,8 @@ #include <xsd-frontend/transformations/schema-per-type.hxx> #include <xsd-frontend/transformations/simplifier.hxx> -#include <backend-elements/regex.hxx> -#include <backend-elements/indentation/clip.hxx> +#include <cxx/tree/options.hxx> +#include <cxx/parser/options.hxx> #include <cxx/tree/generator.hxx> #include <cxx/parser/generator.hxx> @@ -32,98 +29,16 @@ #include <processing/cardinality/processor.hxx> #include <processing/inheritance/processor.hxx> -#include <iostream> -#include <boost/filesystem/fstream.hpp> - -#include <xercesc/util/PlatformUtils.hpp> - #include <xsd.hxx> -#include <usage.hxx> +#include <types.hxx> +#include <options.hxx> #include "../libxsd/xsd/cxx/version.hxx" -using namespace Cult::Types; - -typedef Cult::Containers::Vector<NarrowString> NarrowStrings; - namespace SemanticGraph = XSDFrontend::SemanticGraph; namespace Transformations = XSDFrontend::Transformations; -using std::wcerr; -using std::endl; - -namespace CLI -{ - using namespace Cult::CLI; - - typedef Char const Key[]; - - extern Key help = "help"; - extern Key version = "version"; - extern Key proprietary_license = "proprietary-license"; - - typedef Cult::CLI::Options - < - help, Boolean, - version, Boolean, - proprietary_license, Boolean - > - HelpOptions; - - struct HelpOptionsSpec: Cult::CLI::OptionsSpec<HelpOptions> {}; - - - extern Key disable_warning = "disable-warning"; - extern Key sloc_limit = "sloc-limit"; - extern Key morph_anonymous = "morph-anonymous"; - extern Key preserve_anonymous = "preserve-anonymous"; - extern Key anonymous_regex = "anonymous-regex"; - extern Key anonymous_regex_trace = "anonymous-regex-trace"; - extern Key location_map = "location-map"; - extern Key location_regex = "location-regex"; - extern Key location_regex_trace = "location-regex-trace"; - extern Key custom_literals = "custom-literals"; - extern Key file_per_type = "file-per-type"; - extern Key type_file_regex = "type-file-regex"; - extern Key type_file_regex_trace = "type-file-regex-trace"; - extern Key schema_file_regex = "schema-file-regex"; - extern Key schema_file_regex_trace = "schema-file-regex-trace"; - extern Key file_list = "file-list"; - extern Key file_list_prologue = "file-list-prologue"; - extern Key file_list_epilogue = "file-list-epilogue"; - extern Key file_list_delim = "file-list-delim"; - extern Key disable_multi_import = "disable-multi-import"; // Undocumented. - extern Key disable_full_check = "disable-full-check"; // Undocumented. - - - typedef Cult::CLI::Options - < - disable_warning, Cult::Containers::Vector<NarrowString>, - sloc_limit, UnsignedLong, - morph_anonymous, Boolean, - preserve_anonymous, Boolean, - anonymous_regex, NarrowStrings, - anonymous_regex_trace, Boolean, - location_map, NarrowStrings, - location_regex, NarrowStrings, - location_regex_trace, Boolean, - custom_literals, NarrowString, - file_per_type, Boolean, - type_file_regex, NarrowStrings, - type_file_regex_trace, Boolean, - schema_file_regex, NarrowStrings, - schema_file_regex_trace, Boolean, - file_list, NarrowString, - file_list_prologue, NarrowString, - file_list_epilogue, NarrowString, - file_list_delim, NarrowString, - disable_multi_import, Boolean, - disable_full_check, Boolean - > - CommonOptions; - - struct CommonOptionsSpec: Cult::CLI::OptionsSpec<CommonOptions> {}; -} +using namespace std; // // @@ -133,24 +48,24 @@ struct LocationTranslator: XSDFrontend::LocationTranslator LocationTranslator (NarrowStrings const& map, NarrowStrings const& regex, - Boolean trace); + bool trace); virtual NarrowString translate (NarrowString const&); private: - typedef Cult::Containers::Map<NarrowString, NarrowString> Map; + typedef map<NarrowString, NarrowString> Map; - typedef BackendElements::Regex::Expression<Char> Regex; - typedef BackendElements::Regex::Format<Char> RegexFormat; - typedef Cult::Containers::Vector<Regex> RegexVector; + typedef cutl::re::regexsub Regex; + typedef cutl::re::format RegexFormat; + typedef vector<Regex> RegexVector; - typedef Cult::Containers::Map<NarrowString, NarrowString> Cache; + typedef map<NarrowString, NarrowString> Cache; Map map_; RegexVector regex_; Cache cache_; - Boolean trace_; + bool trace_; }; // @@ -159,21 +74,21 @@ struct AnonymousNameTranslator: Transformations::AnonymousNameTranslator { struct Failed {}; - AnonymousNameTranslator (NarrowStrings const& regex, Boolean trace); + AnonymousNameTranslator (NarrowStrings const& regex, bool trace); - virtual WideString - translate (WideString const& file, - WideString const& ns, - WideString const& name, - WideString const& xpath); + virtual String + translate (String const& file, + String const& ns, + String const& name, + String const& xpath); private: - typedef BackendElements::Regex::Expression<WideChar> Regex; - typedef BackendElements::Regex::Format<WideChar> RegexFormat; - typedef Cult::Containers::Vector<Regex> RegexVector; + typedef cutl::re::wregexsub Regex; + typedef cutl::re::wformat RegexFormat; + typedef vector<Regex> RegexVector; RegexVector regex_; - Boolean trace_; + bool trace_; }; @@ -184,30 +99,30 @@ struct SchemaPerTypeTranslator: Transformations::SchemaPerTypeTranslator struct Failed {}; SchemaPerTypeTranslator (NarrowStrings const& type_regex, - Boolean type_trace, + bool type_trace, NarrowStrings const& schema_regex, - Boolean schema_trace); + bool schema_trace); - virtual WideString - translate_type (WideString const& ns, WideString const& name); + virtual String + translate_type (String const& ns, String const& name); virtual NarrowString translate_schema (NarrowString const& file); private: - typedef BackendElements::Regex::Expression<WideChar> TypeRegex; - typedef BackendElements::Regex::Format<WideChar> TypeRegexFormat; - typedef Cult::Containers::Vector<TypeRegex> TypeRegexVector; + typedef cutl::re::wregexsub TypeRegex; + typedef cutl::re::wformat TypeRegexFormat; + typedef vector<TypeRegex> TypeRegexVector; TypeRegexVector type_regex_; - Boolean type_trace_; + bool type_trace_; - typedef BackendElements::Regex::Expression<Char> SchemaRegex; - typedef BackendElements::Regex::Format<Char> SchemaRegexFormat; - typedef Cult::Containers::Vector<SchemaRegex> SchemaRegexVector; + typedef cutl::re::regexsub SchemaRegex; + typedef cutl::re::format SchemaRegexFormat; + typedef vector<SchemaRegex> SchemaRegexVector; SchemaRegexVector schema_regex_; - Boolean schema_trace_; + bool schema_trace_; }; // @@ -227,57 +142,48 @@ struct XercesInitializer // Expand the \n escape sequence. // -Void +void expand_nl (NarrowString& s); - -Int -main (Int argc, Char* argv[]) +int +main (int argc, char* argv[]) { - std::wostream& e (wcerr); - - Cult::Trace::Log::instance ().level (0); + wostream& e (wcerr); try { - CLI::FileArguments args (argc, argv, "--options-file"); - - CLI::HelpOptions help_options ( - CLI::parse (CLI::HelpOptionsSpec (), args, CLI::UnknownMode::stop)); + cli::argv_file_scanner args (argc, argv, "--options-file"); + help_options help_ops (args, cli::unknown_mode::stop); NarrowString cmd; + if (args.more ()) + cmd = args.next (); - if (args.size () > 1) + if (help_ops.version () || cmd == "version") { - cmd = args[1]; - args.erase (1); - } + wostream& o (wcout); - if (help_options.value<CLI::version> () || cmd == "version") - { - e << "CodeSynthesis XSD XML Schema to C++ compiler " << + o << "CodeSynthesis XSD XML Schema to C++ compiler " << XSD_STR_VERSION << endl - << "Copyright (C) 2005-2010 Code Synthesis Tools CC" << endl; + << "Copyright (c) 2005-2014 Code Synthesis Tools CC" << endl; - if (!help_options.value<CLI::proprietary_license> () && - cmd == "version") + if (!help_ops.proprietary_license () && cmd == "version") { // Parse the options after the command to detect trailing // --proprietary-license. // - help_options = CLI::parse ( - CLI::HelpOptionsSpec (), args, CLI::UnknownMode::stop); + help_ops = help_options (args, cli::unknown_mode::stop); } - if (help_options.value<CLI::proprietary_license> ()) + if (help_ops.proprietary_license ()) { - e << "The compiler was invoked in the Proprietary License mode. You " + o << "The compiler was invoked in the Proprietary License mode. You " << "should have\nreceived a proprietary license from Code Synthesis " << "Tools CC that entitles\nyou to use it in this mode." << endl; } else { - e << "This is free software; see the source for copying conditions. " + o << "This is free software; see the source for copying conditions. " << "There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS " << "FOR A PARTICULAR PURPOSE." << endl; } @@ -285,15 +191,17 @@ main (Int argc, Char* argv[]) return 0; } - if (help_options.value<CLI::help> () || cmd == "help") + if (help_ops.help () || cmd == "help") { - if (cmd == "help" && args.size () > 1) + wostream& o (wcout); + + if (cmd == "help" && args.more ()) { - NarrowString arg (args[1]); + NarrowString arg (args.next ()); if (arg == "cxx-tree") { - e << "Usage: " << args[0] << " cxx-tree [options] file [file ...]" + o << "Usage: " << argv[0] << " cxx-tree [options] file [file ...]" << endl << "Options:" << endl; @@ -301,7 +209,7 @@ main (Int argc, Char* argv[]) } else if (arg == "cxx-parser") { - e << "Usage: " << args[0] << " cxx-parser [options] file [file ...]" + o << "Usage: " << argv[0] << " cxx-parser [options] file [file ...]" << endl << "Options:" << endl; @@ -309,135 +217,33 @@ main (Int argc, Char* argv[]) } else { - e << "error: unknown command '" << arg.c_str () << "'" << endl - << "info: try '" << args[0] << " help' for the list of commands" + o << "error: unknown command '" << arg.c_str () << "'" << endl + << "info: try '" << argv[0] << " help' for the list of commands" << endl; return 1; } - ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); - - // Disable warning option. - // - e << "--disable-warning <warn>" << endl - << " Disable printing warning with id <warn>. If 'all'\n" - << " is specified for the warning id then all warnings\n" - << " are disabled." - << endl; - - // Anonymous morphing options. - // - e << "--preserve-anonymous" << endl - << " Preserve anonymous types. By default anonymous\n" - << " types are automatically named with names derived\n" - << " from the enclosing elements/attributes." - << endl; - - e << "--anonymous-regex <regex>" << endl - << " Add the provided regular expression to the list of\n" - << " regular expressions used to derive names for\n" - << " anonymous types from the names of the enclosing\n" - << " attributes/elements." - << endl; - - e << "--anonymous-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --anonymous-regex option." - << endl; - - // Location mapping options. - // - e << "--location-map <ol>=<nl>" << endl - << " Map the original schema location <ol> that is\n" - << " specified in the XML Schema include or import\n" - << " elements to new schema location <nl>. Repeat\n" - << " this option to map more than one schema location." - << endl; - - e << "--location-regex <regex>" << endl - << " Add <regex> to the list of regular expressions\n" - << " used to map schema locations that are specified\n" - << " in the XML Schema include or import elements." - << endl; - - e << "--location-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --location-regex option." - << endl; - - // File-per-type compilation mode options. - // - e << "--file-per-type" << endl - << " Generate a separate set of C++ files for each\n" - << " type defined in XML Schema." - << endl; - - e << "--type-file-regex <regex>" << endl - << " Add the provided regular expression to the list of\n" - << " regular expressions used to translate type names\n" - << " to file names when the --file-per-type option is\n" - << " specified." - << endl; - - e << "--type-file-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --type-file-regex option." - << endl; - - e << "--schema-file-regex <regex>" << endl - << " Add the provided regular expression to the list\n" - << " of regular expressions used to translate schema\n" - << " file names when the --file-per-type option is\n" - << " specified." - << endl; - - e << "--schema-file-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --schema-file-regex option." - << endl; - - // File list options. + // Add frontend options at the end. // - e << "--file-list <file>" << endl - << " Write a list of generated C++ files to <file>." - << endl; - - e << "--file-list-prologue <p>" << endl - << " Insert <p> at the beginning of the file list. All\n" - << " occurrences of the \\n character sequence in <p>\n" - << " are replaced with new lines." - << endl; - - e << "--file-list-prologue <e>" << endl - << " Insert <e> at the end of the file list. All\n" - << " occurrences of the \\n character sequence in <e>\n" - << " are replaced with new lines." - << endl; - - e << "--file-list-delim <d>" << endl - << " Delimit file names written to the file list with\n" - << " <d> instead of new lines. All occurrences of the\n" - << " \\n character sequence in <d> are replaced with\n" - << " new lines." - << endl; + options::print_usage (o); } else { - e << "Usage: " << args[0] << " <cmd> ..." << endl + o << "Usage: " << argv[0] << " <cmd> ..." << endl << "Commands:" << endl; - e << " help Print usage information and exit. Use\n" + o << " help Print usage information and exit. Use\n" << " 'help <cmd>' for command-specific options." << endl; - e << " version Print version and exit." + o << " version Print version and exit." << endl; - e << " cxx-tree Generate the C++/Tree mapping." + o << " cxx-tree Generate the C++/Tree mapping." << endl; - e << " cxx-parser Generate the C++/Parser mapping." + o << " cxx-parser Generate the C++/Parser mapping." << endl; } @@ -447,7 +253,7 @@ main (Int argc, Char* argv[]) if (cmd.empty ()) { e << "error: no command specified" << endl - << "info: try '" << args[0] << " help' for usage information" << endl; + << "info: try '" << argv[0] << " help' for usage information" << endl; return 1; } @@ -455,7 +261,7 @@ main (Int argc, Char* argv[]) if (cmd != "cxx-tree" && cmd != "cxx-parser") { e << "error: unknown command '" << cmd.c_str () << "'" << endl - << "info: try '" << args[0] << " help' for the list of commands" + << "info: try '" << argv[0] << " help' for the list of commands" << endl; return 1; @@ -464,81 +270,57 @@ main (Int argc, Char* argv[]) // We need to parse command line options before we can get to // the arguments. // - CLI::CommonOptionsSpec common_spec; - common_spec.option<CLI::file_list_delim> ().default_value ("\n"); + auto_ptr<CXX::Tree::options> tree_ops ( + cmd == "cxx-tree" ? new CXX::Tree::options (args) : 0); + + auto_ptr<CXX::Parser::options> parser_ops ( + cmd == "cxx-parser" ? new CXX::Parser::options (args) : 0); - CLI::CommonOptions common_ops ( - CLI::parse ( - common_spec, - args, - CLI::UnknownMode::skip, - CLI::UnknownMode::skip)); + CXX::options& common_ops ( + cmd == "cxx-tree" + ? static_cast<CXX::options&> (*tree_ops) + : static_cast<CXX::options&> (*parser_ops)); + // Disabled warnings. + // WarningSet disabled_w; { - typedef Cult::Containers::Vector<NarrowString> Warnings; - Warnings const& w (common_ops.value<CLI::disable_warning> ()); + NarrowStrings const& w (common_ops.disable_warning ()); - for (Warnings::ConstIterator i (w.begin ()); i != w.end (); ++i) + for (NarrowStrings::const_iterator i (w.begin ()); i != w.end (); ++i) disabled_w.insert (*i); } - Boolean disabled_w_all (disabled_w.find ("all") != disabled_w.end ()); + bool disabled_w_all (disabled_w.find ("all") != disabled_w.end ()); - if (common_ops.value<CLI::morph_anonymous> () && - !disabled_w_all && disabled_w.find ("D001") == disabled_w.end ()) + if (common_ops.morph_anonymous () && + !disabled_w_all && + disabled_w.find ("D001") == disabled_w.end ()) { e << "warning D001: the --morph-anonymous option is on by default and " << "no longer required" << endl; } - Evptr<CXX::Tree::CLI::Options> tree_ops; - Evptr<CXX::Parser::CLI::Options> parser_ops; - - Boolean show_sloc (false); - - if (cmd == "cxx-tree") - { - tree_ops = new CXX::Tree::CLI::Options ( - CLI::parse (CXX::Tree::Generator::options_spec (), args)); - - tree_ops->value<CXX::Tree::CLI::disable_multi_import> () = - common_ops.value<CLI::disable_multi_import> (); - - show_sloc = tree_ops->value<CXX::Tree::CLI::show_sloc> (); - } - else if (cmd == "cxx-parser") - { - parser_ops = new CXX::Parser::CLI::Options ( - CLI::parse (CXX::Parser::Generator::options_spec (), args)); - - show_sloc = parser_ops->value<CXX::Parser::CLI::show_sloc> (); - } + // Collect all the files to compile in a vector. + // + NarrowStrings files; + while (args.more ()) + files.push_back (args.next ()); - if (args.size () < 2) + if (files.empty ()) { e << "error: no input file specified" << endl; return 1; } - Boolean fpt (common_ops.value<CLI::file_per_type> ()); + bool fpt (common_ops.file_per_type ()); if (cmd == "cxx-tree" || cmd == "cxx-parser") { - Boolean gen (false), use (false); - - if (cmd == "cxx-tree") - { - gen = tree_ops->value<CXX::Tree::CLI::generate_xml_schema> (); - use = tree_ops->value<CXX::Tree::CLI::extern_xml_schema> (); - } - else if (cmd == "cxx-parser") - { - gen = parser_ops->value<CXX::Parser::CLI::generate_xml_schema> (); - use = parser_ops->value<CXX::Parser::CLI::extern_xml_schema> (); - } + bool gen (common_ops.generate_xml_schema ()); + bool use (common_ops.extern_xml_schema ()); // Things get complicated when we are compiling several schemas at // once (non-file-per-type mode) and use the --generate-xml-schema/ @@ -549,7 +331,7 @@ main (Int argc, Char* argv[]) // if (!fpt) { - if (args.size () > 2 && gen && !use) + if (files.size () > 1 && gen && !use) { e << "error: --extern-xml-schema is required when compiling more " << "than one schema and --generate-xml-schema is specified" @@ -558,7 +340,7 @@ main (Int argc, Char* argv[]) return 1; } - if (args.size () == 2 && gen && use) + if (files.size () == 1 && gen && use) { e << "error: --generate-xml-schema and --extern-xml-schema are " << "mutually exclusive when compiling a single schema" << endl; @@ -596,22 +378,22 @@ main (Int argc, Char* argv[]) // FileList file_list; AutoUnlinks unlinks; - UnsignedLong sloc (0); + size_t sloc (0); LocationTranslator loc_translator ( - common_ops.value<CLI::location_map> (), - common_ops.value<CLI::location_regex> (), - common_ops.value<CLI::location_regex_trace> ()); + common_ops.location_map (), + common_ops.location_regex (), + common_ops.location_regex_trace ()); AnonymousNameTranslator anon_translator ( - common_ops.value<CLI::anonymous_regex> (), - common_ops.value<CLI::anonymous_regex_trace> ()); + common_ops.anonymous_regex (), + common_ops.anonymous_regex_trace ()); // Load custom string literals, if any. // CXX::StringLiteralMap string_literal_map; - if (NarrowString file = common_ops.value<CLI::custom_literals> ()) + if (NarrowString file = common_ops.custom_literals ()) { XercesInitializer xerces_init; @@ -628,7 +410,7 @@ main (Int argc, Char* argv[]) // File-per-schema compilation mode. // - for (Size i (1); i < args.size (); ++i) + for (size_t i (0); i < files.size (); ++i) { // Parse schema. // @@ -636,15 +418,11 @@ main (Int argc, Char* argv[]) try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - tu = SemanticGraph::Path (args[i], boost::filesystem::native); -#else - tu = SemanticGraph::Path (args[i]); -#endif + tu = SemanticGraph::Path (files[i]); } catch (SemanticGraph::InvalidPath const&) { - e << "error: '" << args[i] << "' is not a valid " + e << "error: '" << files[i].c_str () << "' is not a valid " << "filesystem path" << endl; return 1; @@ -652,12 +430,12 @@ main (Int argc, Char* argv[]) XSDFrontend::Parser parser ( cmd != "cxx-tree", - !common_ops.value<CLI::disable_multi_import> (), - !common_ops.value<CLI::disable_full_check> (), + !common_ops.disable_multi_import (), + !common_ops.disable_full_check (), loc_translator, disabled_w); - Evptr<SemanticGraph::Schema> schema; + auto_ptr<SemanticGraph::Schema> schema; if (cmd == "cxx-tree" || cmd == "cxx-parser") { @@ -667,44 +445,14 @@ main (Int argc, Char* argv[]) // will need to rely on the presence of the --extern-xml-schema // to tell us which (fake) schema file corresponds to XML Schema. // - Boolean gen_xml_schema (false); + bool gen_xml_schema (common_ops.generate_xml_schema ()); - if (cmd == "cxx-tree") - { - gen_xml_schema = - tree_ops->value<CXX::Tree::CLI::generate_xml_schema> (); - - if (gen_xml_schema) - { - if (NarrowString name = - tree_ops->value<CXX::Tree::CLI::extern_xml_schema> ()) - { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - if (tu.native_file_string () != name) -#else - if (tu.string () != name) -#endif - gen_xml_schema = false; - } - } - } - else if (cmd == "cxx-parser") + if (gen_xml_schema) { - gen_xml_schema = - parser_ops->value<CXX::Parser::CLI::generate_xml_schema> (); - - if (gen_xml_schema) + if (NarrowString name = common_ops.extern_xml_schema ()) { - if (NarrowString name = - parser_ops->value<CXX::Parser::CLI::extern_xml_schema> ()) - { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - if (tu.native_file_string () != name) -#else - if (tu.string () != name) -#endif - gen_xml_schema = false; - } + if (tu.string () != name) + gen_xml_schema = false; } } @@ -718,7 +466,7 @@ main (Int argc, Char* argv[]) // Morph anonymous types. // - if (!common_ops.value<CLI::preserve_anonymous> ()) + if (!common_ops.preserve_anonymous ()) { try { @@ -835,21 +583,15 @@ main (Int argc, Char* argv[]) // SemanticGraph::Paths paths; - for (Size i (1); i < args.size (); ++i) + for (size_t i (0); i < files.size (); ++i) { try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - paths.push_back ( - SemanticGraph::Path (args[i], boost::filesystem::native)); -#else - paths.push_back ( - SemanticGraph::Path (args[i])); -#endif + paths.push_back (SemanticGraph::Path (files[i])); } catch (SemanticGraph::InvalidPath const&) { - e << "error: '" << args[i] << "' is not a valid " + e << "error: '" << files[i].c_str () << "' is not a valid " << "filesystem path" << endl; return 1; @@ -858,7 +600,7 @@ main (Int argc, Char* argv[]) if (cmd == "cxx-parser" && paths.size () > 1 && - parser_ops->value<CXX::Parser::CLI::generate_test_driver> ()) + parser_ops->generate_test_driver ()) { e << "info: generating test driver for the first schema only: '" << paths[0] << "'" << endl; @@ -866,21 +608,21 @@ main (Int argc, Char* argv[]) XSDFrontend::Parser parser ( cmd != "cxx-tree", - !common_ops.value<CLI::disable_multi_import> (), - !common_ops.value<CLI::disable_full_check> (), + !common_ops.disable_multi_import (), + !common_ops.disable_full_check (), loc_translator, disabled_w); - Evptr<SemanticGraph::Schema> schema (parser.parse (paths)); + auto_ptr<SemanticGraph::Schema> schema (parser.parse (paths)); // Morph anonymous types. // - if (!common_ops.value<CLI::preserve_anonymous> ()) + if (!common_ops.preserve_anonymous ()) { try { Transformations::Anonymous trans (anon_translator); - trans.transform (*schema, "", false); + trans.transform (*schema, SemanticGraph::Path (), false); } catch (Transformations::Anonymous::Failed const&) { @@ -893,7 +635,7 @@ main (Int argc, Char* argv[]) if (cmd == "cxx-tree") { Transformations::EnumSynthesis trans; - trans.transform (*schema, ""); + trans.transform (*schema, SemanticGraph::Path ()); } // Simplify the schema graph. @@ -901,7 +643,7 @@ main (Int argc, Char* argv[]) if (cmd == "cxx-parser") { Transformations::Simplifier trans; - trans.transform (*schema, ""); + trans.transform (*schema, SemanticGraph::Path ()); } // Normalize and annotate complex content restrictions. @@ -911,7 +653,7 @@ main (Int argc, Char* argv[]) try { Transformations::Restriction trans; - trans.transform (*schema, ""); + trans.transform (*schema, SemanticGraph::Path ()); } catch (Transformations::Restriction::Failed const&) { @@ -923,26 +665,29 @@ main (Int argc, Char* argv[]) // { Processing::Cardinality::Processor proc; - proc.process (*schema, ""); + proc.process (*schema, SemanticGraph::Path ()); } // Rearrange the graph so that each type is in a seperate // schema file. // - typedef Cult::Containers::Vector<SemanticGraph::Schema*> Schemas; + typedef vector<SemanticGraph::Schema*> Schemas; SchemaPerTypeTranslator type_translator ( - common_ops.value<CLI::type_file_regex> (), - common_ops.value<CLI::type_file_regex_trace> (), - common_ops.value<CLI::schema_file_regex> (), - common_ops.value<CLI::schema_file_regex_trace> ()); + common_ops.type_file_regex (), + common_ops.type_file_regex_trace (), + common_ops.schema_file_regex (), + common_ops.schema_file_regex_trace ()); + + Transformations::SchemaPerType trans ( + type_translator, + common_ops.fat_type_file ()); - Transformations::SchemaPerType trans (type_translator); Schemas schemas (trans.transform (*schema)); // Generate code. // - for (Schemas::Iterator b (schemas.begin ()), i (b), e (schemas.end ()); + for (Schemas::iterator b (schemas.begin ()), i (b), e (schemas.end ()); i != e; ++i) { SemanticGraph::Schema& s (**i); @@ -1001,24 +746,16 @@ main (Int argc, Char* argv[]) // See if we need to produce the file list. // - if (NarrowString fl = common_ops.value<CLI::file_list> ()) + if (NarrowString fl = common_ops.file_list ()) { - typedef boost::filesystem::ofstream OutputFileStream; + typedef std::ofstream OutputFileStream; try { OutputFileStream ofs; -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 SemanticGraph::Path path (fl); -#else - SemanticGraph::Path path (fl.c_str()); -#endif -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - ofs.open (fl, std::ios_base::out); -#else - ofs.open (fl.c_str(), std::ios_base::out); -#endif + ofs.open (path.string ().c_str (), ios_base::out); if (!ofs.is_open ()) { @@ -1026,16 +763,16 @@ main (Int argc, Char* argv[]) return 1; } - NarrowString d (common_ops.value<CLI::file_list_delim> ()); + NarrowString d (common_ops.file_list_delim ()); expand_nl (d); - if (NarrowString p = common_ops.value<CLI::file_list_prologue> ()) + if (NarrowString p = common_ops.file_list_prologue ()) { expand_nl (p); ofs << p; } - for (FileList::Iterator i (file_list.begin ()), e (file_list.end ()); + for (FileList::iterator i (file_list.begin ()), e (file_list.end ()); i != e;) { ofs << *i; @@ -1044,7 +781,7 @@ main (Int argc, Char* argv[]) ofs << d; } - if (NarrowString e = common_ops.value<CLI::file_list_epilogue> ()) + if (NarrowString e = common_ops.file_list_epilogue ()) { expand_nl (e); ofs << e; @@ -1058,10 +795,10 @@ main (Int argc, Char* argv[]) } } - if (show_sloc) + if (common_ops.show_sloc ()) e << "total: " << sloc << endl; - if (UnsignedLong sloc_limit = common_ops.value<CLI::sloc_limit> ()) + if (size_t sloc_limit = common_ops.sloc_limit ()) { if (sloc_limit < sloc) { @@ -1096,26 +833,10 @@ main (Int argc, Char* argv[]) { // Diagnostic has already been issued. } - catch (CLI::UnexpectedOption const& e) + catch (cli::exception const& ex) { - wcerr << "error: unknown option '" << e.option ().c_str () << "'" << endl - << "info: try '" << argv[0] << " help' for usage information" - << endl; - } - catch (CLI::OptionFormat const& e) - { - wcerr << "error: value for option '" << e.option ().c_str () - << "' is invalid or missing" << endl - << "info: try '" << argv[0] << " help' for usage information" - << endl; - } - catch (CLI::OptionFile const& e) - { - if (e.value ()) - wcerr << "error: " << e.value ().c_str () << ": " - << e.description ().c_str () << endl; - else - wcerr << "error: missing --options-file argument" << endl; + wcerr << ex << endl; + wcerr << "try '" << argv[0] << " help' for usage information" << endl; } return 1; @@ -1127,16 +848,16 @@ main (Int argc, Char* argv[]) LocationTranslator:: LocationTranslator (NarrowStrings const& map, NarrowStrings const& regex, - Boolean trace) + bool trace) : trace_ (trace) { // Map. // - for (NarrowStrings::ConstIterator i (map.begin ()); i != map.end (); ++i) + for (NarrowStrings::const_iterator i (map.begin ()); i != map.end (); ++i) { // Split the string in two parts at the last '='. // - Size pos (i->rfind ('=')); + size_t pos (i->rfind ('=')); if (pos == NarrowString::npos) { @@ -1151,7 +872,7 @@ LocationTranslator (NarrowStrings const& map, // Regex. // - for (NarrowStrings::ConstIterator i (regex.begin ()); i != regex.end (); ++i) + for (NarrowStrings::const_iterator i (regex.begin ()); i != regex.end (); ++i) { try { @@ -1160,7 +881,7 @@ LocationTranslator (NarrowStrings const& map, catch (RegexFormat const& e) { wcerr << "error: invalid location regex: '" << - e.expression ().c_str () << "': " << + e.regex ().c_str () << "': " << e.description ().c_str () << endl; throw Failed (); @@ -1173,14 +894,14 @@ translate (NarrowString const& l) { // First check the cache. // - Cache::ConstIterator ci (cache_.find (l)); + Cache::const_iterator ci (cache_.find (l)); if (ci != cache_.end ()) return ci->second; // Then check the direct map. // - Map::ConstIterator mi (map_.find (l)); + Map::const_iterator mi (map_.find (l)); if (mi != map_.end ()) { @@ -1193,15 +914,15 @@ translate (NarrowString const& l) if (trace_) wcerr << "location: '" << l.c_str () << "'" << endl; - for (RegexVector::ReverseIterator i (regex_.rbegin ()); + for (RegexVector::reverse_iterator i (regex_.rbegin ()); i != regex_.rend (); ++i) { if (trace_) - wcerr << "try: '" << i->pattern () << "' : "; + wcerr << "try: '" << i->regex ().str ().c_str () << "' : "; if (i->match (l)) { - NarrowString r (i->merge (l)); + NarrowString r (i->replace (l)); if (trace_) wcerr << "'" << r.c_str () << "' : +" << endl; @@ -1224,45 +945,45 @@ translate (NarrowString const& l) // AnonymousNameTranslator:: -AnonymousNameTranslator (NarrowStrings const& regex, Boolean trace) +AnonymousNameTranslator (NarrowStrings const& regex, bool trace) : trace_ (trace) { - for (NarrowStrings::ConstIterator i (regex.begin ()); i != regex.end (); ++i) + for (NarrowStrings::const_iterator i (regex.begin ()); i != regex.end (); ++i) { try { - regex_.push_back (Regex (*i)); + regex_.push_back (Regex (String (*i))); } catch (RegexFormat const& e) { wcerr << "error: invalid anonymous type regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } } } -WideString AnonymousNameTranslator:: -translate (WideString const& file, - WideString const& ns, - WideString const& name, - WideString const& xpath) +String AnonymousNameTranslator:: +translate (String const& file, + String const& ns, + String const& name, + String const& xpath) { - WideString s (file + L' ' + ns + L' ' + xpath); + String s (file + L' ' + ns + L' ' + xpath); if (trace_) wcerr << "anonymous type: '" << s << "'" << endl; - for (RegexVector::ReverseIterator i (regex_.rbegin ()); + for (RegexVector::reverse_iterator i (regex_.rbegin ()); i != regex_.rend (); ++i) { if (trace_) - wcerr << "try: '" << i->pattern () << "' : "; + wcerr << "try: '" << i->regex () << "' : "; if (i->match (s)) { - WideString r (i->merge (s)); + String r (i->replace (s)); if (trace_) wcerr << "'" << r << "' : +" << endl; @@ -1284,28 +1005,28 @@ translate (WideString const& file, SchemaPerTypeTranslator:: SchemaPerTypeTranslator (NarrowStrings const& type_regex, - Boolean type_trace, + bool type_trace, NarrowStrings const& schema_regex, - Boolean schema_trace) + bool schema_trace) : type_trace_ (type_trace), schema_trace_ (schema_trace) { - for (NarrowStrings::ConstIterator i (type_regex.begin ()); + for (NarrowStrings::const_iterator i (type_regex.begin ()); i != type_regex.end (); ++i) { try { - type_regex_.push_back (TypeRegex (*i)); + type_regex_.push_back (TypeRegex (String (*i))); } catch (TypeRegexFormat const& e) { wcerr << "error: invalid type file regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } } - for (NarrowStrings::ConstIterator i (schema_regex.begin ()); + for (NarrowStrings::const_iterator i (schema_regex.begin ()); i != schema_regex.end (); ++i) { try @@ -1315,30 +1036,30 @@ SchemaPerTypeTranslator (NarrowStrings const& type_regex, catch (SchemaRegexFormat const& e) { wcerr << "error: invalid type file regex: '" << - e.expression ().c_str () << "': " << e.description ().c_str () << endl; + e.regex ().c_str () << "': " << e.description ().c_str () << endl; throw Failed (); } } } -WideString SchemaPerTypeTranslator:: -translate_type (WideString const& ns, WideString const& name) +String SchemaPerTypeTranslator:: +translate_type (String const& ns, String const& name) { - WideString s (ns + L' ' + name); + String s (ns + L' ' + name); if (type_trace_) wcerr << "type: '" << s << "'" << endl; - for (TypeRegexVector::ReverseIterator i (type_regex_.rbegin ()); + for (TypeRegexVector::reverse_iterator i (type_regex_.rbegin ()); i != type_regex_.rend (); ++i) { if (type_trace_) - wcerr << "try: '" << i->pattern () << "' : "; + wcerr << "try: '" << i->regex () << "' : "; if (i->match (s)) { - WideString r (i->merge (s)); + String r (i->replace (s)); if (type_trace_) wcerr << "'" << r << "' : +" << endl; @@ -1361,15 +1082,15 @@ translate_schema (NarrowString const& file) if (schema_trace_) wcerr << "schema: '" << file.c_str () << "'" << endl; - for (SchemaRegexVector::ReverseIterator i (schema_regex_.rbegin ()); + for (SchemaRegexVector::reverse_iterator i (schema_regex_.rbegin ()); i != schema_regex_.rend (); ++i) { if (schema_trace_) - wcerr << "try: '" << i->pattern () << "' : "; + wcerr << "try: '" << i->regex ().str ().c_str () << "' : "; if (i->match (file)) { - NarrowString r (i->merge (file)); + NarrowString r (i->replace (file)); if (schema_trace_) wcerr << "'" << r.c_str () << "' : +" << endl; @@ -1388,10 +1109,10 @@ translate_schema (NarrowString const& file) // // -Void +void expand_nl (NarrowString& s) { - for (Size i (0); i < s.size ();) + for (size_t i (0); i < s.size ();) { if (s[i] == '\\' && (i + 1) < s.size () && s[i + 1] == 'n') { |