From 6bf1e46ccc93777ca9f62746ada0e18c72fcf138 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 May 2012 11:50:57 +0200 Subject: Port to use regex from libcutl instead of libbackend-elements --- xsd/cxx/elements.cxx | 22 +++++++++---------- xsd/cxx/elements.hxx | 8 +++---- xsd/cxx/parser/elements.cxx | 4 ++-- xsd/cxx/parser/elements.hxx | 4 ++-- xsd/cxx/parser/generator.cxx | 43 ++++++++++++++++++------------------ xsd/cxx/parser/parser-header.cxx | 2 +- xsd/cxx/parser/type-processor.cxx | 22 ++++++++++--------- xsd/cxx/tree/elements.cxx | 14 ++++++------ xsd/cxx/tree/elements.hxx | 8 +++---- xsd/cxx/tree/generator.cxx | 41 +++++++++++++++++----------------- xsd/cxx/tree/name-processor.cxx | 46 +++++++++++++++++++++++---------------- xsd/cxx/tree/tree-forward.cxx | 2 +- 12 files changed, 113 insertions(+), 103 deletions(-) (limited to 'xsd/cxx') diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx index 1fe2c29..e83f661 100644 --- a/xsd/cxx/elements.cxx +++ b/xsd/cxx/elements.cxx @@ -5,8 +5,6 @@ #include -#include - #include // std::toupper #include #include @@ -218,7 +216,7 @@ namespace CXX for (Containers::Vector::ConstIterator i (nsr.begin ()), e (nsr.end ()); i != e; ++i) { - nsr_mapping_.push_back (Regex (*i)); + nsr_mapping_.push_back (Regex (String (*i))); } // Custom direct mapping. @@ -251,7 +249,7 @@ namespace CXX for (Containers::Vector::ConstIterator i (ir.begin ()), e (ir.end ()); i != e; ++i) { - include_mapping_.push_back (Regex (*i)); + include_mapping_.push_back (Regex (String (*i))); } // Reserved names. @@ -352,12 +350,12 @@ namespace CXX e != nsr_mapping.rend (); ++e) { if (trace_namespace_regex) - wcerr << "try: '" << e->pattern () << "' : "; + wcerr << "try: '" << e->regex () << "' : "; if (e->match (pair)) { - tmp = e->merge (pair); - tmp = colon.merge (tmp); // replace `/' with `::' + tmp = e->replace (pair); + tmp = colon.replace (tmp); // replace `/' with `::' // Check the result. // @@ -388,7 +386,7 @@ namespace CXX } else { - tmp = colon.merge (n); // replace `/' with `::' + tmp = colon.replace (n); // replace `/' with `::' if (!cxx_id_expr.match (tmp)) { @@ -397,8 +395,8 @@ namespace CXX if (urn_mapping.match (n)) { Regex filter (L"#[.:-]#_#"); - tmp = urn_mapping.merge (n); - tmp = filter.merge (tmp); + tmp = urn_mapping.replace (n); + tmp = filter.replace (tmp); if (!cxx_id_expr.match (tmp)) throw NoNamespaceMapping ( @@ -1209,11 +1207,11 @@ namespace CXX e != include_mapping.rend (); ++e) { if (trace_include_regex) - wcerr << "try: '" << e->pattern () << "' : "; + wcerr << "try: '" << e->regex () << "' : "; if (e->match (path)) { - r = e->merge (path); + r = e->replace (path); found = true; if (trace_include_regex) diff --git a/xsd/cxx/elements.hxx b/xsd/cxx/elements.hxx index f9fa619..15518fc 100644 --- a/xsd/cxx/elements.hxx +++ b/xsd/cxx/elements.hxx @@ -8,13 +8,13 @@ #include +#include + #include #include #include #include -#include - #include #include @@ -136,8 +136,8 @@ namespace CXX class Context { public: - typedef BackendElements::Regex::Pattern RegexPat; - typedef BackendElements::Regex::Expression Regex; + typedef cutl::re::wregex RegexPat; + typedef cutl::re::wregexsub Regex; typedef Cult::Containers::Vector RegexMapping; typedef Cult::Containers::Map MapMapping; typedef Cult::Containers::Map MappingCache; diff --git a/xsd/cxx/parser/elements.cxx b/xsd/cxx/parser/elements.cxx index 585d42c..94baa28 100644 --- a/xsd/cxx/parser/elements.cxx +++ b/xsd/cxx/parser/elements.cxx @@ -248,12 +248,12 @@ namespace CXX case header: case source: { - inc_path = ctx_.hxx_expr->merge (path_str); + inc_path = ctx_.hxx_expr->replace (path_str); break; } case impl_header: { - inc_path = ctx_.hxx_impl_expr->merge (path_str); + inc_path = ctx_.hxx_impl_expr->replace (path_str); break; } } diff --git a/xsd/cxx/parser/elements.hxx b/xsd/cxx/parser/elements.hxx index edcd9f2..d8cedd8 100644 --- a/xsd/cxx/parser/elements.hxx +++ b/xsd/cxx/parser/elements.hxx @@ -8,7 +8,7 @@ #include -#include +#include #include @@ -33,7 +33,7 @@ namespace CXX class Context: public CXX::Context { public: - typedef BackendElements::Regex::Expression Regex; + typedef cutl::re::regexsub Regex; public: Context (std::wostream&, diff --git a/xsd/cxx/parser/generator.cxx b/xsd/cxx/parser/generator.cxx index 1a121cd..998c480 100644 --- a/xsd/cxx/parser/generator.cxx +++ b/xsd/cxx/parser/generator.cxx @@ -7,6 +7,8 @@ #include +#include + #include #include @@ -14,7 +16,6 @@ #include #include -#include #include #include @@ -626,7 +627,7 @@ namespace CXX using std::ios_base; namespace Indentation = BackendElements::Indentation; - typedef BackendElements::Regex::Expression Regex; + typedef cutl::re::regexsub Regex; try { @@ -795,7 +796,7 @@ namespace CXX type_map.push_back (xsd); - // Everyhting else maps to void. + // Everything else maps to void. // TypeMap::Namespace rest (".*"); rest.types_push_back (".*", "void", "void"); @@ -861,7 +862,7 @@ namespace CXX if (!hxx_expr.match (name)) { wcerr << "error: header expression '" << - hxx_expr.pattern () << "' does not match '" << + hxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -869,7 +870,7 @@ namespace CXX if (inline_ && !ixx_expr.match (name)) { wcerr << "error: inline expression '" << - ixx_expr.pattern () << "' does not match '" << + ixx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -877,7 +878,7 @@ namespace CXX if (source && !cxx_expr.match (name)) { wcerr << "error: source expression '" << - cxx_expr.pattern () << "' does not match '" << + cxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -887,7 +888,7 @@ namespace CXX if (!hxx_impl_expr.match (name)) { wcerr << "error: implementation header expression '" << - hxx_impl_expr.pattern () << "' does not match '" << + hxx_impl_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -895,7 +896,7 @@ namespace CXX if (!cxx_impl_expr.match (name)) { wcerr << "error: implementation source expression '" << - cxx_impl_expr.pattern () << "' does not match '" << + cxx_impl_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -903,15 +904,15 @@ namespace CXX if (!cxx_driver_expr.match (name)) { wcerr << "error: driver source expression '" << - cxx_driver_expr.pattern () << "' does not match '" << + cxx_driver_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } } - NarrowString hxx_name (hxx_expr.merge (name)); - NarrowString ixx_name (inline_ ? ixx_expr.merge (name) : NarrowString ()); - NarrowString cxx_name (source ? cxx_expr.merge (name) : NarrowString ()); + NarrowString hxx_name (hxx_expr.replace (name)); + NarrowString ixx_name (inline_ ? ixx_expr.replace (name) : NarrowString ()); + NarrowString cxx_name (source ? cxx_expr.replace (name) : NarrowString ()); NarrowString hxx_impl_name; NarrowString cxx_impl_name; @@ -919,9 +920,9 @@ namespace CXX if (impl || driver) { - hxx_impl_name = hxx_impl_expr.merge (name); - cxx_impl_name = cxx_impl_expr.merge (name); - cxx_driver_name = cxx_driver_expr.merge (name); + hxx_impl_name = hxx_impl_expr.replace (name); + cxx_impl_name = cxx_impl_expr.replace (name); + cxx_driver_name = cxx_driver_expr.replace (name); } Path hxx_path (hxx_name, boost::filesystem::native); @@ -1198,7 +1199,7 @@ namespace CXX sloc_filter sloc (hxx); - String guard (guard_expr.merge (guard_prefix + hxx_name)); + String guard (guard_expr.replace (guard_prefix + hxx_name)); guard = ctx.escape (guard); // Make it a C++ id. std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1406,7 +1407,7 @@ namespace CXX &ixx_expr, &hxx_impl_expr); - String guard (guard_expr.merge (guard_prefix + hxx_impl_name)); + String guard (guard_expr.replace (guard_prefix + hxx_impl_name)); guard = ctx.escape (guard); // Make it a C++ id. std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1501,18 +1502,18 @@ namespace CXX throw Failed (); } - catch (BackendElements::Regex::Format const& e) + catch (cutl::re::format const& e) { wcerr << "error: invalid regex: '" << - e.expression ().c_str () << "': " << + e.regex ().c_str () << "': " << e.description ().c_str () << endl; throw Failed (); } - catch (BackendElements::Regex::Format const& e) + catch (cutl::re::wformat const& e) { wcerr << "error: invalid regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } diff --git a/xsd/cxx/parser/parser-header.cxx b/xsd/cxx/parser/parser-header.cxx index 1dd01b2..2490a26 100644 --- a/xsd/cxx/parser/parser-header.cxx +++ b/xsd/cxx/parser/parser-header.cxx @@ -1298,7 +1298,7 @@ namespace CXX if (extern_xml_schema) { - String name (ctx.hxx_expr->merge (extern_xml_schema)); + String name (ctx.hxx_expr->replace (extern_xml_schema)); ctx.os << "#include " << ctx.process_include_path (name) << endl << endl; diff --git a/xsd/cxx/parser/type-processor.cxx b/xsd/cxx/parser/type-processor.cxx index 2207a10..db3e45b 100644 --- a/xsd/cxx/parser/type-processor.cxx +++ b/xsd/cxx/parser/type-processor.cxx @@ -73,7 +73,7 @@ namespace CXX String ns_name (ns.name ()); String t_name (type.name ()); - // std::wcerr << "traversing: " << ns_name << "#" << t_name << endl; + //std::wcerr << "traversing: " << ns_name << "#" << t_name << endl; for (Namespaces::ConstIterator n (type_map_.begin ()); n != type_map_.end (); ++n) @@ -89,7 +89,9 @@ namespace CXX else ns_match = ns_name.empty (); - // std::wcerr << "considering ns expr: " << n->xsd_name () << endl; + //std::wcerr << "considering ns expr: " << n->xsd_name () + // << " for " << ns_name + // << ": " << (ns_match ? "+" : "-") << endl; if (ns_match) { @@ -111,8 +113,8 @@ namespace CXX { if (!n->xsd_name ().empty ()) { - cxx_ns = n->xsd_name ().merge ( - n->cxx_name (), ns_name, true); + cxx_ns = n->xsd_name ().replace ( + ns_name, n->cxx_name (), true); } else cxx_ns = n->cxx_name (); @@ -124,16 +126,16 @@ namespace CXX // String ret_type (cxx_ns); - ret_type += t->xsd_name ().merge ( - t->cxx_ret_name (), t_name, true); + ret_type += t->xsd_name ().replace ( + t_name, t->cxx_ret_name (), true); String arg_type; if (t->cxx_arg_name ()) { arg_type = cxx_ns; - arg_type += t->xsd_name ().merge ( - t->cxx_arg_name (), t_name, true); + arg_type += t->xsd_name ().replace ( + t_name, t->cxx_arg_name (), true); } else { @@ -155,12 +157,12 @@ namespace CXX tc.set ("ret-type", ret_type); tc.set ("arg-type", arg_type); + + //std::wcerr << t_name << " -> " << ret_type << endl; } tc.set ("root-schema", &schema_); - //std::wcerr << t_name << " -> " << ret_type << endl; - // See of we need to add any includes to the translations // unit. // diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx index 0b69fff..233063a 100644 --- a/xsd/cxx/tree/elements.cxx +++ b/xsd/cxx/tree/elements.cxx @@ -291,7 +291,7 @@ namespace CXX } regex_custom_type_map.push_back ( - RegexCustomTypeMapInfo (pat, type, base)); + RegexCustomTypeMapInfo (WideRegexPat (pat), type, base)); } } } @@ -414,7 +414,7 @@ namespace CXX return true; } - r = i->pat.merge (i->type_sub, name); + r = i->pat.replace (name, i->type_sub); return true; } } @@ -467,7 +467,7 @@ namespace CXX { if (!i->base_sub.empty ()) { - r = i->pat.merge (i->base_sub, name); + r = i->pat.replace (name, i->base_sub); } else r.clear (); @@ -1354,25 +1354,25 @@ namespace CXX { case forward: { - inc_path = ctx_.fwd_expr->merge (path_str); + inc_path = ctx_.fwd_expr->replace (path_str); break; } case header: case source: { - inc_path = ctx_.hxx_expr->merge (path_str); + inc_path = ctx_.hxx_expr->replace (path_str); break; } case inline_: { if (weak) { - inc_path = ctx_.hxx_expr->merge (path_str); + inc_path = ctx_.hxx_expr->replace (path_str); ctx_.os << "#include " << ctx_.process_include_path (inc_path) << endl; } - inc_path = ctx_.ixx_expr->merge (path_str); + inc_path = ctx_.ixx_expr->replace (path_str); break; } } diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx index 369dc3a..edcb0d2 100644 --- a/xsd/cxx/tree/elements.hxx +++ b/xsd/cxx/tree/elements.hxx @@ -8,12 +8,12 @@ #include +#include + #include #include #include -#include - #include #include @@ -74,8 +74,8 @@ namespace CXX class Context: public CXX::Context { public: - typedef BackendElements::Regex::Expression Regex; - typedef BackendElements::Regex::Pattern WideRegexPat; + typedef cutl::re::regexsub Regex; + typedef cutl::re::wregex WideRegexPat; struct DirectCustomTypeMapInfo { diff --git a/xsd/cxx/tree/generator.cxx b/xsd/cxx/tree/generator.cxx index d7e77d0..5fe4af5 100644 --- a/xsd/cxx/tree/generator.cxx +++ b/xsd/cxx/tree/generator.cxx @@ -7,6 +7,8 @@ #include +#include + #include #include @@ -14,7 +16,6 @@ #include #include -#include #include #include @@ -853,7 +854,7 @@ namespace CXX using std::ios_base; namespace Indentation = BackendElements::Indentation; - typedef BackendElements::Regex::Expression Regex; + typedef cutl::re::regexsub Regex; using Cult::Containers::Vector; @@ -990,7 +991,7 @@ namespace CXX if (!hxx_expr.match (name)) { wcerr << "error: header expression '" << - hxx_expr.pattern () << "' does not match '" << + hxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -998,7 +999,7 @@ namespace CXX if (inline_ && !ixx_expr.match (name)) { wcerr << "error: inline expression '" << - ixx_expr.pattern () << "' does not match '" << + ixx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -1006,7 +1007,7 @@ namespace CXX if (source && parts == 1 && !cxx_expr.match (name)) { wcerr << "error: source expression '" << - cxx_expr.pattern () << "' does not match '" << + cxx_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } @@ -1014,14 +1015,14 @@ namespace CXX if (forward && !fwd_expr.match (name)) { wcerr << "error: forward expression '" << - fwd_expr.pattern () << "' does not match '" << + fwd_expr.regex ().str ().c_str () << "' does not match '" << name.c_str () << "'" << endl; throw Failed (); } - NarrowString hxx_name (hxx_expr.merge (name)); - NarrowString ixx_name (inline_ ? ixx_expr.merge (name) : NarrowString ()); - NarrowString fwd_name (forward ? fwd_expr.merge (name) : NarrowString ()); + NarrowString hxx_name (hxx_expr.replace (name)); + NarrowString ixx_name (inline_ ? ixx_expr.replace (name) : NarrowString ()); + NarrowString fwd_name (forward ? fwd_expr.replace (name) : NarrowString ()); Path hxx_path (hxx_name, boost::filesystem::native); Path ixx_path (ixx_name, boost::filesystem::native); @@ -1040,23 +1041,23 @@ namespace CXX Regex expr ( "#^(.+?)(\\.[^./\\\\]+)?$#$1" + parts_suffix + os.str () + "$2#"); - NarrowString part_name (expr.merge (name)); + NarrowString part_name (expr.replace (name)); if (!cxx_expr.match (part_name)) { wcerr << "error: source expression '" << - cxx_expr.pattern () << "' does not match '" << + cxx_expr.regex ().str ().c_str () << "' does not match '" << part_name.c_str () << "'" << endl; throw Failed (); } cxx_paths.push_back ( - Path (cxx_expr.merge (part_name), boost::filesystem::native)); + Path (cxx_expr.replace (part_name), boost::filesystem::native)); } } else cxx_paths.push_back ( - Path (cxx_expr.merge (name), boost::filesystem::native)); + Path (cxx_expr.replace (name), boost::filesystem::native)); } Path out_dir; @@ -1272,7 +1273,7 @@ namespace CXX // Guard // - String guard (guard_expr.merge (guard_prefix + fwd_name)); + String guard (guard_expr.replace (guard_prefix + fwd_name)); guard = ctx.escape (guard); // make a c++ id std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1381,7 +1382,7 @@ namespace CXX // Guard // - String guard (guard_expr.merge (guard_prefix + hxx_name)); + String guard (guard_expr.replace (guard_prefix + hxx_name)); guard = ctx.escape (guard); // make a c++ id std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1529,7 +1530,7 @@ namespace CXX // Guard // - String guard (guard_expr.merge (guard_prefix + ixx_name)); + String guard (guard_expr.replace (guard_prefix + ixx_name)); guard = ctx.escape (guard); // make a c++ id std::transform (guard.begin (), guard.end(), guard.begin (), upcase); @@ -1765,18 +1766,18 @@ namespace CXX throw Failed (); } - catch (BackendElements::Regex::Format const& e) + catch (cutl::re::format const& e) { wcerr << "error: invalid regex: '" << - e.expression ().c_str () << "': " << + e.regex ().c_str () << "': " << e.description ().c_str () << endl; throw Failed (); } - catch (BackendElements::Regex::Format const& e) + catch (cutl::re::wformat const& e) { wcerr << "error: invalid regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } diff --git a/xsd/cxx/tree/name-processor.cxx b/xsd/cxx/tree/name-processor.cxx index b731b82..ad1720f 100644 --- a/xsd/cxx/tree/name-processor.cxx +++ b/xsd/cxx/tree/name-processor.cxx @@ -6,12 +6,12 @@ #include #include +#include + #include #include #include -#include - #include #include @@ -288,9 +288,17 @@ namespace CXX } public: - typedef BackendElements::Regex::Expression Regex; - typedef BackendElements::Regex::Format RegexFormat; - typedef Cult::Containers::Vector RegexVector; + typedef cutl::re::wregexsub Regex; + typedef cutl::re::wformat RegexFormat; + + struct RegexVector: Cult::Containers::Vector + { + void + push_back (String const& r) + { + Cult::Containers::Vector::push_back (Regex (r)); + } + }; String process_regex (String const& name, @@ -306,11 +314,11 @@ namespace CXX i != rv.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (name)) { - String r (i->merge (name)); + String r (i->replace (name)); if (trace) os << "'" << r << "' : +" << endl; @@ -340,11 +348,11 @@ namespace CXX i != primary.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (name)) { - String r (i->merge (name)); + String r (i->replace (name)); if (trace) os << "'" << r << "' : +" << endl; @@ -360,11 +368,11 @@ namespace CXX i != backup.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (name)) { - String r (i->merge (name)); + String r (i->replace (name)); if (trace) os << "'" << r << "' : +" << endl; @@ -395,11 +403,11 @@ namespace CXX i != rv.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (s)) { - String r (i->merge (s)); + String r (i->replace (s)); if (trace) os << "'" << r << "' : +" << endl; @@ -431,11 +439,11 @@ namespace CXX i != primary.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (s)) { - String r (i->merge (s)); + String r (i->replace (s)); if (trace) os << "'" << r << "' : +" << endl; @@ -451,11 +459,11 @@ namespace CXX i != backup.rend (); ++i) { if (trace) - os << "try: '" << i->pattern () << "' : "; + os << "try: '" << i->regex () << "' : "; if (i->match (s)) { - String r (i->merge (s)); + String r (i->replace (s)); if (trace) os << "'" << r << "' : +" << endl; @@ -503,12 +511,12 @@ namespace CXX { try { - rv.push_back (Regex (*i)); + rv.push_back (*i); } catch (RegexFormat const& e) { os << "error: invalid " << id << " name regex: '" << - e.expression () << "': " << e.description () << endl; + e.regex () << "': " << e.description ().c_str () << endl; throw Failed (); } diff --git a/xsd/cxx/tree/tree-forward.cxx b/xsd/cxx/tree/tree-forward.cxx index 2c6ad1b..7ec6155 100644 --- a/xsd/cxx/tree/tree-forward.cxx +++ b/xsd/cxx/tree/tree-forward.cxx @@ -145,7 +145,7 @@ namespace CXX // if (xml_schema) { - String name (ctx.hxx_expr->merge (xml_schema)); + String name (ctx.hxx_expr->replace (xml_schema)); ctx.os << "#include " << ctx.process_include_path (name) << endl << endl; -- cgit v1.1