From 5ec1c8ff21b5c19e39d5bd12aa3a017a78b56b98 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 19 Feb 2010 10:31:47 +0200 Subject: Add support for translating schema paths in fpt mode New options: --schema-file-regex, --schema-file-regex-trace. --- xsd/cxx/parser/elements.cxx | 8 ++++++-- xsd/cxx/parser/generator.cxx | 44 +++++++++++++++++++++++++++++++------------- xsd/cxx/parser/generator.hxx | 1 + xsd/cxx/tree/elements.cxx | 8 ++++++-- xsd/cxx/tree/generator.cxx | 38 ++++++++++++++++++++++++++++---------- xsd/cxx/tree/generator.hxx | 1 + 6 files changed, 73 insertions(+), 27 deletions(-) (limited to 'xsd/cxx') diff --git a/xsd/cxx/parser/elements.cxx b/xsd/cxx/parser/elements.cxx index 392bf16..140f041 100644 --- a/xsd/cxx/parser/elements.cxx +++ b/xsd/cxx/parser/elements.cxx @@ -212,6 +212,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)) @@ -220,7 +221,7 @@ namespace CXX // in the impl files. // if (type_ == header) - schema_.dispatch (u.schema ()); + schema_.dispatch (s); return; } @@ -228,7 +229,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/xsd/cxx/parser/generator.cxx b/xsd/cxx/parser/generator.cxx index 60d2785..617ff4f 100644 --- a/xsd/cxx/parser/generator.cxx +++ b/xsd/cxx/parser/generator.cxx @@ -613,6 +613,7 @@ namespace CXX generate (Parser::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, StringLiteralMap const& string_literal_map, Boolean gen_driver, const WarningSet& disabled_warnings, @@ -935,22 +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&) { @@ -959,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/xsd/cxx/parser/generator.hxx b/xsd/cxx/parser/generator.hxx index 47220ca..eaa1ecd 100644 --- a/xsd/cxx/parser/generator.hxx +++ b/xsd/cxx/parser/generator.hxx @@ -42,6 +42,7 @@ namespace CXX generate (CLI::Options const& options, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, + Boolean file_per_type, StringLiteralMap const&, Boolean gen_driver, const WarningSet& disabled_warnings, diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx index aafc442..503ca72 100644 --- a/xsd/cxx/tree/elements.cxx +++ b/xsd/cxx/tree/elements.cxx @@ -1253,6 +1253,7 @@ namespace CXX // Type t (type_); Boolean weak (u.context ().count ("weak")); + SemanticGraph::Schema& s (u.schema ()); if (weak && t == header) { @@ -1262,7 +1263,7 @@ namespace CXX t = forward; else { - schema_.dispatch (u.schema ()); + schema_.dispatch (s); return; } } @@ -1270,7 +1271,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/xsd/cxx/tree/generator.cxx b/xsd/cxx/tree/generator.cxx index ae86767..c13bf1f 100644 --- a/xsd/cxx/tree/generator.cxx +++ b/xsd/cxx/tree/generator.cxx @@ -834,6 +834,7 @@ namespace CXX generate (Tree::CLI::Options const& ops, Schema& schema, Path const& file_path, + Boolean fpt, StringLiteralMap const& string_literal_map, const WarningSet& disabled_warnings, FileList& file_list, @@ -1048,19 +1049,13 @@ namespace CXX Path (cxx_expr.merge (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; - fwd_path = path / fwd_path; - - for (Paths::Iterator i (cxx_paths.begin ()); - i != cxx_paths.end (); ++i) - *i = path / *i; + out_dir = Path (dir, boost::filesystem::native); } catch (InvalidPath const&) { @@ -1069,6 +1064,29 @@ 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; + fwd_path = out_dir / fwd_path; + + for (Paths::Iterator i (cxx_paths.begin ()); + i != cxx_paths.end (); ++i) + *i = out_dir / *i; + } + // // WideOutputFileStream hxx (hxx_path, ios_base::out); diff --git a/xsd/cxx/tree/generator.hxx b/xsd/cxx/tree/generator.hxx index 0bb5bb2..2e50392 100644 --- a/xsd/cxx/tree/generator.hxx +++ b/xsd/cxx/tree/generator.hxx @@ -37,6 +37,7 @@ namespace CXX generate (CLI::Options const& options, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, + Boolean file_per_type, StringLiteralMap const&, const WarningSet& disabled_warnings, FileList& file_list, -- cgit v1.1