summaryrefslogtreecommitdiff
path: root/xsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-02-19 10:31:47 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-02-19 10:31:47 +0200
commit5ec1c8ff21b5c19e39d5bd12aa3a017a78b56b98 (patch)
treea137f9321fcdeaf838cbf3cb8a286d5f09fc3955 /xsd
parente571ff926d9736f48bb37948e29db90e7c6e68d5 (diff)
Add support for translating schema paths in fpt mode
New options: --schema-file-regex, --schema-file-regex-trace.
Diffstat (limited to 'xsd')
-rw-r--r--xsd/cxx/parser/elements.cxx8
-rw-r--r--xsd/cxx/parser/generator.cxx44
-rw-r--r--xsd/cxx/parser/generator.hxx1
-rw-r--r--xsd/cxx/tree/elements.cxx8
-rw-r--r--xsd/cxx/tree/generator.cxx38
-rw-r--r--xsd/cxx/tree/generator.hxx1
-rw-r--r--xsd/xsd.cxx228
7 files changed, 230 insertions, 98 deletions
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<SemanticGraph::Path> ("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<CLI::output_dir> ())
+ Path out_dir;
+
+ if (NarrowString dir = ops.value<CLI::output_dir> ())
{
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<SemanticGraph::Path> ("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<CLI::output_dir> ())
+ Path out_dir;
+
+ if (NarrowString dir = ops.value<CLI::output_dir> ())
{
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,
diff --git a/xsd/xsd.cxx b/xsd/xsd.cxx
index f721699..5c81d7f 100644
--- a/xsd/xsd.cxx
+++ b/xsd/xsd.cxx
@@ -72,48 +72,52 @@ namespace CLI
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 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 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,
- 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<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;
@@ -174,22 +178,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<WideChar> Regex;
- typedef BackendElements::Regex::Format<WideChar> RegexFormat;
- typedef Cult::Containers::Vector<Regex> RegexVector;
+ typedef BackendElements::Regex::Expression<WideChar> TypeRegex;
+ typedef BackendElements::Regex::Format<WideChar> TypeRegexFormat;
+ typedef Cult::Containers::Vector<TypeRegex> TypeRegexVector;
- RegexVector regex_;
- Boolean trace_;
+ TypeRegexVector type_regex_;
+ Boolean type_trace_;
+
+ typedef BackendElements::Regex::Expression<Char> SchemaRegex;
+ typedef BackendElements::Regex::Format<Char> SchemaRegexFormat;
+ typedef Cult::Containers::Vector<SchemaRegex> SchemaRegexVector;
+
+ SchemaRegexVector schema_regex_;
+ Boolean schema_trace_;
};
//
@@ -358,7 +375,7 @@ main (Int argc, Char* argv[])
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 --type-per-file option is\n"
+ << " to file names when the --file-per-type option is\n"
<< " specified."
<< endl;
@@ -367,6 +384,18 @@ main (Int argc, Char* argv[])
<< " 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.
//
e << "--file-list <file>" << endl
@@ -742,6 +771,7 @@ main (Int argc, Char* argv[])
*tree_ops,
*schema,
tu,
+ false,
string_literal_map,
disabled_w,
file_list,
@@ -762,6 +792,7 @@ main (Int argc, Char* argv[])
*parser_ops,
*schema,
tu,
+ false,
string_literal_map,
true,
disabled_w,
@@ -866,9 +897,11 @@ main (Int argc, Char* argv[])
//
typedef Cult::Containers::Vector<SemanticGraph::Schema*> Schemas;
- TypeSchemaTranslator type_translator (
+ SchemaPerTypeTranslator type_translator (
common_ops.value<CLI::type_file_regex> (),
- common_ops.value<CLI::type_file_regex_trace> ());
+ common_ops.value<CLI::type_file_regex_trace> (),
+ common_ops.value<CLI::schema_file_regex> (),
+ common_ops.value<CLI::schema_file_regex_trace> ());
Transformations::SchemaPerType trans (type_translator);
Schemas schemas (trans.transform (*schema));
@@ -879,7 +912,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<SemanticGraph::Path> ("renamed")
+ : s.used_begin ()->path ());
if (cmd == "cxx-tree")
{
@@ -889,6 +925,7 @@ main (Int argc, Char* argv[])
*tree_ops,
s,
path,
+ true,
string_literal_map,
disabled_w,
file_list,
@@ -911,6 +948,7 @@ main (Int argc, Char* argv[])
*parser_ops,
s,
path,
+ true,
string_literal_map,
i == b,
disabled_w,
@@ -1004,7 +1042,7 @@ main (Int argc, Char* argv[])
{
// Diagnostic has already been issued.
}
- catch (TypeSchemaTranslator::Failed const&)
+ catch (SchemaPerTypeTranslator::Failed const&)
{
// Diagnostic has already been issued.
}
@@ -1202,20 +1240,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;
@@ -1223,42 +1265,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 "";
}
//