From 9bd9b2a74362ae6755ac63fbe3990565edd5cff3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 19 Feb 2010 12:25:46 +0200 Subject: Add support for translating schema paths in fpt mode New options: --schema-file-regex, --schema-file-regex-trace. --- NEWS | 21 ++-- documentation/xsde.1 | 75 +++++++++++-- documentation/xsde.xhtml | 63 +++++++++-- xsde/cxx/hybrid/elements.cxx | 8 +- xsde/cxx/hybrid/generator.cxx | 88 ++++++++++++--- xsde/cxx/hybrid/generator.hxx | 3 + xsde/cxx/parser/elements.cxx | 8 +- xsde/cxx/parser/generator.cxx | 45 +++++--- xsde/cxx/parser/generator.hxx | 1 + xsde/cxx/serializer/elements.cxx | 8 +- xsde/cxx/serializer/generator.cxx | 45 +++++--- xsde/cxx/serializer/generator.hxx | 1 + xsde/xsde.cxx | 226 +++++++++++++++++++++++++++----------- 13 files changed, 446 insertions(+), 146 deletions(-) diff --git a/NEWS b/NEWS index 348a7f9..3ad834f 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,5 @@ Version 3.2.0 - * When built with Xerces-C++ 3-series, enable handling of multiple imports - for the same namespace. Before, all subsequent imports for a namespace - were ignored which caused error in some schemas. - - * Automatic mapping for the urn-style XML namespaces. The last component - in the urn name is used to derive the C++ namespace name. - * Support for ISO-8859-1 in addition to UTF-8 as application encoding. Note that this encoding is not the same as the XML document encoding that is being parsed or serialized. Rather, it is the encoding that @@ -16,7 +9,19 @@ Version 3.2.0 application encoding is automatically converted to the resulting document encoding. To select a particular encoding, configure the XSD/e runtime library accordingly and pass the --char-encoding option - to the XSD/e compiler when translating your schemas. + to the XSD/e compiler when translating your schemas. + + * When built with Xerces-C++ 3-series, enable handling of multiple imports + for the same namespace. Before, all subsequent imports for a namespace + were ignored which caused error in some schemas. + + * Automatic mapping for the urn-style XML namespaces. The last component + in the urn name is used to derive the C++ namespace name. + + * New option, --schema-file-regex, in combination with the existing + --type-file-regex, can be used to place the generated files into + subdirectories or to resolve file name conflicts in the file-per- + type mode (--file-per-type). * Strings used to match regular expression supplied with the --namespace-regex and --anonymous-regex options now include the file diff --git a/documentation/xsde.1 b/documentation/xsde.1 index 2562446..e578afa 100644 --- a/documentation/xsde.1 +++ b/documentation/xsde.1 @@ -249,7 +249,7 @@ or .I replacement is not supported. -All regular expressions are pushed into a stack with the last specified +All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form @@ -318,7 +318,7 @@ Add to the list of names that should not be used as identifiers. The name can optionally be followed by .B = -and the replacement name that should be used instead. All C++ keywords +and the replacement name that should be used instead. All the C++ keywords are already in this list. .IP "\fB\--include-with-brackets\fR" @@ -360,7 +360,7 @@ or .I replacement is not supported. -All regular expressions are pushed into a stack with the last specified +All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. As an example, the following expression transforms paths in the form @@ -695,7 +695,7 @@ Disable printing warning with id .IR warn . If .B all -is specified for the warning id then all warnings are disabled. +is specified for the warning id then all the warnings are disabled. .IP "\fB\--show-sloc\fR" Show the number of generated physical source lines of code (SLOC). @@ -752,7 +752,7 @@ or .I replacement is not supported. -All regular expressions are pushed into a stack with the last +All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form @@ -810,7 +810,7 @@ Escaping of the delimiter character in .I pattern or .I replacement -is not supported. All regular expressions are pushed into a stack with the +is not supported. All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. @@ -836,14 +836,18 @@ Note that in this mode you only need to compile the root schema(s) and the code will be generated for all included and imported schemas. This compilation mode is primarily useful when some of your schemas cannot be compiled separately or have cyclic dependencies which involve type -inheritance. +inheritance. Other options related to this mode are: +.BR --type-file-regex , +.BR --schema-file-regex, +and +.BR --file-list . .IP "\fB\--type-file-regex \fIregex\fR" Add .I regex to the list of regular expressions used to translate type names to file names when the -.B --type-per-file +.B --file-per-type option is specified. .I regex is a perl-like regular expression in the form @@ -854,7 +858,7 @@ Escaping of the delimiter character in .I pattern or .I replacement -is not supported. All regular expressions are pushed into a stack with +is not supported. All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form @@ -879,6 +883,57 @@ the option. Use this option to find out why your regular expressions don't do what you expected them to do. +.IP "\fB\--schema-file-regex \fIregex\fR" +Add +.I regex +to the list of regular expressions used to translate schema file names +when the +.B --file-per-type +option is specified. +.I regex +is a perl-like regular expression in the form +.BI / pattern / replacement /\fR. +Any character can be used as a delimiter instead of +.BR / . +Escaping of the delimiter character in +.I pattern +or +.I replacement +is not supported. All the regular expressions are pushed into a stack +with the last specified expression considered first. The first match +that succeeds is used. Regular expressions are applied to the absolute +filesystem path of a schema file and the result, including the directory +part, if any, is used to derive the +.B #include +directive paths as well as the generated C++ file paths. This option, along +with +.B --type-file-regex +are primarily used to place the generated files into subdirectories or to +resolve file name conflicts. + +For example, the following expression maps schema files in the +.B foo/1.0.0/ +subdirectory to the files in the +.B foo/ +subdirectory. As a result, the +.B #include +directive paths for such schemas will be in the +.B foo/schema.hxx +form and the generated C++ files will be placed into the +.B foo/ +subdirectory: + +.B %.*/foo/1.0.0/(.+)%foo/$1% + +See also the REGEX AND SHELL QUOTING section below. + +.IP "\fB\--schema-file-regex-trace\fR" +Trace the process of applying regular expressions specified with +the +.B --schema-file-regex +option. Use this option to find out why your regular expressions +don't do what you expected them to do. + .IP "\fB\--file-list \fIfile\fR" Write a list of generated C++ files to .IR file . @@ -1645,7 +1700,7 @@ namespace http://www.example.com/xmlns/my The compiler has a number of predefined mapping rules for the built-in XML Schema types that vary depending on the mapping used. They are described in the following subsections. The last predefined rule -for all mappings maps anything that wasn't mapped by previous rules to +for all the mappings maps anything that wasn't mapped by previous rules to .BR void : .RS diff --git a/documentation/xsde.xhtml b/documentation/xsde.xhtml index f734f5d..d758905 100644 --- a/documentation/xsde.xhtml +++ b/documentation/xsde.xhtml @@ -220,7 +220,7 @@ Escaping of the delimiter character in pattern or replacement is not supported. -

