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-insertion-source.cxx | |
parent | eaf34adcbd8095bc6d1f3371b1227f654c7b19fc (diff) |
New upstream release
Diffstat (limited to 'xsd/xsd/cxx/tree/stream-insertion-source.cxx')
-rw-r--r-- | xsd/xsd/cxx/tree/stream-insertion-source.cxx | 173 |
1 files changed, 108 insertions, 65 deletions
diff --git a/xsd/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/xsd/cxx/tree/stream-insertion-source.cxx index 09faf71..2c82cfd 100644 --- a/xsd/xsd/cxx/tree/stream-insertion-source.cxx +++ b/xsd/xsd/cxx/tree/stream-insertion-source.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-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-insertion-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_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type ("::xsd::cxx::tree::ostream< " + *i + " >"); @@ -60,7 +58,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. // @@ -68,8 +68,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_insertion_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_insertion_init_" << n++ << " (" << endl << strlit (l.name ()) << "," << endl @@ -100,7 +100,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -113,9 +113,10 @@ namespace CXX String const& base (xs_string_type); - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type ("::xsd::cxx::tree::ostream< " + *i + " >"); @@ -128,7 +129,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. // @@ -136,8 +139,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_insertion_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_insertion_init_" << n++ << " (" << endl << strlit (u.name ()) << "," << endl @@ -157,7 +160,7 @@ namespace CXX inherits_base_ >> base_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -168,26 +171,57 @@ namespace CXX if (renamed_type (e, name) && !name) return; - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + bool string_based (false); + { + IsStringBasedType t (string_based); + t.dispatch (e); + } + + 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_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type ("::xsd::cxx::tree::ostream< " + *i + " >"); os << stream_type << "&" << endl << "operator<< (" << stream_type << "& s," << endl << "const " << name << "& x)" - << "{" - << "return s << static_cast< const "; + << "{"; - inherits (e, inherits_base_); + if (!string_based || enum_based) + { + os << "return s << static_cast< const "; + inherits (e, inherits_base_); + os << "& > (x);"; + } + else + { + os << name << "::" << value << " v (x);" + << "return s << static_cast< unsigned int > (v);"; + } - os << "& > (x);" - << "}"; + os << "}"; // 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. // @@ -195,8 +229,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_insertion_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_insertion_init_" << n++ << " (" << endl << strlit (e.name ()) << "," << endl @@ -218,7 +252,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) return; @@ -233,7 +267,7 @@ 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)); if (max (e) != 1) { @@ -257,8 +291,9 @@ namespace CXX << "if (!d)" << endl << "s << *i;" << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< 0, " << - stream << ", " << char_type << " > ().insert (s, *i);"; + << "::xsd::cxx::tree::stream_insertion_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().insert (s, *i);"; } else os << "s << *i;"; @@ -284,8 +319,9 @@ namespace CXX << "if (!d)" << endl << "s << i;" << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< 0, " << - stream << ", " << char_type << " > ().insert (s, i);" + << "::xsd::cxx::tree::stream_insertion_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().insert (s, i);" << "}"; } else @@ -307,8 +343,9 @@ namespace CXX << "if (!d)" << endl << "s << i;" << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< 0, " << - stream << ", " << char_type << " > ().insert (s, i);" + << "::xsd::cxx::tree::stream_insertion_map_instance< " << + poly_plate << ", " << stream << ", " << char_type << + " > ().insert (s, i);" << "}"; } else @@ -328,7 +365,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& aname (eaname (a)); @@ -358,7 +395,7 @@ namespace CXX inherits_ >> base_; } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -369,11 +406,12 @@ namespace CXX if (renamed_type (c, name) && !name) return; - Boolean has_body (has<Traversal::Member> (c) || c.inherits_p ()); + bool has_body (has<Traversal::Member> (c) || c.inherits_p ()); - UnsignedLong n (0); - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + size_t n (0); + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type ("::xsd::cxx::tree::ostream< " + *i + " >"); @@ -408,7 +446,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. // @@ -416,8 +456,8 @@ namespace CXX os << "static" << endl << "const ::xsd::cxx::tree::stream_insertion_initializer< " << - "0, " << i->c_str () << ", " << - char_type << ", " << name << " >" << endl + poly_plate << ", " << i->c_str () << ", " << char_type << + ", " << name << " >" << endl << "_xsd_" << name << "_stream_insertion_init_" << n++ << " (" << endl << strlit (c.name ()) << "," << endl @@ -433,18 +473,18 @@ namespace CXX }; } - Void + void generate_stream_insertion_source (Context& ctx) { if (ctx.polymorphic) { - Streams const& st (ctx.options.value<CLI::generate_insertion> ()); + NarrowStrings const& st (ctx.options.generate_insertion ()); ctx.os << "#include <xsd/cxx/tree/stream-insertion-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) { @@ -457,7 +497,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); @@ -465,22 +506,22 @@ namespace CXX if (export_maps) ctx.os << "template struct __declspec (dllexport) " << - "stream_insertion_plate< 0, " << stream << ", " << - ctx.char_type << " >;"; + "stream_insertion_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;"; if (import_maps) ctx.os << "template struct __declspec (dllimport) " << - "stream_insertion_plate< 0, " << stream << ", " << - ctx.char_type << " >;"; + "stream_insertion_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;"; ctx.os << "#elif defined(__GNUC__) && __GNUC__ >= 4" << endl << "template struct __attribute__ ((visibility(\"default\"))) " << - "stream_insertion_plate< 0, " << stream << ", " << - ctx.char_type << " >;" + "stream_insertion_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;" << "#elif defined(XSD_MAP_VISIBILITY)" << endl << "template struct XSD_MAP_VISIBILITY " << - "stream_insertion_plate< 0, " << stream << ", " << - ctx.char_type << " >;" + "stream_insertion_plate< " << ctx.poly_plate << ", " << + stream << ", " << ctx.char_type << " >;" << "#endif" << endl; } @@ -494,14 +535,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_insertion_plate< 0, " << - stream << ", " << ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::stream_insertion_plate< " << + ctx.poly_plate << ", " << stream << ", " << ctx.char_type << + " >" << endl << "stream_insertion_plate_init_" << n++ << ";"; } @@ -510,7 +553,7 @@ namespace CXX Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); |