aboutsummaryrefslogtreecommitdiff
path: root/xsd/xsd.cxx
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/xsd.cxx
parente571ff926d9736f48bb37948e29db90e7c6e68d5 (diff)
Add support for translating schema paths in fpt mode
New options: --schema-file-regex, --schema-file-regex-trace.
Diffstat (limited to 'xsd/xsd.cxx')
-rw-r--r--xsd/xsd.cxx228
1 files changed, 157 insertions, 71 deletions
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 "";
}
//