All regular expressions are pushed into a stack with the last +

All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form

@@ -276,7 +276,7 @@
Add name to the list of names that should not be used as identifiers. The name can optionally be followed by = and the replacement name that should be - used instead. All C++ keywords are already in this list. + used instead. All the C++ keywords are already in this list.
--include-with-brackets
@@ -308,7 +308,7 @@ Escaping of the delimiter character in pattern or replacement is not supported. -

All regular expressions are pushed into a stack with the last +

All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used.

@@ -588,7 +588,7 @@
--disable-warning warn
Disable printing warning with id warn. If all - is specified for the warning id then all warnings are disabled. + is specified for the warning id then all the warnings are disabled.
@@ -646,7 +646,7 @@ Escaping of the delimiter character in pattern or replacement is not supported. -

All regular expressions are pushed into a stack with the last +

All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form

@@ -696,7 +696,7 @@ /pattern/replacement/. Any character can be used as a delimiter instead of /. Escaping of the delimiter character in pattern or - replacement is not supported. All regular + replacement is not supported. All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. @@ -724,19 +724,23 @@ schema(s) and the code will be generated for all included and imported schemas. This compilation mode is primarily useful when some of your schemas cannot be compiled separately or have cyclic - dependencies which involve type inheritance. + dependencies which involve type inheritance. Other options related + to this mode are: + --type-file-regex, + --schema-file-regex, and + --file-list.
--type-file-regex regex
Add regex to the list of regular expressions used to translate type names to file names when the - --type-per-file option is specified. + --file-per-type option is specified. regex is a perl-like regular expression in the form /pattern/replacement/. Any character can be used as a delimiter instead of /. Escaping of the delimiter character in pattern or - replacement is not supported. All regular + replacement is not supported. All the regular expressions are pushed into a stack with the last specified expression considered first. The first match that succeeds is used. Regular expressions are applied to a string in the form @@ -759,6 +763,45 @@ them to do.
+
--schema-file-regex regex
+
Add regex to the list of regular expressions + used to translate schema file names when the + --file-per-type option is specified. + regex is a perl-like regular expression in the form + /pattern/replacement/. + Any character can be used as a delimiter instead of /. + Escaping of the delimiter character in pattern or + replacement is not supported. All the regular + expressions are pushed into a stack with the last specified + expression considered first. The first match that succeeds is used. + Regular expressions are applied to the absolute filesystem path + of a schema file and the result, including the directory part, + if any, is used to derive the #include directive + paths as well as the generated C++ file paths. This option, along + with --type-file-regex are primarily used to + place the generated files into subdirectories or to resolve file + name conflicts. + +

