diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:21:29 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-07-23 15:21:29 +0200 |
commit | bada6666c70977a058755ccf232e7d67b24adeed (patch) | |
tree | 1e92d50cebce96abaf9bce19e36026c47f77b9ba /xsd/xsd/cxx/tree/stream-extraction-source.cxx | |
parent | eaf34adcbd8095bc6d1f3371b1227f654c7b19fc (diff) |
New upstream release
Diffstat (limited to 'xsd/xsd/cxx/tree/stream-extraction-source.cxx')
-rw-r--r-- | xsd/xsd/cxx/tree/stream-extraction-source.cxx | 231 |
1 files changed, 138 insertions, 93 deletions
diff --git a/xsd/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/xsd/cxx/tree/stream-extraction-source.cxx index 1378bc6..ceb56c1 100644 --- a/xsd/xsd/cxx/tree/stream-extraction-source.cxx +++ b/xsd/xsd/cxx/tree/stream-extraction-source.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-extraction-source.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <cxx/tree/stream-extraction-source.hxx> @@ -14,8 +13,6 @@ namespace CXX { namespace { - typedef Containers::Vector<NarrowString> Streams; - struct List: Traversal::List, Context { List (Context& c) @@ -23,7 +20,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -45,9 +42,10 @@ namespace CXX base += L" >"; - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); + i != st.end (); ++i) { os << name << "::" << endl << name << " (" << istream_type << "< " << @@ -61,7 +59,9 @@ namespace CXX // Register with type map. // - if (polymorphic && polymorphic_p (l) && !anonymous_p (l)) + if (polymorphic && + polymorphic_p (l) && + (!anonymous_p (l) || anonymous_substitutes_p (l))) { // Note that we are using the original type name. // @@ -69,8 +69,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_extraction_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_extraction_init_" << n++ << " (" << endl << strlit (l.name ()) << "," << endl @@ -101,7 +101,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -114,9 +114,10 @@ namespace CXX String const& base (xs_string_type); - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { os << name << "::" << endl << name << " (" << istream_type << "< " << @@ -129,7 +130,9 @@ namespace CXX // Register with type map. // - if (polymorphic && polymorphic_p (u) && !anonymous_p (u)) + if (polymorphic && + polymorphic_p (u) && + (!anonymous_p (u) || anonymous_substitutes_p (u))) { // Note that we are using the original type name. // @@ -137,8 +140,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_extraction_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_extraction_init_" << n++ << " (" << endl << strlit (u.name ()) << "," << endl @@ -158,7 +161,7 @@ namespace CXX inherits_base_ >> base_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -169,15 +172,30 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + bool enum_based (false); + if (string_based) + { + SemanticGraph::Enumeration* base_enum (0); + IsEnumBasedType t (base_enum); + t.dispatch (e); + + enum_based = (base_enum != 0); + } + + String value; + if (string_based) + value = evalue (e); + + size_t n (0); + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { os << name << "::" << endl << name << " (" << istream_type << "< " << @@ -188,8 +206,18 @@ namespace CXX inherits (e, inherits_base_); - os << " (s, f, c)" - << "{"; + if (string_based && !enum_based) + { + // Use copy c-tor to pass the flags and container. + // + os << " (" << endl; + inherits (e, inherits_base_); + os << " (_xsd_" << name << "_literals_[s.read_uint ()]), f, c)"; + } + else + os << " (s, f, c)"; + + os << "{"; if (string_based) os << "_xsd_" << name << "_convert ();"; @@ -198,7 +226,9 @@ namespace CXX // Register with type map. // - if (polymorphic && polymorphic_p (e) && !anonymous_p (e)) + if (polymorphic && + polymorphic_p (e) && + (!anonymous_p (e) || anonymous_substitutes_p (e))) { // Note that we are using the original type name. // @@ -206,8 +236,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_extraction_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_extraction_init_" << n++ << " (" << endl << strlit (e.name ()) << "," << endl @@ -229,14 +259,14 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Member& m) { if (skip (m)) return; os << "," << endl - << " " << emember (m) << " (f, this)"; + << " " << emember (m) << " (this)"; } }; @@ -249,7 +279,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -261,7 +291,7 @@ namespace CXX << " " << member << " (this->" << dom_doc << " ())"; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& member (emember (a)); @@ -281,7 +311,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) @@ -291,8 +321,9 @@ namespace CXX SemanticGraph::Type& t (e.type ()); String type (etype (e)); + String tr (etraits (e)); // traits type name - Boolean fund (false); + bool fund (false); { IsFundamentalType traverser (fund); traverser.dispatch (t); @@ -304,7 +335,12 @@ namespace CXX // from which makes it impossible to substitute or dynamically- // type with xsi:type. // - Boolean poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + + char const* r ( + (poly || !fund) && std >= cxx_version::cxx11 + ? "::std::move (r)" + : "r"); if (max (e) != 1) { @@ -327,16 +363,17 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "::xsd::cxx::tree::stream_extraction_map_instance< 0, " << - stream << ", " << char_type << " > ().extract (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::stream_extraction_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().extract (" << endl << "s, f, this));" << "r.reset (dynamic_cast< " << type << "* > (tmp.get ()));" << "if (r.get ())" << endl @@ -353,11 +390,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));"; + os << auto_ptr << "< " << type << " > r (" << endl + << tr << "::create (s, f, this));"; } - os << "c.push_back (r);" + os << "c.push_back (" << r << ");" << "}" // while << "}" // if << "}"; @@ -375,16 +412,17 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "::xsd::cxx::tree::stream_extraction_map_instance< 0, " << - stream << ", " << char_type << " > ().extract (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::stream_extraction_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().extract (" << endl << "s, f, this));" << "r.reset (dynamic_cast< " << type << "* > (tmp.get ()));" << "if (r.get ())" << endl @@ -401,11 +439,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));"; + os << auto_ptr << "< " << type << " > r (" << endl + << tr << "::create (s, f, this));"; } - os << "this->" << member << ".set (r);" + os << "this->" << member << ".set (" << r << ");" << "}" // if (p) << "}"; } @@ -418,16 +456,17 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "::xsd::cxx::tree::stream_extraction_map_instance< 0, " << - stream << ", " << char_type << " > ().extract (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::stream_extraction_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().extract (" << endl << "s, f, this));" << "r.reset (dynamic_cast< " << type << "* > (tmp.get ()));" << "if (r.get ())" << endl @@ -444,11 +483,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));"; + os << auto_ptr << "< " << type << " > r (" << endl + << tr << "::create (s, f, this));"; } - os << "this->" << member << ".set (r);" + os << "this->" << member << ".set (" << r << ");" << "}"; } } @@ -464,13 +503,14 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& member (emember (a)); String type (etype (a)); + String tr (etraits (a)); // traits type name - Boolean fund (false); + bool fund (false); { IsFundamentalType traverser (fund); traverser.dispatch (a.type ()); @@ -492,9 +532,8 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));" - << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << tr << + "::create (s, f, this));"; } os << "}" // if (p) @@ -512,9 +551,8 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));" - << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << tr << + "::create (s, f, this));"; } os << "}"; @@ -530,11 +568,11 @@ namespace CXX inherits_ >> base_; names_ctor_member_ >> ctor_member_; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names_ctor_member_ >> ctor_any_; } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -545,9 +583,9 @@ namespace CXX if (renamed_type (c, name) && !name) return; - Boolean has_members (has<Traversal::Member> (c)); + bool has_members (has<Traversal::Member> (c)); - Boolean facets (false); + bool facets (false); if (c.inherits_p ()) { // See if we have any facets that we need to handle. @@ -565,9 +603,10 @@ namespace CXX } } - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { os << name << "::" << endl @@ -613,7 +652,8 @@ namespace CXX << unclash (name, "parse") << " (" << istream_type << "< " << i->c_str () << " >& s," << endl << flags_type << " f)" - << "{"; + << "{" + << "XSD_UNUSED (f);"; // Can be unused. { Element element (*this, *i); Attribute attribute (*this); @@ -631,7 +671,9 @@ namespace CXX // Register with type map. // - if (polymorphic && polymorphic_p (c) && !anonymous_p (c)) + if (polymorphic && + polymorphic_p (c) && + (!anonymous_p (c) || anonymous_substitutes_p (c))) { // Note that we are using the original type name. // @@ -639,8 +681,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_extraction_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_extraction_init_" << n++ << " (" << endl << strlit (c.name ()) << "," << endl @@ -661,18 +703,18 @@ namespace CXX }; } - Void + void generate_stream_extraction_source (Context& ctx) { if (ctx.polymorphic) { - Streams const& st (ctx.options.value<CLI::generate_extraction> ()); + NarrowStrings const& st (ctx.options.generate_extraction ()); ctx.os << "#include <xsd/cxx/tree/stream-extraction-map.hxx>" << endl << endl; - Boolean import_maps (ctx.options.value<CLI::import_maps> ()); - Boolean export_maps (ctx.options.value<CLI::export_maps> ()); + bool import_maps (ctx.options.import_maps ()); + bool export_maps (ctx.options.export_maps ()); if (import_maps || export_maps) { @@ -685,7 +727,8 @@ namespace CXX << "namespace tree" << "{"; - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream (*i); @@ -693,22 +736,22 @@ namespace CXX if (export_maps) ctx.os << "template struct __declspec (dllexport) " << - "stream_extraction_plate< 0, " << stream << ", " << - ctx.char_type << " >;"; + "stream_extraction_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;"; if (import_maps) ctx.os << "template struct __declspec (dllimport) " << - "stream_extraction_plate< 0, " << stream << ", " << - ctx.char_type << " >;"; + "stream_extraction_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;"; ctx.os << "#elif defined(__GNUC__) && __GNUC__ >= 4" << endl << "template struct __attribute__ ((visibility(\"default\"))) " << - "stream_extraction_plate< 0, " << stream << ", " << - ctx.char_type << " >;" + "stream_extraction_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;" << "#elif defined(XSD_MAP_VISIBILITY)" << endl << "template struct XSD_MAP_VISIBILITY " << - "stream_extraction_plate< 0, " << stream << ", " << - ctx.char_type << " >;" + "stream_extraction_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;" << "#endif" << endl; } @@ -723,14 +766,16 @@ namespace CXX ctx.os << "namespace _xsd" << "{"; - UnsignedLong n (0); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream (*i); ctx.os << "static" << endl - << "const ::xsd::cxx::tree::stream_extraction_plate< 0, " << - stream << ", " << ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::stream_extraction_plate< " << + ctx.poly_plate << ", " << stream << ", " << ctx.char_type << + " >" << endl << "stream_extraction_plate_init_" << n++ << ";"; } @@ -739,7 +784,7 @@ namespace CXX Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); |