For example, the following expression maps schema files in the + foo/1.0.0/ subdirectory to the files in + the foo/ subdirectory. As a result, the + #include directive paths for such schemas + will be in the foo/schema.hxx form and + the generated C++ files will be placed into the + foo/ subdirectory:

+ +

%.*/foo/1.0.0/(.+)%foo/$1%

+ +

See also the REGEX AND SHELL QUOTING section below.

+
+ +
--schema-file-regex-trace
+
Trace the process of applying regular expressions specified with + the --schema-file-regex option. Use this option + to find out why your regular expressions don't do what you expected + them to do. +
+
--file-list file
@@ -1398,7 +1441,7 @@ namespace http://www.example.com/xmlns/my

The compiler has a number of predefined mapping rules for the built-in XML Schema types that vary depending on the mapping used. They are described in the following - subsections. The last predefined rule for all mappings + subsections. The last predefined rule for all the mappings maps anything that wasn't mapped by previous rules to void:

diff --git a/xsde/cxx/hybrid/elements.cxx b/xsde/cxx/hybrid/elements.cxx index e3bd02b..3607c37 100644 --- a/xsde/cxx/hybrid/elements.cxx +++ b/xsde/cxx/hybrid/elements.cxx @@ -580,6 +580,7 @@ namespace CXX // compilation model. // Type t (type_); + SemanticGraph::Schema& s (u.schema ()); Boolean weak (u.context ().count ("weak")); if (weak && (t == header || t == impl_header)) @@ -594,7 +595,7 @@ namespace CXX t = forward; else { - schema_.dispatch (u.schema ()); + schema_.dispatch (s); return; } } @@ -602,7 +603,10 @@ namespace CXX if (t == source && !weak) return; - SemanticGraph::Path path (u.path ()); + SemanticGraph::Path path ( + s.context ().count ("renamed") + ? s.context ().get ("renamed") + : u.path ()); // Try to use the portable representation of the path. If that // fails, fall back to the native representation. diff --git a/xsde/cxx/hybrid/generator.cxx b/xsde/cxx/hybrid/generator.cxx index c39b062..34cfa2d 100644 --- a/xsde/cxx/hybrid/generator.cxx +++ b/xsde/cxx/hybrid/generator.cxx @@ -1140,6 +1140,7 @@ namespace CXX generate_tree (Hybrid::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, const WarningSet& disabled_warnings, TypeMap::Namespaces& parser_type_map, TypeMap::Namespaces& serializer_type_map, @@ -1267,16 +1268,13 @@ namespace CXX Path cxx_path (cxx_name, boost::filesystem::native); Path fwd_path (fwd_name, boost::filesystem::native); - if (NarrowString dir = ops.value ()) + Path out_dir; + + if (NarrowString dir = ops.value ()) { try { - Path path (dir, boost::filesystem::native); - - hxx_path = path / hxx_path; - ixx_path = path / ixx_path; - cxx_path = path / cxx_path; - fwd_path = path / fwd_path; + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -1285,6 +1283,26 @@ namespace CXX } } + if (fpt && !generate_xml_schema) + { + // In the file-per-type mode the schema files are always local + // unless the user added the directory so that we propagate this + // to the output files. + // + Path fpt_dir (file_path.branch_path ()); + + if (!fpt_dir.empty ()) + out_dir /= fpt_dir; + } + + if (!out_dir.empty ()) + { + hxx_path = out_dir / hxx_path; + ixx_path = out_dir / ixx_path; + cxx_path = out_dir / cxx_path; + fwd_path = out_dir / fwd_path; + } + // Open the tree files. // WideOutputFileStream hxx (hxx_path, ios_base::out); @@ -1892,6 +1910,7 @@ namespace CXX generate_parser (Hybrid::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, const WarningSet&, FileList& file_list, AutoUnlinks& unlinks) @@ -1998,14 +2017,13 @@ namespace CXX Path hxx_path (hxx_name, boost::filesystem::native); Path cxx_path (cxx_name, boost::filesystem::native); - if (NarrowString dir = ops.value ()) + Path out_dir; + + if (NarrowString dir = ops.value ()) { try { - Path path (dir, boost::filesystem::native); - - hxx_path = path / hxx_path; - cxx_path = path / cxx_path; + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -2014,6 +2032,24 @@ namespace CXX } } + if (fpt) + { + // In the file-per-type mode the schema files are always local + // unless the user added the directory so that we propagate this + // to the output files. + // + Path fpt_dir (file_path.branch_path ()); + + if (!fpt_dir.empty ()) + out_dir /= fpt_dir; + } + + if (!out_dir.empty ()) + { + hxx_path = out_dir / hxx_path; + cxx_path = out_dir / cxx_path; + } + WideOutputFileStream hxx (hxx_path, ios_base::out); WideOutputFileStream cxx (cxx_path, ios_base::out); @@ -2296,6 +2332,7 @@ namespace CXX generate_serializer (Hybrid::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, const WarningSet&, FileList& file_list, AutoUnlinks& unlinks) @@ -2390,14 +2427,13 @@ namespace CXX Path hxx_path (hxx_name, boost::filesystem::native); Path cxx_path (cxx_name, boost::filesystem::native); - if (NarrowString dir = ops.value ()) + Path out_dir; + + if (NarrowString dir = ops.value ()) { try { - Path path (dir, boost::filesystem::native); - - hxx_path = path / hxx_path; - cxx_path = path / cxx_path; + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -2406,6 +2442,24 @@ namespace CXX } } + if (fpt) + { + // In the file-per-type mode the schema files are always local + // unless the user added the directory so that we propagate this + // to the output files. + // + Path fpt_dir (file_path.branch_path ()); + + if (!fpt_dir.empty ()) + out_dir /= fpt_dir; + } + + if (!out_dir.empty ()) + { + hxx_path = out_dir / hxx_path; + cxx_path = out_dir / cxx_path; + } + WideOutputFileStream hxx (hxx_path, ios_base::out); WideOutputFileStream cxx (cxx_path, ios_base::out); diff --git a/xsde/cxx/hybrid/generator.hxx b/xsde/cxx/hybrid/generator.hxx index 5d1afa0..e812801 100644 --- a/xsde/cxx/hybrid/generator.hxx +++ b/xsde/cxx/hybrid/generator.hxx @@ -82,6 +82,7 @@ namespace CXX CLI::Options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const&, + Boolean file_per_type, WarningSet const& disabled_warnings, TypeMap::Namespaces& parser_type_map, TypeMap::Namespaces& serializer_type_map, @@ -93,6 +94,7 @@ namespace CXX CLI::Options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const&, + Boolean file_per_type, WarningSet const& disabled_warnings, FileList&, AutoUnlinks&); @@ -102,6 +104,7 @@ namespace CXX CLI::Options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const&, + Boolean file_per_type, WarningSet const& disabled_warnings, FileList&, AutoUnlinks&); diff --git a/xsde/cxx/parser/elements.cxx b/xsde/cxx/parser/elements.cxx index 2261abd..fafcd52 100644 --- a/xsde/cxx/parser/elements.cxx +++ b/xsde/cxx/parser/elements.cxx @@ -206,6 +206,7 @@ namespace CXX // Support for weak (forward) inclusion used in the file-per-type // compilation model. // + SemanticGraph::Schema& s (u.schema ()); Boolean weak (u.context ().count ("weak")); if (weak && (type_ == header || type_ == impl_header)) @@ -214,7 +215,7 @@ namespace CXX // in the impl files. // if (type_ == header) - schema_.dispatch (u.schema ()); + schema_.dispatch (s); return; } @@ -222,7 +223,10 @@ namespace CXX if (type_ == source && !weak) return; - SemanticGraph::Path path (u.path ()); + SemanticGraph::Path path ( + s.context ().count ("renamed") + ? s.context ().get ("renamed") + : u.path ()); // Try to use the portable representation of the path. If that // fails, fall back to the native representation. diff --git a/xsde/cxx/parser/generator.cxx b/xsde/cxx/parser/generator.cxx index 1645525..c8a9f68 100644 --- a/xsde/cxx/parser/generator.cxx +++ b/xsde/cxx/parser/generator.cxx @@ -613,6 +613,7 @@ namespace CXX generate (Parser::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, TypeMap::Namespaces& type_map, Boolean gen_driver, const WarningSet& disabled_warnings, @@ -949,23 +950,13 @@ namespace CXX cxx_driver_path = Path (cxx_driver_name, boost::filesystem::native); } - if (NarrowString dir = ops.value ()) + Path out_dir; + + if (NarrowString dir = ops.value ()) { try { - Path path (dir, boost::filesystem::native); - - hxx_path = path / hxx_path; - ixx_path = path / ixx_path; - cxx_path = path / cxx_path; - - if (impl || driver) - { - hxx_impl_path = path / hxx_impl_path; - cxx_impl_path = path / cxx_impl_path; - cxx_driver_path = path /cxx_driver_path; - } - + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -974,6 +965,32 @@ namespace CXX } } + if (fpt && !generate_xml_schema) + { + // In the file-per-type mode the schema files are always local + // unless the user added the directory so that we propagate this + // to the output files. + // + Path fpt_dir (file_path.branch_path ()); + + if (!fpt_dir.empty ()) + out_dir /= fpt_dir; + } + + if (!out_dir.empty ()) + { + hxx_path = out_dir / hxx_path; + ixx_path = out_dir / ixx_path; + cxx_path = out_dir / cxx_path; + + if (impl || driver) + { + hxx_impl_path = out_dir / hxx_impl_path; + cxx_impl_path = out_dir / cxx_impl_path; + cxx_driver_path = out_dir /cxx_driver_path; + } + } + // Open the impl files first so that if open fails, the skel files // are not deleted. // diff --git a/xsde/cxx/parser/generator.hxx b/xsde/cxx/parser/generator.hxx index 10b3dd3..9c8f680 100644 --- a/xsde/cxx/parser/generator.hxx +++ b/xsde/cxx/parser/generator.hxx @@ -50,6 +50,7 @@ namespace CXX generate (CLI::Options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const&, + Boolean file_per_type, TypeMap::Namespaces& type_map, Boolean gen_driver, const WarningSet& disabled_warnings, diff --git a/xsde/cxx/serializer/elements.cxx b/xsde/cxx/serializer/elements.cxx index 0192faf..ba59a82 100644 --- a/xsde/cxx/serializer/elements.cxx +++ b/xsde/cxx/serializer/elements.cxx @@ -226,6 +226,7 @@ namespace CXX // Support for weak (forward) inclusion used in the file-per-type // compilation model. // + SemanticGraph::Schema& s (u.schema ()); Boolean weak (u.context ().count ("weak")); if (weak && (type_ == header || type_ == impl_header)) @@ -234,7 +235,7 @@ namespace CXX // in the impl files. // if (type_ == header) - schema_.dispatch (u.schema ()); + schema_.dispatch (s); return; } @@ -242,7 +243,10 @@ namespace CXX if (type_ == source && !weak) return; - SemanticGraph::Path path (u.path ()); + SemanticGraph::Path path ( + s.context ().count ("renamed") + ? s.context ().get ("renamed") + : u.path ()); // Try to use the portable representation of the path. If that // fails, fall back to the native representation. diff --git a/xsde/cxx/serializer/generator.cxx b/xsde/cxx/serializer/generator.cxx index 9d519b9..92e5197 100644 --- a/xsde/cxx/serializer/generator.cxx +++ b/xsde/cxx/serializer/generator.cxx @@ -606,6 +606,7 @@ namespace CXX generate (Serializer::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, TypeMap::Namespaces& type_map, Boolean gen_driver, const WarningSet& disabled_warnings, @@ -935,23 +936,13 @@ namespace CXX cxx_driver_path = Path (cxx_driver_name, boost::filesystem::native); } - if (NarrowString dir = ops.value ()) + Path out_dir; + + if (NarrowString dir = ops.value ()) { try { - Path path (dir, boost::filesystem::native); - - hxx_path = path / hxx_path; - ixx_path = path / ixx_path; - cxx_path = path / cxx_path; - - if (impl || driver) - { - hxx_impl_path = path / hxx_impl_path; - cxx_impl_path = path / cxx_impl_path; - cxx_driver_path = path /cxx_driver_path; - } - + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -960,6 +951,32 @@ namespace CXX } } + if (fpt && !generate_xml_schema) + { + // In the file-per-type mode the schema files are always local + // unless the user added the directory so that we propagate this + // to the output files. + // + Path fpt_dir (file_path.branch_path ()); + + if (!fpt_dir.empty ()) + out_dir /= fpt_dir; + } + + if (!out_dir.empty ()) + { + hxx_path = out_dir / hxx_path; + ixx_path = out_dir / ixx_path; + cxx_path = out_dir / cxx_path; + + if (impl || driver) + { + hxx_impl_path = out_dir / hxx_impl_path; + cxx_impl_path = out_dir / cxx_impl_path; + cxx_driver_path = out_dir /cxx_driver_path; + } + } + // Open the impl files first so that if open fails, the skel files // are not deleted. // diff --git a/xsde/cxx/serializer/generator.hxx b/xsde/cxx/serializer/generator.hxx index dd3c0c5..8c2465c 100644 --- a/xsde/cxx/serializer/generator.hxx +++ b/xsde/cxx/serializer/generator.hxx @@ -50,6 +50,7 @@ namespace CXX generate (CLI::Options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const&, + Boolean file_per_type, TypeMap::Namespaces& type_map, Boolean gen_driver, const WarningSet& disabled_warnings, diff --git a/xsde/xsde.cxx b/xsde/xsde.cxx index fc56a45..e413719 100644 --- a/xsde/xsde.cxx +++ b/xsde/xsde.cxx @@ -71,43 +71,47 @@ namespace CLI struct HelpOptionsSpec: Cult::CLI::OptionsSpec {}; - extern Key disable_warning = "disable-warning"; - extern Key sloc_limit = "sloc-limit"; - 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 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 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. + extern Key disable_warning = "disable-warning"; + extern Key sloc_limit = "sloc-limit"; + 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 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, - sloc_limit, UnsignedLong, - preserve_anonymous, Boolean, - anonymous_regex, NarrowStrings, - anonymous_regex_trace, Boolean, - location_map, NarrowStrings, - location_regex, NarrowStrings, - location_regex_trace, Boolean, - file_per_type, Boolean, - type_file_regex, NarrowStrings, - type_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 + disable_warning, Cult::Containers::Vector, + sloc_limit, UnsignedLong, + preserve_anonymous, Boolean, + anonymous_regex, NarrowStrings, + anonymous_regex_trace, Boolean, + location_map, NarrowStrings, + location_regex, NarrowStrings, + location_regex_trace, Boolean, + 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; @@ -168,22 +172,35 @@ private: // // -struct TypeSchemaTranslator: Transformations::TypeSchemaTranslator +struct SchemaPerTypeTranslator: Transformations::SchemaPerTypeTranslator { struct Failed {}; - TypeSchemaTranslator (NarrowStrings const& regex, Boolean trace); + SchemaPerTypeTranslator (NarrowStrings const& type_regex, + Boolean type_trace, + NarrowStrings const& schema_regex, + Boolean schema_trace); virtual WideString - translate (WideString const& ns, WideString const& name); + translate_type (WideString const& ns, WideString const& name); + + virtual NarrowString + translate_schema (NarrowString const& file); private: - typedef BackendElements::Regex::Expression Regex; - typedef BackendElements::Regex::Format RegexFormat; - typedef Cult::Containers::Vector RegexVector; + typedef BackendElements::Regex::Expression TypeRegex; + typedef BackendElements::Regex::Format TypeRegexFormat; + typedef Cult::Containers::Vector TypeRegexVector; - RegexVector regex_; - Boolean trace_; + TypeRegexVector type_regex_; + Boolean type_trace_; + + typedef BackendElements::Regex::Expression SchemaRegex; + typedef BackendElements::Regex::Format SchemaRegexFormat; + typedef Cult::Containers::Vector SchemaRegexVector; + + SchemaRegexVector schema_regex_; + Boolean schema_trace_; }; // Expand the \n escape sequence. @@ -344,7 +361,7 @@ main (Int argc, Char* argv[]) e << "--type-file-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 --type-per-file option is\n" + << " to file names when the --file-per-type option is\n" << " specified." << endl; @@ -353,6 +370,18 @@ main (Int argc, Char* argv[]) << " specified with the --type-file-regex option." << endl; + e << "--schema-file-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. // e << "--file-list " << endl @@ -885,6 +914,7 @@ main (Int argc, Char* argv[]) *h_ops, *root, tu, + false, disabled_w, parser_type_map, serializer_type_map, @@ -907,6 +937,7 @@ main (Int argc, Char* argv[]) *p_ops, *root, tu, + false, parser_type_map, true, disabled_w, @@ -929,6 +960,7 @@ main (Int argc, Char* argv[]) *s_ops, *root, tu, + false, serializer_type_map, true, disabled_w, @@ -953,6 +985,7 @@ main (Int argc, Char* argv[]) *h_ops, *root, tu, + false, disabled_w, file_list, unlinks); @@ -973,6 +1006,7 @@ main (Int argc, Char* argv[]) *h_ops, *root, tu, + false, disabled_w, file_list, unlinks); @@ -1085,9 +1119,11 @@ main (Int argc, Char* argv[]) // typedef Cult::Containers::Vector Schemas; - TypeSchemaTranslator type_translator ( + SchemaPerTypeTranslator type_translator ( common_ops.value (), - common_ops.value ()); + common_ops.value (), + common_ops.value (), + common_ops.value ()); Transformations::SchemaPerType trans ( type_translator, gen_hybrid ? "fixed" : 0); @@ -1099,7 +1135,10 @@ main (Int argc, Char* argv[]) i != e; ++i) { SemanticGraph::Schema& s (**i); - SemanticGraph::Path path (s.used_begin ()->path ()); + SemanticGraph::Path path ( + s.context ().count ("renamed") + ? s.context ().get ("renamed") + : s.used_begin ()->path ()); TypeMap::Namespaces parser_type_map, serializer_type_map; @@ -1111,6 +1150,7 @@ main (Int argc, Char* argv[]) *h_ops, s, path, + true, disabled_w, parser_type_map, serializer_type_map, @@ -1135,6 +1175,7 @@ main (Int argc, Char* argv[]) *p_ops, s, path, + true, parser_type_map, i == b, disabled_w, @@ -1159,6 +1200,7 @@ main (Int argc, Char* argv[]) *s_ops, s, path, + true, serializer_type_map, i == b, disabled_w, @@ -1183,6 +1225,7 @@ main (Int argc, Char* argv[]) *h_ops, s, path, + true, disabled_w, file_list, unlinks); @@ -1203,6 +1246,7 @@ main (Int argc, Char* argv[]) *h_ops, s, path, + true, disabled_w, file_list, unlinks); @@ -1295,7 +1339,7 @@ main (Int argc, Char* argv[]) { // Diagnostic has already been issued. } - catch (TypeSchemaTranslator::Failed const&) + catch (SchemaPerTypeTranslator::Failed const&) { // Diagnostic has already been issued. } @@ -1493,20 +1537,24 @@ translate (WideString const& file, return name; } -// TypeSchemaTranslator +// SchemaPerTypeTranslator // -TypeSchemaTranslator:: -TypeSchemaTranslator (NarrowStrings const& regex, Boolean trace) - : trace_ (trace) +SchemaPerTypeTranslator:: +SchemaPerTypeTranslator (NarrowStrings const& type_regex, + Boolean type_trace, + NarrowStrings const& schema_regex, + Boolean schema_trace) + : type_trace_ (type_trace), schema_trace_ (schema_trace) { - for (NarrowStrings::ConstIterator i (regex.begin ()); i != regex.end (); ++i) + for (NarrowStrings::ConstIterator i (type_regex.begin ()); + i != type_regex.end (); ++i) { try { - regex_.push_back (Regex (*i)); + type_regex_.push_back (TypeRegex (*i)); } - catch (RegexFormat const& e) + catch (TypeRegexFormat const& e) { wcerr << "error: invalid type file regex: '" << e.expression () << "': " << e.description () << endl; @@ -1514,42 +1562,86 @@ TypeSchemaTranslator (NarrowStrings const& regex, Boolean trace) throw Failed (); } } + + for (NarrowStrings::ConstIterator i (schema_regex.begin ()); + i != schema_regex.end (); ++i) + { + try + { + schema_regex_.push_back (SchemaRegex (*i)); + } + catch (SchemaRegexFormat const& e) + { + wcerr << "error: invalid type file regex: '" << + e.expression ().c_str () << "': " << e.description ().c_str () << endl; + + throw Failed (); + } + } } -WideString TypeSchemaTranslator:: -translate (WideString const& ns, WideString const& name) +WideString SchemaPerTypeTranslator:: +translate_type (WideString const& ns, WideString const& name) { - if (regex_.empty ()) - return name; - WideString s (ns + L' ' + name); - if (trace_) + if (type_trace_) wcerr << "type: '" << s << "'" << endl; - for (RegexVector::ReverseIterator i (regex_.rbegin ()); - i != regex_.rend (); ++i) + for (TypeRegexVector::ReverseIterator i (type_regex_.rbegin ()); + i != type_regex_.rend (); ++i) { - if (trace_) + if (type_trace_) wcerr << "try: '" << i->pattern () << "' : "; if (i->match (s)) { WideString r (i->merge (s)); - if (trace_) + if (type_trace_) wcerr << "'" << r << "' : +" << endl; return r; } - if (trace_) + if (type_trace_) wcerr << '-' << endl; } - // No match - return the type name. + // No match - return empty string. // - return name; + return L""; +} + +NarrowString SchemaPerTypeTranslator:: +translate_schema (NarrowString const& file) +{ + if (schema_trace_) + wcerr << "schema: '" << file.c_str () << "'" << endl; + + for (SchemaRegexVector::ReverseIterator i (schema_regex_.rbegin ()); + i != schema_regex_.rend (); ++i) + { + if (schema_trace_) + wcerr << "try: '" << i->pattern () << "' : "; + + if (i->match (file)) + { + NarrowString r (i->merge (file)); + + if (schema_trace_) + wcerr << "'" << r.c_str () << "' : +" << endl; + + return r; + } + + if (schema_trace_) + wcerr << '-' << endl; + } + + // No match - return empty string. + // + return ""; } // -- cgit v1.1