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 | |
parent | eaf34adcbd8095bc6d1f3371b1227f654c7b19fc (diff) |
New upstream release
Diffstat (limited to 'xsd/xsd/cxx/tree')
48 files changed, 6914 insertions, 3539 deletions
diff --git a/xsd/xsd/cxx/tree/cli.hxx b/xsd/xsd/cxx/tree/cli.hxx deleted file mode 100644 index 171711d..0000000 --- a/xsd/xsd/cxx/tree/cli.hxx +++ /dev/null @@ -1,228 +0,0 @@ -// file : xsd/cxx/tree/cli.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC -// license : GNU GPL v2 + exceptions; see accompanying LICENSE file - -#ifndef CXX_TREE_CLI_HXX -#define CXX_TREE_CLI_HXX - -#include <cult/types.hxx> - -#include <cult/containers/vector.hxx> - -#include <cult/cli/options.hxx> -#include <cult/cli/options-spec.hxx> - -namespace CXX -{ - namespace Tree - { - namespace CLI - { - using namespace Cult::Types; - - typedef Char const Key[]; - - extern Key char_type; - extern Key char_encoding; - extern Key output_dir; - extern Key generate_polymorphic; - extern Key polymorphic_type; - extern Key polymorphic_type_all; - extern Key generate_serialization; - extern Key generate_inline; - extern Key generate_ostream; - extern Key generate_doxygen; - extern Key generate_comparison; - extern Key generate_default_ctor; - extern Key generate_from_base_ctor; - extern Key generate_detach; - extern Key generate_wildcard; - extern Key generate_insertion; - extern Key generate_extraction; - extern Key generate_forward; - extern Key generate_xml_schema; - extern Key extern_xml_schema; - extern Key suppress_parsing; - extern Key generate_element_type; - extern Key generate_element_map; - extern Key generate_intellisense; - extern Key omit_default_attributes; - extern Key namespace_map; - extern Key namespace_regex; - extern Key namespace_regex_trace; - extern Key reserved_name; - extern Key type_naming; - extern Key function_naming; - extern Key type_regex; - extern Key accessor_regex; - extern Key one_accessor_regex; - extern Key opt_accessor_regex; - extern Key seq_accessor_regex; - extern Key modifier_regex; - extern Key one_modifier_regex; - extern Key opt_modifier_regex; - extern Key seq_modifier_regex; - extern Key parser_regex; - extern Key serializer_regex; - extern Key enumerator_regex; - extern Key element_type_regex; - extern Key name_regex_trace; - extern Key include_with_brackets; - extern Key include_prefix; - extern Key include_regex; - extern Key include_regex_trace; - extern Key guard_prefix; - extern Key root_element_first; - extern Key root_element_last; - extern Key root_element_all; - extern Key root_element_none; - extern Key root_element; - extern Key custom_type; - extern Key custom_type_regex; - extern Key hxx_suffix; - extern Key ixx_suffix; - extern Key cxx_suffix; - extern Key fwd_suffix; - extern Key hxx_regex; - extern Key ixx_regex; - extern Key cxx_regex; - extern Key fwd_regex; - extern Key hxx_prologue; - extern Key ixx_prologue; - extern Key cxx_prologue; - extern Key fwd_prologue; - extern Key prologue; - extern Key hxx_epilogue; - extern Key ixx_epilogue; - extern Key cxx_epilogue; - extern Key fwd_epilogue; - extern Key epilogue; - extern Key hxx_prologue_file; - extern Key ixx_prologue_file; - extern Key cxx_prologue_file; - extern Key fwd_prologue_file; - extern Key prologue_file; - extern Key hxx_epilogue_file; - extern Key ixx_epilogue_file; - extern Key cxx_epilogue_file; - extern Key fwd_epilogue_file; - extern Key epilogue_file; - extern Key parts; - extern Key parts_suffix; - extern Key export_symbol; - extern Key export_xml_schema; - extern Key export_maps; - extern Key import_maps; - extern Key show_anonymous; - extern Key show_sloc; - extern Key proprietary_license; - extern Key disable_multi_import; // Undocumented. - - - typedef Cult::CLI::Options< - - char_type, NarrowString, - char_encoding, NarrowString, - output_dir, NarrowString, - generate_polymorphic, Boolean, - polymorphic_type, Cult::Containers::Vector<NarrowString>, - polymorphic_type_all, Boolean, - generate_serialization, Boolean, - generate_inline, Boolean, - generate_ostream, Boolean, - generate_doxygen, Boolean, - generate_comparison, Boolean, - generate_default_ctor, Boolean, - generate_from_base_ctor, Boolean, - generate_detach, Boolean, - generate_wildcard, Boolean, - generate_insertion, Cult::Containers::Vector<NarrowString>, - generate_extraction, Cult::Containers::Vector<NarrowString>, - generate_forward, Boolean, - generate_xml_schema, Boolean, - extern_xml_schema, NarrowString, - suppress_parsing, Boolean, - generate_element_type, Boolean, - generate_element_map, Boolean, - generate_intellisense, Boolean, - omit_default_attributes, Boolean, - namespace_map, Cult::Containers::Vector<NarrowString>, - namespace_regex, Cult::Containers::Vector<NarrowString>, - namespace_regex_trace, Boolean, - reserved_name, Cult::Containers::Vector<NarrowString>, - type_naming, NarrowString, - function_naming, NarrowString, - type_regex, Cult::Containers::Vector<NarrowString>, - accessor_regex, Cult::Containers::Vector<NarrowString>, - one_accessor_regex, Cult::Containers::Vector<NarrowString>, - opt_accessor_regex, Cult::Containers::Vector<NarrowString>, - seq_accessor_regex, Cult::Containers::Vector<NarrowString>, - modifier_regex, Cult::Containers::Vector<NarrowString>, - one_modifier_regex, Cult::Containers::Vector<NarrowString>, - opt_modifier_regex, Cult::Containers::Vector<NarrowString>, - seq_modifier_regex, Cult::Containers::Vector<NarrowString>, - parser_regex, Cult::Containers::Vector<NarrowString>, - serializer_regex, Cult::Containers::Vector<NarrowString>, - enumerator_regex, Cult::Containers::Vector<NarrowString>, - element_type_regex, Cult::Containers::Vector<NarrowString>, - name_regex_trace, Boolean, - include_with_brackets, Boolean, - include_prefix, NarrowString, - include_regex, Cult::Containers::Vector<NarrowString>, - include_regex_trace, Boolean, - guard_prefix, NarrowString, - root_element_first, Boolean, - root_element_last, Boolean, - root_element_all, Boolean, - root_element_none, Boolean, - root_element, Cult::Containers::Vector<NarrowString>, - custom_type, Cult::Containers::Vector<NarrowString>, - custom_type_regex, Cult::Containers::Vector<NarrowString>, - hxx_suffix, NarrowString, - ixx_suffix, NarrowString, - cxx_suffix, NarrowString, - fwd_suffix, NarrowString, - hxx_regex, NarrowString, - ixx_regex, NarrowString, - cxx_regex, NarrowString, - fwd_regex, NarrowString, - hxx_prologue, Cult::Containers::Vector<NarrowString>, - ixx_prologue, Cult::Containers::Vector<NarrowString>, - cxx_prologue, Cult::Containers::Vector<NarrowString>, - fwd_prologue, Cult::Containers::Vector<NarrowString>, - prologue, Cult::Containers::Vector<NarrowString>, - hxx_epilogue, Cult::Containers::Vector<NarrowString>, - ixx_epilogue, Cult::Containers::Vector<NarrowString>, - cxx_epilogue, Cult::Containers::Vector<NarrowString>, - fwd_epilogue, Cult::Containers::Vector<NarrowString>, - epilogue, Cult::Containers::Vector<NarrowString>, - hxx_prologue_file, NarrowString, - ixx_prologue_file, NarrowString, - cxx_prologue_file, NarrowString, - fwd_prologue_file, NarrowString, - prologue_file, NarrowString, - hxx_epilogue_file, NarrowString, - ixx_epilogue_file, NarrowString, - cxx_epilogue_file, NarrowString, - fwd_epilogue_file, NarrowString, - epilogue_file, NarrowString, - parts, UnsignedLong, - parts_suffix, NarrowString, - export_symbol, NarrowString, - export_xml_schema, Boolean, - export_maps, Boolean, - import_maps, Boolean, - show_anonymous, Boolean, - show_sloc, Boolean, - proprietary_license, Boolean, - disable_multi_import, Boolean - - > Options; - - struct OptionsSpec: Cult::CLI::OptionsSpec<Options> {}; - } - } -} - -#endif // CXX_TREE_CLI_HXX diff --git a/xsd/xsd/cxx/tree/counter.cxx b/xsd/xsd/cxx/tree/counter.cxx index 9254226..23fc221 100644 --- a/xsd/xsd/cxx/tree/counter.cxx +++ b/xsd/xsd/cxx/tree/counter.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/counter.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <cxx/tree/counter.hxx> @@ -15,40 +14,40 @@ namespace CXX { struct Member: Traversal::Member { - Member (UnsignedLong& complexity) + Member (size_t& complexity) : complexity_ (complexity) { } - virtual Void + virtual void traverse (Type&) { complexity_++; } - UnsignedLong& complexity_; + size_t& complexity_; }; struct Any: Traversal::Any, Traversal::AnyAttribute { - Any (UnsignedLong& complexity) + Any (size_t& complexity) : complexity_ (complexity) { } - virtual Void + virtual void traverse (SemanticGraph::Any&) { complexity_++; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute&) { complexity_++; } - UnsignedLong& complexity_; + size_t& complexity_; }; struct TypeBase: Traversal::List, @@ -57,27 +56,27 @@ namespace CXX Traversal::Complex, Context { - TypeBase (Context& c, UnsignedLong& complexity) + TypeBase (Context& c, size_t& complexity) : Context (c), complexity_ (complexity) { } - virtual Void + virtual void traverse (SemanticGraph::List&) { complexity_++; } - virtual Void + virtual void traverse (SemanticGraph::Union&) { complexity_++; } - virtual Void + virtual void traverse (SemanticGraph::Enumeration& e) { - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); @@ -86,7 +85,7 @@ namespace CXX complexity_ += (string_based ? 1 : 2); } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { complexity_++; // One for the type itself. @@ -99,14 +98,14 @@ namespace CXX names >> member; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names >> any; Complex::names (c, names); } private: - UnsignedLong& complexity_; + size_t& complexity_; }; @@ -120,12 +119,12 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { counts_.global_types++; - UnsignedLong complexity (0); + size_t complexity (0); TypeBase type (*this, complexity); type.dispatch (t); @@ -160,7 +159,7 @@ namespace CXX } } - virtual Void + virtual void traverse (Type& e) { // Check if the previous element we saw needs to be generated. @@ -177,33 +176,33 @@ namespace CXX } private: - Void + void count_last () { if (generate_p (*last_)) { counts_.generated_global_elements++; - UnsignedLong complexity (0); + size_t complexity (0); if (doc_root_p (*last_)) { - if (options.value<CLI::generate_element_type> ()) + if (options.generate_element_type ()) { complexity += 1; // For c-tors and d-tor. - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) complexity += 1; - if (options.value<CLI::generate_serialization> ()) + if (options.generate_serialization ()) complexity += 1; } else { - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) complexity += 6; // 13 parsing functions. - if (options.value<CLI::generate_serialization> ()) + if (options.generate_serialization ()) complexity += 4; // 8 serialization functions. } } @@ -230,21 +229,16 @@ namespace CXX }; } - Counter:: - Counter () - { - } - Counts Counter:: - count (CLI::Options const& options, + count (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& path) { Counts counts; - Context ctx (std::wcerr, tu, path, options, counts, false, 0, 0, 0, 0); + Context ctx (std::wcerr, tu, path, ops, counts, false, 0, 0, 0, 0); Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; diff --git a/xsd/xsd/cxx/tree/counter.hxx b/xsd/xsd/cxx/tree/counter.hxx index 726de47..ea1a3c3 100644 --- a/xsd/xsd/cxx/tree/counter.hxx +++ b/xsd/xsd/cxx/tree/counter.hxx @@ -1,13 +1,12 @@ // file : xsd/cxx/tree/counter.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef CXX_TREE_COUNTER_HXX #define CXX_TREE_COUNTER_HXX #include <cxx/tree/elements.hxx> -#include <cxx/tree/cli.hxx> +#include <cxx/tree/options.hxx> namespace CXX { @@ -16,10 +15,8 @@ namespace CXX class Counter { public: - Counter (); // Dummy ctor, helps with long symbols on HP-UX. - Counts - count (CLI::Options const&, + count (options const&, SemanticGraph::Schema&, SemanticGraph::Path const&); }; diff --git a/xsd/xsd/cxx/tree/default-value.cxx b/xsd/xsd/cxx/tree/default-value.cxx index ff964d3..4f27d7f 100644 --- a/xsd/xsd/cxx/tree/default-value.cxx +++ b/xsd/xsd/cxx/tree/default-value.cxx @@ -1,11 +1,11 @@ // file : xsd/cxx/tree/default-value.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/default-value.hxx> using std::hex; +using std::dec; namespace CXX { @@ -13,14 +13,14 @@ namespace CXX { namespace { - Void + void normalize (String& s) { - Size n (s.size ()); + size_t n (s.size ()); - for (Size i (0); i < n; ++i) + for (size_t i (0); i < n; ++i) { - WideChar& c (s[i]); + wchar_t& c (s[i]); if (c == 0x0D || // carriage return c == 0x09 || // tab @@ -29,15 +29,15 @@ namespace CXX } } - Void + void collapse (String& s) { - Size n (s.size ()), j (0); - Boolean subs (false), trim (true); + size_t n (s.size ()), j (0); + bool subs (false), trim (true); - for (Size i (0); i < n; ++i) + for (size_t i (0); i < n; ++i) { - WideChar c (s[i]); + wchar_t c (s[i]); if (c == 0x20 || c == 0x09 || c == 0x0A) subs = true; @@ -61,21 +61,21 @@ namespace CXX s.resize (j); } - Void + void strip_zeros (String& s) { - Size n (s.size ()), i (0); + size_t n (s.size ()), i (0); if (n > 0 && (s[i] == '-' || s[i] == '+')) i++; - Size j (i); + size_t j (i); - Boolean strip (true); + bool strip (true); for (; i < n; ++i) { - WideChar c (s[i]); + wchar_t c (s[i]); if (c == '0') { @@ -97,7 +97,7 @@ namespace CXX s.resize (j); } - Void + void make_float (String& s) { if (s.find ('.') == String::npos && @@ -112,13 +112,13 @@ namespace CXX // IsLiteralValue:: - IsLiteralValue (Boolean& r) + IsLiteralValue (bool& r) : IsFundamentalType (r) { *this >> inherits_ >> *this; } - Void IsLiteralValue:: + void IsLiteralValue:: traverse (SemanticGraph::Complex& c) { inherits (c); @@ -144,7 +144,7 @@ namespace CXX return literal_; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Complex& c) { inherits (c); @@ -152,7 +152,7 @@ namespace CXX // Boolean. // - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Boolean&) { collapse (value_); @@ -161,7 +161,7 @@ namespace CXX // Integral types. // - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Byte&) { collapse (value_); @@ -169,15 +169,15 @@ namespace CXX literal_ = value_; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::UnsignedByte&) { collapse (value_); strip_zeros (value_); - literal_ = value_; + literal_ = value_ + L"U"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Short&) { collapse (value_); @@ -185,15 +185,15 @@ namespace CXX literal_ = value_; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::UnsignedShort&) { collapse (value_); strip_zeros (value_); - literal_ = value_; + literal_ = value_ + L"U"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Int&) { collapse (value_); @@ -201,15 +201,15 @@ namespace CXX literal_ = value_; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::UnsignedInt&) { collapse (value_); strip_zeros (value_); - literal_ = value_; + literal_ = value_ + L"U"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Long&) { collapse (value_); @@ -218,7 +218,7 @@ namespace CXX literal_ += L"LL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::UnsignedLong&) { collapse (value_); @@ -227,7 +227,7 @@ namespace CXX literal_ += L"ULL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Integer&) { collapse (value_); @@ -235,7 +235,7 @@ namespace CXX literal_ = value_ + L"LL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::NonPositiveInteger&) { collapse (value_); @@ -243,7 +243,7 @@ namespace CXX literal_ = value_ + L"LL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::NonNegativeInteger&) { collapse (value_); @@ -251,7 +251,7 @@ namespace CXX literal_ = value_ + L"ULL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::PositiveInteger&) { collapse (value_); @@ -259,7 +259,7 @@ namespace CXX literal_ = value_ + L"ULL"; } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::NegativeInteger&) { collapse (value_); @@ -269,7 +269,7 @@ namespace CXX // Floats. // - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Float& t) { collapse (value_); @@ -297,7 +297,7 @@ namespace CXX } } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Double& t) { collapse (value_); @@ -325,7 +325,7 @@ namespace CXX } } - Void LiteralValue:: + void LiteralValue:: traverse (SemanticGraph::Fundamental::Decimal&) { collapse (value_); @@ -345,43 +345,43 @@ namespace CXX *this >> inherits_ >> *this; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::List&) { r_ = function; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Complex& c) { inherits (c); } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Fundamental::Base64Binary&) { r_ = data; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Fundamental::HexBinary&) { r_ = data; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Fundamental::NameTokens&) { r_ = function; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Fundamental::IdRefs&) { r_ = function; } - Void InitKind:: + void InitKind:: traverse (SemanticGraph::Fundamental::Entities&) { r_ = function; @@ -397,14 +397,14 @@ namespace CXX { } - Void InitValue:: + void InitValue:: dispatch (SemanticGraph::Node& type, String const& value) { value_ = value; Traversal::NodeBase::dispatch (type); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::List& l) { collapse (value_); @@ -415,9 +415,9 @@ namespace CXX SemanticGraph::Type& t (l.argumented ().type ()); String ov (value_); - Size b (0); + size_t b (0); - for (Size e (ov.find (' ')); ; e = ov.find (' ', b)) + for (size_t e (ov.find (' ')); ; e = ov.find (' ', b)) { String v (ov, b, e != String::npos ? e - b : e); @@ -448,21 +448,27 @@ namespace CXX value_ = ov; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Union&) { os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Complex& c) { Traversal::NodeBase::dispatch (ultimate_base (c)); } - // anySimpleType. + // anyType & anySimpleType. // - Void InitValue:: + void InitValue:: + traverse (SemanticGraph::AnyType& t) + { + os << fq_name (t) << " (" << strlit (value_) << ")"; + } + + void InitValue:: traverse (SemanticGraph::AnySimpleType& t) { os << fq_name (t) << " (" << strlit (value_) << ")"; @@ -470,34 +476,34 @@ namespace CXX // Strings. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::String&) { os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::NormalizedString&) { normalize (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Token&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::NameToken&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::NameTokens&) { string_sequence_type ( @@ -505,21 +511,21 @@ namespace CXX xs_ns ().find ("NMTOKEN").first->named ())); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Name&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::NCName&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Language&) { collapse (value_); @@ -528,10 +534,10 @@ namespace CXX // Qualified name. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::QName& t) { - Size p (value_.rfind ('#')); + size_t p (value_.rfind ('#')); if (p != String::npos) { @@ -563,21 +569,21 @@ namespace CXX // ID/IDREF. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Id&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::IdRef&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::IdRefs&) { string_sequence_type ( @@ -587,7 +593,7 @@ namespace CXX // URI. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::AnyURI&) { collapse (value_); @@ -615,7 +621,7 @@ namespace CXX return r; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Base64Binary& t) { collapse (value_); @@ -628,17 +634,17 @@ namespace CXX // Decode. // - Size size (value_.size ()); + size_t size (value_.size ()); // Remove all whitespaces. // { - Size j (0); - Boolean subs (false); + size_t j (0); + bool subs (false); - for (Size i (0); i < size; ++i) + for (size_t i (0); i < size; ++i) { - WideChar c (value_[i]); + wchar_t c (value_[i]); if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) subs = true; @@ -657,20 +663,20 @@ namespace CXX // Our length should be a multiple of four. // - Size quad_count (size / 4); + size_t quad_count (size / 4); // Source and destination indexes. // - Size si (0), di (0); + size_t si (0), di (0); // Process all quads except the last one. // unsigned short v; unsigned char b1, b2, b3, b4; - WideChar prev_fill (os.fill ('0')); + wchar_t prev_fill (os.fill ('0')); - for (Size q (0); q < quad_count - 1; ++q) + for (size_t q (0); q < quad_count - 1; ++q) { b1 = base64_decode (value_[si++]); b2 = base64_decode (value_[si++]); @@ -683,17 +689,21 @@ namespace CXX if (di % 9 == 0) os << endl; + os << hex; + v = static_cast<unsigned char> ((b1 << 2) | (b2 >> 4)); os.width (2); - os << "0x" << hex << v; + os << "0x" << v; v = static_cast<unsigned char> ((b2 << 4) | (b3 >> 2)); os.width (2); - os << ", 0x" << hex << v; + os << ", 0x" << v; v = static_cast<unsigned char> ((b3 << 6) | b4); os.width (2); - os << ", 0x" << hex << v; + os << ", 0x" << v; + + os << dec; di += 3; } @@ -703,7 +713,7 @@ namespace CXX b1 = base64_decode (value_[si++]); b2 = base64_decode (value_[si++]); - WideChar e3 (value_[si++]), e4 (value_[si++]); + wchar_t e3 (value_[si++]), e4 (value_[si++]); if (quad_count != 1) os << ", "; @@ -718,7 +728,7 @@ namespace CXX // Two pads. Last 4 bits in b2 should be zero. // v = static_cast<unsigned char> ((b1 << 2) | (b2 >> 4)); - os << "0x" << hex << v; + os << "0x" << hex << v << dec; di++; } else @@ -727,13 +737,17 @@ namespace CXX // b3 = base64_decode (e3); + os << hex; + v = static_cast<unsigned char> ((b1 << 2) | (b2 >> 4)); os.width (2); - os << "0x" << hex << v; + os << "0x" << v; v = static_cast<unsigned char> ((b2 << 4) | (b3 >> 2)); os.width (2); - os << ", 0x" << hex << v; + os << ", 0x" << v; + + os << dec; di += 2; } @@ -745,17 +759,21 @@ namespace CXX b3 = base64_decode (e3); b4 = base64_decode (e4); + os << hex; + v = static_cast<unsigned char> ((b1 << 2) | (b2 >> 4)); os.width (2); - os << "0x" << hex << v; + os << "0x" << v; v = static_cast<unsigned char> ((b2 << 4) | (b3 >> 2)); os.width (2); - os << ", 0x" << hex << v; + os << ", 0x" << v; v = static_cast<unsigned char> ((b3 << 6) | b4); os.width (2); - os << ", 0x" << hex << v; + os << ", 0x" << v; + + os << dec; di += 3; } @@ -797,7 +815,7 @@ namespace CXX return r; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::HexBinary& t) { collapse (value_); @@ -810,10 +828,10 @@ namespace CXX // Decode. // - Size n (value_.size () / 2); - WideChar prev_fill (os.fill ('0')); + size_t n (value_.size () / 2); + wchar_t prev_fill (os.fill ('0')); - for (Size i (0); i < n; ++i) + for (size_t i (0); i < n; ++i) { unsigned char h (hex_decode (value_[2 * i])); unsigned char l (hex_decode (value_[2 * i + 1])); @@ -829,7 +847,7 @@ namespace CXX unsigned short v = static_cast<unsigned char> ((h << 4) | l); os.width (2); - os << "0x" << hex << v; + os << "0x" << hex << v << dec; } os.fill (prev_fill); @@ -856,15 +874,15 @@ namespace CXX // Date/time. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Date& t) { // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] // collapse (value_); - Size b (0); - Size e (value_.find ('-', value_[0] == '-' ? 5 : 4)); + size_t b (0); + size_t e (value_.find ('-', value_[0] == '-' ? 5 : 4)); String year (value_, 0, e); b = e + 1; @@ -882,15 +900,15 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::DateTime& t) { // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] // collapse (value_); - Size b (0); - Size e (value_.find ('-', value_[0] == '-' ? 5 : 4)); + size_t b (0); + size_t e (value_.find ('-', value_[0] == '-' ? 5 : 4)); String year (value_, 0, e); b = e + 1; @@ -909,7 +927,7 @@ namespace CXX e = b + 2; for (; e < value_.size (); ++e) { - WideChar c (value_[e]); + wchar_t c (value_[e]); if (c == 'Z' || c == '+' || c == '-') break; @@ -934,12 +952,12 @@ namespace CXX namespace { - Size - find_delim (String const& s, Size pos) + size_t + find_delim (String const& s, size_t pos) { for (; pos < s.size (); ++pos) { - WideChar c (s[pos]); + wchar_t c (s[pos]); if (c == 'Y' || c == 'D' || c == 'M' || c == 'H' || c == 'M' || c == 'S' || c == 'T') @@ -950,14 +968,14 @@ namespace CXX } } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Duration& t) { // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] // collapse (value_); - Size b (1), e, n (value_.size ()); + size_t b (1), e, n (value_.size ()); os << fq_name (t) << " ("; @@ -1053,7 +1071,7 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Day& t) { // gday := ---DD[Z|(+|-)HH:MM] @@ -1068,7 +1086,7 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Month& t) { // gmonth := --MM[Z|(+|-)HH:MM] @@ -1083,7 +1101,7 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::MonthDay& t) { // gmonth_day := --MM-DD[Z|(+|-)HH:MM] @@ -1101,17 +1119,17 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Year& t) { // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] // collapse (value_); - Size pos (value_[0] == '-' ? 5 : 4); + size_t pos (value_[0] == '-' ? 5 : 4); for (; pos < value_.size (); ++pos) { - WideChar c (value_[pos]); + wchar_t c (value_[pos]); if (c == 'Z' || c == '+' || c == '-') break; @@ -1125,14 +1143,14 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::YearMonth& t) { // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] // collapse (value_); - Size pos (value_.find ('-', value_[0] == '-' ? 5 : 4)); + size_t pos (value_.find ('-', value_[0] == '-' ? 5 : 4)); String year (value_, 0, pos); String month (value_, pos + 1, 2); @@ -1145,7 +1163,7 @@ namespace CXX os << ")"; } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Time& t) { // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] @@ -1155,10 +1173,10 @@ namespace CXX String hours (value_, 0, 2); String minutes (value_, 3, 2); - Size e (8); + size_t e (8); for (; e < value_.size (); ++e) { - WideChar c (value_[e]); + wchar_t c (value_[e]); if (c == 'Z' || c == '+' || c == '-') break; @@ -1176,8 +1194,8 @@ namespace CXX os << ")"; } - Void InitValue:: - time_zone (Size pos) + void InitValue:: + time_zone (size_t pos) { // time_zone := Z|(+|-)HH:MM // @@ -1211,14 +1229,14 @@ namespace CXX // Entity. // - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Entity&) { collapse (value_); os << strlit (value_); } - Void InitValue:: + void InitValue:: traverse (SemanticGraph::Fundamental::Entities&) { string_sequence_type ( @@ -1226,7 +1244,7 @@ namespace CXX xs_ns ().find ("ENTITY").first->named ())); } - Void InitValue:: + void InitValue:: string_sequence_type (SemanticGraph::Type& t) { collapse (value_); @@ -1234,9 +1252,9 @@ namespace CXX if (!value_) return; - Size b (0); + size_t b (0); - for (Size e (value_.find (' ')); ; e = value_.find (' ', b)) + for (size_t e (value_.find (' ')); ; e = value_.find (' ', b)) { String v (value_, b, e != String::npos ? e - b : e); diff --git a/xsd/xsd/cxx/tree/default-value.hxx b/xsd/xsd/cxx/tree/default-value.hxx index c80132e..eb91a8c 100644 --- a/xsd/xsd/cxx/tree/default-value.hxx +++ b/xsd/xsd/cxx/tree/default-value.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/default-value.hxx -// 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 #ifndef CXX_TREE_DEFAULT_VALUE_HXX @@ -17,9 +16,9 @@ namespace CXX { struct IsLiteralValue: IsFundamentalType, Traversal::Complex { - IsLiteralValue (Boolean& r); + IsLiteralValue (bool& r); - virtual Void + virtual void traverse (SemanticGraph::Complex&); private: @@ -57,64 +56,64 @@ namespace CXX // Handle inheritance. // - virtual Void + virtual void traverse (SemanticGraph::Complex&); // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean&); // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger&); // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal&); private: @@ -148,25 +147,25 @@ namespace CXX // InitKind (Kind& r); - virtual Void + virtual void traverse (SemanticGraph::List&); - virtual Void + virtual void traverse (SemanticGraph::Complex&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities&); private: @@ -178,6 +177,7 @@ namespace CXX Traversal::Union, Traversal::Complex, + Traversal::AnyType, Traversal::AnySimpleType, Traversal::Fundamental::String, @@ -217,133 +217,136 @@ namespace CXX { InitValue (Context&); - Void + void data (String const& data) { data_ = data; dispatch_count_ = 0; } - Void + void dispatch (SemanticGraph::Node& type, String const& value); - virtual Void + virtual void traverse (SemanticGraph::List&); - virtual Void + virtual void traverse (SemanticGraph::Union&); - virtual Void + virtual void traverse (SemanticGraph::Complex&); - // anySimpleType. + // anyType & anySimpleType. // - virtual Void + virtual void + traverse (SemanticGraph::AnyType&); + + virtual void traverse (SemanticGraph::AnySimpleType&); // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language&); // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName&); // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs&); // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI&); // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary&); // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time&); // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity&); - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities&); private: - Void + void string_sequence_type (SemanticGraph::Type& element_type); - Void - time_zone (Size pos); + void + time_zone (size_t pos); private: String value_; String data_; - Size dispatch_count_; + size_t dispatch_count_; MemberTypeName type_name_; LiteralValue literal_value_; }; diff --git a/xsd/xsd/cxx/tree/elements.cxx b/xsd/xsd/cxx/tree/elements.cxx index cad5a33..202ab62 100644 --- a/xsd/xsd/cxx/tree/elements.cxx +++ b/xsd/xsd/cxx/tree/elements.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/elements.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/elements.hxx> @@ -11,55 +10,18 @@ namespace CXX { // Context // - Void Context:: - update_ns_scope () // Keeping this function first helps HP-UX - { // (long symbols). - ns_scope.clear (); - - Boolean first (true); - - for (NamespaceStack::Iterator i (ns_scope_stack.begin ()); - i != ns_scope_stack.end (); - ++i) - { - // We only qualify names until the namespace level. - // - if (first) - first = false; - else - ns_scope += L"::"; - - ns_scope += *i; - } - } - Context:: Context (std::wostream& o, SemanticGraph::Schema& root, SemanticGraph::Path const& path, - CLI::Options const& ops, + options_type const& ops, Counts const& counts_, - Boolean generate_xml_schema__, + bool generate_xml_schema__, StringLiteralMap const* map, Regex const* fe, Regex const* he, Regex const* ie) - : CXX::Context (o, - root, - path, - map, - ops.value<CLI::char_type> (), - ops.value<CLI::char_encoding> (), - ops.value<CLI::include_with_brackets> (), - ops.value<CLI::include_prefix> (), - ops.value<CLI::export_symbol> (), - ops.value<CLI::namespace_map> (), - ops.value<CLI::namespace_regex> (), - ops.value<CLI::namespace_regex_trace> (), - ops.value<CLI::include_regex> (), - ops.value<CLI::include_regex_trace> (), - ops.value<CLI::generate_inline> (), - ops.value<CLI::reserved_name> ()), + : CXX::Context (o, root, path, ops, map), options (ops), counts (counts_), any_type (any_type_), @@ -84,9 +46,10 @@ namespace CXX as_decimal_type (as_decimal_type_), generate_xml_schema (generate_xml_schema_), doxygen (doxygen_), - polymorphic (ops.value<CLI::generate_polymorphic> ()), - polymorphic_all (ops.value<CLI::polymorphic_type_all> ()), - detach (ops.value<CLI::generate_detach> ()), + polymorphic (ops.generate_polymorphic ()), + polymorphic_all (ops.polymorphic_type_all ()), + poly_plate (ops.polymorphic_plate ()), + detach (ops.generate_detach ()), fwd_expr (fe), hxx_expr (he), ixx_expr (ie), @@ -96,7 +59,7 @@ namespace CXX qname_type_ (L"::xsd::cxx::xml::qualified_name< " + char_type + L" >"), parser_type_ (L"::xsd::cxx::xml::dom::parser< " + char_type + L" >"), generate_xml_schema_ (generate_xml_schema__), - doxygen_ (ops.value<CLI::generate_doxygen> ()), + doxygen_ (ops.generate_doxygen ()), ns_scope_stack (ns_scope_stack_), cxx_uq_id_expr_ (L"^[a-zA-Z_]\\w*$"), cxx_uq_id_expr (cxx_uq_id_expr_) @@ -118,23 +81,25 @@ namespace CXX container = xs_name + L"::" + xsc.get<String> ("container"); flags_type = xs_name + L"::" + xsc.get<String> ("flags"); - if (ops.value<CLI::generate_element_type> ()) + if (ops.generate_element_type ()) element_type = xs_name + L"::" + xsc.get<String> ("element-type"); properties_type = xs_name + L"::" + xsc.get<String> ("properties"); - if (!ops.value<CLI::suppress_parsing> () || - ops.value<CLI::generate_serialization> ()) + if (!ops.suppress_parsing () || ops.generate_serialization ()) { error_handler_type = xs_name + L"::" + xsc.get<String> ("error-handler"); } - dom_auto_ptr_ = xs_name + L"::dom::auto_ptr"; + dom_auto_ptr_ = xs_name + (std >= cxx_version::cxx11 + ? L"::dom::unique_ptr" + : L"::dom::auto_ptr"); + dom_node_key_ = xs_name + L"::dom::" + xsc.get<String> ("tree-node-key"); - if (ops.value<CLI::generate_serialization> ()) + if (ops.generate_serialization ()) { as_double_type_ = xs_name + L"::" + xsc.get<String> ("as-double"); @@ -152,17 +117,17 @@ namespace CXX // istream and ostream are templates and for now use the same // names regardless of the naming convention. // - if (!ops.value<CLI::generate_extraction> ().empty ()) + if (!ops.generate_extraction ().empty ()) istream_type = xs_name + L"::istream"; - if (!ops.value<CLI::generate_insertion> ().empty ()) + if (!ops.generate_insertion ().empty ()) ostream_type = xs_name + L"::ostream"; } // Xerces-C++ namespace. IntelliSense for some reason does not like // it fully-qualified (maybe because it's a namespace alias). // - if (ops.value<CLI::generate_intellisense> ()) + if (ops.generate_intellisense ()) xerces_ns = "xercesc"; else xerces_ns = "::xercesc"; @@ -178,14 +143,14 @@ namespace CXX // Custom type mapping. // - typedef Containers::Vector<NarrowString> Vector; // Direct custom type mapping. // { - Vector const& v (ops.value<CLI::custom_type> ()); + NarrowStrings const& v (ops.custom_type ()); - for (Vector::ConstIterator i (v.begin ()), e (v.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (v.begin ()), + e (v.end ()); i != e; ++i) { String s (*i); @@ -194,7 +159,7 @@ namespace CXX // Split the string in two parts at the last '='. // - Size pos (s.rfind ('=')); + size_t pos (s.rfind ('=')); // If no delimiter found then both type and base are empty. // @@ -237,20 +202,21 @@ namespace CXX // Regex custom type mapping. // { - Vector const& v (ops.value<CLI::custom_type_regex> ()); + NarrowStrings const& v (ops.custom_type_regex ()); - for (Vector::ConstIterator i (v.begin ()), e (v.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (v.begin ()), + e (v.end ()); i != e; ++i) { String s (*i); if (s.empty ()) throw InvalidCustomTypeMapping (s, "mapping string is empty"); - WideChar delimiter (s[0]); + wchar_t delimiter (s[0]); // First get pattern. // - Size pos (s.find (delimiter, 1)); + size_t pos (s.find (delimiter, 1)); if (pos == String::npos) throw InvalidCustomTypeMapping ( @@ -291,7 +257,7 @@ namespace CXX } regex_custom_type_map.push_back ( - RegexCustomTypeMapInfo (pat, type, base)); + RegexCustomTypeMapInfo (WideRegexPat (pat), type, base)); } } } @@ -325,6 +291,7 @@ namespace CXX doxygen (c.doxygen), polymorphic (c.polymorphic), polymorphic_all (c.polymorphic_all), + poly_plate (c.poly_plate), detach (c.detach), fwd_expr (c.fwd_expr), hxx_expr (c.hxx_expr), @@ -366,6 +333,7 @@ namespace CXX doxygen (c.doxygen), polymorphic (c.polymorphic), polymorphic_all (c.polymorphic_all), + poly_plate (c.poly_plate), detach (c.detach), fwd_expr (c.fwd_expr), hxx_expr (c.hxx_expr), @@ -378,7 +346,29 @@ namespace CXX { } - Boolean Context:: + void Context:: + update_ns_scope () + { + ns_scope.clear (); + + bool first (true); + + for (NamespaceStack::iterator i (ns_scope_stack.begin ()); + i != ns_scope_stack.end (); + ++i) + { + // We only qualify names until the namespace level. + // + if (first) + first = false; + else + ns_scope += L"::"; + + ns_scope += *i; + } + } + + bool Context:: custom_type (SemanticGraph::Type const& t, String& r) const { String const& name (t.name ()); @@ -386,7 +376,7 @@ namespace CXX // First search the direct mapping. // { - DirectCustomTypeMap::ConstIterator i ( + DirectCustomTypeMap::const_iterator i ( direct_custom_type_map.find (name)); if (i != direct_custom_type_map.end ()) @@ -399,7 +389,7 @@ namespace CXX // Second search the regex mapping. // - for (RegexCustomTypeMap::ConstIterator + for (RegexCustomTypeMap::const_iterator i (regex_custom_type_map.begin ()), e (regex_custom_type_map.end ()); i != e; ++i) @@ -414,7 +404,7 @@ namespace CXX return true; } - r = i->pat.merge (i->type_sub, name); + r = i->pat.replace (name, i->type_sub); return true; } } @@ -437,7 +427,7 @@ namespace CXX return r; } - Boolean Context:: + bool Context:: renamed_type (SemanticGraph::Type const& t, String& r) const { String const& name (t.name ()); @@ -445,7 +435,7 @@ namespace CXX // First search the direct mapping. // { - DirectCustomTypeMap::ConstIterator i ( + DirectCustomTypeMap::const_iterator i ( direct_custom_type_map.find (name)); if (i != direct_custom_type_map.end ()) @@ -458,7 +448,7 @@ namespace CXX // Second search the regex mapping. // - for (RegexCustomTypeMap::ConstIterator + for (RegexCustomTypeMap::const_iterator i (regex_custom_type_map.begin ()), e (regex_custom_type_map.end ()); i != e; ++i) @@ -467,7 +457,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 (); @@ -479,17 +469,17 @@ namespace CXX return false; } - Void Context:: + void Context:: write_annotation (SemanticGraph::Annotation& a) { String const& doc (a.documentation ()); - WideChar const* s (doc.c_str ()); - Size size (doc.size ()); + wchar_t const* s (doc.c_str ()); + size_t size (doc.size ()); // Remove leading and trailing whitespaces. // - while (*s == WideChar (0x20) || *s == WideChar (0x0A) || - *s == WideChar (0x0D) || *s == WideChar (0x09)) + while (*s == wchar_t (0x20) || *s == wchar_t (0x0A) || + *s == wchar_t (0x0D) || *s == wchar_t (0x09)) { s++; size--; @@ -497,11 +487,11 @@ namespace CXX if (size != 0) { - WideChar const* e (s + size - 1); + wchar_t const* e (s + size - 1); while (e > s && - (*e == WideChar (0x20) || *e == WideChar (0x0A) || - *e == WideChar (0x0D) || *e == WideChar (0x09))) + (*e == wchar_t (0x20) || *e == wchar_t (0x0A) || + *e == wchar_t (0x0D) || *e == wchar_t (0x09))) --e; size = s <= e ? e - s + 1 : 0; @@ -514,15 +504,15 @@ namespace CXX // Go over the data, forcing newline after 80 chars and adding // ' * ' after each new line. // - WideChar const* last_space (0); - WideChar const* b (s); - WideChar const* e (s); - Boolean after_newline (false); - Boolean rogue (false); + wchar_t const* last_space (0); + wchar_t const* b (s); + wchar_t const* e (s); + bool after_newline (false); + bool rogue (false); for (; e < s + size; ++e) { - UnsignedLong u (unicode_char (e)); // May advance e. + unsigned int u (unicode_char (e)); // May advance e. // We are going to treat \v and \f as rogue here even though // they can be present in C++ source code. @@ -579,16 +569,16 @@ namespace CXX } } - Void Context:: - write_rogue_text (WideChar const* s, Size size, Boolean rogue) + void Context:: + write_rogue_text (wchar_t const* s, size_t size, bool rogue) { if (!rogue) os.write (s, size); else { - for (WideChar const* p (s); p < s + size; ++p) + for (wchar_t const* p (s); p < s + size; ++p) { - UnsignedLong u (unicode_char (p)); // May advance p. + unsigned int u (unicode_char (p)); // May advance p. // We are going to treat \v and \f as rogue here even though // they can be present in C++ source code. @@ -596,36 +586,69 @@ namespace CXX if (u > 127 || (u < 32 && u != '\t' && u != '\n')) os.put ('?'); else - os.put (static_cast<WideChar> (u)); + os.put (static_cast<wchar_t> (u)); } } } - Boolean Context:: + bool Context:: polymorphic_p (SemanticGraph::Type& t) { + // IDREF templates cannot be polymorphic. + // + if (!t.named_p () && + (t.is_a<SemanticGraph::Fundamental::IdRef> () || + t.is_a<SemanticGraph::Fundamental::IdRefs> ())) + return false; + if (polymorphic_all) { - Boolean fund (false); + bool fund (false); IsFundamentalType test (fund); test.dispatch (t); return !fund; } else - return t.context ().get<Boolean> ("polymorphic"); + return t.context ().get<bool> ("polymorphic"); + } + + bool Context:: + anonymous_substitutes_p (SemanticGraph::Type& t) + { + // IDREF templates cannot match. + // + if (!t.named_p () && + (t.is_a<SemanticGraph::Fundamental::IdRef> () || + t.is_a<SemanticGraph::Fundamental::IdRefs> ())) + return false; + + // See which elements this type classifies. + // + for (SemanticGraph::Type::ClassifiesIterator i (t.classifies_begin ()), + e (t.classifies_end ()); i != e; ++i) + { + if (SemanticGraph::Element* e = + dynamic_cast<SemanticGraph::Element*> (&i->instance ())) + { + if (e->substitutes_p ()) + return true; + } + } + + return false; } // GenerateDefautCtor // GenerateDefaultCtor:: - GenerateDefaultCtor (Context& c, Boolean& generate, Boolean no_base) + GenerateDefaultCtor (Context& c, bool& generate, bool no_base) : Context (c), generate_ (generate), no_base_ (no_base) { *this >> inherits_ >> *this; *this >> names_ >> *this; } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Complex& c) { // Make sure we figure out if we have any required members before @@ -637,38 +660,38 @@ namespace CXX Complex::inherits (c, inherits_); } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Type&) { if (!no_base_) generate_ = true; } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Enumeration&) { if (!no_base_) generate_ = true; } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Element& e) { if (!skip (e) && min (e) == 1 && max (e) == 1) generate_ = true; } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Attribute& a) { if (min (a) == 1 && !a.fixed_p ()) generate_ = true; } - Void GenerateDefaultCtor:: + void GenerateDefaultCtor:: traverse (SemanticGraph::Any& a) { - if (options.value<CLI::generate_wildcard> () && + if (options.generate_wildcard () && min (a) == 1 && max (a) == 1) generate_ = true; } @@ -677,7 +700,7 @@ namespace CXX // GenerateFromBaseCtor // GenerateFromBaseCtor:: - GenerateFromBaseCtor (Context& c, Boolean& generate) + GenerateFromBaseCtor (Context& c, bool& generate) : generate_ (generate), custom_ (false), traverser_ (c, generate, custom_) @@ -685,7 +708,7 @@ namespace CXX inherits_ >> traverser_; } - Void GenerateFromBaseCtor:: + void GenerateFromBaseCtor:: traverse (SemanticGraph::Complex& c) { inherits (c, inherits_); @@ -703,14 +726,14 @@ namespace CXX } GenerateFromBaseCtor::Traverser:: - Traverser (Context& c, Boolean& generate, Boolean& custom) + Traverser (Context& c, bool& generate, bool& custom) : Context (c), generate_ (generate), custom_ (custom) { *this >> inherits_ >> *this; *this >> names_ >> *this; } - Void GenerateFromBaseCtor::Traverser:: + void GenerateFromBaseCtor::Traverser:: traverse (SemanticGraph::Type& t) { if (!custom_) @@ -720,7 +743,7 @@ namespace CXX } } - Void GenerateFromBaseCtor::Traverser:: + void GenerateFromBaseCtor::Traverser:: traverse (SemanticGraph::Complex& c) { names (c, names_); @@ -732,24 +755,24 @@ namespace CXX traverse (static_cast<SemanticGraph::Type&> (c)); } - Void GenerateFromBaseCtor::Traverser:: + void GenerateFromBaseCtor::Traverser:: traverse (SemanticGraph::Element& e) { if (!skip (e) && min (e) == 1 && max (e) == 1) generate_ = true; } - Void GenerateFromBaseCtor::Traverser:: + void GenerateFromBaseCtor::Traverser:: traverse (SemanticGraph::Attribute& a) { if (min (a) == 1 && !a.fixed_p ()) generate_ = true; } - Void GenerateFromBaseCtor::Traverser:: + void GenerateFromBaseCtor::Traverser:: traverse (SemanticGraph::Any& a) { - if (options.value<CLI::generate_wildcard> () && + if (options.generate_wildcard () && min (a) == 1 && max (a) == 1) generate_ = true; } @@ -758,10 +781,10 @@ namespace CXX // HasComplexPolyNonOptArgs:: HasComplexPolyNonOptArgs (Context& c, - Boolean base, - Boolean& complex, - Boolean& poly, - Boolean& clash) + bool base, + bool& complex, + bool& poly, + bool& clash) : Context (c), complex_ (complex), poly_ (poly), @@ -773,7 +796,7 @@ namespace CXX *this >> names_ >> *this; } - Void HasComplexPolyNonOptArgs:: + void HasComplexPolyNonOptArgs:: traverse (SemanticGraph::Complex& c) { // No optimizations: need to check every arg for clashes. @@ -782,14 +805,14 @@ namespace CXX names (c, names_); } - Void HasComplexPolyNonOptArgs:: + void HasComplexPolyNonOptArgs:: traverse (SemanticGraph::Element& e) { if (!skip (e) && min (e) == 1 && max (e) == 1) { - Boolean poly (polymorphic && polymorphic_p (e.type ())); + bool poly (polymorphic && polymorphic_p (e.type ())); - Boolean simple (true); + bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); @@ -807,15 +830,15 @@ namespace CXX // FromBaseCtorArg // FromBaseCtorArg:: - FromBaseCtorArg (Context& c, ArgType at, Boolean arg) + FromBaseCtorArg (Context& c, CtorArgType at, bool arg) : Context (c), arg_type_ (at), arg_ (arg) { } - Void FromBaseCtorArg:: + void FromBaseCtorArg:: traverse (SemanticGraph::Any& a) { - if (!options.value<CLI::generate_wildcard> ()) + if (!options.generate_wildcard ()) return; if (min (a) == 1 && max (a) == 1) @@ -830,7 +853,7 @@ namespace CXX } } - Void FromBaseCtorArg:: + void FromBaseCtorArg:: traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -842,29 +865,29 @@ namespace CXX os << "," << endl; - Boolean auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { - Boolean simple (true); + bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << auto_ptr << "< " << etype (e) << " >"; else os << "const " << etype (e) << "&"; @@ -873,7 +896,7 @@ namespace CXX } } - Void FromBaseCtorArg:: + void FromBaseCtorArg:: traverse (SemanticGraph::Attribute& a) { // Note that we are not going to include attributes with @@ -895,7 +918,7 @@ namespace CXX // CtorArgs // CtorArgs:: - CtorArgs (Context& c, ArgType at) + CtorArgs (Context& c, CtorArgType at) : Context (c), arg_type_ (at), base_arg_ (0), @@ -907,7 +930,7 @@ namespace CXX } CtorArgs:: - CtorArgs (Context& c, ArgType at, String& base_arg) + CtorArgs (Context& c, CtorArgType at, String& base_arg) : Context (c), arg_type_ (at), base_arg_ (&base_arg), @@ -918,7 +941,7 @@ namespace CXX *this >> names_ >> *this; } - Void CtorArgs:: + void CtorArgs:: traverse (SemanticGraph::Type& t) { os << comma () << "const "; @@ -929,13 +952,17 @@ namespace CXX if (base_arg_ != 0) { - *base_arg_ = L"_xsd_" + ename (t) + L"_base"; + // IDREF templates don't have a name. + // + *base_arg_ = t.named_p () + ? (L"_xsd_" + ename (t) + L"_base") + : L"_xsd_base"; os << " " << *base_arg_; } } - Void CtorArgs:: + void CtorArgs:: traverse (SemanticGraph::Enumeration& e) { os << comma () << "const "; @@ -952,10 +979,10 @@ namespace CXX } } - Void CtorArgs:: + void CtorArgs:: traverse (SemanticGraph::Any& a) { - if (!options.value<CLI::generate_wildcard> ()) + if (!options.generate_wildcard ()) return; if (min (a) == 1 && max (a) == 1) @@ -967,7 +994,7 @@ namespace CXX } } - Void CtorArgs:: + void CtorArgs:: traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -975,29 +1002,29 @@ namespace CXX if (min (e) == 1 && max (e) == 1) { - Boolean auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { - Boolean simple (true); + bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << comma () << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << comma () << auto_ptr << "< " << etype (e) << " >"; else os << comma () << "const " << etype (e) << "&"; @@ -1006,7 +1033,7 @@ namespace CXX } } - Void CtorArgs:: + void CtorArgs:: traverse (SemanticGraph::Attribute& a) { // Note that we are not going to include attributes with @@ -1025,7 +1052,7 @@ namespace CXX String CtorArgs:: comma () { - Boolean tmp (first_); + bool tmp (first_); first_ = false; return tmp ? "" : ",\n"; } @@ -1034,17 +1061,17 @@ namespace CXX // CtorArgsWithoutBase // CtorArgsWithoutBase:: - CtorArgsWithoutBase (Context& c, ArgType at, Boolean arg, Boolean first) + CtorArgsWithoutBase (Context& c, CtorArgType at, bool arg, bool first) : Context (c), arg_type_ (at), arg_ (arg), first_ (first) { *this >> inherits_ >> *this; *this >> names_ >> *this; } - Void CtorArgsWithoutBase:: + void CtorArgsWithoutBase:: traverse (SemanticGraph::Any& a) { - if (!options.value<CLI::generate_wildcard> ()) + if (!options.generate_wildcard ()) return; if (min (a) == 1 && max (a) == 1) @@ -1056,7 +1083,7 @@ namespace CXX } } - Void CtorArgsWithoutBase:: + void CtorArgsWithoutBase:: traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -1064,29 +1091,29 @@ namespace CXX if (min (e) == 1 && max (e) == 1) { - Boolean auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { - Boolean simple (true); + bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << comma () << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << comma () << auto_ptr << "< " << etype (e) << " >"; else os << comma () << "const " << etype (e) << "&"; @@ -1095,7 +1122,7 @@ namespace CXX } } - Void CtorArgsWithoutBase:: + void CtorArgsWithoutBase:: traverse (SemanticGraph::Attribute& a) { // Note that we are not going to include attributes with @@ -1114,14 +1141,14 @@ namespace CXX String CtorArgsWithoutBase:: comma () { - Boolean tmp (first_); + bool tmp (first_); first_ = false; return tmp ? "" : ",\n"; } // GlobalElementBase // - Boolean GlobalElementBase:: + bool GlobalElementBase:: generate_p (SemanticGraph::Element& e) { if (e.substitutes_p () && ctx_.polymorphic) @@ -1133,44 +1160,44 @@ namespace CXX // If we are not generating element types nor parsing/serialization // code then we won't generate anything from it. // - if (!ctx_.options.value<CLI::generate_element_type> () && - ctx_.options.value<CLI::suppress_parsing> () && - !ctx_.options.value<CLI::generate_serialization> ()) + if (!ctx_.options.generate_element_type () && + ctx_.options.suppress_parsing () && + !ctx_.options.generate_serialization ()) return false; return true; } - Boolean GlobalElementBase:: + bool GlobalElementBase:: doc_root_p (SemanticGraph::Element& e) { - if (!ctx_.options.value<CLI::root_element_first> () && - !ctx_.options.value<CLI::root_element_last> () && - !ctx_.options.value<CLI::root_element_all> () && - !ctx_.options.value<CLI::root_element_none> () && - ctx_.options.value<CLI::root_element> ().empty ()) + if (!ctx_.options.root_element_first () && + !ctx_.options.root_element_last () && + !ctx_.options.root_element_all () && + !ctx_.options.root_element_none () && + ctx_.options.root_element ().empty ()) return true; // By default treat them all. - if (ctx_.options.value<CLI::root_element_none> ()) + if (ctx_.options.root_element_none ()) return false; - if (ctx_.options.value<CLI::root_element_all> ()) + if (ctx_.options.root_element_all ()) return true; - if (ctx_.options.value<CLI::root_element_first> () && + if (ctx_.options.root_element_first () && e.context ().count ("first") != 0) return true; - if (ctx_.options.value<CLI::root_element_last> () && + if (ctx_.options.root_element_last () && e.context ().count ("last") != 0) return true; - typedef Cult::Containers::Vector<NarrowString> Names; - Names const& names (ctx_.options.value<CLI::root_element> ()); + NarrowStrings const& names (ctx_.options.root_element ()); // Hopefully nobody will specify more than a handful of names ;-). // - for (Names::ConstIterator i (names.begin ()); i != names.end (); ++i) + for (NarrowStrings::const_iterator i (names.begin ()); + i != names.end (); ++i) { String name (*i); @@ -1185,8 +1212,8 @@ namespace CXX // Namespace:: Namespace (Context& c, - UnsignedLong first, - UnsignedLong last) + size_t first, + size_t last) : CXX::Namespace (c, *this), GlobalElementBase (c), ctx_ (c), @@ -1196,7 +1223,7 @@ namespace CXX { } - Void Namespace:: + void Namespace:: traverse (Type& ns) { using SemanticGraph::Element; @@ -1205,7 +1232,7 @@ namespace CXX CXX::Namespace::traverse (ns); else { - Boolean opened (false); + bool opened (false); for (Type::NamesIterator i (ns.names_begin ()); i != ns.names_end (); ++i) @@ -1235,13 +1262,13 @@ namespace CXX } } - Void Namespace:: - enter (Type&, String const& name, Boolean) + void Namespace:: + enter (Type&, String const& name, bool) { ctx_.enter_ns_scope (name); } - Void Namespace:: + void Namespace:: leave () { ctx_.leave_ns_scope (); @@ -1249,7 +1276,7 @@ namespace CXX // Includes // - Void TypeForward:: + void TypeForward:: traverse (SemanticGraph::Type& t) { String const& name (ename (t)); @@ -1271,14 +1298,14 @@ namespace CXX os << "class " << name << ";"; } - Void Includes:: + void Includes:: traverse_ (SemanticGraph::Uses& u) { // Support for weak (forward) inclusion used in the file-per-type // compilation model. // Type t (type_); - Boolean weak (u.context ().count ("weak")); + bool weak (u.context ().count ("weak")); SemanticGraph::Schema& s (u.schema ()); if (weak && t == header) @@ -1301,6 +1328,7 @@ namespace CXX s.context ().count ("renamed") ? s.context ().get<SemanticGraph::Path> ("renamed") : u.path ()); + path.normalize (); // Try to use the portable representation of the path. If that // fails, fall back to the native representation. @@ -1308,15 +1336,11 @@ namespace CXX NarrowString path_str; try { - path_str = path.string (); + path_str = path.posix_string (); } catch (SemanticGraph::InvalidPath const&) { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - path_str = path.native_file_string (); -#else path_str = path.string (); -#endif } String inc_path; @@ -1325,25 +1349,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/xsd/cxx/tree/elements.hxx b/xsd/xsd/cxx/tree/elements.hxx index afe3951..6874e6a 100644 --- a/xsd/xsd/cxx/tree/elements.hxx +++ b/xsd/xsd/cxx/tree/elements.hxx @@ -1,23 +1,23 @@ // file : xsd/cxx/tree/elements.hxx -// 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 #ifndef CXX_TREE_ELEMENTS_HXX #define CXX_TREE_ELEMENTS_HXX +#include <map> +#include <set> +#include <deque> +#include <vector> #include <sstream> -#include <cult/containers/map.hxx> -#include <cult/containers/deque.hxx> -#include <cult/containers/vector.hxx> +#include <cutl/re.hxx> -#include <backend-elements/regex.hxx> +#include <types.hxx> #include <cxx/elements.hxx> -#include <cxx/tree/cli.hxx> - +#include <cxx/tree/options.hxx> namespace CXX { @@ -33,15 +33,15 @@ namespace CXX { } - UnsignedLong global_types; - UnsignedLong global_elements; - UnsignedLong generated_global_elements; + size_t global_types; + size_t global_elements; + size_t generated_global_elements; // Complexity value for each global type and generated global // element, in order. // - Cult::Containers::Vector<UnsignedLong> complexity; - UnsignedLong complexity_total; + std::vector<size_t> complexity; + size_t complexity_total; }; struct InvalidCustomTypeMapping @@ -69,13 +69,63 @@ namespace CXX String reason_; }; + // A set of potentially qualified XML Schema type names. + // + struct TypeNameSet + { + template <typename I> + TypeNameSet (I begin, I end) + { + for (; begin != end; ++begin) + insert (*begin); + } + + void + insert (String const& name) + { + size_t p (name.rfind ('#')); + + if (p == String::npos) + unames_.insert (name); + else + qnames_.insert (name); + } + + bool + find (SemanticGraph::Type& t) + { + if (!unames_.empty ()) + { + if (unames_.find (t.name ()) != unames_.end ()) + return true; + } + + if (!qnames_.empty ()) + { + if (qnames_.find (t.scope ().name () + L"#" + t.name ()) != + qnames_.end ()) + return true; + } + + return false; + } + + private: + typedef std::set<String> StringSet; + + StringSet unames_; + StringSet qnames_; + }; + // // class Context: public CXX::Context { public: - typedef BackendElements::Regex::Expression<Char> Regex; - typedef BackendElements::Regex::Pattern<WideChar> WideRegexPat; + typedef cutl::re::regexsub Regex; + typedef cutl::re::wregex WideRegexPat; + + typedef Tree::options options_type; struct DirectCustomTypeMapInfo { @@ -103,21 +153,16 @@ namespace CXX String base_sub; }; - typedef - Cult::Containers::Vector<RegexCustomTypeMapInfo> - RegexCustomTypeMap; - - typedef - Cult::Containers::Map<String, DirectCustomTypeMapInfo> - DirectCustomTypeMap; + typedef std::vector<RegexCustomTypeMapInfo> RegexCustomTypeMap; + typedef std::map<String, DirectCustomTypeMapInfo> DirectCustomTypeMap; public: Context (std::wostream& o, SemanticGraph::Schema& root, SemanticGraph::Path const& path, - CLI::Options const& ops, + options_type const& ops, Counts const& counts_, - Boolean generate_xml_schema, + bool generate_xml_schema, StringLiteralMap const*, Regex const* fwd_expr, Regex const* hxx_expr, @@ -139,7 +184,7 @@ namespace CXX // populated with the custom type name or empty if the // original name should be used. // - Boolean + bool custom_type (SemanticGraph::Type const&, String& name) const; // Returns true if this type has been renamed as part of the @@ -147,7 +192,7 @@ namespace CXX // name string is populated with the new name or empty if // the type should not be generated at all. // - Boolean + bool renamed_type (SemanticGraph::Type const&, String& name) const; public: @@ -155,21 +200,43 @@ namespace CXX // line after 80 characters as well as "commentizing" the text by // adding '* ' after each newline. // - Void + void write_annotation (SemanticGraph::Annotation&); // // public: - Boolean + static bool + ordered_p (SemanticGraph::Type const& t) + { + return t.context ().count ("ordered") && + t.context ().get<bool> ("ordered"); + } + + // Check if we are generating mixed support for this type. We only + // do it for ordered types. + // + static bool + mixed_p (SemanticGraph::Complex const& c) + { + return c.mixed_p () && ordered_p (c); + } + + bool polymorphic_p (SemanticGraph::Type&); - Boolean + bool anonymous_p (SemanticGraph::Type const& t) { return t.context ().count ("anonymous"); } + // Return true if this anonymous type is defined in an element + // that belongs to a substitution group. + // + bool + anonymous_substitutes_p (SemanticGraph::Type&); + // Escaped names. // public: @@ -329,7 +396,7 @@ namespace CXX // dom_document // - static Boolean + static bool edom_document_p (SemanticGraph::Complex const& c) { return c.context ().count ("dom-document"); @@ -341,7 +408,7 @@ namespace CXX return c.context ().get<String> ("dom-document"); } - static Boolean + static bool edom_document_member_p (SemanticGraph::Complex const& c) { return c.context ().count ("dom-document-member"); @@ -368,14 +435,14 @@ namespace CXX } public: - Void + void enter_ns_scope (String const& name) { ns_scope_stack.push_back (name); update_ns_scope (); } - Void + void leave_ns_scope () { ns_scope_stack.pop_back (); @@ -383,18 +450,18 @@ namespace CXX } private: - Void + void update_ns_scope (); private: // Write text that may contain characters that we will have // to escape (indicated by the rogue flag). // - Void - write_rogue_text (WideChar const* s, Size size, Boolean rogue); + void + write_rogue_text (wchar_t const* s, size_t size, bool rogue); public: - CLI::Options const& options; + options_type const& options; Counts const& counts; String& any_type; String& any_simple_type; @@ -417,11 +484,12 @@ namespace CXX String& as_double_type; String& as_decimal_type; - Boolean& generate_xml_schema; - Boolean& doxygen; - Boolean polymorphic; - Boolean polymorphic_all; - Boolean detach; + bool& generate_xml_schema; + bool& doxygen; + bool polymorphic; + bool polymorphic_all; + unsigned long poly_plate; + bool detach; Regex const* fwd_expr; Regex const* hxx_expr; @@ -454,16 +522,11 @@ namespace CXX String as_double_type_; String as_decimal_type_; - Boolean generate_xml_schema_; - Boolean doxygen_; + bool generate_xml_schema_; + bool doxygen_; - typedef - Cult::Containers::Deque<String> - NamespaceStack; - - typedef - Cult::Containers::Deque<String> - ScopeStack; + typedef std::deque<String> NamespaceStack; + typedef std::deque<String> ScopeStack; String ns_scope_; @@ -501,86 +564,86 @@ namespace CXX Traversal::Fundamental::Decimal { - IsFundamentalType (Boolean& r) + IsFundamentalType (bool& r) : r_ (r) { } // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger&) { r_ = true; @@ -588,7 +651,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean&) { r_ = true; @@ -596,26 +659,26 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal&) { r_ = true; } private: - Boolean& r_; + bool& r_; }; // Check whether this is a string-based type. @@ -630,19 +693,19 @@ namespace CXX Traversal::Fundamental::NCName, Traversal::Fundamental::Language { - IsStringBasedType (Boolean& r) + IsStringBasedType (bool& r) : r_ (r) { *this >> inherits_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { inherits (c, inherits_); } - virtual Void + virtual void traverse (SemanticGraph::Union&) { // Current mapping of union is string-based. @@ -652,50 +715,50 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName&) { r_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language&) { r_ = true; } private: - Boolean& r_; + bool& r_; Traversal::Inherits inherits_; }; @@ -713,7 +776,7 @@ namespace CXX inherits_ >> enum_; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { inherits (c, inherits_); @@ -727,7 +790,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (e_ == 0) @@ -820,25 +883,25 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Type&) { abort (); } - virtual Void + virtual void traverse (SemanticGraph::List& l) { os << fq_name (l); } - virtual Void + virtual void traverse (SemanticGraph::Union& u) { os << fq_name (u); } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { os << fq_name (c); @@ -846,13 +909,13 @@ namespace CXX // anyType & anySimpleType. // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { os << fq_name (t); @@ -860,79 +923,79 @@ namespace CXX // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { os << fq_name (t); @@ -940,7 +1003,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { os << fq_name (t); @@ -948,19 +1011,19 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { os << fq_name (t); @@ -968,49 +1031,49 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { os << fq_name (t); @@ -1019,7 +1082,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { os << fq_name (t); @@ -1028,13 +1091,13 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { if (t.named_p ()) @@ -1054,7 +1117,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { if (t.named_p ()) @@ -1077,7 +1140,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { os << fq_name (t); @@ -1085,13 +1148,13 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { os << fq_name (t); @@ -1100,55 +1163,55 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { os << fq_name (t); @@ -1156,13 +1219,13 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { os << fq_name (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { os << fq_name (t); @@ -1200,7 +1263,7 @@ namespace CXX { } - virtual Void + virtual void fundamental_base (SemanticGraph::Type& t) { os << "::xsd::cxx::tree::fundamental_base< " << @@ -1210,79 +1273,79 @@ namespace CXX // Integrals. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { fundamental_base (t); @@ -1290,7 +1353,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { fundamental_base (t); @@ -1298,13 +1361,13 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { fundamental_base (t); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { os << "::xsd::cxx::tree::fundamental_base< " << @@ -1313,7 +1376,7 @@ namespace CXX "::xsd::cxx::tree::schema_type::double_ >"; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { os << "::xsd::cxx::tree::fundamental_base< " << @@ -1330,42 +1393,46 @@ namespace CXX Traversal::Any, Traversal::AnyAttribute { - IsSimpleType (Boolean& v) + IsSimpleType (bool& v) : v_ (v) { *this >> names_ >> *this; *this >> inherits_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { - names (c, names_); + if (c.mixed_p ()) + v_ = false; + + if (v_) + names (c, names_); if (v_) inherits (c, inherits_); } - virtual Void + virtual void traverse (SemanticGraph::Member&) { v_ = false; } - virtual Void + virtual void traverse (SemanticGraph::Any&) { v_ = false; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute&) { v_ = false; } private: - Boolean& v_; + bool& v_; Traversal::Names names_; Traversal::Inherits inherits_; }; @@ -1383,29 +1450,29 @@ namespace CXX { // generate should initially be false. // - GenerateDefaultCtor (Context&, Boolean& generate, Boolean no_base); + GenerateDefaultCtor (Context&, bool& generate, bool no_base); - virtual Void + virtual void traverse (SemanticGraph::Complex&); - virtual Void + virtual void traverse (SemanticGraph::Type&); - virtual Void + virtual void traverse (SemanticGraph::Enumeration&); - virtual Void + virtual void traverse (SemanticGraph::Element&); - virtual Void + virtual void traverse (SemanticGraph::Attribute&); - virtual Void + virtual void traverse (SemanticGraph::Any&); private: - Boolean& generate_; - Boolean no_base_; + bool& generate_; + bool no_base_; private: Traversal::Inherits inherits_; @@ -1418,14 +1485,14 @@ namespace CXX { // generate should initially be false. // - GenerateFromBaseCtor (Context& c, Boolean& generate); + GenerateFromBaseCtor (Context& c, bool& generate); - virtual Void + virtual void traverse (SemanticGraph::Complex& c); private: - Boolean& generate_; - Boolean custom_; + bool& generate_; + bool custom_; // Note that we are not interested in anyAttribute since it is always // mapped to a sequence. @@ -1437,26 +1504,26 @@ namespace CXX Traversal::Any, Context { - Traverser (Context& c, Boolean& generate, Boolean& custom); + Traverser (Context& c, bool& generate, bool& custom); - virtual Void + virtual void traverse (SemanticGraph::Type&); - virtual Void + virtual void traverse (SemanticGraph::Complex&); - virtual Void + virtual void traverse (SemanticGraph::Attribute&); - virtual Void + virtual void traverse (SemanticGraph::Element&); - virtual Void + virtual void traverse (SemanticGraph::Any&); private: - Boolean& generate_; - Boolean& custom_; + bool& generate_; + bool& custom_; private: Traversal::Inherits inherits_; @@ -1477,26 +1544,44 @@ namespace CXX // should initially be true. // HasComplexPolyNonOptArgs (Context& c, - Boolean including_base, - Boolean& complex, - Boolean& poly, - Boolean& clash); + bool including_base, + bool& complex, + bool& poly, + bool& clash); - virtual Void + virtual void traverse (SemanticGraph::Complex&); - virtual Void + virtual void traverse (SemanticGraph::Element&); private: - Boolean& complex_; - Boolean& poly_; - Boolean& clash_; + bool& complex_; + bool& poly_; + bool& clash_; Traversal::Inherits inherits_; Traversal::Names names_; }; + // Contructor argument types. + // + struct CtorArgType + { + enum Value + { + type, + complex_auto_ptr, + poly_auto_ptr + }; + + CtorArgType (Value v = Value (0)) : v_ (v) {} + operator Value () const {return v_;} + + private: + Value v_; + }; + // Immediate non-optional member. Note that AnyAttribute is always // mapped to a sequence. // @@ -1505,27 +1590,20 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; + FromBaseCtorArg (Context& c, CtorArgType, bool arg); - FromBaseCtorArg (Context& c, ArgType, Boolean arg); - - virtual Void + virtual void traverse (SemanticGraph::Any&); - virtual Void + virtual void traverse (SemanticGraph::Attribute&); - virtual Void + virtual void traverse (SemanticGraph::Element&); private: - ArgType arg_type_; - Boolean arg_; + CtorArgType arg_type_; + bool arg_; }; // List of all non-optional members and a simple base. Note that @@ -1539,32 +1617,25 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; - // The second version outputs the argument name and stores // in in the base_arg string. // - CtorArgs (Context&, ArgType); - CtorArgs (Context&, ArgType, String& base_arg); + CtorArgs (Context&, CtorArgType); + CtorArgs (Context&, CtorArgType, String& base_arg); - virtual Void + virtual void traverse (SemanticGraph::Type&); - virtual Void + virtual void traverse (SemanticGraph::Enumeration&); - virtual Void + virtual void traverse (SemanticGraph::Any&); - virtual Void + virtual void traverse (SemanticGraph::Attribute&); - virtual Void + virtual void traverse (SemanticGraph::Element&); private: @@ -1572,10 +1643,10 @@ namespace CXX comma (); private: - ArgType arg_type_; + CtorArgType arg_type_; String base_; String* base_arg_; - Boolean first_; + bool first_; private: Traversal::Inherits inherits_; @@ -1607,92 +1678,92 @@ namespace CXX { // generate should initially be false. // - GenerateWithoutBaseCtor (Boolean& generate) + GenerateWithoutBaseCtor (bool& generate) : generate_ (generate) { *this >> inherits_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::List&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Union&) { // No default initialization. } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { Complex::inherits (c); } - virtual Void + virtual void traverse (SemanticGraph::Enumeration&) { // No default initialization. } - virtual Void + virtual void traverse (SemanticGraph::AnyType&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary&) { generate_ = true; } private: - Boolean& generate_; + bool& generate_; Traversal::Inherits inherits_; }; @@ -1706,22 +1777,15 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; - - CtorArgsWithoutBase (Context& c, ArgType, Boolean arg, Boolean first); + CtorArgsWithoutBase (Context& c, CtorArgType, bool arg, bool first); - virtual Void + virtual void traverse (SemanticGraph::Any&); - virtual Void + virtual void traverse (SemanticGraph::Element&); - virtual Void + virtual void traverse (SemanticGraph::Attribute&); private: @@ -1729,9 +1793,9 @@ namespace CXX comma (); private: - ArgType arg_type_; - Boolean arg_; - Boolean first_; + CtorArgType arg_type_; + bool arg_; + bool first_; private: Traversal::Inherits inherits_; @@ -1747,10 +1811,10 @@ namespace CXX { } - Boolean + bool generate_p (SemanticGraph::Element&); - Boolean + bool doc_root_p (SemanticGraph::Element&); private: @@ -1765,26 +1829,26 @@ namespace CXX CXX::Namespace::ScopeTracker { Namespace (Context&, - UnsignedLong first = 1, - UnsignedLong last = 0); + size_t first = 1, + size_t last = 0); - virtual Void + virtual void traverse (Type&); protected: - virtual Void - enter (Type&, String const& name, Boolean last); + virtual void + enter (Type&, String const& name, bool last); - virtual Void + virtual void leave (); protected: Context& ctx_; private: - UnsignedLong first_; - UnsignedLong last_; - UnsignedLong count_; + size_t first_; + size_t last_; + size_t count_; }; // @@ -1796,8 +1860,8 @@ namespace CXX { } - virtual Void - enter (Type& ns, String const& name, Boolean last) + virtual void + enter (Type& ns, String const& name, bool last) { Namespace::enter (ns, name, last); @@ -1823,7 +1887,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Type& t); }; @@ -1841,33 +1905,33 @@ namespace CXX Includes (Context& c, Type type) : ctx_ (c), type_ (type), - forward_ (c.options.value<CLI::generate_forward> ()), + forward_ (c.options.generate_forward ()), namespace_ (c), type_forward_ (c) { schema_ >> schema_names_ >> namespace_ >> names_ >> type_forward_; } - virtual Void + virtual void traverse (SemanticGraph::Imports& i) { traverse_ (i); } - virtual Void + virtual void traverse (SemanticGraph::Includes& i) { traverse_ (i); } private: - Void + void traverse_ (SemanticGraph::Uses&); private: Context& ctx_; Type type_; - Boolean forward_; + bool forward_; Traversal::Schema schema_; Traversal::Names schema_names_; @@ -1907,85 +1971,85 @@ namespace CXX // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { gen_include (t, "byte.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { gen_include (t, "unsigned-byte.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { gen_include (t, "short.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { gen_include (t, "unsigned-short.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { gen_include (t, "int.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { gen_include (t, "unsigned-int.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { if (!long_) long_ = gen_include (t, "long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { if (!unsigned_long_) unsigned_long_ = gen_include (t, "unsigned-long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { if (!long_) long_ = gen_include (t, "long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { if (!long_) long_ = gen_include (t, "long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { if (!unsigned_long_) unsigned_long_ = gen_include (t, "unsigned-long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { if (!unsigned_long_) unsigned_long_ = gen_include (t, "unsigned-long.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { if (!long_) @@ -1994,7 +2058,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { gen_include (t, "boolean.hxx"); @@ -2002,26 +2066,26 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { gen_include (t, "float.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { gen_include (t, "double.hxx"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { gen_include (t, "decimal.hxx"); } private: - Boolean + bool gen_include (SemanticGraph::Type& t, String const& file) { String custom; @@ -2046,8 +2110,8 @@ namespace CXX private: String prefix_; - Boolean long_; - Boolean unsigned_long_; + bool long_; + bool unsigned_long_; }; } } diff --git a/xsd/xsd/cxx/tree/fundamental-header.hxx b/xsd/xsd/cxx/tree/fundamental-header.hxx index 71cfbea..925d65e 100644 --- a/xsd/xsd/cxx/tree/fundamental-header.hxx +++ b/xsd/xsd/cxx/tree/fundamental-header.hxx @@ -1,13 +1,13 @@ // file : xsd/cxx/tree/fundamental-header.hxx -// 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 #ifndef CXX_TREE_FUNDAMENTAL_HEADER_HXX #define CXX_TREE_FUNDAMENTAL_HEADER_HXX -#include <cult/containers/set.hxx> -#include <cult/containers/vector.hxx> +#include <set> +#include <vector> +#include <algorithm> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> @@ -80,7 +80,7 @@ namespace CXX FundamentalNamespace (Context& c) : DocumentedNamespace (c), Context (c), - export_ (c.options.value<CLI::export_xml_schema> () && type_exp) + export_ (c.options.export_xml_schema () && type_exp) { *this >> names_ >> *this; @@ -88,13 +88,13 @@ namespace CXX xs_ns_ = ns_name (xs_ns ()); } - Void + void gen_typedef (String const& name, String const& type, String const& arg1 = L"", String const& arg2 = L"", String const& arg3 = L"", - Boolean export_type = true) + bool export_type = true) { os << "typedef " << type; @@ -225,7 +225,7 @@ namespace CXX // anyType and anySimpleType // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { os << "// anyType and anySimpleType." << endl @@ -237,11 +237,11 @@ namespace CXX type_ = built_in_type (t, "::xsd::cxx::tree::type"); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { simple_type_ = built_in_type ( - t, L"::xsd::cxx::tree::simple_type< ", type_); + t, L"::xsd::cxx::tree::simple_type< " + char_type + L", ", type_); if (doxygen) os << "/**" << endl @@ -259,7 +259,7 @@ namespace CXX // Integrals. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { os << "// 8-bit" << endl @@ -271,14 +271,14 @@ namespace CXX built_in_type (t, "signed char"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { built_in_type (t, "unsigned char"); os << endl; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { os << "// 16-bit" << endl @@ -290,14 +290,14 @@ namespace CXX built_in_type (t, "short"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { built_in_type (t, "unsigned short"); os << endl; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { os << "// 32-bit" << endl @@ -309,14 +309,14 @@ namespace CXX built_in_type (t, "int"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { built_in_type (t, "unsigned int"); os << endl; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { os << "// 64-bit" << endl @@ -328,14 +328,14 @@ namespace CXX built_in_type (t, "long long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { built_in_type (t, "unsigned long long"); os << endl; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { os << "// Supposed to be arbitrary-length integral types." << endl @@ -347,25 +347,25 @@ namespace CXX built_in_type (t, "long long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { built_in_type (t, "long long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { built_in_type (t, "unsigned long long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { built_in_type (t, "unsigned long long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { built_in_type (t, "long long"); @@ -374,7 +374,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { os << "// Boolean." << endl @@ -390,7 +390,7 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { os << "// Floating-point types." << endl @@ -402,13 +402,13 @@ namespace CXX built_in_type (t, "float"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { double_ = built_in_type (t, "double"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { decimal_ = built_in_type (t, "double"); @@ -418,7 +418,7 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { os << "// String types." << endl @@ -431,7 +431,7 @@ namespace CXX t, L"::xsd::cxx::tree::string< " + char_type + L", ", simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { norm_string_ = built_in_type ( @@ -440,21 +440,21 @@ namespace CXX string_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { token_ = built_in_type ( t, L"::xsd::cxx::tree::token< " + char_type + L", ", norm_string_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { nmtoken_ = built_in_type ( t, L"::xsd::cxx::tree::nmtoken< " + char_type + L", ", token_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { built_in_type ( @@ -464,21 +464,21 @@ namespace CXX nmtoken_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { name_ = built_in_type ( t, L"::xsd::cxx::tree::name< " + char_type + L", ", token_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { ncname_ = built_in_type ( t, L"::xsd::cxx::tree::ncname< " + char_type + L", ", name_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { built_in_type ( @@ -489,7 +489,7 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { os << "// ID/IDREF." << endl @@ -502,14 +502,14 @@ namespace CXX t, L"::xsd::cxx::tree::id< " + char_type + L", ", ncname_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { idref_ = built_in_type ( t, L"::xsd::cxx::tree::idref< " + char_type + L", ", ncname_, type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { built_in_type ( @@ -524,7 +524,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { os << "// URI." << endl @@ -541,7 +541,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { os << "// Qualified name." << endl @@ -562,7 +562,7 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { os << "// Binary." << endl @@ -586,7 +586,7 @@ namespace CXX simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { built_in_type ( @@ -600,7 +600,7 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { os << "// Date/time." << endl @@ -622,7 +622,7 @@ namespace CXX t, L"::xsd::cxx::tree::date< " + char_type + L", ", simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { built_in_type ( @@ -631,7 +631,7 @@ namespace CXX simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { built_in_type ( @@ -640,21 +640,21 @@ namespace CXX simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { built_in_type ( t, L"::xsd::cxx::tree::gday< " + char_type + L", ", simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { built_in_type ( t, L"::xsd::cxx::tree::gmonth< " + char_type + L", ", simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { built_in_type ( @@ -663,14 +663,14 @@ namespace CXX simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { built_in_type ( t, L"::xsd::cxx::tree::gyear< " + char_type + L", ", simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { built_in_type ( @@ -679,7 +679,7 @@ namespace CXX simple_type_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { built_in_type ( @@ -690,7 +690,7 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { os << "// Entity." << endl @@ -703,7 +703,7 @@ namespace CXX t, L"::xsd::cxx::tree::entity< " + char_type + L", ", ncname_); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { built_in_type ( @@ -715,16 +715,27 @@ namespace CXX os << endl; } - virtual Void + virtual void post (SemanticGraph::Namespace& n) { SemanticGraph::Context& c (xs_ns ().context()); - Boolean parsing (!options.value<CLI::suppress_parsing> ()); - Boolean serialization (options.value<CLI::generate_serialization> ()); - Boolean element_map (options.value<CLI::generate_element_map> ()); + bool parsing (!options.suppress_parsing ()); + bool serialization (options.generate_serialization ()); + bool element_map (options.generate_element_map ()); - if (options.value<CLI::generate_element_type> ()) + { + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Content order sequence entry." << endl + << " */" << endl; + + gen_typedef (c.get<String> ("content-order"), + "::xsd::cxx::tree::content_order"); + } + + if (options.generate_element_type ()) { if (doxygen) os << "/**" << endl @@ -838,7 +849,7 @@ namespace CXX //@@ Can't change names of ostream/istream since they are // templates. // - if (!options.value<CLI::generate_insertion> ().empty ()) + if (!options.generate_insertion ().empty ()) { if (doxygen) os << "/**" << endl @@ -852,7 +863,7 @@ namespace CXX << endl; } - if (!options.value<CLI::generate_extraction> ().empty ()) + if (!options.generate_extraction ().empty ()) { if (doxygen) os << "/**" << endl @@ -1050,7 +1061,7 @@ namespace CXX L"::xsd::cxx::tree::no_prefix_mapping< " + char_type + L" >"); } - if (options.value<CLI::generate_polymorphic> ()) + if (options.generate_polymorphic ()) { if (parsing || serialization) { @@ -1145,7 +1156,8 @@ namespace CXX << "{"; // @@ Disregarding current naming convention by using the - // fixed name (no template typedef). + // fixed name (even in C++11, template alias is not yet + // widely supported). // if (doxygen) os << "/**" << endl @@ -1155,8 +1167,12 @@ namespace CXX os << "// Automatic pointer for DOMDocument." << endl << "//" << endl; - os << "using ::xsd::cxx::xml::dom::auto_ptr;" - << endl; + if (std >= cxx_version::cxx11) + os << "using ::xsd::cxx::xml::dom::unique_ptr;"; + else + os << "using ::xsd::cxx::xml::dom::auto_ptr;"; + + os << endl; if (parsing) { @@ -1228,7 +1244,7 @@ namespace CXX { StringSet ns_set; - for (StringList::ConstIterator i (exports_.begin ()); + for (StringList::const_iterator i (exports_.begin ()); i != exports_.end (); ++i) { String const& e (*i); @@ -1245,14 +1261,14 @@ namespace CXX << "namespace cxx" << "{"; - for (StringSet::ConstIterator i (ns_set.begin ()); + for (StringSet::const_iterator i (ns_set.begin ()); i != ns_set.end (); ++i) { String const& ns (*i); String prefix (L"::xsd::cxx::" + ns); - Size n (1); - for (Size b (0), e (ns.find (':')); ; n++) + size_t n (1); + for (size_t b (0), e (ns.find (':')); ; n++) { os << "namespace " << String (ns, b, e) << "{"; @@ -1264,7 +1280,7 @@ namespace CXX e = ns.find (':', b); } - for (StringList::ConstIterator i (exports_.begin ()); + for (StringList::const_iterator i (exports_.begin ()); i != exports_.end (); ++i) { String const& e (*i); @@ -1289,10 +1305,10 @@ namespace CXX } private: - typedef Cult::Containers::Set<String> StringSet; - typedef Cult::Containers::Vector<String> StringList; + typedef std::set<String> StringSet; + typedef std::vector<String> StringList; - Boolean export_; + bool export_; StringList exports_; StringSet exports_set_; String xs_ns_; diff --git a/xsd/xsd/cxx/tree/generator.cxx b/xsd/xsd/cxx/tree/generator.cxx index fe5286a..7a413bd 100644 --- a/xsd/xsd/cxx/tree/generator.cxx +++ b/xsd/xsd/cxx/tree/generator.cxx @@ -1,8 +1,22 @@ // file : xsd/cxx/tree/generator.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 <vector> +#include <algorithm> +#include <iostream> +#include <fstream> + +#include <cutl/re.hxx> +#include <cutl/shared-ptr.hxx> + +#include <cutl/compiler/code-stream.hxx> +#include <cutl/compiler/cxx-indenter.hxx> +#include <cutl/compiler/sloc-counter.hxx> + +#include <xsd-frontend/semantic-graph.hxx> +#include <xsd-frontend/generators/dependencies.hxx> + #include <cxx/tree/generator.hxx> #include <cxx/tree/elements.hxx> @@ -10,6 +24,7 @@ #include <cxx/tree/counter.hxx> #include <cxx/tree/validator.hxx> #include <cxx/tree/name-processor.hxx> +#include <cxx/tree/order-processor.hxx> #include <cxx/tree/polymorphism-processor.hxx> #include <cxx/tree/tree-forward.hxx> @@ -30,45 +45,25 @@ #include <cxx/tree/stream-insertion-source.hxx> #include <cxx/tree/stream-extraction-source.hxx> -#include <xsd-frontend/semantic-graph.hxx> - -#include <backend-elements/regex.hxx> -#include <backend-elements/indentation/cxx.hxx> -#include <backend-elements/indentation/sloc.hxx> -#include <backend-elements/indentation/clip.hxx> - -#include <cult/containers/set.hxx> -#include <cult/containers/vector.hxx> - -#include <boost/filesystem/fstream.hpp> - -#include <iostream> - -#include <usage.hxx> +#include <cxx/tree/options.hxx> #include "../../../libxsd/xsd/cxx/version.hxx" -using std::endl; -using std::wcerr; - +using namespace std; +using namespace cutl; using namespace XSDFrontend::SemanticGraph; // // -typedef -boost::filesystem::wifstream -WideInputFileStream; - -typedef -boost::filesystem::wofstream -WideOutputFileStream; +typedef std::wifstream WideInputFileStream; +typedef std::wofstream WideOutputFileStream; namespace CXX { namespace { - Char const copyright_gpl[] = - "// Copyright (C) 2005-2010 Code Synthesis Tools CC\n" + char const copyright_gpl[] = + "// Copyright (c) 2005-2014 Code Synthesis Tools CC\n" "//\n" "// This program was generated by CodeSynthesis XSD, an XML Schema to\n" "// C++ data binding compiler.\n" @@ -101,8 +96,8 @@ namespace CXX "// in the accompanying FLOSSE file.\n" "//\n\n"; - Char const copyright_proprietary[] = - "// Copyright (C) 2005-2010 Code Synthesis Tools CC\n" + char const copyright_proprietary[] = + "// Copyright (c) 2005-2014 Code Synthesis Tools CC\n" "//\n" "// This program was generated by CodeSynthesis XSD, an XML Schema\n" "// to C++ data binding compiler, in the Proprietary License mode.\n" @@ -112,673 +107,23 @@ namespace CXX "//\n\n"; } - namespace Tree - { - namespace CLI - { - extern Key char_type = "char-type"; - extern Key char_encoding = "char-encoding"; - extern Key output_dir = "output-dir"; - extern Key generate_polymorphic = "generate-polymorphic"; - extern Key polymorphic_type = "polymorphic-type"; - extern Key polymorphic_type_all = "polymorphic-type-all"; - extern Key generate_serialization = "generate-serialization"; - extern Key generate_inline = "generate-inline"; - extern Key generate_ostream = "generate-ostream"; - extern Key generate_doxygen = "generate-doxygen"; - extern Key generate_comparison = "generate-comparison"; - extern Key generate_default_ctor = "generate-default-ctor"; - extern Key generate_from_base_ctor = "generate-from-base-ctor"; - extern Key generate_detach = "generate-detach"; - extern Key generate_wildcard = "generate-wildcard"; - extern Key generate_insertion = "generate-insertion"; - extern Key generate_extraction = "generate-extraction"; - extern Key generate_forward = "generate-forward"; - extern Key generate_xml_schema = "generate-xml-schema"; - extern Key extern_xml_schema = "extern-xml-schema"; - extern Key suppress_parsing = "suppress-parsing"; - extern Key generate_element_type = "generate-element-type"; - extern Key generate_element_map = "generate-element-map"; - extern Key generate_intellisense = "generate-intellisense"; - extern Key omit_default_attributes = "omit-default-attributes"; - extern Key namespace_map = "namespace-map"; - extern Key namespace_regex = "namespace-regex"; - extern Key namespace_regex_trace = "namespace-regex-trace"; - extern Key reserved_name = "reserved-name"; - extern Key type_naming = "type-naming"; - extern Key function_naming = "function-naming"; - extern Key type_regex = "type-regex"; - extern Key accessor_regex = "accessor-regex"; - extern Key one_accessor_regex = "one-accessor-regex"; - extern Key opt_accessor_regex = "opt-accessor-regex"; - extern Key seq_accessor_regex = "seq-accessor-regex"; - extern Key modifier_regex = "modifier-regex"; - extern Key one_modifier_regex = "one-modifier-regex"; - extern Key opt_modifier_regex = "opt-modifier-regex"; - extern Key seq_modifier_regex = "seq-modifier-regex"; - extern Key parser_regex = "parser-regex"; - extern Key serializer_regex = "serializer-regex"; - extern Key enumerator_regex = "enumerator-regex"; - extern Key element_type_regex = "element-type-regex"; - extern Key name_regex_trace = "name-regex-trace"; - extern Key include_with_brackets = "include-with-brackets"; - extern Key include_prefix = "include-prefix"; - extern Key include_regex = "include-regex"; - extern Key include_regex_trace = "include-regex-trace"; - extern Key guard_prefix = "guard-prefix"; - extern Key root_element_first = "root-element-first"; - extern Key root_element_last = "root-element-last"; - extern Key root_element_all = "root-element-all"; - extern Key root_element_none = "root-element-none"; - extern Key root_element = "root-element"; - extern Key custom_type = "custom-type"; - extern Key custom_type_regex = "custom-type-regex"; - extern Key hxx_suffix = "hxx-suffix"; - extern Key ixx_suffix = "ixx-suffix"; - extern Key cxx_suffix = "cxx-suffix"; - extern Key fwd_suffix = "fwd-suffix"; - extern Key hxx_regex = "hxx-regex"; - extern Key ixx_regex = "ixx-regex"; - extern Key cxx_regex = "cxx-regex"; - extern Key fwd_regex = "fwd-regex"; - extern Key hxx_prologue = "hxx-prologue"; - extern Key ixx_prologue = "ixx-prologue"; - extern Key cxx_prologue = "cxx-prologue"; - extern Key fwd_prologue = "fwd-prologue"; - extern Key prologue = "prologue"; - extern Key hxx_epilogue = "hxx-epilogue"; - extern Key ixx_epilogue = "ixx-epilogue"; - extern Key cxx_epilogue = "cxx-epilogue"; - extern Key fwd_epilogue = "fwd-epilogue"; - extern Key epilogue = "epilogue"; - extern Key hxx_prologue_file = "hxx-prologue-file"; - extern Key ixx_prologue_file = "ixx-prologue-file"; - extern Key cxx_prologue_file = "cxx-prologue-file"; - extern Key fwd_prologue_file = "fwd-prologue-file"; - extern Key prologue_file = "prologue-file"; - extern Key hxx_epilogue_file = "hxx-epilogue-file"; - extern Key ixx_epilogue_file = "ixx-epilogue-file"; - extern Key cxx_epilogue_file = "cxx-epilogue-file"; - extern Key fwd_epilogue_file = "fwd-epilogue-file"; - extern Key epilogue_file = "epilogue-file"; - extern Key parts = "parts"; - extern Key parts_suffix = "parts-suffix"; - extern Key export_symbol = "export-symbol"; - extern Key export_xml_schema = "export-xml-schema"; - extern Key export_maps = "export-maps"; - extern Key import_maps = "import-maps"; - extern Key show_anonymous = "show-anonymous"; - extern Key show_sloc = "show-sloc"; - extern Key proprietary_license = "proprietary-license"; - extern Key disable_multi_import = "disable-multi-import"; - } - } - - Void Tree::Generator:: + void Tree::Generator:: usage () { - std::wostream& e (wcerr); - ::CLI::Indent::Clip< ::CLI::OptionsUsage, WideChar> clip (e); - - e << "--char-type <type>" << endl - << " Use <type> as the base character type. Valid\n" - << " values are 'char' (default) and 'wchar_t'." - << endl; - - e << "--char-encoding <enc>" << endl - << " Specify the character encoding that should be used\n" - << " in the object model. Valid values for the 'char'\n" - << " character type are 'utf8' (default), 'iso8859-1',\n" - << " 'lcp', and 'custom'. For the 'wchar_t' character\n" - << " type the only valid value is 'auto'." - << endl; - - e << "--output-dir <dir>" << endl - << " Write generated files to <dir> instead of current\n" - << " directory." - << endl; - - e << "--generate-polymorphic" << endl - << " Generate polymorphism-aware code. Specify this\n" - << " option if you use substitution groups or xsi:type." - << endl; - - e << "--polymorphic-type <type>" << endl - << " Indicate that <type> is a root of a polymorphic\n" - << " type hierarchy." - << endl; - - e << "--polymorphic-type-all" << endl - << " Indicate that all types should be treated as\n" - << " polymorphic." - << endl; - - e << "--generate-serialization" << endl - << " Generate serialization functions. They convert an\n" - << " in-memory representation back to XML." - << endl; - - e << "--generate-inline" << endl - << " Generate certain functions inline." - << endl; - - e << "--generate-ostream" << endl - << " Generate ostream insertion operators." - << endl; - - e << "--generate-doxygen" << endl - << " Generate documentation comments in the Doxygen\n" - << " format." - << endl; - - e << "--generate-comparison" << endl - << " Generate comparison operators." - << endl; - - e << "--generate-default-ctor" << endl - << " Generate default constructors even for types that\n" - << " have required members." - << endl; - - e << "--generate-from-base-ctor" << endl - << " Generate from-base constructors." - << endl; - - e << "--generate-detach" << endl - << " Generate detach functions for required members." - << endl; - - e << "--generate-wildcard" << endl - << " Generate accessors/modifiers as well as parsing\n" - << " and serialization code for XML Schema wildcards." - << endl; - - e << "--generate-insertion <os>" << endl - << " Generate data representation stream insertion\n" - << " operators for the <os> output stream type." - << endl; - - e << "--generate-extraction <is>" << endl - << " Generate data representation stream extraction\n" - << " constructors for the <is> input stream type." - << endl; - - e << "--generate-forward" << endl - << " Generate forward declaration file." - << endl; - - e << "--generate-xml-schema" << endl - << " Generate a C++ header file as if the schema being\n" - << " compiled defines the XML Schema namespace." - << endl; - - e << "--extern-xml-schema <file>" << endl - << " Generate code as if the XML Schema namespace was\n" - << " defined in <file> and xsd:included in the schema\n" - << " being compiled." - << endl; - - e << "--suppress-parsing" << endl - << " Suppress the generation of parsing functions." - << endl; - - e << "--generate-element-type" << endl - << " Generate types instead of parsing/serialization\n" - << " functions for root elements." - << endl; - - e << "--generate-element-map" << endl - << " Generate a root element map that allows uniform\n" - << " parsing/serialization of multiple root elements.\n" - << endl; - - e << "--generate-intellisense" << endl - << " Generate workarounds for IntelliSense bugs in\n" - << " Visual Studio 2005 (8.0)." - << endl; - - e << "--omit-default-attributes" << endl - << " Omit attributes with default and fixed values\n" - << " from serialized XML documents." - << endl; - - e << "--namespace-map <xns>=<cns>" << endl - << " Map XML Schema namespace <xns> to C++ namespace\n" - << " <cns>. Repeat this option to specify mapping for\n" - << " more than one XML Schema namespace." - << endl; - - e << "--namespace-regex <regex>" << endl - << " Add <regex> to the list of regular expressions\n" - << " used to translate XML Schema namespace names to\n" - << " C++ namespace names." - << endl; - - e << "--namespace-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --namespace-regex option." - << endl; - - e << "--reserved-name <name>" << endl - << " Add <name> to the list of names that should not\n" - << " be used as identifiers. The name can optionally\n" - << " be followed by '=' and the replacement name that\n" - << " should be used instead." - << endl; - - e << "--type-naming <style>" << endl - << " Specify the type naming convention that should be\n" - << " used in the generated code. Valid styles are 'knr'\n" - << " (default), 'ucc', and 'java'." - << endl; - - e << "--function-naming <style>" << endl - << " Specify the function naming convention that should\n" - << " be used in the generated code. Valid styles are\n" - << " 'knr' (default), 'lcc', and 'java'." - << endl; - - e << "--type-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema type names to C++\n" - << " type names." - << endl; - - e << "--accessor-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements and\n" - << " attributes to C++ accessor function names." - << endl; - - e << "--one-accessor-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality one to C++\n" - << " accessor function names." - << endl; - - e << "--opt-accessor-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality optional to C++\n" - << " accessor function names." - << endl; - - e << "--seq-accessor-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality sequence to C++\n" - << " accessor function names." - << endl; - - e << "--modifier-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements and\n" - << " attributes to C++ modifier function names." - << endl; - - e << "--one-modifier-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality one to C++\n" - << " modifier function names." - << endl; - - e << "--opt-modifier-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality optional to C++\n" - << " modifier function names." - << endl; - - e << "--seq-modifier-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema names of elements\n" - << " and attributes with cardinality sequence to C++\n" - << " modifier function names." - << endl; - - e << "--parser-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema element names to\n" - << " C++ parsing function names." - << endl; - - e << "--serializer-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema element names to\n" - << " C++ serialization function names." - << endl; - - e << "--enumerator-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema enumeration values\n" - << " to C++ enumerator names." - << endl; - - e << "--element-type-regex <expr>" << endl - << " Add <expr> to the list of regular expressions\n" - << " used to translate XML Schema element names to\n" - << " C++ element type names." - << endl; - - e << "--name-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the name transformation options." - << endl; - - e << "--include-with-brackets" << endl - << " Use angle brackets (<>) instead of quotes (\"\") in\n" - << " generated #include directives." - << endl; - - e << "--include-prefix <prefix>" << endl - << " Add <prefix> to generated #include directive\n" - << " paths." - << endl; - - e << "--include-regex <regex>" << endl - << " Add <regex> to the list of regular expressions\n" - << " used to transform #include directive paths." - << endl; - - e << "--include-regex-trace" << endl - << " Trace the process of applying regular expressions\n" - << " specified with the --include-regex option." - << endl; - - e << "--guard-prefix <prefix>" << endl - << " Add <prefix> to generated header inclusion guards." - << endl; - - e << "--root-element-first" << endl - << " Treat only the first global element as a document\n" - << " root." - << endl; - - e << "--root-element-last" << endl - << " Treat only the last global element as a document\n" - << " root." - << endl; - - e << "--root-element-all" << endl - << " Treat all global elements as document roots." - << endl; - - e << "--root-element-none" << endl - << " Don't treat any global elements as document roots." - << endl; - - e << "--root-element <element>" << endl - << " Treat only <element> as a document root. Repeat\n" - << " this option to specify more than one root element." - << endl; - - e << "--custom-type <map>" << endl - << " Use a custom C++ type instead of the generated\n" - << " class. The <map> argument is in the form\n" - << " name[=type[/base]], where <name> is a type name as\n" - << " defined in XML Schema, <type> is a C++ type name\n" - << " that should be used instead, and optional <base>\n" - << " is a C++ name that should be given to the C++\n" - << " class generated from the XML Schema definition\n" - << " which is normally used as a base for the custom\n" - << " type." - << endl; - - e << "--custom-type-regex <regex>" << endl - << " Use custom C++ types instead of the generated\n" - << " classes. The <regex> argument is in the form\n" - << " /name/[type/[base/]], where <name> is a regex\n" - << " pattern that will be matched against type names\n" - << " as defined in XML Schema, <type> is a C++ type\n" - << " name that should be used instead, and optional\n" - << " <base> is a C++ name that should be given to\n" - << " the C++ class generated from the XML Schema\n" - << " definition." - << endl; - - e << "--hxx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.hxx' to\n" - << " construct the name of the header file." - << endl; - - e << "--ixx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.ixx' to\n" - << " construct the name of the inline file." - << endl; - - e << "--cxx-suffix <suffix>" << endl - << " Use <suffix> instead of the default '.cxx' to\n" - << " construct the name of the source file." - << endl; - - e << "--fwd-suffix <suffix>" << endl - << " Use <suffix> instead of the default '-fwd.hxx'\n" - << " to construct the name of the forward declaration\n" - << " file." - << endl; - - e << "--hxx-regex <regex>" << endl - << " Use <regex> to construct the name of the header\n" - << " file." - << endl; - - e << "--ixx-regex <regex>" << endl - << " Use <regex> to construct the name of the inline\n" - << " file." - << endl; - - e << "--cxx-regex <regex>" << endl - << " Use <regex> to construct the name of the source\n" - << " file." - << endl; - - e << "--fwd-regex <regex>" << endl - << " Use <regex> to construct the name of the forward\n" - << " declaration file." - << endl; - - // Prologues. - // - e << "--hxx-prologue <text>" << endl - << " Insert <text> at the beginning of the header file." - << endl; - - e << "--ixx-prologue <text>" << endl - << " Insert <text> at the beginning of the inline file." - << endl; - - e << "--cxx-prologue <text>" << endl - << " Insert <text> at the beginning of the source file." - << endl; - - e << "--fwd-prologue <text>" << endl - << " Insert <text> at the beginning of the forward\n" - << " declaration file." - << endl; - - e << "--prologue <text>" << endl - << " Insert <text> at the beginning of each generated\n" - << " file for which there is no file-specific prologue." - << endl; - - - // Epilogues. - // - e << "--hxx-epilogue <text>" << endl - << " Insert <text> at the end of the header file." - << endl; - - e << "--ixx-epilogue <text>" << endl - << " Insert <text> at the end of the inline file." - << endl; - - e << "--cxx-epilogue <text>" << endl - << " Insert <text> at the end of the source file." - << endl; - - e << "--fwd-epilogue <text>" << endl - << " Insert <text> at the end of the forward\n" - << " declaration file." - << endl; - - e << "--epilogue <text>" << endl - << " Insert <text> at the end of each generated file\n" - << " for which there is no file-specific epilogue." - << endl; - - - // Prologue files. - // - e << "--hxx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the header file." - << endl; - - e << "--ixx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the inline file." - << endl; - - e << "--cxx-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the source file." - << endl; - - e << "--fwd-prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of the forward declaration file." - << endl; - - e << "--prologue-file <file>" << endl - << " Insert the content of the <file> at the beginning\n" - << " of each generated file for which there is no file-\n" - << " specific prologue file." - << endl; - - // Epilogue files. - // - e << "--hxx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the header file." - << endl; - - e << "--ixx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the inline file." - << endl; - - e << "--cxx-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the source file." - << endl; - - e << "--fwd-epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " the forward declaration file." - << endl; - - e << "--epilogue-file <file>" << endl - << " Insert the content of the <file> at the end of\n" - << " each generated file for which there is no file-\n" - << " specific epilogue file." - << endl; - - // Misc. - // - e << "--parts <num>" << endl - << " Split generated source code into <num> parts." - << endl; - - e << "--parts-suffix <suffix>" << endl - << " Use <suffix> instead of the default '-' to\n" - << " separate the file name from the part number." - << endl; - - e << "--custom-literals <file>" << endl - << " Load custom XML string to C++ literal mappings\n" - << " from <file>." - << endl; - - e << "--export-symbol <symbol>" << endl - << " Export symbol for Win32 DLL export/import control." - << endl; - - e << "--export-xml-schema" << endl - << " Export/import types in the XML Schema namespace." - << endl; - - e << "--export-maps" << endl - << " Export polymorphism support maps from Win32 DLL." - << endl; - - e << "--import-maps" << endl - << " Import polymorphism support maps from Win32 DLL." - << endl; - - e << "--show-anonymous" << endl - << " Show elements and attributes that are of anonymous\n" - << " types." - << endl; - - e << "--show-sloc" << endl - << " Show the number of generated physical source lines\n" - << " of code (SLOC)." - << endl; - - e << "--sloc-limit <num>" << endl - << " Check that the number of generated physical source\n" - << " lines of code (SLOC) does not exceed <num>." - << endl; - - e << "--options-file <file>" << endl - << " Read additional options from <file>. Each option\n" - << " should appear on a separate line optionally\n" - << " followed by space and an argument." - << endl; - - e << "--proprietary-license" << endl - << " Indicate that the generated code is licensed under\n" - << " a proprietary license instead of the GPL." - << endl; + CXX::Tree::options::print_usage (wcout); + CXX::options::print_usage (wcout); } - Tree::CLI::OptionsSpec Tree::Generator:: - options_spec () - { - CLI::OptionsSpec spec; - - spec.option<CLI::char_type> ().default_value ("char"); - - spec.option<CLI::hxx_suffix> ().default_value (".hxx"); - spec.option<CLI::ixx_suffix> ().default_value (".ixx"); - spec.option<CLI::cxx_suffix> ().default_value (".cxx"); - spec.option<CLI::fwd_suffix> ().default_value ("-fwd.hxx"); - - spec.option<CLI::type_naming> ().default_value ("knr"); - spec.option<CLI::function_naming> ().default_value ("knr"); - - spec.option<CLI::parts> ().default_value (1); - spec.option<CLI::parts_suffix> ().default_value ("-"); - - return spec; - } - - namespace { - Void + void open (WideInputFileStream& ifs, NarrowString const& path) { try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path fs_path (path, boost::filesystem::native); -#else - Path fs_path (path.c_str()); -#endif - ifs.open (fs_path, std::ios_base::in | std::ios_base::binary); + Path fs_path (path); + ifs.open (fs_path.string ().c_str (), + std::ios_base::in | std::ios_base::binary); if (!ifs.is_open ()) { @@ -797,7 +142,7 @@ namespace CXX } } - Void + void append (WideOutputFileStream& os, NarrowString const& path, WideInputFileStream& default_is) @@ -817,16 +162,15 @@ namespace CXX } } - Void + void append (WideOutputFileStream& os, - Cult::Containers::Vector<NarrowString> const& primary, - Cult::Containers::Vector<NarrowString> const& def) + NarrowStrings const& primary, + NarrowStrings const& def) { - Cult::Containers::Vector<NarrowString> const& v ( - primary.empty () ? def : primary); + NarrowStrings const& v (primary.empty () ? def : primary); - for (Containers::Vector<NarrowString>::ConstIterator - i (v.begin ()), e (v.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (v.begin ()), e (v.end ()); + i != e; ++i) { os << i->c_str () << endl; } @@ -834,34 +178,30 @@ namespace CXX } - UnsignedLong Tree::Generator:: - generate (Tree::CLI::Options const& ops, + size_t Tree::Generator:: + generate (Tree::options const& ops, Schema& schema, Path const& file_path, - Boolean fpt, + bool fpt, StringLiteralMap const& string_literal_map, const WarningSet& disabled_warnings, FileList& file_list, AutoUnlinks& unlinks) { - using std::ios_base; - namespace Indentation = BackendElements::Indentation; - - typedef BackendElements::Regex::Expression<Char> Regex; - - using Cult::Containers::Vector; + using cutl::shared_ptr; + typedef cutl::re::regexsub Regex; - typedef Vector<Path> Paths; - typedef Vector<Evptr<WideOutputFileStream> > WideOutputFileStreams; + typedef vector<Path> Paths; + typedef vector<shared_ptr<WideOutputFileStream> > WideOutputFileStreams; try { // Do option validation. // - if (ops.value<CLI::parts> () < 1) + if (ops.parts () < 1) { wcerr << "error: invalid value for option --parts: " << - ops.value<CLI::parts> () << endl; + ops.parts () << endl; throw Failed (); } @@ -893,8 +233,20 @@ namespace CXX throw Failed (); } + bool gen_cxx (!ops.generate_dep_only ()); + + // Process ordered types. + // + if (gen_cxx) + { + OrderProcessor proc; + if (!proc.process (ops, schema, file_path)) + throw Failed (); + } + // Process names. // + if (gen_cxx) { NameProcessor proc; if (!proc.process (ops, schema, file_path, string_literal_map)) @@ -903,8 +255,9 @@ namespace CXX // Process polymorphic types. // - if (ops.value<CLI::generate_polymorphic> () && - !ops.value<CLI::polymorphic_type_all> ()) + if (gen_cxx && + ops.generate_polymorphic () && + !ops.polymorphic_type_all ()) { PolymorphismProcessor proc; if (!proc.process (ops, schema, file_path, disabled_warnings)) @@ -913,11 +266,9 @@ namespace CXX // Parts. // - UnsignedLong parts (ops.value<CLI::parts> ()); - UnsignedLong units ( - counts.global_types + counts.generated_global_elements); - - UnsignedLong units_per_part (units / parts); + size_t parts (ops.parts ()); + size_t units (counts.global_types + counts.generated_global_elements); + size_t units_per_part (units / parts); if (parts != 1 && units_per_part < 1) { @@ -925,14 +276,14 @@ namespace CXX throw Failed (); } - UnsignedLong complexity_per_part (counts.complexity_total / parts); + size_t complexity_per_part (counts.complexity_total / parts); - NarrowString parts_suffix (ops.value<CLI::parts_suffix> ()); + NarrowString parts_suffix (ops.parts_suffix ()); // // - Boolean generate_xml_schema (ops.value<CLI::generate_xml_schema> ()); + bool generate_xml_schema (ops.generate_xml_schema ()); // We could be compiling several schemas at once in which case // handling of the --generate-xml-schema option gets tricky: we @@ -941,58 +292,68 @@ namespace CXX // if (generate_xml_schema) { - if (NarrowString name = ops.value<CLI::extern_xml_schema> ()) + if (NarrowString name = ops.extern_xml_schema ()) { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - if (file_path.native_file_string () != name) -#else if (file_path.string () != name) -#endif generate_xml_schema = false; } } - Boolean inline_ (ops.value<CLI::generate_inline> () && - !generate_xml_schema); + bool header (true); + bool inline_ (ops.generate_inline () && !generate_xml_schema); + bool forward (ops.generate_forward () && !generate_xml_schema); + bool source (!generate_xml_schema); + bool gen_dep ((ops.generate_dep () || ops.generate_dep_only ()) && + !generate_xml_schema); - Boolean forward (ops.value<CLI::generate_forward> () && - !generate_xml_schema); + if (ops.generate_dep_only () && generate_xml_schema) + { + wcerr << "error: no dependency information can be generated for " + "XML Schema header" << endl; + throw Failed (); + } - Boolean source (!generate_xml_schema); + if (gen_dep && fpt) + { + wcerr << "error: dependency generation not support in the " << + "file-per-type mode" << endl; + throw Failed (); + } // Generate code. // -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - NarrowString name (file_path.leaf ()); -#else - NarrowString name (file_path.filename ().string()); -#endif - - NarrowString hxx_suffix (ops.value <CLI::hxx_suffix> ()); - NarrowString ixx_suffix (ops.value <CLI::ixx_suffix> ()); - NarrowString cxx_suffix (ops.value <CLI::cxx_suffix> ()); - NarrowString fwd_suffix (ops.value <CLI::fwd_suffix> ()); - - Regex hxx_expr (ops.value <CLI::hxx_regex> ().empty () + NarrowString name (file_path.leaf ().string ()); + + NarrowString hxx_suffix (ops.hxx_suffix ()); + NarrowString ixx_suffix (ops.ixx_suffix ()); + NarrowString cxx_suffix (ops.cxx_suffix ()); + NarrowString fwd_suffix (ops.fwd_suffix ()); + NarrowString dep_suffix (ops.dep_suffix ()); + + Regex hxx_expr (ops.hxx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + hxx_suffix + "#" - : ops.value <CLI::hxx_regex> ()); + : ops.hxx_regex ()); - Regex ixx_expr (ops.value <CLI::ixx_regex> ().empty () + Regex ixx_expr (ops.ixx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + ixx_suffix + "#" - : ops.value <CLI::ixx_regex> ()); + : ops.ixx_regex ()); - Regex cxx_expr (ops.value <CLI::cxx_regex> ().empty () + Regex cxx_expr (ops.cxx_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + cxx_suffix + "#" - : ops.value <CLI::cxx_regex> ()); + : ops.cxx_regex ()); - Regex fwd_expr (ops.value <CLI::fwd_regex> ().empty () + Regex fwd_expr (ops.fwd_regex ().empty () ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + fwd_suffix + "#" - : ops.value <CLI::fwd_regex> ()); + : ops.fwd_regex ()); + + Regex dep_expr (ops.dep_regex ().empty () + ? "#^(.+?)(\\.[^./\\\\]+)?$#$1" + dep_suffix + "#" + : ops.dep_regex ()); - if (!hxx_expr.match (name)) + if (header && !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 (); } @@ -1000,7 +361,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 (); } @@ -1008,7 +369,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 (); } @@ -1016,31 +377,35 @@ 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 ()); - -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path hxx_path (hxx_name, boost::filesystem::native); - Path ixx_path (ixx_name, boost::filesystem::native); - Path fwd_path (fwd_name, boost::filesystem::native); -#else - Path hxx_path (hxx_name.c_str()); - Path ixx_path (ixx_name.c_str()); - Path fwd_path (fwd_name.c_str()); -#endif + if (gen_dep && !dep_expr.match (name)) + { + wcerr << "error: dependency expression '" << + dep_expr.regex ().str ().c_str () << "' does not match '" << + name.c_str () << "'" << endl; + throw Failed (); + } + + NarrowString hxx_name (header ? hxx_expr.replace (name) : NarrowString ()); + NarrowString ixx_name (inline_ ? ixx_expr.replace (name) : NarrowString ()); + NarrowString fwd_name (forward ? fwd_expr.replace (name) : NarrowString ()); + NarrowString dep_name (gen_dep ? dep_expr.replace (name) : NarrowString ()); + + Path hxx_path (hxx_name); + Path ixx_path (ixx_name); + Path fwd_path (fwd_name); + Path dep_path (dep_name); Paths cxx_paths; if (source) { if (parts > 1) { - for (UnsignedLong i (0); i < parts; ++i) + for (size_t i (0); i < parts; ++i) { std::ostringstream os; os << i; @@ -1048,44 +413,30 @@ 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 ( -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path (cxx_expr.merge (part_name), boost::filesystem::native)); -#else - Path (cxx_expr.merge (part_name).c_str())); -#endif + cxx_paths.push_back (Path (cxx_expr.replace (part_name))); } } else - cxx_paths.push_back ( -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - Path (cxx_expr.merge (name), boost::filesystem::native)); -#else - Path (cxx_expr.merge (name).c_str())); -#endif + cxx_paths.push_back (Path (cxx_expr.replace (name))); } Path out_dir; - if (NarrowString dir = ops.value<CLI::output_dir> ()) + if (NarrowString dir = ops.output_dir ()) { try { -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - out_dir = Path (dir, boost::filesystem::native); -#else - out_dir = Path (dir.c_str()); -#endif + out_dir = Path (dir); } catch (InvalidPath const&) { @@ -1100,7 +451,7 @@ namespace CXX // unless the user added the directory so that we propagate this // to the output files. // - Path fpt_dir (file_path.branch_path ()); + Path fpt_dir (file_path.directory ()); if (!fpt_dir.empty ()) out_dir /= fpt_dir; @@ -1111,25 +462,42 @@ namespace CXX hxx_path = out_dir / hxx_path; ixx_path = out_dir / ixx_path; fwd_path = out_dir / fwd_path; + dep_path = out_dir / dep_path; - for (Paths::Iterator i (cxx_paths.begin ()); + for (Paths::iterator i (cxx_paths.begin ()); i != cxx_paths.end (); ++i) *i = out_dir / *i; } // // - WideOutputFileStream hxx (hxx_path, ios_base::out); + WideOutputFileStream hxx; WideOutputFileStream ixx; WideOutputFileStream fwd; + WideOutputFileStream dep; WideOutputFileStreams cxx; + // DEP + // + if (gen_dep) + { + dep.open (dep_path.string ().c_str (), ios_base::out); + + if (!dep.is_open ()) + { + wcerr << dep_path << ": error: unable to open in write mode" << endl; + throw Failed (); + } + + unlinks.add (dep_path); + file_list.push_back (dep_path.string ()); + } // FWD // - if (forward) + if (gen_cxx && forward) { - fwd.open (fwd_path, ios_base::out); + fwd.open (fwd_path.string ().c_str (), ios_base::out); if (!fwd.is_open ()) { @@ -1138,35 +506,30 @@ namespace CXX } unlinks.add (fwd_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (fwd_path.native_file_string ()); -#else file_list.push_back (fwd_path.string ()); -#endif } - // HXX // - if (!hxx.is_open ()) + if (gen_cxx && header) { - wcerr << hxx_path << ": error: unable to open in write mode" << endl; - throw Failed (); - } + hxx.open (hxx_path.string ().c_str (), ios_base::out); - unlinks.add (hxx_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (hxx_path.native_file_string ()); -#else - file_list.push_back (hxx_path.string ()); -#endif + if (!hxx.is_open ()) + { + wcerr << hxx_path << ": error: unable to open in write mode" << endl; + throw Failed (); + } + unlinks.add (hxx_path); + file_list.push_back (hxx_path.string ()); + } // IXX // - if (inline_) + if (gen_cxx && inline_) { - ixx.open (ixx_path, ios_base::out); + ixx.open (ixx_path.string ().c_str (), ios_base::out); if (!ixx.is_open ()) { @@ -1175,23 +538,19 @@ namespace CXX } unlinks.add (ixx_path); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (ixx_path.native_file_string ()); -#else file_list.push_back (ixx_path.string ()); -#endif } - // CXX // - if (source) + if (gen_cxx && source) { - for (Paths::Iterator i (cxx_paths.begin ()); + for (Paths::iterator i (cxx_paths.begin ()); i != cxx_paths.end (); ++i) { - Evptr<WideOutputFileStream> s ( - new WideOutputFileStream (*i, ios_base::out)); + shared_ptr<WideOutputFileStream> s ( + new (shared) WideOutputFileStream ( + i->string ().c_str (), ios_base::out)); if (!s->is_open ()) { @@ -1200,29 +559,23 @@ namespace CXX } unlinks.add (*i); -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - file_list.push_back (i->native_file_string ()); -#else file_list.push_back (i->string ()); -#endif cxx.push_back (s); } } - // Print copyright and license. // - Char const* copyright ( - ops.value<CLI::proprietary_license> () - ? copyright_proprietary - : copyright_gpl); + char const* copyright ( + ops.proprietary_license () ? copyright_proprietary : copyright_gpl); - if (forward) - fwd << copyright; + if (gen_cxx && header) + hxx << copyright; - hxx << copyright; + if (gen_cxx && forward) + fwd << copyright; - if (ops.value<CLI::generate_doxygen> ()) + if (ops.generate_doxygen ()) { // Use native path format. // @@ -1234,12 +587,12 @@ namespace CXX } - if (inline_) + if (gen_cxx && inline_) ixx << copyright; - if (source) + if (gen_cxx && source) { - for (WideOutputFileStreams::Iterator i (cxx.begin ()); + for (WideOutputFileStreams::iterator i (cxx.begin ()); i != cxx.end (); ++i) **i << copyright; } @@ -1249,7 +602,7 @@ namespace CXX // WideInputFileStream prologue; { - NarrowString name (ops.value<CLI::prologue_file> ()); + NarrowString name (ops.prologue_file ()); if (name) open (prologue, name); @@ -1259,7 +612,7 @@ namespace CXX // WideInputFileStream epilogue; { - NarrowString name (ops.value<CLI::epilogue_file> ()); + NarrowString name (ops.epilogue_file ()); if (name) open (epilogue, name); @@ -1267,27 +620,83 @@ namespace CXX // SLOC counter. // - UnsignedLong sloc (0); - Boolean show_sloc (ops.value<CLI::show_sloc> ()); + size_t sloc_total (0); + bool show_sloc (ops.show_sloc ()); + + typedef + compiler::ostream_filter<compiler::cxx_indenter, wchar_t> + ind_filter; + + typedef + compiler::ostream_filter<compiler::sloc_counter, wchar_t> + sloc_filter; // // Regex guard_expr ("/([a-z])([A-Z])/$1_$2/"); // Split words. - NarrowString guard_prefix (ops.value<CLI::guard_prefix> ()); + NarrowString guard_prefix (ops.guard_prefix ()); if (!guard_prefix) -#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2 - guard_prefix = file_path.branch_path ().native_directory_string (); -#else - guard_prefix = file_path.branch_path ().string (); -#endif + guard_prefix = file_path.directory ().string (); if (guard_prefix) guard_prefix += '_'; + // DEP + // + if (gen_dep) + { + NarrowString target; + NarrowStrings const& ts (ops.dep_target ()); + + if (!ts.empty ()) + { + for (NarrowStrings::const_iterator i (ts.begin ()); + i != ts.end (); ++i) + target += (target.empty () ? "" : " \\\n") + *i; + } + else + { + target = hxx_path.string (); + + if (forward) + target += " \\\n" + fwd_path.string (); + + if (inline_) + target += " \\\n" + ixx_path.string (); + + for (Paths::iterator i (cxx_paths.begin ()); + i != cxx_paths.end (); ++i) + target += " \\\n" + i->string (); + + target += " \\\n" + dep_path.string (); + } + + dep << target.c_str () << ':'; + + XSDFrontend::Generators::Dependencies gen; + Paths prq (gen.generate (schema, file_path)); + + for (Paths::iterator i (prq.begin ()); i != prq.end (); ++i) + dep << " \\" << endl + << " " << *i; + + dep << endl; + + // If requested, generate phony rules for included/imported schemas + // but not the main file which is the first in the list. + // + if (ops.dep_phony () && prq.size () > 1) + { + for (Paths::iterator i (prq.begin () + 1); i != prq.end (); ++i) + dep << endl + << *i << ':' << endl; + } + } + // FWD // - if (forward) + if (gen_cxx && forward) { Context ctx (fwd, schema, @@ -1300,11 +709,11 @@ namespace CXX &hxx_expr, &ixx_expr); - Indentation::Clip<Indentation::SLOC, WideChar> fwd_sloc (fwd); + sloc_filter sloc (fwd); // 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); @@ -1312,15 +721,46 @@ namespace CXX << "#define " << guard << endl << endl; + if (ctx.std >= cxx_version::cxx11) + { + fwd << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl + << endl; + } + + if (ctx.char_type == L"char") + { + fwd << "#ifndef XSD_USE_CHAR" << endl + << "#define XSD_USE_CHAR" << endl + << "#endif" << endl + << endl; + + fwd << "#ifndef XSD_CXX_TREE_USE_CHAR" << endl + << "#define XSD_CXX_TREE_USE_CHAR" << endl + << "#endif" << endl + << endl; + } + else if (ctx.char_type == L"wchar_t") + { + fwd << "#ifndef XSD_USE_WCHAR" << endl + << "#define XSD_USE_WCHAR" << endl + << "#endif" << endl + << endl; + + fwd << "#ifndef XSD_CXX_TREE_USE_WCHAR" << endl + << "#define XSD_CXX_TREE_USE_WCHAR" << endl + << "#endif" << endl + << endl; + } + // Copy prologue. // fwd << "// Begin prologue." << endl << "//" << endl; - append (fwd, - ops.value<CLI::fwd_prologue> (), - ops.value<CLI::prologue> ()); - append (fwd, ops.value<CLI::fwd_prologue_file> (), prologue); + append (fwd, ops.fwd_prologue (), ops.prologue ()); + append (fwd, ops.fwd_prologue_file (), prologue); fwd << "//" << endl << "// End prologue." << endl @@ -1333,59 +773,28 @@ namespace CXX << "#if (XSD_INT_VERSION != " << XSD_INT_VERSION << "L)" << endl << "#error XSD runtime version mismatch" << endl << "#endif" << endl - << endl; - { - fwd << "#include <xsd/cxx/pre.hxx>" << endl - << endl; - - if (ctx.char_type == L"char") - { - fwd << "#ifndef XSD_USE_CHAR" << endl - << "#define XSD_USE_CHAR" << endl - << "#endif" << endl - << endl; - - fwd << "#ifndef XSD_CXX_TREE_USE_CHAR" << endl - << "#define XSD_CXX_TREE_USE_CHAR" << endl - << "#endif" << endl - << endl; - } - else if (ctx.char_type == L"wchar_t") - { - fwd << "#ifndef XSD_USE_WCHAR" << endl - << "#define XSD_USE_WCHAR" << endl - << "#endif" << endl - << endl; - - fwd << "#ifndef XSD_CXX_TREE_USE_WCHAR" << endl - << "#define XSD_CXX_TREE_USE_WCHAR" << endl - << "#endif" << endl - << endl; - } - - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> fwd_clip (fwd); + fwd << "#include <xsd/cxx/pre.hxx>" << endl + << endl; - // Generate. - // + // Generate. + // + { + ind_filter ind (fwd); // We don't want to indent prologues/epilogues. generate_forward (ctx); - - fwd << "#include <xsd/cxx/post.hxx>" << endl - << endl; } + fwd << "#include <xsd/cxx/post.hxx>" << endl + << endl; + // Copy epilogue. // fwd << "// Begin epilogue." << endl << "//" << endl; - append (fwd, ops.value<CLI::fwd_epilogue_file> (), epilogue); - append (fwd, - ops.value<CLI::fwd_epilogue> (), - ops.value<CLI::epilogue> ()); + append (fwd, ops.fwd_epilogue_file (), epilogue); + append (fwd, ops.fwd_epilogue (), ops.epilogue ()); fwd << "//" << endl << "// End epilogue." << endl @@ -1394,16 +803,14 @@ namespace CXX fwd << "#endif // " << guard << endl; if (show_sloc) - { - wcerr << fwd_path << ": " - << fwd_sloc.buffer ().count () << endl; + wcerr << fwd_path << ": " << sloc.stream ().count () << endl; - sloc += fwd_sloc.buffer ().count (); - } + sloc_total += sloc.stream ().count (); } // HXX // + if (gen_cxx && header) { Context ctx (hxx, schema, @@ -1416,11 +823,11 @@ namespace CXX &hxx_expr, &ixx_expr); - Indentation::Clip<Indentation::SLOC, WideChar> hxx_sloc (hxx); + sloc_filter sloc (hxx); // 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); @@ -1428,14 +835,57 @@ namespace CXX << "#define " << guard << endl << endl; + if (!forward) + { + if (ctx.std >= cxx_version::cxx11) + { + hxx << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl + << endl; + } + + if (ctx.char_type == L"char") + { + hxx << "#ifndef XSD_USE_CHAR" << endl + << "#define XSD_USE_CHAR" << endl + << "#endif" << endl + << endl; + + hxx << "#ifndef XSD_CXX_TREE_USE_CHAR" << endl + << "#define XSD_CXX_TREE_USE_CHAR" << endl + << "#endif" << endl + << endl; + } + else if (ctx.char_type == L"wchar_t") + { + hxx << "#ifndef XSD_USE_WCHAR" << endl + << "#define XSD_USE_WCHAR" << endl + << "#endif" << endl + << endl; + + hxx << "#ifndef XSD_CXX_TREE_USE_WCHAR" << endl + << "#define XSD_CXX_TREE_USE_WCHAR" << endl + << "#endif" << endl + << endl; + } + } + else if (!generate_xml_schema) + { + // Generate it before the prologue so that we get the above + // defines. + // + hxx << "#include " << ctx.process_include_path (fwd_name) + << endl << endl; + } + // Copy prologue. // hxx << "// Begin prologue." << endl << "//" << endl; - append ( - hxx, ops.value<CLI::hxx_prologue> (), ops.value<CLI::prologue> ()); - append (hxx, ops.value<CLI::hxx_prologue_file> (), prologue); + append (hxx, ops.hxx_prologue (), ops.prologue ()); + append (hxx, ops.hxx_prologue_file (), prologue); hxx << "//" << endl << "// End prologue." << endl @@ -1450,95 +900,53 @@ namespace CXX << "#endif" << endl << endl; - { - hxx << "#include <xsd/cxx/pre.hxx>" << endl - << endl; - - // Generate character selection defines. - // - if (!forward) - { - if (ctx.char_type == L"char") - { - hxx << "#ifndef XSD_USE_CHAR" << endl - << "#define XSD_USE_CHAR" << endl - << "#endif" << endl - << endl; - - hxx << "#ifndef XSD_CXX_TREE_USE_CHAR" << endl - << "#define XSD_CXX_TREE_USE_CHAR" << endl - << "#endif" << endl - << endl; - } - else if (ctx.char_type == L"wchar_t") - { - hxx << "#ifndef XSD_USE_WCHAR" << endl - << "#define XSD_USE_WCHAR" << endl - << "#endif" << endl - << endl; - - hxx << "#ifndef XSD_CXX_TREE_USE_WCHAR" << endl - << "#define XSD_CXX_TREE_USE_WCHAR" << endl - << "#endif" << endl - << endl; - } - } - - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> hxx_clip (hxx); + hxx << "#include <xsd/cxx/pre.hxx>" << endl + << endl; + // Generate. + // + { + ind_filter ind (hxx); // We don't want to indent prologues/epilogues. - // Generate. - // - if (!generate_xml_schema) - { - if (forward) - hxx << "#include " << ctx.process_include_path (fwd_name) - << endl << endl; - else - generate_forward (ctx); - } + if (!generate_xml_schema && !forward) + generate_forward (ctx); generate_tree_header (ctx); if (!generate_xml_schema) { - - if (ops.value<CLI::generate_ostream> ()) + if (ops.generate_ostream ()) generate_stream_header (ctx); - if (!ops.value<CLI::generate_element_type> () && - !ops.value<CLI::suppress_parsing> ()) + if (!ops.generate_element_type () && !ops.suppress_parsing ()) generate_parser_header (ctx); - if (ops.value<CLI::generate_serialization> ()) + if (ops.generate_serialization ()) generate_serialization_header (ctx); - if (!ops.value<CLI::generate_insertion> ().empty ()) + if (!ops.generate_insertion ().empty ()) generate_stream_insertion_header (ctx); } + } - if (inline_) - { - hxx << "#ifndef XSD_DONT_INCLUDE_INLINE" << endl - << "#include " << ctx.process_include_path (ixx_name) << endl - << "#endif // XSD_DONT_INCLUDE_INLINE" << endl - << endl; - } - - hxx << "#include <xsd/cxx/post.hxx>" << endl + if (inline_) + { + hxx << "#ifndef XSD_DONT_INCLUDE_INLINE" << endl + << "#include " << ctx.process_include_path (ixx_name) << endl + << "#endif // XSD_DONT_INCLUDE_INLINE" << endl << endl; } + hxx << "#include <xsd/cxx/post.hxx>" << endl + << endl; + // Copy epilogue. // hxx << "// Begin epilogue." << endl << "//" << endl; - append (hxx, ops.value<CLI::hxx_epilogue_file> (), epilogue); - append ( - hxx, ops.value<CLI::hxx_epilogue> (), ops.value<CLI::epilogue> ()); + append (hxx, ops.hxx_epilogue_file (), epilogue); + append (hxx, ops.hxx_epilogue (), ops.epilogue ()); hxx << "//" << endl << "// End epilogue." << endl @@ -1547,18 +955,15 @@ namespace CXX hxx << "#endif // " << guard << endl; if (show_sloc) - { - wcerr << hxx_path << ": " - << hxx_sloc.buffer ().count () << endl; + wcerr << hxx_path << ": " << sloc.stream ().count () << endl; - sloc += hxx_sloc.buffer ().count (); - } + sloc_total += sloc.stream ().count (); } // IXX // - if (inline_) + if (gen_cxx && inline_) { Context ctx (ixx, schema, @@ -1571,11 +976,11 @@ namespace CXX &hxx_expr, &ixx_expr); - Indentation::Clip<Indentation::SLOC, WideChar> ixx_sloc (ixx); + sloc_filter sloc (ixx); // 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); @@ -1588,22 +993,17 @@ namespace CXX ixx << "// Begin prologue." << endl << "//" << endl; - append ( - ixx, ops.value<CLI::ixx_prologue> (), ops.value<CLI::prologue> ()); - append (ixx, ops.value<CLI::ixx_prologue_file> (), prologue); + append (ixx, ops.ixx_prologue (), ops.prologue ()); + append (ixx, ops.ixx_prologue_file (), prologue); ixx << "//" << endl << "// End prologue." << endl << endl; + // Generate. + // { - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> ixx_clip (ixx); - - - // Generate. - // + ind_filter ind (ixx); // We don't want to indent prologues/epilogues. generate_tree_inline (ctx, 1, 0); } @@ -1612,9 +1012,8 @@ namespace CXX ixx << "// Begin epilogue." << endl << "//" << endl; - append (ixx, ops.value<CLI::ixx_epilogue_file> (), epilogue); - append ( - ixx, ops.value<CLI::ixx_epilogue> (), ops.value<CLI::epilogue> ()); + append (ixx, ops.ixx_epilogue_file (), epilogue); + append (ixx, ops.ixx_epilogue (), ops.epilogue ()); ixx << "//" << endl << "// End epilogue." << endl @@ -1623,31 +1022,26 @@ namespace CXX ixx << "#endif // " << guard.c_str () << endl; if (show_sloc) - { - wcerr << ixx_path << ": " - << ixx_sloc.buffer ().count () << endl; + wcerr << ixx_path << ": " << sloc.stream ().count () << endl; - sloc += ixx_sloc.buffer ().count (); - } + sloc_total += sloc.stream ().count (); } - // CXX // - - if (source) + if (gen_cxx && source) { - UnsignedLong first_unit (0); // First unit in the current part. + size_t first_unit (0); // First unit in the current part. - for (UnsignedLong part (0); part < parts; ++part) + for (size_t part (0); part < parts; ++part) { // Figure out the range of units for this part. // - UnsignedLong last_unit (first_unit); + size_t last_unit (first_unit); if (units != 0) { - UnsignedLong complexity (counts.complexity[last_unit]); + size_t complexity (counts.complexity[last_unit]); while (complexity < complexity_per_part) { @@ -1660,7 +1054,7 @@ namespace CXX // Check if the increase in complexity should be kept in this // part or moved to the next. // - UnsignedLong new_complexity ( + size_t new_complexity ( complexity + counts.complexity[last_unit + 1]); if (new_complexity > complexity_per_part) @@ -1684,8 +1078,8 @@ namespace CXX // // - UnsignedLong first (first_unit); - UnsignedLong last (last_unit); + size_t first (first_unit); + size_t last (last_unit); first_unit = last_unit + 1; @@ -1705,86 +1099,78 @@ namespace CXX &hxx_expr, &ixx_expr); - Indentation::Clip<Indentation::SLOC, WideChar> cxx_sloc (os); + sloc_filter sloc (os); // Copy prologue. // os << "// Begin prologue." << endl << "//" << endl; - append (os, - ops.value<CLI::cxx_prologue> (), - ops.value<CLI::prologue> ()); - append (os, ops.value<CLI::cxx_prologue_file> (), prologue); + append (os, ops.cxx_prologue (), ops.prologue ()); + append (os, ops.cxx_prologue_file (), prologue); os << "//" << endl << "// End prologue." << endl << endl; - { - os << "#include <xsd/cxx/pre.hxx>" << endl - << endl; - - // Set auto-indentation. - // - Indentation::Clip<Indentation::CXX, WideChar> cxx_clip (os); + os << "#include <xsd/cxx/pre.hxx>" << endl + << endl; + os << "#include " << ctx.process_include_path (hxx_name) << endl + << endl; - // Generate. + // Generate. + // + { + // We don't want to indent prologues/epilogues. // - os << "#include " << ctx.process_include_path (hxx_name) << endl - << endl; + ind_filter ind (os); if (!inline_) generate_tree_inline (ctx, first, last); generate_tree_source (ctx, first, last); - if (ops.value<CLI::generate_ostream> ()) + if (ops.generate_ostream ()) generate_stream_source (ctx, first, last); - if (!ops.value<CLI::generate_element_type> () && - !ops.value<CLI::suppress_parsing> ()) + if (!ops.generate_element_type () && !ops.suppress_parsing ()) generate_parser_source (ctx, first, last); - if (ops.value<CLI::generate_serialization> ()) + if (ops.generate_serialization ()) generate_serialization_source (ctx, first, last); - if (!ops.value<CLI::generate_extraction> ().empty ()) + if (!ops.generate_extraction ().empty ()) generate_stream_extraction_source (ctx); - if (!ops.value<CLI::generate_insertion> ().empty ()) + if (!ops.generate_insertion ().empty ()) generate_stream_insertion_source (ctx); - - os << "#include <xsd/cxx/post.hxx>" << endl - << endl; } + os << "#include <xsd/cxx/post.hxx>" << endl + << endl; + // Copy epilogue. // os << "// Begin epilogue." << endl << "//" << endl; - append (os, ops.value<CLI::cxx_epilogue_file> (), epilogue); - append (os, - ops.value<CLI::cxx_epilogue> (), - ops.value<CLI::epilogue> ()); + append (os, ops.cxx_epilogue_file (), epilogue); + append (os, ops.cxx_epilogue (), ops.epilogue ()); os << "//" << endl << "// End epilogue." << endl << endl; if (show_sloc) - { - wcerr << cxx_paths[part] << ": " - << cxx_sloc.buffer ().count () << endl; + wcerr << cxx_paths[part] << ": " << sloc.stream ().count () + << endl; - sloc += cxx_sloc.buffer ().count (); - } + sloc_total += sloc.stream ().count (); } } - return sloc; + return sloc_total; } catch (UnrepresentableCharacter const& e) { @@ -1823,18 +1209,18 @@ namespace CXX throw Failed (); } - catch (BackendElements::Regex::Format<Char> 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<WideChar> 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/xsd/cxx/tree/generator.hxx b/xsd/xsd/cxx/tree/generator.hxx index 2e50392..f81f8e3 100644 --- a/xsd/xsd/cxx/tree/generator.hxx +++ b/xsd/xsd/cxx/tree/generator.hxx @@ -1,43 +1,36 @@ // file : xsd/cxx/tree/generator.hxx -// 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 #ifndef CXX_TREE_GENERATOR_HXX #define CXX_TREE_GENERATOR_HXX -#include <cult/types.hxx> - #include <xsd-frontend/semantic-graph/elements.hxx> // Path #include <xsd-frontend/semantic-graph/schema.hxx> #include <xsd.hxx> +#include <types.hxx> #include <cxx/literal-map.hxx> -#include <cxx/tree/cli.hxx> +#include <cxx/tree/options.hxx> namespace CXX { namespace Tree { - using namespace Cult::Types; - class Generator { public: - static Void + static void usage (); - static CLI::OptionsSpec - options_spec (); - struct Failed {}; - static UnsignedLong - generate (CLI::Options const& options, + static size_t + generate (options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, - Boolean file_per_type, + bool file_per_type, StringLiteralMap const&, const WarningSet& disabled_warnings, FileList& file_list, diff --git a/xsd/xsd/cxx/tree/name-processor.cxx b/xsd/xsd/cxx/tree/name-processor.cxx index 4949bed..1f3844b 100644 --- a/xsd/xsd/cxx/tree/name-processor.cxx +++ b/xsd/xsd/cxx/tree/name-processor.cxx @@ -1,51 +1,45 @@ // file : xsd/cxx/tree/name-processor.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <set> +#include <map> +#include <vector> #include <sstream> #include <iostream> -#include <cult/containers/set.hxx> -#include <cult/containers/map.hxx> -#include <cult/containers/vector.hxx> - -#include <backend-elements/regex.hxx> +#include <cutl/re.hxx> #include <cxx/tree/default-value.hxx> #include <cxx/tree/name-processor.hxx> +using namespace std; + namespace CXX { namespace Tree { - NameProcessor:: - NameProcessor () - { - // Dummy ctor, helps with long symbols on HP-UX. - } - namespace { // // - typedef Cult::Containers::Set<String> NameSet; + typedef set<String> NameSet; class Context: public Tree::Context { public: struct Failed {}; - Context (CLI::Options const& options, + Context (Tree::options const& ops, Counts const& counts, - Boolean generate_xml_schema, + bool generate_xml_schema, SemanticGraph::Schema& root, SemanticGraph::Path const& path, StringLiteralMap const& map) : Tree::Context (std::wcerr, root, path, - options, + ops, counts, generate_xml_schema, &map, @@ -54,7 +48,7 @@ namespace CXX 0), global_type_names (global_type_names_), global_element_names (global_element_names_), - detach (options.value<CLI::generate_detach> ()), + detach (ops.generate_detach ()), type_regex (type_regex_), accessor_regex (accessor_regex_), one_accessor_regex (one_accessor_regex_), @@ -66,14 +60,12 @@ namespace CXX seq_modifier_regex (seq_modifier_regex_), parser_regex (parser_regex_), serializer_regex (serializer_regex_), + const_regex (const_regex_), enumerator_regex (enumerator_regex_), element_type_regex (element_type_regex_) { - typedef Containers::Vector<NarrowString> Vector; - - NarrowString tn (options.value<CLI::type_naming> ()); - NarrowString fn (options.value<CLI::function_naming> ()); - + NarrowString tn (options.type_naming ()); + NarrowString fn (options.function_naming ()); // Type name regex. // @@ -116,9 +108,7 @@ namespace CXX } - compile_regex (options.value<CLI::type_regex> (), - type_regex, - "type"); + compile_regex (options.type_regex (), type_regex, "type"); } // Accessor name regex. @@ -149,24 +139,23 @@ namespace CXX accessor_regex.push_back ("/([^,]+)/get\\u$1/"); } - compile_regex (options.value<CLI::accessor_regex> (), + compile_regex (options.accessor_regex (), accessor_regex, "accessor"); - compile_regex (options.value<CLI::one_accessor_regex> (), + compile_regex (options.one_accessor_regex (), one_accessor_regex, "one accessor"); - compile_regex (options.value<CLI::opt_accessor_regex> (), + compile_regex (options.opt_accessor_regex (), opt_accessor_regex, "optional accessor"); - compile_regex (options.value<CLI::seq_accessor_regex> (), + compile_regex (options.seq_accessor_regex (), seq_accessor_regex, "sequence accessor"); } - // Modifier name regex. // { @@ -190,24 +179,23 @@ namespace CXX modifier_regex.push_back ("/detach,([^,]+)/detach\\u$1/"); } - compile_regex (options.value<CLI::modifier_regex> (), + compile_regex (options.modifier_regex (), modifier_regex, "modifier"); - compile_regex (options.value<CLI::one_modifier_regex> (), + compile_regex (options.one_modifier_regex (), one_modifier_regex, "one modifier"); - compile_regex (options.value<CLI::opt_modifier_regex> (), + compile_regex (options.opt_modifier_regex (), opt_modifier_regex, "optional modifier"); - compile_regex (options.value<CLI::seq_modifier_regex> (), + compile_regex (options.seq_modifier_regex (), seq_modifier_regex, "sequence modifier"); } - // Parser name regex. // { @@ -222,9 +210,7 @@ namespace CXX parser_regex.push_back ("/(.+)/parse\\u$1/"); } - compile_regex (options.value<CLI::parser_regex> (), - parser_regex, - "parser"); + compile_regex (options.parser_regex (), parser_regex, "parser"); } // Serializer name regex. @@ -241,11 +227,35 @@ namespace CXX serializer_regex.push_back ("/(.+)/serialize\\u$1/"); } - compile_regex (options.value<CLI::serializer_regex> (), + compile_regex (options.serializer_regex (), serializer_regex, "serializer"); } + // Const regex. + // + { + if (fn == "knr") + { + const_regex.push_back ("/([^,]+),([^,]+),([^,]+)/$1_$2_$3/"); + const_regex.push_back ("/([^,]+),([^,]+)/$1_$2/"); + } + else if (fn == "lcc") + { + const_regex.push_back ("/([^,]+),([^,]+),([^,]+)/\\l$1_\\u$2_\\u$3/"); + const_regex.push_back ("/([^,]+),([^,]+)/\\l$1\\u$2/"); + } + else + { + // Java: all uppercase. + // + const_regex.push_back ("/([^,]+),([^,]+),([^,]+)/\\U$1_$2_$3/"); + const_regex.push_back ("/([^,]+),([^,]+)/\\U$1_$2/"); + } + + compile_regex (options.const_regex (), const_regex, "const"); + } + // Enumerator name regex. // { @@ -253,14 +263,14 @@ namespace CXX // enumerator_regex.push_back ("/^$/empty/"); - compile_regex (options.value<CLI::enumerator_regex> (), + compile_regex (options.enumerator_regex (), enumerator_regex, "enumerator"); } // Element type regex. // - compile_regex (options.value<CLI::element_type_regex> (), + compile_regex (options.element_type_regex (), element_type_regex, "element_type"); } @@ -282,35 +292,44 @@ namespace CXX seq_modifier_regex (c.seq_modifier_regex), parser_regex (c.parser_regex), serializer_regex (c.serializer_regex), + const_regex (c.const_regex), enumerator_regex (c.enumerator_regex), element_type_regex (c.element_type_regex) { } public: - typedef BackendElements::Regex::Expression<WideChar> Regex; - typedef BackendElements::Regex::Format<WideChar> RegexFormat; - typedef Cult::Containers::Vector<Regex> RegexVector; + typedef cutl::re::wregexsub Regex; + typedef cutl::re::wformat RegexFormat; + + struct RegexVector: vector<Regex> + { + void + push_back (String const& r) + { + vector<Regex>::push_back (Regex (r)); + } + }; String process_regex (String const& name, RegexVector const& rv, String const& id) { - Boolean trace (options.value<CLI::name_regex_trace> ()); + bool trace (options.name_regex_trace ()); if (trace) os << id << " name: '" << name << "'" << endl; - for (RegexVector::ConstReverseIterator i (rv.rbegin ()); + for (RegexVector::const_reverse_iterator i (rv.rbegin ()); 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; @@ -331,20 +350,20 @@ namespace CXX RegexVector const& backup, String const& id) { - Boolean trace (options.value<CLI::name_regex_trace> ()); + bool trace (options.name_regex_trace ()); if (trace) os << id << " name: '" << name << "'" << endl; - for (RegexVector::ConstReverseIterator i (primary.rbegin ()); + for (RegexVector::const_reverse_iterator i (primary.rbegin ()); 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; @@ -356,15 +375,15 @@ namespace CXX os << '-' << endl; } - for (RegexVector::ConstReverseIterator i (backup.rbegin ()); + for (RegexVector::const_reverse_iterator i (backup.rbegin ()); 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; @@ -386,20 +405,20 @@ namespace CXX String const& id) { String s (ns + L' ' + name); - Boolean trace (options.value<CLI::name_regex_trace> ()); + bool trace (options.name_regex_trace ()); if (trace) os << id << " name: '" << s << "'" << endl; - for (RegexVector::ConstReverseIterator i (rv.rbegin ()); + for (RegexVector::const_reverse_iterator i (rv.rbegin ()); 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; @@ -422,20 +441,20 @@ namespace CXX String const& id) { String s (ns + L' ' + name); - Boolean trace (options.value<CLI::name_regex_trace> ()); + bool trace (options.name_regex_trace ()); if (trace) os << id << " name: '" << s << "'" << endl; - for (RegexVector::ConstReverseIterator i (primary.rbegin ()); + for (RegexVector::const_reverse_iterator i (primary.rbegin ()); 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; @@ -447,15 +466,15 @@ namespace CXX os << '-' << endl; } - for (RegexVector::ConstReverseIterator i (backup.rbegin ()); + for (RegexVector::const_reverse_iterator i (backup.rbegin ()); 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; @@ -474,11 +493,11 @@ namespace CXX String find_name (String const& base_name, NameSet& set, - Boolean insert = true) + bool insert = true) { String name (base_name); - for (UnsignedLong i (1); set.find (name) != set.end (); ++i) + for (size_t i (1); set.find (name) != set.end (); ++i) { std::wostringstream os; os << i; @@ -492,23 +511,22 @@ namespace CXX } private: - Void - compile_regex (Containers::Vector<NarrowString> const& sv, + void + compile_regex (NarrowStrings const& sv, RegexVector& rv, String const& id) { - typedef Containers::Vector<NarrowString> Vector; - - for (Vector::ConstIterator i (sv.begin ()); i != sv.end (); ++i) + for (NarrowStrings::const_iterator i (sv.begin ()); i != sv.end (); + ++i) { 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 (); } @@ -516,8 +534,8 @@ namespace CXX } private: - Cult::Containers::Map<String, NameSet> global_type_names_; - Cult::Containers::Map<String, NameSet> global_element_names_; + map<String, NameSet> global_type_names_; + map<String, NameSet> global_element_names_; RegexVector type_regex_; RegexVector accessor_regex_; @@ -530,14 +548,15 @@ namespace CXX RegexVector seq_modifier_regex_; RegexVector parser_regex_; RegexVector serializer_regex_; + RegexVector const_regex_; RegexVector enumerator_regex_; RegexVector element_type_regex_; public: - Cult::Containers::Map<String, NameSet>& global_type_names; - Cult::Containers::Map<String, NameSet>& global_element_names; + map<String, NameSet>& global_type_names; + map<String, NameSet>& global_element_names; - Boolean detach; + bool detach; RegexVector& type_regex; RegexVector& accessor_regex; @@ -550,6 +569,7 @@ namespace CXX RegexVector& seq_modifier_regex; RegexVector& parser_regex; RegexVector& serializer_regex; + RegexVector& const_regex; RegexVector& enumerator_regex; RegexVector& element_type_regex; }; @@ -563,7 +583,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { // Process the name with enumerator name regex. @@ -590,7 +610,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { // Use processed name. @@ -630,7 +650,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Tree::Context::skip (m)) @@ -657,20 +677,23 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Tree::Context::skip (m)) return; - UnsignedLong max (Tree::Context::max (m)); - UnsignedLong min (Tree::Context::min (m)); + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (m.scope ())); + + size_t max (Tree::Context::max (m)); + size_t min (Tree::Context::min (m)); String const& s (m.context ().get<String> ("stem")); String const& b (m.context ().get<String> ("name")); - Boolean def_attr (m.default_p () && - m.is_a<SemanticGraph::Attribute> ()); + bool def_attr (m.default_p () && + m.is_a<SemanticGraph::Attribute> ()); // Accessors/modifiers. Note that we postpone inserting // the names into the name_set to avoid over-escaping. @@ -809,7 +832,7 @@ namespace CXX // if (m.default_p ()) { - Boolean simple (true); + bool simple (true); if (m.is_a<SemanticGraph::Element> ()) { @@ -824,9 +847,9 @@ namespace CXX process_regex ( s + L",default,value", accessor_regex, L"accessor"))); - m.context ().set ( "default-value", find_name (an, name_set_)); + m.context ().set ("default-value", find_name (an, name_set_)); - Boolean lit (false); + bool lit (false); { IsLiteralValue test (lit); test.dispatch (m.type ()); @@ -840,6 +863,18 @@ namespace CXX } } } + + // Element id. + // + if (m.is_a<SemanticGraph::Element> () && ordered_p (c)) + { + String id ( + escape ( + process_regex ( + s + L",id", const_regex, L"const"))); + + m.context ().set ("ordered-id-name", find_name (id, name_set_)); + } } private: @@ -854,7 +889,7 @@ namespace CXX Any (Context& c, NameSet& name_set, NameSet& stem_set, - Boolean& has_wildcard) + bool& has_wildcard) : Context (c), name_set_ (name_set), stem_set_ (stem_set), @@ -862,11 +897,14 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { - UnsignedLong max (Tree::Context::max (a)); - UnsignedLong min (Tree::Context::min (a)); + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (a.scope ())); + + size_t max (Tree::Context::max (a)); + size_t min (Tree::Context::min (a)); String s (find_name (L"any", stem_set_)); @@ -980,11 +1018,23 @@ namespace CXX // a.context ().set ("member", find_name (b + L"_", name_set_)); + // Wildcard id. + // + if (ordered_p (c)) + { + String id ( + escape ( + process_regex ( + s + L",id", const_regex, L"const"))); + + a.context ().set ("ordered-id-name", find_name (id, name_set_)); + } + if (!has_wildcard_) has_wildcard_ = true; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String s (find_name (L"any,attribute", stem_set_)); @@ -1050,7 +1100,7 @@ namespace CXX private: NameSet& name_set_; NameSet& stem_set_; - Boolean& has_wildcard_; + bool& has_wildcard_; }; // @@ -1062,20 +1112,20 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { - SemanticGraph::Context& cc (c.context ()); + SemanticGraph::Context& ctx (c.context ()); // We leave this set around to allow other mappings to use // this information. // - cc.set ("cxx-tree-name-processor-stem-set", NameSet ()); - cc.set ("cxx-tree-name-processor-member-set", NameSet ()); + ctx.set ("cxx-tree-name-processor-stem-set", NameSet ()); + ctx.set ("cxx-tree-name-processor-member-set", NameSet ()); // Use processed name. // - String name (cc.get<String> ("name")); + String name (ctx.get<String> ("name")); // If renamed name is empty then we are not generating // anything for this type and name processing is not @@ -1085,10 +1135,10 @@ namespace CXX return; NameSet& stem_set ( - cc.get<NameSet> ("cxx-tree-name-processor-stem-set")); + ctx.get<NameSet> ("cxx-tree-name-processor-stem-set")); NameSet& member_set ( - cc.get<NameSet> ("cxx-tree-name-processor-member-set")); + ctx.get<NameSet> ("cxx-tree-name-processor-member-set")); stem_set.insert (c.name ()); member_set.insert (name); @@ -1144,11 +1194,121 @@ namespace CXX Complex::names (c, names); } + // Names for the mixed content. + // + if (mixed_p (c)) + { + // Check if we already have the mixed content down inheritance + // hierarchy. + // + using SemanticGraph::Complex; + + for (Complex* p (&c); p->inherits_p ();) + { + if (Complex* b = dynamic_cast<Complex*> ( + &p->inherits ().base ())) + { + if (mixed_p (*b)) + { + SemanticGraph::Context& bctx (b->context ()); + ctx.set ("mixed-type", bctx.get<String> ("mixed-type")); + ctx.set ("mixed-const-iterator", + bctx.get<String> ("mixed-const-iterator")); + ctx.set ("mixed-ordered-id-name", + bctx.get<String> ("mixed-ordered-id-name")); + ctx.set ("mixed-aname", bctx.get<String> ("mixed-aname")); + ctx.set ("mixed-member", bctx.get<String> ("mixed-member")); + ctx.set ("mixed-in-base", true); + break; + } + + p = b; + } + else + break; + } + + // If not, set up the names. + // + if (!ctx.count ("mixed-in-base")) + { + String s (find_name (L"text,content", stem_set)); + String n (find_name (escape (s), member_set, false)); + + String an (find_name ( + escape (process_regex (s, + seq_accessor_regex, + accessor_regex, + L"sequence accessor")), + member_set, + false)); + + String mn (find_name ( + escape (process_regex (s, + seq_modifier_regex, + modifier_regex, + L"sequence modifier")), + member_set, + false)); + + ctx.set ("mixed-aname", an); + ctx.set ("mixed-mname", mn); + + member_set.insert (name); + + if (an != n) + member_set.insert (an); + + if (mn != n && mn != an) + member_set.insert (mn); + + // Types. + // + ctx.set ( + "mixed-type", + find_name ( + escape (process_regex (s + L",type", type_regex, L"type")), + member_set)); + + ctx.set ( + "mixed-container", + find_name ( + escape (process_regex (s + L",sequence", type_regex, L"type")), + member_set)); + + ctx.set ( + "mixed-iterator", + find_name ( + escape (process_regex (s + L",iterator", type_regex, L"type")), + member_set)); + + ctx.set ( + "mixed-const-iterator", + find_name ( + escape ( + process_regex (s + L",const,iterator", type_regex, L"type")), + member_set)); + + // Text content id. + // + ctx.set ( + "mixed-ordered-id-name", + find_name ( + escape ( + process_regex (s + L",id", const_regex, L"const")), + member_set)); + + // Data member. + // + ctx.set ("mixed-member", find_name (n + L"_", member_set)); + } + } + // Names for wildcards. // - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) { - Boolean has_wildcard (false); + bool has_wildcard (false); Any any (*this, member_set, stem_set, has_wildcard); Traversal::Names names (any); Complex::names (c, names); @@ -1198,6 +1358,105 @@ namespace CXX } } } + + // Names for the order container. + // + if (ordered_p (c)) + { + // Check if we already have the order container down + // inheritance hierarchy. + // + using SemanticGraph::Complex; + + for (Complex* p (&c); p->inherits_p ();) + { + if (Complex* b = dynamic_cast<Complex*> ( + &p->inherits ().base ())) + { + if (ordered_p (*b)) + { + SemanticGraph::Context& bctx (b->context ()); + ctx.set ("order-type", bctx.get<String> ("order-type")); + ctx.set ("order-const-iterator", + bctx.get<String> ("order-const-iterator")); + ctx.set ("order-aname", bctx.get<String> ("order-aname")); + ctx.set ("order-member", bctx.get<String> ("order-member")); + ctx.set ("order-in-base", true); + break; + } + + p = b; + } + else + break; + } + + // If not, set up the names. + // + if (!ctx.count ("order-in-base")) + { + String s (find_name (L"content,order", stem_set)); + String n (find_name (escape (s), member_set, false)); + + String an (find_name ( + escape (process_regex (s, + seq_accessor_regex, + accessor_regex, + L"sequence accessor")), + member_set, + false)); + + String mn (find_name ( + escape (process_regex (s, + seq_modifier_regex, + modifier_regex, + L"sequence modifier")), + member_set, + false)); + + ctx.set ("order-aname", an); + ctx.set ("order-mname", mn); + + member_set.insert (name); + + if (an != n) + member_set.insert (an); + + if (mn != n && mn != an) + member_set.insert (mn); + + // Types. + // + ctx.set ( + "order-type", + find_name ( + escape (process_regex (s + L",type", type_regex, L"type")), + member_set)); + + ctx.set ( + "order-container", + find_name ( + escape (process_regex (s + L",sequence", type_regex, L"type")), + member_set)); + + ctx.set ( + "order-iterator", + find_name ( + escape (process_regex (s + L",iterator", type_regex, L"type")), + member_set)); + + ctx.set ( + "order-const-iterator", + find_name ( + escape ( + process_regex (s + L",const,iterator", type_regex, L"type")), + member_set)); + + // Data member. + // + ctx.set ("order-member", find_name (n + L"_", member_set)); + } + } } }; @@ -1211,7 +1470,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { // Process the name with type name regex. @@ -1254,7 +1513,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { // First we need to figure out if we need to process this @@ -1263,7 +1522,7 @@ namespace CXX if (!generate_p (e)) return; - if (options.value<CLI::generate_element_type> ()) + if (options.generate_element_type ()) { SemanticGraph::Context& ec (e.context ()); @@ -1379,7 +1638,7 @@ namespace CXX // String p; - if (!options.value<CLI::suppress_parsing> () && doc_root_p (e)) + if (!options.suppress_parsing () && doc_root_p (e)) { p = find_name ( escape ( @@ -1392,8 +1651,7 @@ namespace CXX // String s; - if (options.value<CLI::generate_serialization> () && - doc_root_p (e)) + if (options.generate_serialization () && doc_root_p (e)) { s = find_name ( escape ( @@ -1430,7 +1688,7 @@ namespace CXX if (type_set_.find (r) != type_set_.end ()) r += L"_"; - for (UnsignedLong i (1); + for (size_t i (1); element_set_.find (r) != element_set_.end () || type_set_.find (r) != type_set_.end (); ++i) { @@ -1454,7 +1712,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& ns) { NameSet& type_set (global_type_names[ns.name ()]); @@ -1475,7 +1733,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& ns) { String const& name (ns.name ()); @@ -1557,7 +1815,7 @@ namespace CXX *this >> names_ >> *this; } - Void + void process_name (SemanticGraph::Type& t, String const& name) { String r ( @@ -1567,10 +1825,10 @@ namespace CXX t.context ().set ("name", escape (r)); } - Void + void process_name (SemanticGraph::Namespace& n, String const& name, - Char const* key) + char const* key) { String r (process_regex (name, type_regex, L"type")); n.context ().set (key, escape (r)); @@ -1578,13 +1836,13 @@ namespace CXX // anyType and anySimpleType // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { process_name (t, "type"); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { process_name (t, "simple,type"); @@ -1592,79 +1850,79 @@ namespace CXX // Integrals. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { process_name (t, "byte"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { process_name (t, "unsigned,byte"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { process_name (t, "short"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { process_name (t, "unsigned,short"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { process_name (t, "int"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { process_name (t, "unsigned,int"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { process_name (t, "long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { process_name (t, "unsigned,long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { process_name (t, "integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { process_name (t, "non,positive,integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { process_name (t, "non,negative,integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { process_name (t, "positive,integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { process_name (t, "negative,integer"); @@ -1672,7 +1930,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { process_name (t, "boolean"); @@ -1680,19 +1938,19 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { process_name (t, "float"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { process_name (t, "double"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { process_name (t, "decimal"); @@ -1700,49 +1958,49 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { process_name (t, "string"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { process_name (t, "normalized,string"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { process_name (t, "token"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { process_name (t, "nmtoken"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { process_name (t, "nmtokens"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { process_name (t, "name"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { process_name (t, "ncname"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { process_name (t, "language"); @@ -1750,19 +2008,19 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { process_name (t, "id"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { process_name (t, "idref"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { process_name (t, "idrefs"); @@ -1771,7 +2029,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { process_name (t, "uri"); @@ -1779,7 +2037,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { process_name (t, "qname"); @@ -1787,13 +2045,13 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { process_name (t, "base64,binary"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { process_name (t, "hex,binary"); @@ -1802,55 +2060,55 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { process_name (t, "date"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { process_name (t, "date,time"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { process_name (t, "duration"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { process_name (t, "gday"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { process_name (t, "gmonth"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { process_name (t, "gmonth,day"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { process_name (t, "gyear"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { process_name (t, "gyear,month"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { process_name (t, "time"); @@ -1858,19 +2116,19 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { process_name (t, "entity"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { process_name (t, "entities"); } - virtual Void + virtual void post (SemanticGraph::Namespace& n) { // Assign names to extra stuff in the XML Schema namespace. @@ -1879,13 +2137,15 @@ namespace CXX process_name (n, "buffer", "buffer"); process_name (n, "time,zone", "time-zone"); - if (options.value<CLI::generate_element_type> ()) + process_name (n, "content,order", "content-order"); + + if (options.generate_element_type ()) process_name (n, "element,type", "element-type"); - if (options.value<CLI::generate_element_map> ()) + if (options.generate_element_map ()) process_name (n, "element,map", "element-map"); - if (options.value<CLI::generate_serialization> ()) + if (options.generate_serialization ()) { process_name (n, "namespace,info", "namespace-info"); process_name (n, "namespace,infomap", "namespace-infomap"); @@ -1895,12 +2155,12 @@ namespace CXX process_name (n, "facet", "facet"); } - if (!options.value<CLI::generate_insertion> ().empty ()) + if (!options.generate_insertion ().empty ()) { process_name (n, "ostream", "ostream"); } - if (!options.value<CLI::generate_extraction> ().empty ()) + if (!options.generate_extraction ().empty ()) { process_name (n, "istream", "istream"); } @@ -1908,7 +2168,7 @@ namespace CXX process_name (n, "flags", "flags"); process_name (n, "properties", "properties"); - NarrowString fn (options.value<CLI::function_naming> ()); + NarrowString fn (options.function_naming ()); if (fn == "knr") n.context ().set ("tree-node-key", String ("tree_node_key")); @@ -1936,8 +2196,8 @@ namespace CXX process_name (n, "error", "error"); process_name (n, "diagnostics", "diagnostics"); - if (!options.value<CLI::suppress_parsing> () || - options.value<CLI::generate_serialization> ()) + if (!options.suppress_parsing () || + options.generate_serialization ()) { process_name (n, "error,handler", "error-handler"); } @@ -1955,7 +2215,7 @@ namespace CXX // struct UsesPassOne: Traversal::Uses { - virtual Void + virtual void traverse (Type& u) { SemanticGraph::Schema& s (u.schema ()); @@ -1970,7 +2230,7 @@ namespace CXX struct UsesPassThree: Traversal::Uses { - virtual Void + virtual void traverse (Type& u) { SemanticGraph::Schema& s (u.schema ()); @@ -1988,7 +2248,7 @@ namespace CXX // struct Implies: Traversal::Implies { - virtual Void + virtual void traverse (SemanticGraph::Implies& i) { SemanticGraph::Schema& s (i.schema ()); @@ -2001,8 +2261,8 @@ namespace CXX } }; - Boolean - process_impl (CLI::Options const& ops, + bool + process_impl (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& file, StringLiteralMap const& map) @@ -2064,7 +2324,7 @@ namespace CXX // { Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; @@ -2128,8 +2388,8 @@ namespace CXX } } - Boolean NameProcessor:: - process (CLI::Options const& ops, + bool NameProcessor:: + process (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& file, StringLiteralMap const& map) diff --git a/xsd/xsd/cxx/tree/name-processor.hxx b/xsd/xsd/cxx/tree/name-processor.hxx index cf187b7..46ea883 100644 --- a/xsd/xsd/cxx/tree/name-processor.hxx +++ b/xsd/xsd/cxx/tree/name-processor.hxx @@ -1,26 +1,24 @@ // file : xsd/cxx/tree/name-processor.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef CXX_TREE_NAME_PROCESSOR_HXX #define CXX_TREE_NAME_PROCESSOR_HXX +#include <types.hxx> + #include <cxx/tree/elements.hxx> +#include <cxx/tree/options.hxx> namespace CXX { namespace Tree { - using namespace Cult::Types; - class NameProcessor { public: - NameProcessor (); // Dummy ctor, helps with long symbols on HP-UX. - - Boolean - process (CLI::Options const&, + bool + process (options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, StringLiteralMap const&); diff --git a/xsd/xsd/cxx/tree/options.cli b/xsd/xsd/cxx/tree/options.cli new file mode 100644 index 0000000..f1b343a --- /dev/null +++ b/xsd/xsd/cxx/tree/options.cli @@ -0,0 +1,480 @@ +// file : xsd/cxx/tree/options.cli +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include <cstddef>; // std::size_t + +include <types.hxx>; // NarrowString, NarrowStrings + +include <cxx/options.cli>; + +namespace CXX +{ + namespace Tree + { + class options: CXX::options + { + // Polymorphism. + // + bool --generate-polymorphic + { + "Generate polymorphism-aware code. Specify this option if you use + substitution groups or \cb{xsi:type}. Use the \cb{--polymorphic-type} + or \cb{--polymorphic-type-all} option to specify which type + hierarchies are polymorphic." + }; + + NarrowStrings --polymorphic-type + { + "<type>", + "Indicate that <type> is a root of a polymorphic type hierarchy. The + compiler can often automatically determine which types are + polymorphic based on the substitution group declarations. However, + you may need to use this option if you are not using substitution + groups or if substitution groups are defined in another schema. You + need to specify this option when compiling every schema file that + references <type>. The <type> argument is an XML Schema type name + that can be optionally qualified with a namespace in the + \c{\i{namespace}\b{#}\i{name}} form." + }; + + bool --polymorphic-type-all + { + "Indicate that all types should be treated as polymorphic." + }; + + unsigned long --polymorphic-plate = 0 + { + "<num>", + "Specify the polymorphic map plate the generated code should register + on. This functionality is primarily useful to segregate multiple + schemas that define the same polymorphic types." + }; + + // Ordered content. + // + NarrowStrings --ordered-type + { + "<type>", + "Indicate that element order in <type> is significant. An example + would be a complex type with unbounded choice as a content model + where the element order in XML has application-specific semantics. + For ordered types the compiler generates a special container data + member and a corresponding set of accessors and modifiers that are + used to capture the order of elements and, for mixed content, of + text. + + The <type> argument is an XML Schema type name that can be optionally + qualified with a namespace in the \c{\i{namespace}\b{#}\i{name}} form. + Note also that you will need to specify this option when compiling + every schema file that has other ordered types derived from this + type." + }; + + bool --ordered-type-derived + { + "Automatically treat types derived from ordered bases as also + ordered. This is primarily useful if you would like to be able + to iterate over the complete content using the content order + container." + }; + + bool --ordered-type-mixed + { + "Automatically treat complex types with mixed content as ordered." + }; + + bool --ordered-type-all + { + "Indicate that element order in all types is significant." + }; + + NarrowString --order-container + { + "<type>", + "Specify a custom class template that should be used as a container + for the content order in ordered types instead of the default + \cb{std::vector}. See \cb{--ordered-type} for more information on + ordered type. This option is primarily useful if you need to + perform more complex lookups in the content order container, for + example by element id. In this case, a container like Boost + multi-index may be more convenient. Note that if using a custom + container, you will also most likely need to include the relevant + headers using the \cb{--hxx-prologue*} options." + }; + + // Features. + // + bool --generate-serialization + { + "Generate serialization functions. Serialization functions convert + the object model back to XML." + }; + + bool --generate-ostream + { + "Generate ostream insertion operators (\cb{operator<<}) for generated + types. This allows one to easily print a fragment or the whole object + model for debugging or logging." + }; + + bool --generate-doxygen + { + "Generate documentation comments suitable for extraction by the + Doxygen documentation system. Documentation from annotations is + added to the comments if present in the schema." + }; + + bool --generate-comparison + { + "Generate comparison operators (\cb{operator==} and \cb{operator!=}) + for complex types. Comparison is performed member-wise." + }; + + bool --generate-default-ctor + { + "Generate default constructors even for types that have required + members. Required members of an instance constructed using such a + constructor are not initialized and accessing them results in + undefined behavior." + }; + + bool --generate-from-base-ctor + { + "Generate constructors that expect an instance of a base type + followed by all required members." + }; + + bool --suppress-assignment + { + "Suppress the generation of copy assignment operators for complex + types. If this option is specified, the copy assignment operators + for such types are declared private and left unimplemented." + }; + + bool --generate-detach + { + "Generate detach functions for required elements and attributes. + Detach functions for optional and sequence cardinalities are + provided by the respective containers. These functions, for + example, allow you to move sub-trees in the object model either + within the same tree or between different trees." + }; + + bool --generate-wildcard + { + "Generate accessors and modifiers as well as parsing and serialization + code for XML Schema wildcards (\cb{any} and \cb{anyAttribute}). XML + content matched by wildcards is presented as DOM fragments. Note + that you need to initialize the Xerces-C++ runtime if you are using + this option." + }; + + bool --generate-any-type + { + "Extract and store content of the XML Schema \cb{anyType} type as a + DOM fragment. Note that you need to initialize the Xerces-C++ runtime + if you are using this option." + }; + + NarrowStrings --generate-insertion + { + "<os>", + "Generate data representation stream insertion operators for the <os> + output stream type. Repeat this option to specify more than one + stream type. The ACE CDR stream (\cb{ACE_OutputCDR}) and RPC XDR + are recognized by the compiler and the necessary \cb{#include} + directives are automatically generated. For custom stream types use + the \cb{--hxx-prologue*} options to provide the necessary + declarations." + }; + + NarrowStrings --generate-extraction + { + "<is>", + "Generate data representation stream extraction constructors for the + <is> input stream type. Repeat this option to specify more than one + stream type. The ACE CDR stream (\cb{ACE_InputCDR}) and RPC XDR are + recognized by the compiler and the necessary \cb{#include} directives + are automatically generated. For custom stream types use the + \cb{--hxx-prologue*} options to provide the necessary declarations." + }; + + bool --generate-forward + { + "Generate a separate header file with forward declarations for the + types being generated." + }; + + bool --suppress-parsing + { + "Suppress the generation of the parsing functions and constructors. + Use this option to reduce the generated code size when parsing from + XML is not needed." + }; + + bool --generate-element-type + { + "Generate types instead of parsing and serialization functions for + root elements. This is primarily useful to distinguish object models + with the same root type but with different root elements." + }; + + bool --generate-element-map + { + "Generate a root element map that allows uniform parsing and + serialization of multiple root elements. This option is only valid + together with \cb{--generate-element-type}." + }; + + bool --generate-intellisense + { + "Generate workarounds for IntelliSense bugs in Visual Studio 2005 + (8.0). When this option is used, the resulting code is slightly + more verbose. IntelliSense in Visual Studio 2008 (9.0) and later + does not require these workarounds. Support for IntelliSense in + Visual Studio 2003 (7.1) is improved with this option but is + still incomplete." + }; + + bool --omit-default-attributes + { + "Omit attributes with default and fixed values from serialized XML + documents." + }; + + // Naming. + // + NarrowString --type-naming = "knr" + { + "<style>", + "Specify the type naming convention that should be used in the + generated code. Valid styles are \cb{knr} (default), \cb{ucc}, + and \cb{java}. See the NAMING CONVENTION section below for more + information." + }; + + NarrowString --function-naming = "knr" + { + "<style>", + "Specify the function naming convention that should be used in the + generated code. Valid styles are \cb{knr} (default), \cb{lcc}, and + \cb{java}. See the NAMING CONVENTION section below for more + information." + }; + + NarrowStrings --type-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema type names to C++ type names. See the NAMING CONVENTION + section below for more information." + }; + + NarrowStrings --accessor-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes to C++ accessor function + names. See the NAMING CONVENTION section below for more information." + }; + + NarrowStrings --one-accessor-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality one to + C++ accessor function names. See the NAMING CONVENTION section + below for more information." + }; + + NarrowStrings --opt-accessor-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality optional + to C++ accessor function names. See the NAMING CONVENTION section + below for more information." + }; + + NarrowStrings --seq-accessor-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality sequence + to C++ accessor function names. See the NAMING CONVENTION section + below for more information." + }; + + NarrowStrings --modifier-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes to C++ modifier function + names. See the NAMING CONVENTION section below for more information." + }; + + NarrowStrings --one-modifier-regex + + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality one to C++ + modifier function names. See the NAMING CONVENTION section below + for more information." + }; + + NarrowStrings --opt-modifier-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality optional + to C++ modifier function names. See the NAMING CONVENTION section + below for more information." + }; + + NarrowStrings --seq-modifier-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema names of elements/attributes with cardinality sequence + to C++ modifier function names. See the NAMING CONVENTION section + below for more information." + }; + + NarrowStrings --parser-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema element names to C++ parsing function names. See the + NAMING CONVENTION section below for more information." + }; + + NarrowStrings --serializer-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema element names to C++ serialization function names. See + the NAMING CONVENTION section below for more information." + }; + + NarrowStrings --const-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema-derived names to C++ constant names. See the NAMING + CONVENTION section below for more information." + }; + + NarrowStrings --enumerator-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema enumeration values to C++ enumerator names. See the + NAMING CONVENTION section below for more information." + }; + + NarrowStrings --element-type-regex + { + "<regex>", + "Add <regex> to the list of regular expressions used to translate + XML Schema element names to C++ element type names. See the NAMING + CONVENTION section below for more information." + }; + + bool --name-regex-trace + { + "Trace the process of applying regular expressions specified with + the name transformation options. Use this option to find out why + your regular expressions don't do what you expected them to do." + }; + + // Root element. + // + bool --root-element-first + { + "Treat only the first global element as a document root. By default + all global elements are considered document roots." + }; + + bool --root-element-last + { + "Treat only the last global element as a document root. By default + all global elements are considered document roots." + }; + + bool --root-element-all + { + "Treat all global elements as document roots. This is the default + behavior. By explicitly specifying this option you can suppress + the warning that is issued if more than one global element is + defined." + }; + + bool --root-element-none + { + "Do not treat any global elements as document roots. By default all + global elements are considered document roots." + }; + + NarrowStrings --root-element + { + "<element>", + "Treat only <element> as a document root. Repeat this option to + specify more than one root element." + }; + + // Custom type. + // + NarrowStrings --custom-type + { + "<map>", + "Use a custom C++ type instead of the generated class. The <map> + argument is in the form \c{\i{name}[\b{=}\i{type}[\b{/}\i{base}]]}, + where \i{name} is a type name as defined in XML Schema and \i{type} + is a C++ type name that should be used instead. If \i{type} is not + present or empty then the custom type is assumed to have the same + name and be defined in the same namespace as the generated class + would have. If \i{base} is specified then the generated class is + still generated but with that name." + }; + + NarrowStrings --custom-type-regex + { + "<regex>", + "Use custom C++ types instead of the generated classes. The <regex> + argument is in the form + \c{\b{/}\i{name-pat}\b{/}[\i{type-sub}\b{/}[\i{base-sub}\b{/}]]}, + where \i{name-pat} is a regex pattern that will be matched against + type names as defined in XML Schema and \i{type-sub} is a C++ type + name substitution that should be used instead. If \i{type-sub} is + not present or its substitution results in an empty string then + the custom type is assumed to have the same name and be defined + in the same namespace as the generated class would have. If + \i{base-sub} is present and its substitution results in a + non-empty string then the generated class is still generated + but with the result of this substitution as its name. The pattern + and substitutions are in the Perl regular expression format. + See also the REGEX AND SHELL QUOTING section below." + }; + + // Parts. + // + std::size_t --parts = 1 + { + "<num>", + "Split generated source code into <num> parts. This is useful when + translating large, monolithic schemas and a C++ compiler is not + able to compile the resulting source code at once (usually due + to insufficient memory)." + }; + + NarrowString --parts-suffix = "-" + { + "<suffix>", + "Use <suffix> instead of the default '\cb{-}' to separate the file + name from the part number." + }; + }; + } +} diff --git a/xsd/xsd/cxx/tree/options.cxx b/xsd/xsd/cxx/tree/options.cxx new file mode 100644 index 0000000..820ebac --- /dev/null +++ b/xsd/xsd/cxx/tree/options.cxx @@ -0,0 +1,1149 @@ +// This code was generated by CLI, a command line interface +// compiler for C++. +// + +// Begin prologue. +// +#include <options-parser.hxx> +// +// End prologue. + +#include <cxx/tree/options.hxx> + +#include <map> +#include <set> +#include <string> +#include <vector> +#include <ostream> +#include <sstream> + +namespace cli +{ + template <typename X> + struct parser + { + static void + parse (X& x, bool& xs, scanner& s) + { + std::string o (s.next ()); + + if (s.more ()) + { + std::string v (s.next ()); + std::istringstream is (v); + if (!(is >> x && is.eof ())) + throw invalid_value (o, v); + } + else + throw missing_value (o); + + xs = true; + } + }; + + template <> + struct parser<bool> + { + static void + parse (bool& x, scanner& s) + { + s.next (); + x = true; + } + }; + + template <> + struct parser<std::string> + { + static void + parse (std::string& x, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (s.more ()) + x = s.next (); + else + throw missing_value (o); + + xs = true; + } + }; + + template <typename X> + struct parser<std::vector<X> > + { + static void + parse (std::vector<X>& c, bool& xs, scanner& s) + { + X x; + bool dummy; + parser<X>::parse (x, dummy, s); + c.push_back (x); + xs = true; + } + }; + + template <typename X> + struct parser<std::set<X> > + { + static void + parse (std::set<X>& c, bool& xs, scanner& s) + { + X x; + bool dummy; + parser<X>::parse (x, dummy, s); + c.insert (x); + xs = true; + } + }; + + template <typename K, typename V> + struct parser<std::map<K, V> > + { + static void + parse (std::map<K, V>& m, bool& xs, scanner& s) + { + std::string o (s.next ()); + + if (s.more ()) + { + std::string ov (s.next ()); + std::string::size_type p = ov.find ('='); + + if (p == std::string::npos) + { + K k = K (); + + if (!ov.empty ()) + { + std::istringstream ks (ov); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (o, ov); + } + + m[k] = V (); + } + else + { + K k = K (); + V v = V (); + std::string kstr (ov, 0, p); + std::string vstr (ov, p + 1); + + if (!kstr.empty ()) + { + std::istringstream ks (kstr); + + if (!(ks >> k && ks.eof ())) + throw invalid_value (o, ov); + } + + if (!vstr.empty ()) + { + std::istringstream vs (vstr); + + if (!(vs >> v && vs.eof ())) + throw invalid_value (o, ov); + } + + m[k] = v; + } + } + else + throw missing_value (o); + + xs = true; + } + }; + + template <typename X, typename T, T X::*M> + void + thunk (X& x, scanner& s) + { + parser<T>::parse (x.*M, s); + } + + template <typename X, typename T, T X::*M, bool X::*S> + void + thunk (X& x, scanner& s) + { + parser<T>::parse (x.*M, x.*S, s); + } +} + +#include <map> +#include <cstring> + +namespace CXX +{ + namespace Tree + { + // options + // + + options:: + options () + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + } + + options:: + options (int& argc, + char** argv, + bool erase, + ::cli::unknown_mode opt, + ::cli::unknown_mode arg) + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + ::cli::argv_scanner s (argc, argv, erase); + _parse (s, opt, arg); + } + + options:: + options (int start, + int& argc, + char** argv, + bool erase, + ::cli::unknown_mode opt, + ::cli::unknown_mode arg) + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + ::cli::argv_scanner s (start, argc, argv, erase); + _parse (s, opt, arg); + } + + options:: + options (int& argc, + char** argv, + int& end, + bool erase, + ::cli::unknown_mode opt, + ::cli::unknown_mode arg) + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + ::cli::argv_scanner s (argc, argv, erase); + _parse (s, opt, arg); + end = s.end (); + } + + options:: + options (int start, + int& argc, + char** argv, + int& end, + bool erase, + ::cli::unknown_mode opt, + ::cli::unknown_mode arg) + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + ::cli::argv_scanner s (start, argc, argv, erase); + _parse (s, opt, arg); + end = s.end (); + } + + options:: + options (::cli::scanner& s, + ::cli::unknown_mode opt, + ::cli::unknown_mode arg) + : generate_polymorphic_ (), + polymorphic_type_ (), + polymorphic_type_specified_ (false), + polymorphic_type_all_ (), + polymorphic_plate_ (0), + polymorphic_plate_specified_ (false), + ordered_type_ (), + ordered_type_specified_ (false), + ordered_type_derived_ (), + ordered_type_mixed_ (), + ordered_type_all_ (), + order_container_ (), + order_container_specified_ (false), + generate_serialization_ (), + generate_ostream_ (), + generate_doxygen_ (), + generate_comparison_ (), + generate_default_ctor_ (), + generate_from_base_ctor_ (), + suppress_assignment_ (), + generate_detach_ (), + generate_wildcard_ (), + generate_any_type_ (), + generate_insertion_ (), + generate_insertion_specified_ (false), + generate_extraction_ (), + generate_extraction_specified_ (false), + generate_forward_ (), + suppress_parsing_ (), + generate_element_type_ (), + generate_element_map_ (), + generate_intellisense_ (), + omit_default_attributes_ (), + type_naming_ ("knr"), + type_naming_specified_ (false), + function_naming_ ("knr"), + function_naming_specified_ (false), + type_regex_ (), + type_regex_specified_ (false), + accessor_regex_ (), + accessor_regex_specified_ (false), + one_accessor_regex_ (), + one_accessor_regex_specified_ (false), + opt_accessor_regex_ (), + opt_accessor_regex_specified_ (false), + seq_accessor_regex_ (), + seq_accessor_regex_specified_ (false), + modifier_regex_ (), + modifier_regex_specified_ (false), + one_modifier_regex_ (), + one_modifier_regex_specified_ (false), + opt_modifier_regex_ (), + opt_modifier_regex_specified_ (false), + seq_modifier_regex_ (), + seq_modifier_regex_specified_ (false), + parser_regex_ (), + parser_regex_specified_ (false), + serializer_regex_ (), + serializer_regex_specified_ (false), + const_regex_ (), + const_regex_specified_ (false), + enumerator_regex_ (), + enumerator_regex_specified_ (false), + element_type_regex_ (), + element_type_regex_specified_ (false), + name_regex_trace_ (), + root_element_first_ (), + root_element_last_ (), + root_element_all_ (), + root_element_none_ (), + root_element_ (), + root_element_specified_ (false), + custom_type_ (), + custom_type_specified_ (false), + custom_type_regex_ (), + custom_type_regex_specified_ (false), + parts_ (1), + parts_specified_ (false), + parts_suffix_ ("-"), + parts_suffix_specified_ (false) + { + _parse (s, opt, arg); + } + + void options:: + print_usage (::std::wostream& os) + { + os << "--generate-polymorphic Generate polymorphism-aware code." << ::std::endl; + + os << "--polymorphic-type <type> Indicate that <type> is a root of a polymorphic" << ::std::endl + << " type hierarchy." << ::std::endl; + + os << "--polymorphic-type-all Indicate that all types should be treated as" << ::std::endl + << " polymorphic." << ::std::endl; + + os << "--polymorphic-plate <num> Specify the polymorphic map plate the generated" << ::std::endl + << " code should register on." << ::std::endl; + + os << "--ordered-type <type> Indicate that element order in <type> is" << ::std::endl + << " significant." << ::std::endl; + + os << "--ordered-type-derived Automatically treat types derived from ordered" << ::std::endl + << " bases as also ordered." << ::std::endl; + + os << "--ordered-type-mixed Automatically treat complex types with mixed" << ::std::endl + << " content as ordered." << ::std::endl; + + os << "--ordered-type-all Indicate that element order in all types is" << ::std::endl + << " significant." << ::std::endl; + + os << "--order-container <type> Specify a custom class template that should be" << ::std::endl + << " used as a container for the content order in" << ::std::endl + << " ordered types instead of the default" << ::std::endl + << " 'std::vector'." << ::std::endl; + + os << "--generate-serialization Generate serialization functions." << ::std::endl; + + os << "--generate-ostream Generate ostream insertion operators" << ::std::endl + << " ('operator<<') for generated types." << ::std::endl; + + os << "--generate-doxygen Generate documentation comments suitable for" << ::std::endl + << " extraction by the Doxygen documentation system." << ::std::endl; + + os << "--generate-comparison Generate comparison operators ('operator==' and" << ::std::endl + << " 'operator!=') for complex types." << ::std::endl; + + os << "--generate-default-ctor Generate default constructors even for types that" << ::std::endl + << " have required members." << ::std::endl; + + os << "--generate-from-base-ctor Generate constructors that expect an instance of a" << ::std::endl + << " base type followed by all required members." << ::std::endl; + + os << "--suppress-assignment Suppress the generation of copy assignment" << ::std::endl + << " operators for complex types." << ::std::endl; + + os << "--generate-detach Generate detach functions for required elements" << ::std::endl + << " and attributes." << ::std::endl; + + os << "--generate-wildcard Generate accessors and modifiers as well as" << ::std::endl + << " parsing and serialization code for XML Schema" << ::std::endl + << " wildcards ('any' and 'anyAttribute')." << ::std::endl; + + os << "--generate-any-type Extract and store content of the XML Schema" << ::std::endl + << " 'anyType' type as a DOM fragment." << ::std::endl; + + os << "--generate-insertion <os> Generate data representation stream insertion" << ::std::endl + << " operators for the <os> output stream type." << ::std::endl; + + os << "--generate-extraction <is> Generate data representation stream extraction" << ::std::endl + << " constructors for the <is> input stream type." << ::std::endl; + + os << "--generate-forward Generate a separate header file with forward" << ::std::endl + << " declarations for the types being generated." << ::std::endl; + + os << "--suppress-parsing Suppress the generation of the parsing functions" << ::std::endl + << " and constructors." << ::std::endl; + + os << "--generate-element-type Generate types instead of parsing and" << ::std::endl + << " serialization functions for root elements." << ::std::endl; + + os << "--generate-element-map Generate a root element map that allows uniform" << ::std::endl + << " parsing and serialization of multiple root" << ::std::endl + << " elements." << ::std::endl; + + os << "--generate-intellisense Generate workarounds for IntelliSense bugs in" << ::std::endl + << " Visual Studio 2005 (8.0)." << ::std::endl; + + os << "--omit-default-attributes Omit attributes with default and fixed values from" << ::std::endl + << " serialized XML documents." << ::std::endl; + + os << "--type-naming <style> Specify the type naming convention that should be" << ::std::endl + << " used in the generated code." << ::std::endl; + + os << "--function-naming <style> Specify the function naming convention that should" << ::std::endl + << " be used in the generated code." << ::std::endl; + + os << "--type-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema type names to C++" << ::std::endl + << " type names." << ::std::endl; + + os << "--accessor-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes to C++ accessor function" << ::std::endl + << " names." << ::std::endl; + + os << "--one-accessor-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality one to C++" << ::std::endl + << " accessor function names." << ::std::endl; + + os << "--opt-accessor-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality optional to" << ::std::endl + << " C++ accessor function names." << ::std::endl; + + os << "--seq-accessor-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality sequence to" << ::std::endl + << " C++ accessor function names." << ::std::endl; + + os << "--modifier-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes to C++ modifier function" << ::std::endl + << " names." << ::std::endl; + + os << "--one-modifier-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality one to C++" << ::std::endl + << " modifier function names." << ::std::endl; + + os << "--opt-modifier-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality optional to" << ::std::endl + << " C++ modifier function names." << ::std::endl; + + os << "--seq-modifier-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema names of" << ::std::endl + << " elements/attributes with cardinality sequence to" << ::std::endl + << " C++ modifier function names." << ::std::endl; + + os << "--parser-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema element names to C++" << ::std::endl + << " parsing function names." << ::std::endl; + + os << "--serializer-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema element names to C++" << ::std::endl + << " serialization function names." << ::std::endl; + + os << "--const-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema-derived names to C++" << ::std::endl + << " constant names." << ::std::endl; + + os << "--enumerator-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema enumeration values to" << ::std::endl + << " C++ enumerator names." << ::std::endl; + + os << "--element-type-regex <regex> Add <regex> to the list of regular expressions" << ::std::endl + << " used to translate XML Schema element names to C++" << ::std::endl + << " element type names." << ::std::endl; + + os << "--name-regex-trace Trace the process of applying regular expressions" << ::std::endl + << " specified with the name transformation options." << ::std::endl; + + os << "--root-element-first Treat only the first global element as a document" << ::std::endl + << " root." << ::std::endl; + + os << "--root-element-last Treat only the last global element as a document" << ::std::endl + << " root." << ::std::endl; + + os << "--root-element-all Treat all global elements as document roots." << ::std::endl; + + os << "--root-element-none Do not treat any global elements as document" << ::std::endl + << " roots." << ::std::endl; + + os << "--root-element <element> Treat only <element> as a document root." << ::std::endl; + + os << "--custom-type <map> Use a custom C++ type instead of the generated" << ::std::endl + << " class." << ::std::endl; + + os << "--custom-type-regex <regex> Use custom C++ types instead of the generated" << ::std::endl + << " classes." << ::std::endl; + + os << "--parts <num> Split generated source code into <num> parts." << ::std::endl; + + os << "--parts-suffix <suffix> Use <suffix> instead of the default ''-'' to" << ::std::endl + << " separate the file name from the part number." << ::std::endl; + } + + typedef + std::map<std::string, void (*) (options&, ::cli::scanner&)> + _cli_options_map; + + static _cli_options_map _cli_options_map_; + + struct _cli_options_map_init + { + _cli_options_map_init () + { + _cli_options_map_["--generate-polymorphic"] = + &::cli::thunk< options, bool, &options::generate_polymorphic_ >; + _cli_options_map_["--polymorphic-type"] = + &::cli::thunk< options, NarrowStrings, &options::polymorphic_type_, + &options::polymorphic_type_specified_ >; + _cli_options_map_["--polymorphic-type-all"] = + &::cli::thunk< options, bool, &options::polymorphic_type_all_ >; + _cli_options_map_["--polymorphic-plate"] = + &::cli::thunk< options, unsigned long, &options::polymorphic_plate_, + &options::polymorphic_plate_specified_ >; + _cli_options_map_["--ordered-type"] = + &::cli::thunk< options, NarrowStrings, &options::ordered_type_, + &options::ordered_type_specified_ >; + _cli_options_map_["--ordered-type-derived"] = + &::cli::thunk< options, bool, &options::ordered_type_derived_ >; + _cli_options_map_["--ordered-type-mixed"] = + &::cli::thunk< options, bool, &options::ordered_type_mixed_ >; + _cli_options_map_["--ordered-type-all"] = + &::cli::thunk< options, bool, &options::ordered_type_all_ >; + _cli_options_map_["--order-container"] = + &::cli::thunk< options, NarrowString, &options::order_container_, + &options::order_container_specified_ >; + _cli_options_map_["--generate-serialization"] = + &::cli::thunk< options, bool, &options::generate_serialization_ >; + _cli_options_map_["--generate-ostream"] = + &::cli::thunk< options, bool, &options::generate_ostream_ >; + _cli_options_map_["--generate-doxygen"] = + &::cli::thunk< options, bool, &options::generate_doxygen_ >; + _cli_options_map_["--generate-comparison"] = + &::cli::thunk< options, bool, &options::generate_comparison_ >; + _cli_options_map_["--generate-default-ctor"] = + &::cli::thunk< options, bool, &options::generate_default_ctor_ >; + _cli_options_map_["--generate-from-base-ctor"] = + &::cli::thunk< options, bool, &options::generate_from_base_ctor_ >; + _cli_options_map_["--suppress-assignment"] = + &::cli::thunk< options, bool, &options::suppress_assignment_ >; + _cli_options_map_["--generate-detach"] = + &::cli::thunk< options, bool, &options::generate_detach_ >; + _cli_options_map_["--generate-wildcard"] = + &::cli::thunk< options, bool, &options::generate_wildcard_ >; + _cli_options_map_["--generate-any-type"] = + &::cli::thunk< options, bool, &options::generate_any_type_ >; + _cli_options_map_["--generate-insertion"] = + &::cli::thunk< options, NarrowStrings, &options::generate_insertion_, + &options::generate_insertion_specified_ >; + _cli_options_map_["--generate-extraction"] = + &::cli::thunk< options, NarrowStrings, &options::generate_extraction_, + &options::generate_extraction_specified_ >; + _cli_options_map_["--generate-forward"] = + &::cli::thunk< options, bool, &options::generate_forward_ >; + _cli_options_map_["--suppress-parsing"] = + &::cli::thunk< options, bool, &options::suppress_parsing_ >; + _cli_options_map_["--generate-element-type"] = + &::cli::thunk< options, bool, &options::generate_element_type_ >; + _cli_options_map_["--generate-element-map"] = + &::cli::thunk< options, bool, &options::generate_element_map_ >; + _cli_options_map_["--generate-intellisense"] = + &::cli::thunk< options, bool, &options::generate_intellisense_ >; + _cli_options_map_["--omit-default-attributes"] = + &::cli::thunk< options, bool, &options::omit_default_attributes_ >; + _cli_options_map_["--type-naming"] = + &::cli::thunk< options, NarrowString, &options::type_naming_, + &options::type_naming_specified_ >; + _cli_options_map_["--function-naming"] = + &::cli::thunk< options, NarrowString, &options::function_naming_, + &options::function_naming_specified_ >; + _cli_options_map_["--type-regex"] = + &::cli::thunk< options, NarrowStrings, &options::type_regex_, + &options::type_regex_specified_ >; + _cli_options_map_["--accessor-regex"] = + &::cli::thunk< options, NarrowStrings, &options::accessor_regex_, + &options::accessor_regex_specified_ >; + _cli_options_map_["--one-accessor-regex"] = + &::cli::thunk< options, NarrowStrings, &options::one_accessor_regex_, + &options::one_accessor_regex_specified_ >; + _cli_options_map_["--opt-accessor-regex"] = + &::cli::thunk< options, NarrowStrings, &options::opt_accessor_regex_, + &options::opt_accessor_regex_specified_ >; + _cli_options_map_["--seq-accessor-regex"] = + &::cli::thunk< options, NarrowStrings, &options::seq_accessor_regex_, + &options::seq_accessor_regex_specified_ >; + _cli_options_map_["--modifier-regex"] = + &::cli::thunk< options, NarrowStrings, &options::modifier_regex_, + &options::modifier_regex_specified_ >; + _cli_options_map_["--one-modifier-regex"] = + &::cli::thunk< options, NarrowStrings, &options::one_modifier_regex_, + &options::one_modifier_regex_specified_ >; + _cli_options_map_["--opt-modifier-regex"] = + &::cli::thunk< options, NarrowStrings, &options::opt_modifier_regex_, + &options::opt_modifier_regex_specified_ >; + _cli_options_map_["--seq-modifier-regex"] = + &::cli::thunk< options, NarrowStrings, &options::seq_modifier_regex_, + &options::seq_modifier_regex_specified_ >; + _cli_options_map_["--parser-regex"] = + &::cli::thunk< options, NarrowStrings, &options::parser_regex_, + &options::parser_regex_specified_ >; + _cli_options_map_["--serializer-regex"] = + &::cli::thunk< options, NarrowStrings, &options::serializer_regex_, + &options::serializer_regex_specified_ >; + _cli_options_map_["--const-regex"] = + &::cli::thunk< options, NarrowStrings, &options::const_regex_, + &options::const_regex_specified_ >; + _cli_options_map_["--enumerator-regex"] = + &::cli::thunk< options, NarrowStrings, &options::enumerator_regex_, + &options::enumerator_regex_specified_ >; + _cli_options_map_["--element-type-regex"] = + &::cli::thunk< options, NarrowStrings, &options::element_type_regex_, + &options::element_type_regex_specified_ >; + _cli_options_map_["--name-regex-trace"] = + &::cli::thunk< options, bool, &options::name_regex_trace_ >; + _cli_options_map_["--root-element-first"] = + &::cli::thunk< options, bool, &options::root_element_first_ >; + _cli_options_map_["--root-element-last"] = + &::cli::thunk< options, bool, &options::root_element_last_ >; + _cli_options_map_["--root-element-all"] = + &::cli::thunk< options, bool, &options::root_element_all_ >; + _cli_options_map_["--root-element-none"] = + &::cli::thunk< options, bool, &options::root_element_none_ >; + _cli_options_map_["--root-element"] = + &::cli::thunk< options, NarrowStrings, &options::root_element_, + &options::root_element_specified_ >; + _cli_options_map_["--custom-type"] = + &::cli::thunk< options, NarrowStrings, &options::custom_type_, + &options::custom_type_specified_ >; + _cli_options_map_["--custom-type-regex"] = + &::cli::thunk< options, NarrowStrings, &options::custom_type_regex_, + &options::custom_type_regex_specified_ >; + _cli_options_map_["--parts"] = + &::cli::thunk< options, std::size_t, &options::parts_, + &options::parts_specified_ >; + _cli_options_map_["--parts-suffix"] = + &::cli::thunk< options, NarrowString, &options::parts_suffix_, + &options::parts_suffix_specified_ >; + } + }; + + static _cli_options_map_init _cli_options_map_init_; + + bool options:: + _parse (const char* o, ::cli::scanner& s) + { + _cli_options_map::const_iterator i (_cli_options_map_.find (o)); + + if (i != _cli_options_map_.end ()) + { + (*(i->second)) (*this, s); + return true; + } + + // options base + // + if (::CXX::options::_parse (o, s)) + return true; + + return false; + } + + void options:: + _parse (::cli::scanner& s, + ::cli::unknown_mode opt_mode, + ::cli::unknown_mode arg_mode) + { + bool opt = true; + + while (s.more ()) + { + const char* o = s.peek (); + + if (std::strcmp (o, "--") == 0) + { + s.skip (); + opt = false; + continue; + } + + if (opt && _parse (o, s)); + else if (opt && std::strncmp (o, "-", 1) == 0 && o[1] != '\0') + { + switch (opt_mode) + { + case ::cli::unknown_mode::skip: + { + s.skip (); + continue; + } + case ::cli::unknown_mode::stop: + { + break; + } + case ::cli::unknown_mode::fail: + { + throw ::cli::unknown_option (o); + } + } + + break; + } + else + { + switch (arg_mode) + { + case ::cli::unknown_mode::skip: + { + s.skip (); + continue; + } + case ::cli::unknown_mode::stop: + { + break; + } + case ::cli::unknown_mode::fail: + { + throw ::cli::unknown_argument (o); + } + } + + break; + } + } + } + } +} + +// Begin epilogue. +// +// +// End epilogue. + diff --git a/xsd/xsd/cxx/tree/options.hxx b/xsd/xsd/cxx/tree/options.hxx new file mode 100644 index 0000000..b190dc5 --- /dev/null +++ b/xsd/xsd/cxx/tree/options.hxx @@ -0,0 +1,411 @@ +// This code was generated by CLI, a command line interface +// compiler for C++. +// + +#ifndef CXX_TREE_OPTIONS_HXX +#define CXX_TREE_OPTIONS_HXX + +// Begin prologue. +// +// +// End prologue. + +#include <cstddef> + +#include <types.hxx> + +#include <cxx/options.hxx> + +namespace CXX +{ + namespace Tree + { + class options: public ::CXX::options + { + public: + options (int& argc, + char** argv, + bool erase = false, + ::cli::unknown_mode option = ::cli::unknown_mode::fail, + ::cli::unknown_mode argument = ::cli::unknown_mode::stop); + + options (int start, + int& argc, + char** argv, + bool erase = false, + ::cli::unknown_mode option = ::cli::unknown_mode::fail, + ::cli::unknown_mode argument = ::cli::unknown_mode::stop); + + options (int& argc, + char** argv, + int& end, + bool erase = false, + ::cli::unknown_mode option = ::cli::unknown_mode::fail, + ::cli::unknown_mode argument = ::cli::unknown_mode::stop); + + options (int start, + int& argc, + char** argv, + int& end, + bool erase = false, + ::cli::unknown_mode option = ::cli::unknown_mode::fail, + ::cli::unknown_mode argument = ::cli::unknown_mode::stop); + + options (::cli::scanner&, + ::cli::unknown_mode option = ::cli::unknown_mode::fail, + ::cli::unknown_mode argument = ::cli::unknown_mode::stop); + + options (); + + // Option accessors. + // + const bool& + generate_polymorphic () const; + + const NarrowStrings& + polymorphic_type () const; + + bool + polymorphic_type_specified () const; + + const bool& + polymorphic_type_all () const; + + const unsigned long& + polymorphic_plate () const; + + bool + polymorphic_plate_specified () const; + + const NarrowStrings& + ordered_type () const; + + bool + ordered_type_specified () const; + + const bool& + ordered_type_derived () const; + + const bool& + ordered_type_mixed () const; + + const bool& + ordered_type_all () const; + + const NarrowString& + order_container () const; + + bool + order_container_specified () const; + + const bool& + generate_serialization () const; + + const bool& + generate_ostream () const; + + const bool& + generate_doxygen () const; + + const bool& + generate_comparison () const; + + const bool& + generate_default_ctor () const; + + const bool& + generate_from_base_ctor () const; + + const bool& + suppress_assignment () const; + + const bool& + generate_detach () const; + + const bool& + generate_wildcard () const; + + const bool& + generate_any_type () const; + + const NarrowStrings& + generate_insertion () const; + + bool + generate_insertion_specified () const; + + const NarrowStrings& + generate_extraction () const; + + bool + generate_extraction_specified () const; + + const bool& + generate_forward () const; + + const bool& + suppress_parsing () const; + + const bool& + generate_element_type () const; + + const bool& + generate_element_map () const; + + const bool& + generate_intellisense () const; + + const bool& + omit_default_attributes () const; + + const NarrowString& + type_naming () const; + + bool + type_naming_specified () const; + + const NarrowString& + function_naming () const; + + bool + function_naming_specified () const; + + const NarrowStrings& + type_regex () const; + + bool + type_regex_specified () const; + + const NarrowStrings& + accessor_regex () const; + + bool + accessor_regex_specified () const; + + const NarrowStrings& + one_accessor_regex () const; + + bool + one_accessor_regex_specified () const; + + const NarrowStrings& + opt_accessor_regex () const; + + bool + opt_accessor_regex_specified () const; + + const NarrowStrings& + seq_accessor_regex () const; + + bool + seq_accessor_regex_specified () const; + + const NarrowStrings& + modifier_regex () const; + + bool + modifier_regex_specified () const; + + const NarrowStrings& + one_modifier_regex () const; + + bool + one_modifier_regex_specified () const; + + const NarrowStrings& + opt_modifier_regex () const; + + bool + opt_modifier_regex_specified () const; + + const NarrowStrings& + seq_modifier_regex () const; + + bool + seq_modifier_regex_specified () const; + + const NarrowStrings& + parser_regex () const; + + bool + parser_regex_specified () const; + + const NarrowStrings& + serializer_regex () const; + + bool + serializer_regex_specified () const; + + const NarrowStrings& + const_regex () const; + + bool + const_regex_specified () const; + + const NarrowStrings& + enumerator_regex () const; + + bool + enumerator_regex_specified () const; + + const NarrowStrings& + element_type_regex () const; + + bool + element_type_regex_specified () const; + + const bool& + name_regex_trace () const; + + const bool& + root_element_first () const; + + const bool& + root_element_last () const; + + const bool& + root_element_all () const; + + const bool& + root_element_none () const; + + const NarrowStrings& + root_element () const; + + bool + root_element_specified () const; + + const NarrowStrings& + custom_type () const; + + bool + custom_type_specified () const; + + const NarrowStrings& + custom_type_regex () const; + + bool + custom_type_regex_specified () const; + + const std::size_t& + parts () const; + + bool + parts_specified () const; + + const NarrowString& + parts_suffix () const; + + bool + parts_suffix_specified () const; + + // Print usage information. + // + static void + print_usage (::std::wostream&); + + // Implementation details. + // + protected: + bool + _parse (const char*, ::cli::scanner&); + + private: + void + _parse (::cli::scanner&, + ::cli::unknown_mode option, + ::cli::unknown_mode argument); + + public: + bool generate_polymorphic_; + NarrowStrings polymorphic_type_; + bool polymorphic_type_specified_; + bool polymorphic_type_all_; + unsigned long polymorphic_plate_; + bool polymorphic_plate_specified_; + NarrowStrings ordered_type_; + bool ordered_type_specified_; + bool ordered_type_derived_; + bool ordered_type_mixed_; + bool ordered_type_all_; + NarrowString order_container_; + bool order_container_specified_; + bool generate_serialization_; + bool generate_ostream_; + bool generate_doxygen_; + bool generate_comparison_; + bool generate_default_ctor_; + bool generate_from_base_ctor_; + bool suppress_assignment_; + bool generate_detach_; + bool generate_wildcard_; + bool generate_any_type_; + NarrowStrings generate_insertion_; + bool generate_insertion_specified_; + NarrowStrings generate_extraction_; + bool generate_extraction_specified_; + bool generate_forward_; + bool suppress_parsing_; + bool generate_element_type_; + bool generate_element_map_; + bool generate_intellisense_; + bool omit_default_attributes_; + NarrowString type_naming_; + bool type_naming_specified_; + NarrowString function_naming_; + bool function_naming_specified_; + NarrowStrings type_regex_; + bool type_regex_specified_; + NarrowStrings accessor_regex_; + bool accessor_regex_specified_; + NarrowStrings one_accessor_regex_; + bool one_accessor_regex_specified_; + NarrowStrings opt_accessor_regex_; + bool opt_accessor_regex_specified_; + NarrowStrings seq_accessor_regex_; + bool seq_accessor_regex_specified_; + NarrowStrings modifier_regex_; + bool modifier_regex_specified_; + NarrowStrings one_modifier_regex_; + bool one_modifier_regex_specified_; + NarrowStrings opt_modifier_regex_; + bool opt_modifier_regex_specified_; + NarrowStrings seq_modifier_regex_; + bool seq_modifier_regex_specified_; + NarrowStrings parser_regex_; + bool parser_regex_specified_; + NarrowStrings serializer_regex_; + bool serializer_regex_specified_; + NarrowStrings const_regex_; + bool const_regex_specified_; + NarrowStrings enumerator_regex_; + bool enumerator_regex_specified_; + NarrowStrings element_type_regex_; + bool element_type_regex_specified_; + bool name_regex_trace_; + bool root_element_first_; + bool root_element_last_; + bool root_element_all_; + bool root_element_none_; + NarrowStrings root_element_; + bool root_element_specified_; + NarrowStrings custom_type_; + bool custom_type_specified_; + NarrowStrings custom_type_regex_; + bool custom_type_regex_specified_; + std::size_t parts_; + bool parts_specified_; + NarrowString parts_suffix_; + bool parts_suffix_specified_; + }; + } +} + +#include <cxx/tree/options.ixx> + +// Begin epilogue. +// +// +// End epilogue. + +#endif // CXX_TREE_OPTIONS_HXX diff --git a/xsd/xsd/cxx/tree/options.ixx b/xsd/xsd/cxx/tree/options.ixx new file mode 100644 index 0000000..824fbee --- /dev/null +++ b/xsd/xsd/cxx/tree/options.ixx @@ -0,0 +1,502 @@ +// This code was generated by CLI, a command line interface +// compiler for C++. +// + +// Begin prologue. +// +// +// End prologue. + +namespace CXX +{ + namespace Tree + { + // options + // + + inline const bool& options:: + generate_polymorphic () const + { + return this->generate_polymorphic_; + } + + inline const NarrowStrings& options:: + polymorphic_type () const + { + return this->polymorphic_type_; + } + + inline bool options:: + polymorphic_type_specified () const + { + return this->polymorphic_type_specified_; + } + + inline const bool& options:: + polymorphic_type_all () const + { + return this->polymorphic_type_all_; + } + + inline const unsigned long& options:: + polymorphic_plate () const + { + return this->polymorphic_plate_; + } + + inline bool options:: + polymorphic_plate_specified () const + { + return this->polymorphic_plate_specified_; + } + + inline const NarrowStrings& options:: + ordered_type () const + { + return this->ordered_type_; + } + + inline bool options:: + ordered_type_specified () const + { + return this->ordered_type_specified_; + } + + inline const bool& options:: + ordered_type_derived () const + { + return this->ordered_type_derived_; + } + + inline const bool& options:: + ordered_type_mixed () const + { + return this->ordered_type_mixed_; + } + + inline const bool& options:: + ordered_type_all () const + { + return this->ordered_type_all_; + } + + inline const NarrowString& options:: + order_container () const + { + return this->order_container_; + } + + inline bool options:: + order_container_specified () const + { + return this->order_container_specified_; + } + + inline const bool& options:: + generate_serialization () const + { + return this->generate_serialization_; + } + + inline const bool& options:: + generate_ostream () const + { + return this->generate_ostream_; + } + + inline const bool& options:: + generate_doxygen () const + { + return this->generate_doxygen_; + } + + inline const bool& options:: + generate_comparison () const + { + return this->generate_comparison_; + } + + inline const bool& options:: + generate_default_ctor () const + { + return this->generate_default_ctor_; + } + + inline const bool& options:: + generate_from_base_ctor () const + { + return this->generate_from_base_ctor_; + } + + inline const bool& options:: + suppress_assignment () const + { + return this->suppress_assignment_; + } + + inline const bool& options:: + generate_detach () const + { + return this->generate_detach_; + } + + inline const bool& options:: + generate_wildcard () const + { + return this->generate_wildcard_; + } + + inline const bool& options:: + generate_any_type () const + { + return this->generate_any_type_; + } + + inline const NarrowStrings& options:: + generate_insertion () const + { + return this->generate_insertion_; + } + + inline bool options:: + generate_insertion_specified () const + { + return this->generate_insertion_specified_; + } + + inline const NarrowStrings& options:: + generate_extraction () const + { + return this->generate_extraction_; + } + + inline bool options:: + generate_extraction_specified () const + { + return this->generate_extraction_specified_; + } + + inline const bool& options:: + generate_forward () const + { + return this->generate_forward_; + } + + inline const bool& options:: + suppress_parsing () const + { + return this->suppress_parsing_; + } + + inline const bool& options:: + generate_element_type () const + { + return this->generate_element_type_; + } + + inline const bool& options:: + generate_element_map () const + { + return this->generate_element_map_; + } + + inline const bool& options:: + generate_intellisense () const + { + return this->generate_intellisense_; + } + + inline const bool& options:: + omit_default_attributes () const + { + return this->omit_default_attributes_; + } + + inline const NarrowString& options:: + type_naming () const + { + return this->type_naming_; + } + + inline bool options:: + type_naming_specified () const + { + return this->type_naming_specified_; + } + + inline const NarrowString& options:: + function_naming () const + { + return this->function_naming_; + } + + inline bool options:: + function_naming_specified () const + { + return this->function_naming_specified_; + } + + inline const NarrowStrings& options:: + type_regex () const + { + return this->type_regex_; + } + + inline bool options:: + type_regex_specified () const + { + return this->type_regex_specified_; + } + + inline const NarrowStrings& options:: + accessor_regex () const + { + return this->accessor_regex_; + } + + inline bool options:: + accessor_regex_specified () const + { + return this->accessor_regex_specified_; + } + + inline const NarrowStrings& options:: + one_accessor_regex () const + { + return this->one_accessor_regex_; + } + + inline bool options:: + one_accessor_regex_specified () const + { + return this->one_accessor_regex_specified_; + } + + inline const NarrowStrings& options:: + opt_accessor_regex () const + { + return this->opt_accessor_regex_; + } + + inline bool options:: + opt_accessor_regex_specified () const + { + return this->opt_accessor_regex_specified_; + } + + inline const NarrowStrings& options:: + seq_accessor_regex () const + { + return this->seq_accessor_regex_; + } + + inline bool options:: + seq_accessor_regex_specified () const + { + return this->seq_accessor_regex_specified_; + } + + inline const NarrowStrings& options:: + modifier_regex () const + { + return this->modifier_regex_; + } + + inline bool options:: + modifier_regex_specified () const + { + return this->modifier_regex_specified_; + } + + inline const NarrowStrings& options:: + one_modifier_regex () const + { + return this->one_modifier_regex_; + } + + inline bool options:: + one_modifier_regex_specified () const + { + return this->one_modifier_regex_specified_; + } + + inline const NarrowStrings& options:: + opt_modifier_regex () const + { + return this->opt_modifier_regex_; + } + + inline bool options:: + opt_modifier_regex_specified () const + { + return this->opt_modifier_regex_specified_; + } + + inline const NarrowStrings& options:: + seq_modifier_regex () const + { + return this->seq_modifier_regex_; + } + + inline bool options:: + seq_modifier_regex_specified () const + { + return this->seq_modifier_regex_specified_; + } + + inline const NarrowStrings& options:: + parser_regex () const + { + return this->parser_regex_; + } + + inline bool options:: + parser_regex_specified () const + { + return this->parser_regex_specified_; + } + + inline const NarrowStrings& options:: + serializer_regex () const + { + return this->serializer_regex_; + } + + inline bool options:: + serializer_regex_specified () const + { + return this->serializer_regex_specified_; + } + + inline const NarrowStrings& options:: + const_regex () const + { + return this->const_regex_; + } + + inline bool options:: + const_regex_specified () const + { + return this->const_regex_specified_; + } + + inline const NarrowStrings& options:: + enumerator_regex () const + { + return this->enumerator_regex_; + } + + inline bool options:: + enumerator_regex_specified () const + { + return this->enumerator_regex_specified_; + } + + inline const NarrowStrings& options:: + element_type_regex () const + { + return this->element_type_regex_; + } + + inline bool options:: + element_type_regex_specified () const + { + return this->element_type_regex_specified_; + } + + inline const bool& options:: + name_regex_trace () const + { + return this->name_regex_trace_; + } + + inline const bool& options:: + root_element_first () const + { + return this->root_element_first_; + } + + inline const bool& options:: + root_element_last () const + { + return this->root_element_last_; + } + + inline const bool& options:: + root_element_all () const + { + return this->root_element_all_; + } + + inline const bool& options:: + root_element_none () const + { + return this->root_element_none_; + } + + inline const NarrowStrings& options:: + root_element () const + { + return this->root_element_; + } + + inline bool options:: + root_element_specified () const + { + return this->root_element_specified_; + } + + inline const NarrowStrings& options:: + custom_type () const + { + return this->custom_type_; + } + + inline bool options:: + custom_type_specified () const + { + return this->custom_type_specified_; + } + + inline const NarrowStrings& options:: + custom_type_regex () const + { + return this->custom_type_regex_; + } + + inline bool options:: + custom_type_regex_specified () const + { + return this->custom_type_regex_specified_; + } + + inline const std::size_t& options:: + parts () const + { + return this->parts_; + } + + inline bool options:: + parts_specified () const + { + return this->parts_specified_; + } + + inline const NarrowString& options:: + parts_suffix () const + { + return this->parts_suffix_; + } + + inline bool options:: + parts_suffix_specified () const + { + return this->parts_suffix_specified_; + } + } +} + +// Begin epilogue. +// +// +// End epilogue. diff --git a/xsd/xsd/cxx/tree/order-processor.cxx b/xsd/xsd/cxx/tree/order-processor.cxx new file mode 100644 index 0000000..68eee8c --- /dev/null +++ b/xsd/xsd/cxx/tree/order-processor.cxx @@ -0,0 +1,244 @@ +// file : xsde/cxx/tree/order-processor.cxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <iostream> + +#include <cxx/tree/elements.hxx> +#include <cxx/tree/order-processor.hxx> + +#include <xsd-frontend/semantic-graph.hxx> +#include <xsd-frontend/traversal.hxx> + +using namespace std; + +namespace CXX +{ + namespace Tree + { + namespace + { + struct Member: Traversal::Element, Traversal::Any + { + Member (size_t count): count_ (count) {} + + virtual void + traverse (SemanticGraph::Element& e) + { + if (Context::skip (e)) + return; + + e.context ().set ("ordered-id", count_++); + } + + virtual void + traverse (SemanticGraph::Any& a) + { + a.context ().set ("ordered-id", count_++); + } + + size_t count_; + }; + + // + // + struct Type: Traversal::Complex + { + Type (TypeNameSet& ordered_types, bool derived, bool mixed, bool all) + : ordered_types_ (ordered_types), + derived_ (derived), + mixed_ (mixed), + all_ (all) + { + } + + virtual void + traverse (SemanticGraph::Complex& c) + { + SemanticGraph::Context& ctx (c.context ()); + + if (!ctx.count ("ordered")) + { + // First process our base. + // + if (c.inherits_p ()) + { + SemanticGraph::Type& b (c.inherits ().base ()); + + if (!b.context ().count ("ordered")) + dispatch (b); + } + + // See if our base (not necessarily immediate) is ordered. + // + using SemanticGraph::Complex; + + Complex* b (0); + + for (Complex* p (&c); p->inherits_p ();) + { + if ((b = dynamic_cast<Complex*> (&p->inherits ().base ()))) + { + if (Context::ordered_p (*b)) + break; + + p = b; + } + else + break; + } + + bool o (all_ || + (derived_ && b != 0 && Context::ordered_p (*b)) || + (mixed_ && c.mixed_p ()) || + ordered_types_.find (c)); + ctx.set ("ordered", o); + + // Assign ids to elements and wildcards, calculate total count. + // + if (o) + { + size_t count ( + b != 0 && Context::ordered_p (*b) + ? b->context ().get<size_t> ("ordered-count") + : 1); + + ctx.set ("ordered-start", count); + + Member m (count); + Traversal::Names n (m); + names (c, n); + + // Assign content id for mixed text. + // + if (Context::mixed_p (c) && count == 1) + ctx.set ("mixed-ordered-id", m.count_++); + + ctx.set ("ordered-count", m.count_); + } + } + } + + private: + TypeNameSet& ordered_types_; + bool derived_; + bool mixed_; + bool all_; + }; + + // Go into sourced/included/imported schemas while making sure + // we don't process the same stuff more than once. + // + struct Uses: Traversal::Sources, + Traversal::Includes, + Traversal::Imports + { + Uses (char const* seen_key) + : seen_key_ (seen_key) + { + } + + virtual void + traverse (SemanticGraph::Sources& sr) + { + SemanticGraph::Schema& s (sr.schema ()); + + if (!s.context ().count (seen_key_)) + { + s.context ().set (seen_key_, true); + Traversal::Sources::traverse (sr); + } + } + + virtual void + traverse (SemanticGraph::Includes& i) + { + SemanticGraph::Schema& s (i.schema ()); + + if (!s.context ().count (seen_key_)) + { + s.context ().set (seen_key_, true); + Traversal::Includes::traverse (i); + } + } + + virtual void + traverse (SemanticGraph::Imports& i) + { + SemanticGraph::Schema& s (i.schema ()); + + if (!s.context ().count (seen_key_)) + { + s.context ().set (seen_key_, true); + Traversal::Imports::traverse (i); + } + } + + private: + char const* seen_key_; + }; + + char const* seen_key = "cxx-tree-order-processor-seen"; + + bool + process_impl (options const& ops, + SemanticGraph::Schema& tu, + SemanticGraph::Path const&) + { + // Prepare a set of ordered types. + // + TypeNameSet ordered_types (ops.ordered_type ().begin (), + ops.ordered_type ().end ()); + + // Root schema in the file-per-type mode is just a bunch + // of includes without a namespace. + // + SemanticGraph::Schema::NamesIterator i (tu.names_begin ()); + + // Nothing to do if this is the XML Schema namespace. + // + if (i == tu.names_end () || + i->named ().name () != L"http://www.w3.org/2001/XMLSchema") + { + // Note that we check first if this schema has already been + // processed which may happen in the file-per-type compilation + // mode. + // + if (!tu.context ().count (seen_key)) + { + Traversal::Schema schema; + Uses uses (seen_key); + + schema >> uses >> schema; + + Traversal::Names schema_names; + Traversal::Namespace ns; + Traversal::Names ns_names; + Type type (ordered_types, + ops.ordered_type_derived (), + ops.ordered_type_mixed (), + ops.ordered_type_all ()); + + schema >> schema_names >> ns >> ns_names >> type; + + // Some twisted schemas do recusive self-inclusion. + // + tu.context ().set (seen_key, true); + + schema.dispatch (tu); + } + } + + return true; + } + } + + bool OrderProcessor:: + process (options const& ops, + SemanticGraph::Schema& tu, + SemanticGraph::Path const& file) + { + return process_impl (ops, tu, file); + } + } +} diff --git a/xsd/xsd/cxx/tree/order-processor.hxx b/xsd/xsd/cxx/tree/order-processor.hxx new file mode 100644 index 0000000..fa68d21 --- /dev/null +++ b/xsd/xsd/cxx/tree/order-processor.hxx @@ -0,0 +1,30 @@ +// file : xsde/cxx/tree/order-processor.hxx +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef CXX_TREE_ORDER_PROCESSOR_HXX +#define CXX_TREE_ORDER_PROCESSOR_HXX + +#include <xsd-frontend/semantic-graph.hxx> + +#include <xsd.hxx> +#include <types.hxx> + +#include <cxx/tree/options.hxx> + +namespace CXX +{ + namespace Tree + { + class OrderProcessor + { + public: + bool + process (options const&, + XSDFrontend::SemanticGraph::Schema&, + XSDFrontend::SemanticGraph::Path const& file); + }; + } +} + +#endif // CXX_TREE_ORDER_PROCESSOR_HXX diff --git a/xsd/xsd/cxx/tree/parser-header.cxx b/xsd/xsd/cxx/tree/parser-header.cxx index c1d1ab9..8aff44f 100644 --- a/xsd/xsd/cxx/tree/parser-header.cxx +++ b/xsd/xsd/cxx/tree/parser-header.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parser-header.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/parser-header.hxx> @@ -23,7 +22,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) @@ -71,7 +70,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -94,7 +93,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -120,7 +119,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -149,7 +148,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -172,7 +171,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -198,7 +197,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -225,7 +224,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << flags_type << " f = 0," << endl @@ -256,7 +255,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << error_handler << "& eh," << endl @@ -288,7 +287,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl @@ -318,7 +317,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -342,7 +341,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -368,7 +367,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -395,7 +394,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << xerces_ns << "::DOMDocument& d," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -420,9 +419,9 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument >& d," << endl + "::DOMDocument > d," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" << endl; @@ -449,7 +448,7 @@ namespace CXX } - Void + void generate_parser_header (Context& ctx) { ctx.os << "#include <iosfwd>" << endl @@ -460,7 +459,7 @@ namespace CXX << endl; Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); ElementFunction element (ctx); diff --git a/xsd/xsd/cxx/tree/parser-header.hxx b/xsd/xsd/cxx/tree/parser-header.hxx index 20ca7d4..dfe7843 100644 --- a/xsd/xsd/cxx/tree/parser-header.hxx +++ b/xsd/xsd/cxx/tree/parser-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parser-header.hxx -// 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 #ifndef CXX_TREE_PARSER_HEADER_HXX @@ -13,7 +12,7 @@ namespace CXX { namespace Tree { - Void + void generate_parser_header (Context&); } } diff --git a/xsd/xsd/cxx/tree/parser-source.cxx b/xsd/xsd/cxx/tree/parser-source.cxx index 7291cb8..c93368c 100644 --- a/xsd/xsd/cxx/tree/parser-source.cxx +++ b/xsd/xsd/cxx/tree/parser-source.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parser-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/parser-source.hxx> @@ -23,7 +22,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) @@ -38,9 +37,11 @@ namespace CXX // confused if the name is 'type'. (see tests/schema/anonymous) // + char const* d (std >= cxx_version::cxx11 ? "std::move (d)" : "d"); + // URI. // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -56,22 +57,20 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "u, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; - os << "));" + os << "));" << endl << "h.throw_if_failed< ::xsd::cxx::tree::parsing< " << char_type << " > > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -86,7 +85,7 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "u, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; os << "));" @@ -94,14 +93,12 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -112,7 +109,7 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "u, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; os << "));" @@ -120,17 +117,15 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; // istream // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -143,7 +138,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -157,7 +152,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -167,7 +162,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << flags_type << " f," << endl @@ -181,7 +176,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << error_handler << "& h," << endl @@ -196,7 +191,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << xerces_ns << "::DOMErrorHandler& h," << endl @@ -210,7 +205,7 @@ namespace CXX // InputSource. // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -222,7 +217,7 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "i, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; os << "));" @@ -230,14 +225,12 @@ namespace CXX << "h.throw_if_failed< ::xsd::cxx::tree::parsing< " << char_type << " > > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -248,7 +241,7 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "i, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; os << "));" @@ -256,15 +249,13 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -275,7 +266,7 @@ namespace CXX << "::xsd::cxx::xml::dom::parse< " << char_type << " > (" << endl << "i, h, p, f"; - if (options.value<CLI::disable_multi_import> ()) + if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; os << "));" @@ -283,18 +274,16 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; // DOM. // - Boolean fund (false); + bool fund (false); { IsFundamentalType test (fund); test.dispatch (t); @@ -304,44 +293,36 @@ namespace CXX // If this element's type is anonymous then we don't need to do // anything. // - Boolean poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); // const DOMDocument& // - os << "::std::auto_ptr< " << type << " >" << endl - << name << " (const " << xerces_ns << "::DOMDocument& d," << endl + os << auto_ptr << "< " << type << " >" << endl + << name << " (const " << xerces_ns << "::DOMDocument& doc," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" << "{" << "if (f & " << flags_type << "::keep_dom)" << "{" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument > c (" << endl + "::DOMDocument > d (" << endl << "static_cast< " << xerces_ns << - "::DOMDocument* > (d.cloneNode (true)));" + "::DOMDocument* > (doc.cloneNode (true)));" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "c, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}" - << "const " << xerces_ns << "::DOMElement& e (*d.getDocumentElement ());" + << "const " << xerces_ns << "::DOMElement& e (*doc.getDocumentElement ());" << "const " << qname_type << " n (" << endl << "::xsd::cxx::xml::dom::name< " << char_type << " > (e));" << endl; if (poly) { - // aCC cannot handle an inline call to type_factory_map_instance. - // - os << "::xsd::cxx::tree::type_factory_map< " << char_type << - " >& tfm (" << endl - << "::xsd::cxx::tree::type_factory_map_instance< 0, " << - char_type << " > ());" - << endl - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "tfm.create (" << endl + os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::type_factory_map_instance< " << + poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl << strlit (e.namespace_().name ()) << "," << endl << "&::xsd::cxx::tree::factory_impl< " << type << " >," << endl @@ -349,7 +330,7 @@ namespace CXX << endl << "if (tmp.get () != 0)" << "{" - << "::std::auto_ptr< " << type << " > r (" << endl + << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl @@ -367,7 +348,7 @@ namespace CXX if (fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "new " << type << " (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type; @@ -382,7 +363,7 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type << " >::create (" << endl << "e, f, 0));"; @@ -400,11 +381,11 @@ namespace CXX << "}"; - // dom::auto_ptr<DOMDocument> + // dom::auto_ptr/unique_ptr<DOMDocument> // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument >& d," << endl + "::DOMDocument > d," << endl << flags_type << " f," << endl << "const " << properties_type << "&)" << "{" @@ -431,15 +412,9 @@ namespace CXX if (poly) { - // aCC cannot handle an inline call to type_factory_map_instance. - // - os << "::xsd::cxx::tree::type_factory_map< " << char_type << - " >& tfm (" << endl - << "::xsd::cxx::tree::type_factory_map_instance< 0, " << - char_type << " > ());" - << endl - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "tfm.create (" << endl + os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::type_factory_map_instance< " << + poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl << strlit (e.namespace_().name ()) << "," << endl << "&::xsd::cxx::tree::factory_impl< " << type << " >," << endl @@ -456,7 +431,7 @@ namespace CXX if (fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "new " << type << " (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type; @@ -471,7 +446,7 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type << " >::create (" << endl << "e, f, 0));"; @@ -481,7 +456,7 @@ namespace CXX if (poly) { os << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl @@ -517,10 +492,8 @@ namespace CXX }; } - Void - generate_parser_source (Context& ctx, - UnsignedLong first, - UnsignedLong last) + void + generate_parser_source (Context& ctx, size_t first, size_t last) { ctx.os << "#include <istream>" << endl << "#include <xsd/cxx/xml/sax/std-input-source.hxx>" << endl @@ -528,7 +501,7 @@ namespace CXX << endl; Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx, first, last); ElementFunction element (ctx); diff --git a/xsd/xsd/cxx/tree/parser-source.hxx b/xsd/xsd/cxx/tree/parser-source.hxx index 2a85571..a5cd597 100644 --- a/xsd/xsd/cxx/tree/parser-source.hxx +++ b/xsd/xsd/cxx/tree/parser-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parser-source.hxx -// 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 #ifndef CXX_TREE_PARSER_SOURCE_HXX @@ -12,8 +11,8 @@ namespace CXX { namespace Tree { - Void - generate_parser_source (Context&, UnsignedLong first, UnsignedLong last); + void + generate_parser_source (Context&, size_t first, size_t last); } } diff --git a/xsd/xsd/cxx/tree/polymorphism-processor.cxx b/xsd/xsd/cxx/tree/polymorphism-processor.cxx index 0763f0f..cbd2471 100644 --- a/xsd/xsd/cxx/tree/polymorphism-processor.cxx +++ b/xsd/xsd/cxx/tree/polymorphism-processor.cxx @@ -1,19 +1,16 @@ // file : xsde/cxx/tree/polymorphism-processor.cxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file +#include <iostream> + #include <cxx/tree/elements.hxx> #include <cxx/tree/polymorphism-processor.hxx> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/set.hxx> - -#include <iostream> - -using std::wcerr; +using namespace std; namespace CXX { @@ -21,64 +18,17 @@ namespace CXX { namespace { - struct TypeSet - { - template <typename I> - TypeSet (I begin, I end) - { - for (; begin != end; ++begin) - insert (*begin); - } - - Void - insert (String const& name) - { - Size p (name.rfind ('#')); - - if (p == String::npos) - unames_.insert (name); - else - qnames_.insert (name); - } - - Boolean - find (SemanticGraph::Type& t) - { - if (!unames_.empty ()) - { - if (unames_.find (t.name ()) != unames_.end ()) - return true; - } - - if (!qnames_.empty ()) - { - if (qnames_.find (t.scope ().name () + L"#" + t.name ()) != - qnames_.end ()) - return true; - } - - return false; - } - - private: - typedef Cult::Containers::Set<String> StringSet; - - StringSet unames_; - StringSet qnames_; - }; - - // // struct Type: Traversal::Type, Traversal::Complex { - Type (TypeSet& poly_types) + Type (TypeNameSet& poly_types) : poly_types_ (poly_types) { } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { SemanticGraph::Context& ctx (t.context ()); @@ -87,7 +37,7 @@ namespace CXX ctx.set ("polymorphic", poly_types_.find (t)); } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { SemanticGraph::Context& ctx (c.context ()); @@ -96,7 +46,7 @@ namespace CXX { // First check our base. // - Boolean pb (false); + bool pb (false); if (c.inherits_p ()) { SemanticGraph::Type& b (c.inherits ().base ()); @@ -104,7 +54,7 @@ namespace CXX if (!b.context ().count ("polymorphic")) dispatch (b); - pb = b.context ().get<Boolean> ("polymorphic"); + pb = b.context ().get<bool> ("polymorphic"); } ctx.set ("polymorphic", pb || poly_types_.find (c)); @@ -112,7 +62,7 @@ namespace CXX } private: - TypeSet& poly_types_; + TypeNameSet& poly_types_; }; struct FundType: Traversal::AnyType, @@ -171,13 +121,13 @@ namespace CXX Traversal::Fundamental::Entity, Traversal::Fundamental::Entities { - FundType (TypeSet& poly_types, Boolean& valid) + FundType (TypeNameSet& poly_types, bool& valid) : poly_types_ (poly_types), valid_ (valid) { } - Void - check (SemanticGraph::Type& t, Boolean fund) + void + check (SemanticGraph::Type& t, bool fund) { SemanticGraph::Context& ctx (t.context ()); @@ -201,13 +151,13 @@ namespace CXX // anyType & anySimpleType. // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { check (t, false); @@ -215,7 +165,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { check (t, true); @@ -223,79 +173,79 @@ namespace CXX // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { check (t, true); @@ -303,19 +253,19 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { check (t, true); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { check (t, true); @@ -323,49 +273,49 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { check (t, false); @@ -374,7 +324,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { check (t, false); @@ -383,19 +333,19 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { check (t, false); @@ -403,7 +353,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { check (t, false); @@ -411,13 +361,13 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { check (t, false); @@ -426,55 +376,55 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { check (t, false); @@ -482,27 +432,27 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { check (t, false); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { check (t, false); } private: - TypeSet& poly_types_; - Boolean& valid_; + TypeNameSet& poly_types_; + bool& valid_; }; struct GlobalElement: Traversal::Element { - GlobalElement (TypeSet& poly_types, - Boolean& valid, + GlobalElement (TypeNameSet& poly_types, + bool& valid, const WarningSet& disabled_warnings) : poly_types_ (poly_types), valid_ (valid), warning_ (true) { @@ -511,7 +461,7 @@ namespace CXX warning_ = false; } - virtual Void + virtual void traverse (Type& e) { using SemanticGraph::Schema; @@ -528,13 +478,13 @@ namespace CXX // We may need to override the previous value. // - if (ctx.count ("polymorphic") && ctx.get<Boolean> ("polymorphic")) + if (ctx.count ("polymorphic") && ctx.get<bool> ("polymorphic")) return; // Built-in types that are mapped to fundamental types cannot // be declared polymorphic. // - Boolean fund (false); + bool fund (false); IsFundamentalType test (fund); test.dispatch (rt); @@ -585,7 +535,7 @@ namespace CXX private: // Return true if root sources s. // - Boolean + bool sources_p (SemanticGraph::Schema& root, SemanticGraph::Schema& s) { using SemanticGraph::Schema; @@ -605,9 +555,9 @@ namespace CXX } private: - TypeSet& poly_types_; - Boolean& valid_; - Boolean warning_; + TypeNameSet& poly_types_; + bool& valid_; + bool warning_; }; // Go into sourced/included/imported schemas while making sure @@ -617,12 +567,12 @@ namespace CXX Traversal::Includes, Traversal::Imports { - Uses (Char const* seen_key) + Uses (char const* seen_key) : seen_key_ (seen_key) { } - virtual Void + virtual void traverse (SemanticGraph::Sources& sr) { SemanticGraph::Schema& s (sr.schema ()); @@ -634,7 +584,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Includes& i) { SemanticGraph::Schema& s (i.schema ()); @@ -646,7 +596,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Imports& i) { SemanticGraph::Schema& s (i.schema ()); @@ -659,25 +609,25 @@ namespace CXX } private: - Char const* seen_key_; + char const* seen_key_; }; - Char const* pass_one_key = "cxx-tree-polymorphism-processor-seen-one"; - Char const* pass_two_key = "cxx-tree-polymorphism-processor-seen-two"; + char const* pass_one_key = "cxx-tree-polymorphism-processor-seen-one"; + char const* pass_two_key = "cxx-tree-polymorphism-processor-seen-two"; - Boolean - process_impl (CLI::Options const& ops, + bool + process_impl (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const&, const WarningSet& disabled_warnings) { - Boolean valid (true); + bool valid (true); // Prepare a set of polymorphic types. // - TypeSet poly_types (ops.value<CLI::polymorphic_type> ().begin (), - ops.value<CLI::polymorphic_type> ().end ()); + TypeNameSet poly_types (ops.polymorphic_type ().begin (), + ops.polymorphic_type ().end ()); // Root schema in the file-per-type mode is just a bunch // of includes without a namespace. @@ -779,8 +729,8 @@ namespace CXX } } - Boolean PolymorphismProcessor:: - process (CLI::Options const& ops, + bool PolymorphismProcessor:: + process (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& file, const WarningSet& disabled_warnings) diff --git a/xsd/xsd/cxx/tree/polymorphism-processor.hxx b/xsd/xsd/cxx/tree/polymorphism-processor.hxx index 3fbeca8..7338790 100644 --- a/xsd/xsd/cxx/tree/polymorphism-processor.hxx +++ b/xsd/xsd/cxx/tree/polymorphism-processor.hxx @@ -1,30 +1,26 @@ // file : xsde/cxx/tree/polymorphism-processor.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2006-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef CXX_TREE_POLYMORPHISM_PROCESSOR_HXX #define CXX_TREE_POLYMORPHISM_PROCESSOR_HXX -#include <cult/types.hxx> - #include <xsd-frontend/semantic-graph.hxx> -#include <cxx/tree/cli.hxx> - #include <xsd.hxx> +#include <types.hxx> + +#include <cxx/tree/options.hxx> namespace CXX { namespace Tree { - using namespace Cult::Types; - class PolymorphismProcessor { public: - Boolean - process (CLI::Options const& options, + bool + process (options const&, XSDFrontend::SemanticGraph::Schema&, XSDFrontend::SemanticGraph::Path const& file, const WarningSet& disabled_warnings); diff --git a/xsd/xsd/cxx/tree/serialization-header.cxx b/xsd/xsd/cxx/tree/serialization-header.cxx index d024a38..67da857 100644 --- a/xsd/xsd/cxx/tree/serialization-header.cxx +++ b/xsd/xsd/cxx/tree/serialization-header.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization-header.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/serialization-header.hxx> @@ -21,7 +20,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -67,7 +66,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -112,7 +111,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -156,7 +155,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -175,7 +174,7 @@ namespace CXX "const " << name << "&);" << endl; - Boolean simple (true); + bool simple (true); { IsSimpleType t (simple); t.dispatch (c); @@ -211,7 +210,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (doc_root_p (e)) @@ -237,7 +236,7 @@ namespace CXX } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) @@ -533,10 +532,10 @@ namespace CXX } - Void + void generate_serialization_header (Context& ctx) { - Boolean elemen_type (ctx.options.value<CLI::generate_element_type> ()); + bool elemen_type (ctx.options.generate_element_type ()); if (!elemen_type) ctx.os << "#include <iosfwd>" << endl @@ -550,7 +549,7 @@ namespace CXX Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); diff --git a/xsd/xsd/cxx/tree/serialization-header.hxx b/xsd/xsd/cxx/tree/serialization-header.hxx index 86c6b6a..979bb2e 100644 --- a/xsd/xsd/cxx/tree/serialization-header.hxx +++ b/xsd/xsd/cxx/tree/serialization-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization-header.hxx -// 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 #ifndef CXX_TREE_SERIALIZATION_HEADER_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_serialization_header (Context&); } } diff --git a/xsd/xsd/cxx/tree/serialization-source.cxx b/xsd/xsd/cxx/tree/serialization-source.cxx index 40ae031..559a3cf 100644 --- a/xsd/xsd/cxx/tree/serialization-source.cxx +++ b/xsd/xsd/cxx/tree/serialization-source.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization-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/serialization-source.hxx> @@ -42,7 +41,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -91,7 +90,9 @@ namespace CXX << "l << static_cast< const " << base << "& > (i);" << "}"; - // Register with type factory map. + // Register with type factory map. If this type is anonymous + // but substitutes, then it will be registered as part of the + // substitution registration. // if (polymorphic && polymorphic_p (l) && !anonymous_p (l)) { @@ -100,8 +101,8 @@ namespace CXX String const& name (ename (l)); os << "static" << endl - << "const ::xsd::cxx::tree::type_serializer_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_serializer_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_serializer_init (" << endl << strlit (l.name ()) << "," << endl << strlit (xml_ns_name (l)) << ");" @@ -131,7 +132,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -171,7 +172,9 @@ namespace CXX << "l << static_cast< const " << base << "& > (i);" << "}"; - // Register with type factory map. + // Register with type factory map. If this type is anonymous + // but substitutes, then it will be registered as part of the + // substitution registration. // if (polymorphic && polymorphic_p (u) && !anonymous_p (u)) { @@ -180,8 +183,8 @@ namespace CXX String const& name (ename (u)); os << "static" << endl - << "const ::xsd::cxx::tree::type_serializer_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_serializer_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_serializer_init (" << endl << strlit (u.name ()) << "," << endl << strlit (xml_ns_name (u)) << ");" @@ -200,7 +203,7 @@ namespace CXX inherits_base_ >> base_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -253,7 +256,9 @@ namespace CXX << "}"; - // Register with type factory map. + // Register with type factory map. If this type is anonymous + // but substitutes, then it will be registered as part of the + // substitution registration. // if (polymorphic && polymorphic_p (e) && !anonymous_p (e)) { @@ -262,8 +267,8 @@ namespace CXX String const& name (ename (e)); os << "static" << endl - << "const ::xsd::cxx::tree::type_serializer_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_serializer_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_serializer_init (" << endl << strlit (e.name ()) << "," << endl << strlit (xml_ns_name (e)) << ");" @@ -284,12 +289,17 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) return; + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (e.scope ())); + + bool ordered (ordered_p (c)); + String const& aname (eaname (e)); String ns (e.qualified_p () ? e.namespace_ ().name () : ""); String type (scope + L"::" + etype (e)); @@ -301,20 +311,23 @@ namespace CXX // dynamically-type with xsi:type. // SemanticGraph::Type& t (e.type ()); - Boolean poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); os << "// " << comment (e.name ()) << endl << "//" << endl; - // aCC cannot handle an inline call to type_serializer_map_instance. - // + if (ordered) + os << "case " << scope << "::" << + e.context ().get<String> ("ordered-id-name") << ":" + << "{"; + if (poly) { - os << "{" + os << (ordered ? "" : "{") << "::xsd::cxx::tree::type_serializer_map< " << char_type << " >& tsm (" << endl - << "::xsd::cxx::tree::type_serializer_map_instance< 0, " << - char_type << " > ());" + << "::xsd::cxx::tree::type_serializer_map_instance< " << + poly_plate << ", " << char_type << " > ());" << endl; } @@ -322,15 +335,22 @@ namespace CXX { // sequence // - os << "for (" << scope << "::" << econst_iterator (e) << endl - << "b (i." << aname << " ().begin ()), " << - "n (i." << aname << " ().end ());" << endl - << "b != n; ++b)" - << "{"; + if (ordered) + os << "const " << type << "& x (i." << aname << + " ()[b->index]);" + << endl; + else + os << "for (" << scope << "::" << econst_iterator (e) << endl + << "b (i." << aname << " ().begin ()), " << + "n (i." << aname << " ().end ());" << endl + << "b != n; ++b)" + << "{"; + + char const* x (ordered ? "x" : "*b"); if (poly) { - os << "if (typeid (" << type << ") == typeid (*b))" + os << "if (typeid (" << type << ") == typeid (" << x << "))" << "{" << xerces_ns << "::DOMElement& s (" << endl << "::xsd::cxx::xml::dom::create_element (" << endl @@ -338,14 +358,14 @@ namespace CXX << (ns ? strlit (ns) + L",\n" : L"") << "e));" << endl - << "s << *b;" + << "s << " << x << ";" << "}" << "else" << endl << "tsm.serialize (" << endl << strlit (e.name ()) << "," << endl << strlit (ns) << "," << endl << (e.global_p () ? "true" : "false") << ", " << - (e.qualified_p () ? "true" : "false") << ", e, *b);"; + (e.qualified_p () ? "true" : "false") << ", e, " << x << ");"; } else { @@ -360,30 +380,29 @@ namespace CXX { case st_other: { - os << "s << *b;"; + os << "s << " << x << ";"; break; } case st_double: { - os << "s << " << as_double_type << " (*b);"; + os << "s << " << as_double_type << " (" << x << ");"; break; } case st_decimal: { - os << "s << " << as_decimal_type << " (*b);"; + os << "s << " << as_decimal_type << " (" << x << ");"; break; } } } - - os << "}"; } else if (min (e) == 0) { // optional // - os << "if (i." << aname << " ())" - << "{"; + if (!ordered) + os << "if (i." << aname << " ())" + << "{"; if (poly) { @@ -433,8 +452,6 @@ namespace CXX } } } - - os << "}"; } else { @@ -462,8 +479,10 @@ namespace CXX } else { - os << "{" - << xerces_ns << "::DOMElement& s (" << endl + if (!ordered) + os << "{"; + + os << xerces_ns << "::DOMElement& s (" << endl << "::xsd::cxx::xml::dom::create_element (" << endl << strlit (e.name ()) << "," << endl << (ns ? strlit (ns) + L",\n" : L"") @@ -488,13 +507,26 @@ namespace CXX break; } } - - os << "}"; } } - if (poly) + if (ordered) + { + // See comment for bool text (false); below. + // + if (mixed_p (c) && c.context ().get<size_t> ("ordered-start") != 1) + os << "text = true;"; + + os << "continue;" + << "}"; + } + else + { os << "}"; + + if (poly && (max (e) != 1 || min (e) == 0)) + os << "}"; // There is no extra block for poly one. + } } private: @@ -508,51 +540,80 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (a.scope ())); + + bool ordered (ordered_p (c)); + String const& aname (eaname (a)); os << "// " << ename (a) << endl << "//" << endl; + if (ordered) + os << "case " << scope << "::" << + a.context ().get<String> ("ordered-id-name") << ":"; + if (max (a) != 1) { // sequence // - os << "for (" << scope << "::" << econst_iterator (a) << endl - << "b (i." << aname << " ().begin ()), " << - "n (i." << aname << " ().end ());" << endl - << "b != n; ++b)" - << "{" + if (!ordered) + os << "for (" << scope << "::" << econst_iterator (a) << endl + << "b (i." << aname << " ().begin ()), " << + "n (i." << aname << " ().end ());" << endl + << "b != n; ++b)"; + + os << "{" << "e.appendChild (" << endl << "e.getOwnerDocument ()->importNode (" << endl << "const_cast< " << xerces_ns << - "::DOMElement* > (&(*b)), true));" - << "}"; + "::DOMElement* > (&(" << + (ordered ? (L"i." + aname + L" ()[b->index]") : L"*b") << + ")), true));"; } else if (min (a) == 0) { // optional // - os << "if (i." << aname << " ())" - << "{" + if (!ordered) + os << "if (i." << aname << " ())"; + + os << "{" << "e.appendChild (" << endl << "e.getOwnerDocument ()->importNode (" << endl << "const_cast< " << xerces_ns << "::DOMElement* > (&(*i." << - aname << " ())), true));" - << "}"; + aname << " ())), true));"; } else { // one // + if (ordered) + os << "{"; + os << "e.appendChild (" << endl << "e.getOwnerDocument ()->importNode (" << endl << "const_cast< " << xerces_ns << "::DOMElement* > (&(i." << aname << " ())), true));" << endl; } + + if (ordered) + { + // See comment for bool text (false); below. + // + if (mixed_p (c) && c.context ().get<size_t> ("ordered-start") != 1) + os << "text = true;"; + + os << "continue;"; + } + + if (ordered || max (a) != 1 || min (a) == 0) + os << "}"; } private: @@ -566,7 +627,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& aname (eaname (a)); @@ -611,8 +672,7 @@ namespace CXX { // Make sure we serialize required fixed attributes. // - if (a.optional_p () && - options.value<CLI::omit_default_attributes> ()) + if (a.optional_p () && options.omit_default_attributes ()) { os << "if (i." << aname << " () != " << scope << "::" << edefault_value (a) << " ())"; @@ -660,7 +720,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& aname (eaname (a)); @@ -697,9 +757,11 @@ namespace CXX inherits_ >> base_; } - virtual Void + virtual void traverse (Type& c) { + SemanticGraph::Context& ctx (c.context ()); + String name (ename (c)); // If renamed name is empty then we do not need to generate @@ -729,7 +791,7 @@ namespace CXX // Serialize anyAttribute content first so that is gets // overriden by schema-defined attributes. // - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) { AnyAttribute any_attribute (*this, name); Traversal::Names names (any_attribute); @@ -738,24 +800,109 @@ namespace CXX } { + bool o (ordered_p (c)); + size_t start, count; + + if (o) + { + start = ctx.get<size_t> ("ordered-start"); + count = ctx.get<size_t> ("ordered-count"); + + if (start != count) + { + String const& ci (ctx.get<String> ("order-const-iterator")); + String const& an (ctx.get<String> ("order-aname")); + + // If we have mixed content and a base, then we have to + // skip the text content until we serialize one of "our" + // elements. + // + if (mixed_p (c) && start != 1) + os << "bool text (false);" + << endl; + + os << "for (" << name << "::" << ci << endl + << "b (i." << an << " ().begin ()), n (i." << an << + " ().end ());" << endl + << "b != n; ++b)" + << "{" + << "switch (b->id)" + << "{"; + } + } + Traversal::Names names; Any any (*this, name); Element element (*this, name); - Attribute attribute (*this, name); names >> element; - names >> attribute; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names >> any; Complex::names (c, names); + + if (o) + { + if (start != count) + { + if (mixed_p (c)) + { + //@@ propagate mixed-ordered-id to derived + + os << "// text_content" << endl + << "//" << endl + << "case " << name << "::" << + ctx.get<String> ("mixed-ordered-id-name") << ":" + << "{"; + + // See the comment above. + // + if (start != 1) + os << "if (text)" << endl; + + os << "e.appendChild (" << endl + << "e.getOwnerDocument ()->createTextNode (" << endl + << "::xsd::cxx::xml::string (" << endl + << "i." << ctx.get<String> ("mixed-aname") << + " ()[b->index].c_str ()).c_str ()));"; + + // os << "e << i." << ctx.get<String> ("mixed-aname") << + // " ()[b->index];"; + + os << "continue;" + << "}"; + } + + // Ignore content before our id range and stop serializing + // if we see anything past. This handles inheritance. + // + os << "default:" + << "{"; + + if (start != 1) + os << "if (b->id < " << start << "UL)" << endl + << "continue;"; + + os << "break;" // Stop (see break below). + << "}"; + + os << "}" // switch + << "break;" // Unknown element past our elements. + << "}"; // for + } + } } - os << "}"; + { + Attribute attribute (*this, name); + Traversal::Names names (attribute); + Complex::names (c, names); + } + os << "}"; - Boolean simple (true); + bool simple (true); { IsSimpleType t (simple); t.dispatch (c); @@ -763,7 +910,7 @@ namespace CXX if (simple) { - Boolean hb (c.inherits_p ()); + bool hb (c.inherits_p ()); // operator<< (xercesc::DOMAttr) // @@ -805,7 +952,9 @@ namespace CXX os << "}"; } - // Register with type factory map. + // Register with type factory map. If this type is anonymous + // but substitutes, then it will be registered as part of the + // substitution registration. // if (polymorphic && polymorphic_p (c) && !anonymous_p (c)) { @@ -814,8 +963,8 @@ namespace CXX String const& name (ename (c)); os << "static" << endl - << "const ::xsd::cxx::tree::type_serializer_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_serializer_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_serializer_init (" << endl << strlit (c.name ()) << "," << endl << strlit (xml_ns_name (c)) << ");" @@ -842,7 +991,7 @@ namespace CXX belongs_ >> type_name_; } - virtual Void + virtual void traverse (Type& e) { if (polymorphic && e.substitutes_p ()) @@ -852,8 +1001,8 @@ namespace CXX String const& name (ename (e)); os << "static" << endl - << "const ::xsd::cxx::tree::element_serializer_initializer< 0, " << - char_type << ", "; + << "const ::xsd::cxx::tree::element_serializer_initializer< " << + poly_plate << ", " << char_type << ", "; belongs (e, belongs_); @@ -881,11 +1030,11 @@ namespace CXX ElementType (Context& c) : GlobalElementBase (c), Context (c), - element_map_ (c.options.value<CLI::generate_element_map> ()) + element_map_ (c.options.generate_element_map ()) { } - virtual Void + virtual void traverse (Type& e) { if (doc_root_p (e)) @@ -921,7 +1070,7 @@ namespace CXX } private: - Boolean element_map_; + bool element_map_; }; struct ElementFunction: Traversal::Element, @@ -933,7 +1082,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) @@ -954,7 +1103,7 @@ namespace CXX // If this element's type is anonymous then we don't need to do // anything. // - Boolean poly (polymorphic && + bool poly (polymorphic && polymorphic_p (type) && !anonymous_p (type)); @@ -1137,18 +1286,11 @@ namespace CXX if (poly) { - // aCC cannot handle an inline call to - // type_serializer_map_instance. - // os << "}" << "else" << "{" - << "::xsd::cxx::tree::type_serializer_map< " << char_type - << " >& tsm (" << endl - << "::xsd::cxx::tree::type_serializer_map_instance< 0, " << - char_type << " > ());" - << endl - << "tsm.serialize (" << endl + << "::xsd::cxx::tree::type_serializer_map_instance< " << + poly_plate << ", " << char_type << " > ().serialize (" << endl << strlit (e.name ()) << "," << endl << strlit (e.namespace_().name ()) << "," << endl << "e, n, s);" @@ -1168,37 +1310,23 @@ namespace CXX if (poly) { - // aCC cannot handle an inline call to - // type_serializer_map_instance as well as the direct - // auto_ptr assignment. - // os << dom_auto_ptr << "< " << xerces_ns << "::DOMDocument > d;" << endl << "if (typeid (" << type_name (e) << ") == typeid (s))" << "{" - << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument > r (" << endl - << "::xsd::cxx::xml::dom::serialize< " << + << "d = ::xsd::cxx::xml::dom::serialize< " << char_type << " > (" << endl << strlit (e.name ()) << "," << endl << strlit (ns) << "," << endl - << "m, f));" - << "d = r;" + << "m, f);" << "}" << "else" << "{" - << "::xsd::cxx::tree::type_serializer_map< " << char_type - << " >& tsm (" << endl - << "::xsd::cxx::tree::type_serializer_map_instance< 0, " << - char_type << " > ());" - << endl - << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument > r (" << endl - << "tsm.serialize (" << endl + << "d = ::xsd::cxx::tree::type_serializer_map_instance< " << + poly_plate << ", " << char_type << " > ().serialize (" << endl << strlit (e.name ()) << "," << endl << strlit (e.namespace_().name ()) << "," << endl - << "m, s, f));" - << "d = r;" + << "m, s, f);" << "}"; } else @@ -1233,12 +1361,10 @@ namespace CXX }; } - Void - generate_serialization_source (Context& ctx, - UnsignedLong first, - UnsignedLong last) + void + generate_serialization_source (Context& ctx, size_t first, size_t last) { - Boolean elemen_type (ctx.options.value<CLI::generate_element_type> ()); + bool elemen_type (ctx.options.generate_element_type ()); if (!elemen_type) ctx.os << "#include <ostream>" << endl @@ -1252,8 +1378,8 @@ namespace CXX ctx.os << "#include <xsd/cxx/tree/type-serializer-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) { @@ -1269,19 +1395,23 @@ namespace CXX if (export_maps) ctx.os << "template struct __declspec (dllexport) " << - "type_serializer_plate< 0, " << ctx.char_type << " >;"; + "type_serializer_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (import_maps) ctx.os << "template struct __declspec (dllimport) " << - "type_serializer_plate< 0, " << ctx.char_type << " >;"; + "type_serializer_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#elif defined(__GNUC__) && __GNUC__ >= 4" << endl << "template struct __attribute__ ((visibility(\"default\"))) " << - "type_serializer_plate< 0, " << ctx.char_type << " >;"; + "type_serializer_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl << "template struct XSD_MAP_VISIBILITY " << - "type_serializer_plate< 0, " << ctx.char_type << " >;"; + "type_serializer_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#endif" << endl << "}" // tree @@ -1294,15 +1424,15 @@ namespace CXX ctx.os << "namespace _xsd" << "{" << "static" << endl - << "const ::xsd::cxx::tree::type_serializer_plate< 0, " << - ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::type_serializer_plate< " << + ctx.poly_plate << ", " << ctx.char_type << " >" << endl << "type_serializer_plate_init;" << "}"; } Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx, first, last); diff --git a/xsd/xsd/cxx/tree/serialization-source.hxx b/xsd/xsd/cxx/tree/serialization-source.hxx index 322949a..1a74126 100644 --- a/xsd/xsd/cxx/tree/serialization-source.hxx +++ b/xsd/xsd/cxx/tree/serialization-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization-source.hxx -// 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 #ifndef CXX_TREE_SERIALIZATION_SOURCE_HXX @@ -12,10 +11,8 @@ namespace CXX { namespace Tree { - Void - generate_serialization_source (Context&, - UnsignedLong first, - UnsignedLong last); + void + generate_serialization_source (Context&, size_t first, size_t last); } } 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); diff --git a/xsd/xsd/cxx/tree/stream-extraction-source.hxx b/xsd/xsd/cxx/tree/stream-extraction-source.hxx index 23ab17c..9104281 100644 --- a/xsd/xsd/cxx/tree/stream-extraction-source.hxx +++ b/xsd/xsd/cxx/tree/stream-extraction-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-extraction-source.hxx -// 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 #ifndef CXX_TREE_EXTRACTION_SOURCE_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_stream_extraction_source (Context&); } } diff --git a/xsd/xsd/cxx/tree/stream-header.cxx b/xsd/xsd/cxx/tree/stream-header.cxx index 02e2651..9ba9b3b 100644 --- a/xsd/xsd/cxx/tree/stream-header.cxx +++ b/xsd/xsd/cxx/tree/stream-header.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-header.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-header.hxx> @@ -21,7 +20,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -48,7 +47,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -75,7 +74,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -86,13 +85,13 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } - Boolean enum_based (false); + bool enum_based (false); if (string_based) { SemanticGraph::Enumeration* be (0); @@ -129,7 +128,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -149,7 +148,7 @@ namespace CXX }; } - Void + void generate_stream_header (Context& ctx) { String c (ctx.char_type); @@ -159,7 +158,7 @@ namespace CXX Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); diff --git a/xsd/xsd/cxx/tree/stream-header.hxx b/xsd/xsd/cxx/tree/stream-header.hxx index 246a06e..36eea87 100644 --- a/xsd/xsd/cxx/tree/stream-header.hxx +++ b/xsd/xsd/cxx/tree/stream-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-header.hxx -// 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 #ifndef CXX_TREE_STREAM_HEADER_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_stream_header (Context&); } } diff --git a/xsd/xsd/cxx/tree/stream-insertion-header.cxx b/xsd/xsd/cxx/tree/stream-insertion-header.cxx index 1669fdd..e9ee438 100644 --- a/xsd/xsd/cxx/tree/stream-insertion-header.cxx +++ b/xsd/xsd/cxx/tree/stream-insertion-header.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-header.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-header.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)); @@ -34,8 +31,9 @@ namespace CXX if (renamed_type (l, name) && !name) return; - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type (ostream_type + L"< " + String (*i) + L" >"); @@ -56,7 +54,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -67,8 +65,9 @@ namespace CXX if (renamed_type (u, name) && !name) return; - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type (ostream_type + L"< " + String (*i) + L" >"); @@ -89,7 +88,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -100,8 +99,9 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type (ostream_type + L"< " + String (*i) + L" >"); @@ -121,7 +121,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -132,8 +132,9 @@ namespace CXX if (renamed_type (c, name) && !name) return; - Streams const& st (options.value<CLI::generate_insertion> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_insertion ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { String stream_type (ostream_type + L"< " + String (*i) + L" >"); @@ -147,14 +148,14 @@ namespace CXX }; } - Void + void generate_stream_insertion_header (Context& ctx) { String c (ctx.char_type); Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); diff --git a/xsd/xsd/cxx/tree/stream-insertion-header.hxx b/xsd/xsd/cxx/tree/stream-insertion-header.hxx index ca93713..31b6328 100644 --- a/xsd/xsd/cxx/tree/stream-insertion-header.hxx +++ b/xsd/xsd/cxx/tree/stream-insertion-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-header.hxx -// 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 #ifndef CXX_TREE_STREAM_INSERTION_HEADER_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_stream_insertion_header (Context&); } } 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); diff --git a/xsd/xsd/cxx/tree/stream-insertion-source.hxx b/xsd/xsd/cxx/tree/stream-insertion-source.hxx index b270912..d2d5534 100644 --- a/xsd/xsd/cxx/tree/stream-insertion-source.hxx +++ b/xsd/xsd/cxx/tree/stream-insertion-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-source.hxx -// 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 #ifndef CXX_TREE_INSERTION_SOURCE_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_stream_insertion_source (Context&); } } diff --git a/xsd/xsd/cxx/tree/stream-source.cxx b/xsd/xsd/cxx/tree/stream-source.cxx index e8a7fc4..935ad40 100644 --- a/xsd/xsd/cxx/tree/stream-source.cxx +++ b/xsd/xsd/cxx/tree/stream-source.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-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-source.hxx> @@ -21,7 +20,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -52,15 +51,17 @@ namespace CXX // Register with ostream 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. // String const& name (ename (l)); os << "static" << endl - << "const ::xsd::cxx::tree::std_ostream_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::std_ostream_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_std_ostream_init;" << endl; } @@ -87,7 +88,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -107,15 +108,17 @@ namespace CXX // Register with ostream 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. // String const& name (ename (u)); os << "static" << endl - << "const ::xsd::cxx::tree::std_ostream_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::std_ostream_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_std_ostream_init;" << endl; } @@ -131,7 +134,7 @@ namespace CXX inherits_base_ >> base_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -142,13 +145,13 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } - Boolean enum_based (false); + bool enum_based (false); if (string_based) { SemanticGraph::Enumeration* be (0); @@ -185,15 +188,17 @@ namespace CXX // Register with ostream 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. // String const& name (ename (e)); os << "static" << endl - << "const ::xsd::cxx::tree::std_ostream_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::std_ostream_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_std_ostream_init;" << endl; } @@ -211,7 +216,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) @@ -226,17 +231,15 @@ namespace CXX // dynamically-type with xsi:type. // SemanticGraph::Type& t (e.type ()); - Boolean poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); - // aCC cannot handle an inline call to std_ostream_map_instance. - // if (poly) { os << "{" << "::xsd::cxx::tree::std_ostream_map< " << char_type << " >& om (" << endl - << "::xsd::cxx::tree::std_ostream_map_instance< 0, " << - char_type << " > ());" + << "::xsd::cxx::tree::std_ostream_map_instance< " << + poly_plate << ", " << char_type << " > ());" << endl; } @@ -304,7 +307,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& aname (eaname (a)); @@ -334,7 +337,7 @@ namespace CXX inherits_ >> base_; } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -347,7 +350,7 @@ namespace CXX // // - Boolean has_body (has<Traversal::Member> (c) || c.inherits_p ()); + bool has_body (has<Traversal::Member> (c) || c.inherits_p ()); os << std_ostream_type << "&" << endl << "operator<< (" << std_ostream_type << "& o, " << @@ -380,15 +383,17 @@ namespace CXX // Register with ostream 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. // String const& name (ename (c)); os << "static" << endl - << "const ::xsd::cxx::tree::std_ostream_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::std_ostream_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_std_ostream_init;" << endl; } @@ -400,10 +405,8 @@ namespace CXX }; } - Void - generate_stream_source (Context& ctx, - UnsignedLong first, - UnsignedLong last) + void + generate_stream_source (Context& ctx, size_t first, size_t last) { String c (ctx.char_type); @@ -415,8 +418,8 @@ namespace CXX ctx.os << "#include <xsd/cxx/tree/std-ostream-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) { @@ -432,19 +435,23 @@ namespace CXX if (export_maps) ctx.os << "template struct __declspec (dllexport) " << - "std_ostream_plate< 0, " << ctx.char_type << " >;"; + "std_ostream_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (import_maps) ctx.os << "template struct __declspec (dllimport) " << - "std_ostream_plate< 0, " << ctx.char_type << " >;"; + "std_ostream_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#elif defined(__GNUC__) && __GNUC__ >= 4" << endl << "template struct __attribute__ ((visibility(\"default\"))) " << - "std_ostream_plate< 0, " << ctx.char_type << " >;"; + "std_ostream_plate< " << ctx.poly_plate << ", " << ctx.char_type << + " >;"; ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl << "template struct XSD_MAP_VISIBILITY " << - "std_ostream_plate< 0, " << ctx.char_type << " >;"; + "std_ostream_plate< " << ctx.poly_plate << ", " << ctx.char_type << + " >;"; ctx.os << "#endif" << endl << "}" // tree @@ -457,15 +464,15 @@ namespace CXX ctx.os << "namespace _xsd" << "{" << "static" << endl - << "const ::xsd::cxx::tree::std_ostream_plate< 0, " << - ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::std_ostream_plate< " << + ctx.poly_plate << ", " << ctx.char_type << " >" << endl << "std_ostream_plate_init;" << "}"; } Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx, first, last); diff --git a/xsd/xsd/cxx/tree/stream-source.hxx b/xsd/xsd/cxx/tree/stream-source.hxx index 13e8f37..f13a23e 100644 --- a/xsd/xsd/cxx/tree/stream-source.hxx +++ b/xsd/xsd/cxx/tree/stream-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-source.hxx -// 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 #ifndef CXX_TREE_STREAM_SOURCE_HXX @@ -12,10 +11,8 @@ namespace CXX { namespace Tree { - Void - generate_stream_source (Context&, - UnsignedLong first, - UnsignedLong last); + void + generate_stream_source (Context&, size_t first, size_t last); } } diff --git a/xsd/xsd/cxx/tree/tree-forward.cxx b/xsd/xsd/cxx/tree/tree-forward.cxx index 214cc75..5afae3c 100644 --- a/xsd/xsd/cxx/tree/tree-forward.cxx +++ b/xsd/xsd/cxx/tree/tree-forward.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-forward.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/tree-forward.hxx> @@ -22,7 +21,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String const& name (ename (l)); @@ -52,7 +51,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String const& name (ename (u)); @@ -82,7 +81,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { String const& name (ename (e)); @@ -112,7 +111,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { String const& name (ename (c)); @@ -136,16 +135,16 @@ namespace CXX }; } - Void + void generate_forward (Context& ctx) { - NarrowString xml_schema (ctx.options.value<CLI::extern_xml_schema> ()); + NarrowString xml_schema (ctx.options.extern_xml_schema ()); // Inlcude or Emit fundamental types. // 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; @@ -164,21 +163,21 @@ namespace CXX << "#include <xsd/cxx/tree/types.hxx>" << endl << endl; - if (!ctx.options.value<CLI::suppress_parsing> () || - ctx.options.value<CLI::generate_serialization> ()) + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/error-handler.hxx>" << endl << endl; } - if (!ctx.options.value<CLI::suppress_parsing> () || - ctx.options.value<CLI::generate_serialization> ()) + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/dom/auto-ptr.hxx>" << endl << endl; } - Boolean element_map (ctx.options.value<CLI::generate_element_map> ()); + bool element_map (ctx.options.generate_element_map ()); if (element_map) ctx.os << "#include <xsd/cxx/tree/element-map.hxx>" << endl @@ -188,7 +187,7 @@ namespace CXX // later in the individual generators for each feature because // those headers provide implementation for the fundamental types. // - if (!ctx.options.value<CLI::suppress_parsing> ()) + if (!ctx.options.suppress_parsing ()) { ctx.os << "#include <xsd/cxx/tree/parsing.hxx>" << endl; @@ -210,7 +209,7 @@ namespace CXX ctx.os << endl; } - if (ctx.options.value<CLI::generate_serialization> ()) + if (ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/dom/serialization-header.hxx>" << endl << "#include <xsd/cxx/tree/serialization.hxx>" << endl; @@ -233,18 +232,17 @@ namespace CXX ctx.os << endl; } - if (ctx.options.value<CLI::generate_ostream> ()) + if (ctx.options.generate_ostream ()) { ctx.os << "#include <xsd/cxx/tree/std-ostream-operators.hxx>" << endl << endl; } - typedef Containers::Vector<NarrowString> Streams; - - Streams const& ist (ctx.options.value<CLI::generate_insertion> ()); + NarrowStrings const& ist (ctx.options.generate_insertion ()); if (!ist.empty ()) { - for (Streams::ConstIterator i (ist.begin ()); i != ist.end (); ++i) + for (NarrowStrings::const_iterator i (ist.begin ()); i != ist.end (); + ++i) { if (*i == "ACE_OutputCDR") ctx.os << "#include <xsd/cxx/tree/ace-cdr-stream-insertion.hxx>" @@ -258,10 +256,11 @@ namespace CXX << endl; } - Streams const& est (ctx.options.value<CLI::generate_extraction> ()); + NarrowStrings const& est (ctx.options.generate_extraction ()); if (!est.empty ()) { - for (Streams::ConstIterator i (est.begin ()); i != est.end (); ++i) + for (NarrowStrings::const_iterator i (est.begin ()); i != est.end (); + ++i) { if (*i == "ACE_InputCDR") ctx.os << "#include <xsd/cxx/tree/ace-cdr-stream-extraction.hxx>" @@ -288,7 +287,7 @@ namespace CXX // First emit header includes. // - if (ctx.options.value<CLI::generate_forward> ()) + if (ctx.options.generate_forward ()) { Traversal::Schema schema; Includes includes (ctx, Includes::forward); @@ -302,7 +301,7 @@ namespace CXX << "//" << endl; Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx); diff --git a/xsd/xsd/cxx/tree/tree-forward.hxx b/xsd/xsd/cxx/tree/tree-forward.hxx index efe0e02..5b08a10 100644 --- a/xsd/xsd/cxx/tree/tree-forward.hxx +++ b/xsd/xsd/cxx/tree/tree-forward.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-forward.hxx -// 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 #ifndef CXX_TREE_TREE_FORWARD_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_forward (Context&); } } diff --git a/xsd/xsd/cxx/tree/tree-header.cxx b/xsd/xsd/cxx/tree/tree-header.cxx index 9b5acc6..f0c3560 100644 --- a/xsd/xsd/cxx/tree/tree-header.cxx +++ b/xsd/xsd/cxx/tree/tree-header.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-header.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 <xsd-frontend/semantic-graph.hxx> @@ -16,8 +15,6 @@ namespace CXX { namespace { - typedef Containers::Vector<NarrowString> Streams; - // List mapping. // struct List: Traversal::List, Context @@ -27,7 +24,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -142,8 +139,9 @@ namespace CXX // c-tor (istream&) // - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { if (doxygen) { @@ -167,7 +165,7 @@ namespace CXX << endl; } - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -293,6 +291,22 @@ namespace CXX << "~" << name << " ();"; os << "};"; + + // Comparison operators. + // + if (options.generate_comparison ()) + { + os << inst_exp + << "bool" << endl + << "operator== (const " << name << "&, const " << name << "&);" + << endl; + + os << inst_exp + << "bool" << endl + << "operator!= (const " << name << "&, const " << name << "&);" + << endl + << endl; + } } private: @@ -318,7 +332,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -353,7 +367,7 @@ namespace CXX << "public:" << endl << endl; - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { // c-tor () // @@ -400,8 +414,9 @@ namespace CXX // c-tor (istream&) // - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { if (doxygen) { @@ -425,7 +440,7 @@ namespace CXX << endl; } - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -551,7 +566,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (doxygen && e.annotated_p ()) @@ -579,7 +594,7 @@ namespace CXX names_ >> enumerator_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -590,13 +605,13 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } - Boolean enum_based (false); + bool enum_based (false); SemanticGraph::Enumeration* base_enum (0); if (string_based) @@ -614,7 +629,7 @@ namespace CXX // Get to the ultimate base and see if is a fundamental type. // - Boolean fund_based (false); + bool fund_based (false); SemanticGraph::Type& ult_base (ultimate_base (e)); { IsFundamentalType t (fund_based); @@ -623,7 +638,7 @@ namespace CXX // Count enumerators. // - UnsignedLong enum_count (0); + size_t enum_count (0); for (Type::NamesIterator i (e.names_begin ()), end (e.names_end ()); i != end; ++i) @@ -688,7 +703,7 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { if (doxygen) { @@ -808,8 +823,9 @@ namespace CXX // c-tor (istream&) // - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { if (doxygen) { @@ -833,7 +849,7 @@ namespace CXX << endl; } - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -1031,7 +1047,7 @@ namespace CXX os << "};"; } - virtual Void + virtual void comma (Type&) { os << "," << endl; @@ -1058,7 +1074,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) @@ -1069,14 +1085,14 @@ namespace CXX String kind (m.is_a<SemanticGraph::Element> () ? "element" : "attribute"); - Boolean fund (false); + bool fund (false); { IsFundamentalType t (fund); t.dispatch (m.type ()); } - Boolean def_attr (m.default_p () && - m.is_a<SemanticGraph::Attribute> ()); + bool def_attr (m.default_p () && + m.is_a<SemanticGraph::Attribute> ()); if (max (m) != 1) { @@ -1249,7 +1265,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } } @@ -1338,7 +1354,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } @@ -1362,7 +1378,7 @@ namespace CXX << " */" << endl; } - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << edname (m) << " ();" << endl; } @@ -1373,7 +1389,7 @@ namespace CXX // if (m.default_p ()) { - Boolean simple (true); + bool simple (true); if (m.is_a<SemanticGraph::Element> ()) { @@ -1383,7 +1399,7 @@ namespace CXX if (simple) { - Boolean lit (false); + bool lit (false); { IsLiteralValue test (lit); test.dispatch (m.type ()); @@ -1425,7 +1441,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& aname (eaname (a)); @@ -1698,7 +1714,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& aname (eaname (a)); @@ -1778,16 +1794,19 @@ namespace CXX belongs_ >> type_name_; } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) return; + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (m.scope ())); + String const& type (etype (m)); - Boolean el (m.is_a<SemanticGraph::Element> ()); + bool el (m.is_a<SemanticGraph::Element> ()); - Boolean def_attr (m.default_p () && !el); + bool def_attr (m.default_p () && !el); if (doxygen) { @@ -1826,7 +1845,7 @@ namespace CXX else { os << "// " << comment (m.name ()) << endl - << "// " << endl; + << "//" << endl; } // Typedefs. @@ -1849,7 +1868,7 @@ namespace CXX if (max (m) != 1) { String const& container (econtainer (m)); - Boolean isense (options.value<CLI::generate_intellisense> ()); + bool isense (options.generate_intellisense ()); // sequence // @@ -1872,7 +1891,7 @@ namespace CXX << " */" << endl; } - // IntelliSense does not not like aliases and fully-qualified + // IntelliSense does not like aliases and fully-qualified // names here. // if (!isense) @@ -1941,6 +1960,24 @@ namespace CXX os << " > " << etraits (m) << ";" << endl; + + // Element id. + // + if (el && ordered_p (c)) + { + if (doxygen) + os << "/**" << endl + << " * @brief Element id used for capturing content " << + "order." << endl + << " */" << endl; + + SemanticGraph::Context& ctx (m.context ()); + + os << "static const ::std::size_t " << + ctx.get<String> ("ordered-id-name") << " = " << + ctx.get<size_t> ("ordered-id") << "UL;" << endl; + } + member_function_.traverse (m); if (doxygen) @@ -1967,9 +2004,12 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (a.scope ())); + if (doxygen) { os << "/**" << endl @@ -1990,7 +2030,7 @@ namespace CXX else { os << "// " << ename (a) << endl - << "// " << endl; + << "//" << endl; } // Typedefs. @@ -2060,6 +2100,23 @@ namespace CXX os << endl; } + // Wildcard id. + // + if (ordered_p (c)) + { + if (doxygen) + os << "/**" << endl + << " * @brief Wildcard id used for capturing content " << + "order." << endl + << " */" << endl; + + SemanticGraph::Context& ctx (a.context ()); + + os << "static const ::std::size_t " << + ctx.get<String> ("ordered-id-name") << " = " << + ctx.get<size_t> ("ordered-id") << "UL;" << endl; + } + any_function_.traverse (a); if (doxygen) @@ -2069,7 +2126,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& container (econtainer (a)); @@ -2095,7 +2152,7 @@ namespace CXX else { os << "// " << ename (a) << endl - << "// " << endl; + << "//" << endl; } if (doxygen) @@ -2152,14 +2209,14 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) return; String const& member (emember (m)); - Boolean def_attr (m.default_p () && + bool def_attr (m.default_p () && m.is_a<SemanticGraph::Attribute> ()); if (max (m) != 1) @@ -2186,7 +2243,7 @@ namespace CXX // if (m.default_p ()) { - Boolean simple (true); + bool simple (true); if (m.is_a<SemanticGraph::Element> ()) { @@ -2196,7 +2253,7 @@ namespace CXX if (simple) { - Boolean lit (false); + bool lit (false); { IsLiteralValue test (lit); test.dispatch (m.type ()); @@ -2221,7 +2278,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -2246,7 +2303,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { os << econtainer (a) << " " << emember (a) << ";"; @@ -2269,15 +2326,15 @@ namespace CXX inherits_member_ >> member_name_; names_ >> member_; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names_ >> any_; names_data_ >> data_member_; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names_data_ >> data_any_; } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -2288,20 +2345,25 @@ namespace CXX if (renamed_type (c, name) && !name) return; - Boolean has_members (has<Traversal::Member> (c)); + SemanticGraph::Context& ctx (c.context ()); + + bool has_members (has<Traversal::Member> (c)); - Boolean hae (has<Traversal::Any> (c)); - Boolean haa (has<Traversal::AnyAttribute> (c)); + bool hae (has<Traversal::Any> (c)); + bool haa (has<Traversal::AnyAttribute> (c)); - Boolean gen_wildcard (options.value<CLI::generate_wildcard> ()); + bool gen_wildcard (options.generate_wildcard ()); - Boolean simple (true); + bool mixed (mixed_p (c) && !ctx.count ("mixed-in-base")); + bool ordered (ordered_p (c) && !ctx.count ("order-in-base")); + + bool simple (true); { IsSimpleType t (simple); t.dispatch (c); } - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (c); @@ -2344,17 +2406,148 @@ namespace CXX // names (c, names_); - // dom_document accessors. + // Mixed content. // - if (edom_document_member_p (c)) + if (mixed) { + String const& type (ctx.get<String> ("mixed-type")); + String const& cont (ctx.get<String> ("mixed-container")); + String const& iter (ctx.get<String> ("mixed-iterator")); + String const& citer (ctx.get<String> ("mixed-const-iterator")); - if (!doxygen) - { - os << "// DOMDocument for wildcard content." << endl + if (doxygen) + os << "/**" << endl + << " * @name " << comment ("text_content") << endl + << " *" << endl + << " * @brief Accessor and modifier functions for text " << + "content." << endl + << " */" << endl + << "//@{" << endl; + else + os << "// text_content" << endl << "//" << endl; - } + // Typedefs. + // + bool isense (options.generate_intellisense ()); + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Text content type." << endl + << " */" << endl; + + os << "typedef " << xs_string_type << " " << type << ";"; + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Text content sequence container type." << endl + << " */" << endl; + + os << "typedef ::xsd::cxx::tree::sequence< " << type << + " > " << cont << ";"; + + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Text content iterator type." << endl + << " */" << endl; + + // IntelliSense does not like aliases and fully-qualified + // names here. + // + if (!isense) + os << "typedef " << cont << "::iterator " << iter<< ";"; + else + os << "typedef ::xsd::cxx::tree::sequence< " << type << + " >::iterator " << iter << ";"; + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Text content constant iterator type." << endl + << " */" << endl; + + if (!isense) + os << "typedef " << cont << "::const_iterator " << citer<< ";"; + else + os << "typedef ::xsd::cxx::tree::sequence< " << type << + " >::const_iterator " << citer << ";"; + + os << endl; + + // Content id. + // + if (doxygen) + os << "/**" << endl + << " * @brief Text content id used for capturing content " << + "order." << endl + << " */" << endl; + + os << "static const ::std::size_t " << + ctx.get<String> ("mixed-ordered-id-name") << " = " << + ctx.get<size_t> ("mixed-ordered-id") << "UL;" << endl; + + // Accessors and modifiers. + // + String const& aname (ctx.get<String> ("mixed-aname")); + String const& mname (ctx.get<String> ("mixed-mname")); + + if (doxygen) + os << "/**" << endl + << " * @brief Return a read-only (constant) reference " << + "to the text" << endl + << " * content sequence." << endl + << " *" << endl + << " * @return A constant reference to the sequence " << + "container." << endl + << " */" << endl; + + os << "const " << cont << "&" << endl + << aname << " () const;" + << endl; + + if (doxygen) + os << "/**" << endl + << " * @brief Return a read-write reference to the " << + "text content" << endl + << " * sequence." << endl + << " *" << endl + << " * @return A reference to the sequence container." << endl + << " */" << endl; + + os << cont << "&" << endl + << aname << " ();" + << endl; + + if (doxygen) + os << "/**" << endl + << " * @brief Copy elements from a given sequence." << endl + << " *" << endl + << " * @param s A sequence to copy entries from." << endl + << " *" << endl + << " * For each element in @a s this function " << + "add it to the sequence." << endl + << " * Note that this operation " << + "completely changes the sequence and" << endl + << " * all old elements will be lost." << endl + << " */" << endl; + + os << "void" << endl + << mname << " (const " << cont << "& s);" + << endl; + + if (doxygen) + os << "//@}" << endl + << endl; + } + + // dom_document accessors. + // + if (edom_document_member_p (c)) + { if (doxygen) { os << "/**" << endl @@ -2369,6 +2562,9 @@ namespace CXX << " * the raw XML content corresponding to wildcards." << endl << " */" << endl; } + else + os << "// DOMDocument for wildcard content." << endl + << "//" << endl; os << "const " << xerces_ns << "::DOMDocument&" << endl << edom_document (c) << " () const;" @@ -2393,6 +2589,137 @@ namespace CXX << endl; } + // Order container. + // + if (ordered) + { + String const& type (ctx.get<String> ("order-type")); + String const& cont (ctx.get<String> ("order-container")); + String const& iter (ctx.get<String> ("order-iterator")); + String const& citer (ctx.get<String> ("order-const-iterator")); + + String const ct (options.order_container_specified () + ? options.order_container () + : "::std::vector"); + + if (doxygen) + os << "/**" << endl + << " * @name " << comment ("content_order") << endl + << " *" << endl + << " * @brief Accessor and modifier functions for content " << + "order." << endl + << " */" << endl + << "//@{" << endl; + else + os << "// content_order" << endl + << "//" << endl; + + // Typedefs. + // + bool isense (options.generate_intellisense ()); + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Content order entry type." << endl + << " */" << endl; + + os << "typedef " << ns_name (xs_ns ()) << "::" << + xs_ns ().context ().get<String> ("content-order") << " " << + type << ";"; + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Content order sequence container type." << endl + << " */" << endl; + + os << "typedef " << ct << "< " << type << " > " << cont << ";"; + + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Content order iterator type." << endl + << " */" << endl; + + // IntelliSense does not like aliases and fully-qualified + // names here. + // + if (!isense) + os << "typedef " << cont << "::iterator " << iter<< ";"; + else + os << "typedef " << ct << "< " << type << " >::iterator " << + iter << ";"; + + if (doxygen) + os << endl + << "/**" << endl + << " * @brief Content order constant iterator type." << endl + << " */" << endl; + + if (!isense) + os << "typedef " << cont << "::const_iterator " << citer<< ";"; + else + os << "typedef " << ct << "< " << type << + " >::const_iterator " << citer << ";"; + + os << endl; + + // Accessors and modifiers. + // + String const& aname (ctx.get<String> ("order-aname")); + String const& mname (ctx.get<String> ("order-mname")); + + if (doxygen) + os << "/**" << endl + << " * @brief Return a read-only (constant) reference " << + "to the content" << endl + << " * order sequence." << endl + << " *" << endl + << " * @return A constant reference to the sequence " << + "container." << endl + << " */" << endl; + + os << "const " << cont << "&" << endl + << aname << " () const;" + << endl; + + if (doxygen) + os << "/**" << endl + << " * @brief Return a read-write reference to the " << + "content order" << endl + << " * sequence." << endl + << " *" << endl + << " * @return A reference to the sequence container." << endl + << " */" << endl; + + os << cont << "&" << endl + << aname << " ();" + << endl; + + if (doxygen) + os << "/**" << endl + << " * @brief Copy elements from a given sequence." << endl + << " *" << endl + << " * @param s A sequence to copy entries from." << endl + << " *" << endl + << " * For each element in @a s this function " << + "add it to the sequence." << endl + << " * Note that this operation " << + "completely changes the sequence and" << endl + << " * all old elements will be lost." << endl + << " */" << endl; + + os << "void" << endl + << mname << " (const " << cont << "& s);" + << endl; + + if (doxygen) + os << "//@}" << endl + << endl; + } + if (doxygen) { os << "/**" << endl @@ -2407,15 +2734,15 @@ namespace CXX << "//" << endl; } - Boolean generate_no_base_ctor (false); + bool generate_no_base_ctor (false); { GenerateWithoutBaseCtor t (generate_no_base_ctor); t.traverse (c); } - Boolean has_complex_non_op_args (false); - Boolean has_poly_non_op_args (false); - Boolean complex_poly_args_clash (true); + bool has_complex_non_op_args (false); + bool has_poly_non_op_args (false); + bool complex_poly_args_clash (true); { HasComplexPolyNonOptArgs t (*this, true, has_complex_non_op_args, @@ -2426,7 +2753,7 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { // c-tor (ultimate-base, all-non-optional-members) will become // default c-tor if our inheritance hierarchy has no required @@ -2434,7 +2761,7 @@ namespace CXX // c-tor (all-non-optional-members) if we have no required // members. // - Boolean generate (false); + bool generate (false); { GenerateDefaultCtor t (*this, generate, generate_no_base_ctor); t.traverse (c); @@ -2460,7 +2787,7 @@ namespace CXX // c-tor (base, all-non-optional-members) // - if (options.value<CLI::generate_from_base_ctor> ()) + if (options.generate_from_base_ctor ()) { // c-tor (base, all-non-optional-members) will be equivalent to // c-tor (ultimate-base, all-non-optional-members) unless our @@ -2470,7 +2797,7 @@ namespace CXX // customized version may not necessarily be convertible to // the base without loss of information. // - Boolean generate (false); + bool generate (false); { GenerateFromBaseCtor t (*this, generate); t.traverse (c); @@ -2478,9 +2805,9 @@ namespace CXX if (generate) { - Boolean has_complex_non_op_args (false); - Boolean has_poly_non_op_args (false); - Boolean complex_poly_args_clash (true); + bool has_complex_non_op_args (false); + bool has_poly_non_op_args (false); + bool complex_poly_args_clash (true); { HasComplexPolyNonOptArgs t (*this, false, has_complex_non_op_args, @@ -2505,7 +2832,7 @@ namespace CXX inherits (c, inherits_member_); os << "&"; { - FromBaseCtorArg args (*this, FromBaseCtorArg::arg_type, false); + FromBaseCtorArg args (*this, CtorArgType::type, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2524,7 +2851,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2537,7 +2864,7 @@ namespace CXX os << "&"; { FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_complex_auto_ptr, false); + *this, CtorArgType::complex_auto_ptr, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2558,7 +2885,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2571,7 +2898,7 @@ namespace CXX os << "&"; { FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_poly_auto_ptr, false); + *this, CtorArgType::poly_auto_ptr, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2597,7 +2924,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, true); + *this, CtorArgType::type, false, true); ctor_args.dispatch (c); } os << ");" @@ -2615,7 +2942,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from initializers " << "for required " << endl - << " * elements and attributes (auto_ptr version)." << endl + << " * elements and attributes (" << auto_ptr << + " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2626,7 +2954,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_complex_auto_ptr, false, true); + *this, CtorArgType::complex_auto_ptr, false, true); ctor_args.dispatch (c); } os << ");" @@ -2644,7 +2972,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from initializers " << "for required " << endl - << " * elements and attributes (auto_ptr version)." << endl + << " * elements and attributes (" << auto_ptr << + " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2655,7 +2984,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_poly_auto_ptr, false, true); + *this, CtorArgType::poly_auto_ptr, false, true); ctor_args.dispatch (c); } os << ");" @@ -2686,7 +3015,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2709,7 +3038,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2731,7 +3060,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2755,7 +3084,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_type); + CtorArgs ctor_args (*this, CtorArgType::type); ctor_args.dispatch (c); } @@ -2774,7 +3103,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2785,7 +3114,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_complex_auto_ptr); + CtorArgs ctor_args (*this, CtorArgType::complex_auto_ptr); ctor_args.dispatch (c); } @@ -2805,7 +3134,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2816,7 +3145,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_poly_auto_ptr); + CtorArgs ctor_args (*this, CtorArgType::poly_auto_ptr); ctor_args.dispatch (c); } @@ -2826,8 +3155,9 @@ namespace CXX // c-tor (istream&) // - Streams const& st (options.value<CLI::generate_extraction> ()); - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + NarrowStrings const& st (options.generate_extraction ()); + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { if (doxygen) { @@ -2852,7 +3182,7 @@ namespace CXX } - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -2969,12 +3299,61 @@ namespace CXX << container << "* c = 0) const;" << endl; + // operator= + // + bool priv (false); + + if (!simple) + { + if (options.suppress_assignment ()) + { + priv = true; + os << "private:" << endl; + + if (doxygen) + { + os << "/**" << endl + << " * @brief Disabled copy assignment operator." << endl + << " *" << endl + << " * @param x An instance to make a copy of." << endl + << " * @return A reference to itself." << endl + << " */" << endl; + } + + os << name << "&" << endl + << "operator= (const " << name << "& x);" + << endl; + } + else if (has_members || (gen_wildcard && (hae || haa))) + { + if (doxygen) + { + os << "/**" << endl + << " * @brief Copy assignment operator." << endl + << " *" << endl + << " * @param x An instance to make a copy of." << endl + << " * @return A reference to itself." << endl + << " *" << endl + << " * For polymorphic object models use the @c _clone " << + "function instead." << endl + << " */" << endl; + } + + os << name << "&" << endl + << "operator= (const " << name << "& x);" + << endl; + } + } + if (doxygen) { os << "//@}" << endl << endl; } + if (priv) + os << "public:" << endl; + // d-tor // if (doxygen) @@ -2990,7 +3369,7 @@ namespace CXX // Data members and implementation functions. // - if (has_members || hae || (haa && gen_wildcard)) + if (has_members || hae || (haa && gen_wildcard) || ordered || mixed) { os << "// Implementation." << endl << "//" << endl; @@ -3000,9 +3379,10 @@ namespace CXX << "//@cond" << endl << endl; - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing () && + (has_members || hae || (haa && gen_wildcard) || mixed)) { - // parse (xercesc::DOMElement) + // parse () // os << "protected:" << endl << "void" << endl @@ -3019,7 +3399,8 @@ namespace CXX // if (has_members) { - for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i) + for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); + ++i) { os << "void" << endl << unclash (name, "parse") << " (" << @@ -3029,7 +3410,7 @@ namespace CXX } } - // + // DOM document. // if (edom_document_member_p (c)) { @@ -3038,6 +3419,24 @@ namespace CXX << endl; } + // Mixed text content. + // + if (mixed) + { + os << ctx.get<String> ("mixed-container") << " " << + ctx.get<String> ("mixed-member") << ";" + << endl; + } + + // Order container. + // + if (ordered) + { + os << ctx.get<String> ("order-container") << " " << + ctx.get<String> ("order-member") << ";" + << endl; + } + // // names (c, names_data_); @@ -3051,7 +3450,7 @@ namespace CXX // Comparison operators. // - if (options.value<CLI::generate_comparison> () && + if (options.generate_comparison () && (has_members || !c.inherits_p () || ((hae || haa) && gen_wildcard))) { @@ -3095,7 +3494,7 @@ namespace CXX belongs_ >> type_name_; } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) @@ -3103,13 +3502,13 @@ namespace CXX SemanticGraph::Type& t (e.type ()); - Boolean fund (false); + bool fund (false); { IsFundamentalType test (fund); test.dispatch (t); } - Boolean simple (true); + bool simple (true); if (!fund) { IsSimpleType test (simple); @@ -3274,7 +3673,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } @@ -3296,7 +3695,7 @@ namespace CXX << " */" << endl; } - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << edname (e) << " ();" << endl; } @@ -3357,7 +3756,7 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { if (doxygen) { @@ -3403,7 +3802,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from an initializer " << "for" << endl - << " * the element value (auto_ptr version)." << endl + << " * the element value (" << auto_ptr << + " version)." << endl << " *" << endl << " * @param p Element value to use." << endl << " *" << endl @@ -3413,11 +3813,11 @@ namespace CXX << " */" << endl; } - os << name << " (::std::auto_ptr< " << type << " > p);" + os << name << " (" << auto_ptr << "< " << type << " > p);" << endl; } - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -3608,7 +4008,7 @@ namespace CXX }; } - Void + void generate_tree_header (Context& ctx) { if (ctx.generate_xml_schema) @@ -3625,21 +4025,21 @@ namespace CXX << "#include <xsd/cxx/tree/types.hxx>" << endl << endl; - if (!ctx.options.value<CLI::suppress_parsing> () || - ctx.options.value<CLI::generate_serialization> ()) + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/error-handler.hxx>" << endl << endl; } - if (!ctx.options.value<CLI::suppress_parsing> () || - ctx.options.value<CLI::generate_serialization> ()) + if (!ctx.options.suppress_parsing () || + ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/dom/auto-ptr.hxx>" << endl << endl; } - Boolean element_map (ctx.options.value<CLI::generate_element_map> ()); + bool element_map (ctx.options.generate_element_map ()); if (element_map) ctx.os << "#include <xsd/cxx/tree/element-map.hxx>" << endl @@ -3649,7 +4049,7 @@ namespace CXX // later in the individual generators for each feature because // those headers provide implementation for the fundamental types. // - if (!ctx.options.value<CLI::suppress_parsing> ()) + if (!ctx.options.suppress_parsing ()) { ctx.os << "#include <xsd/cxx/tree/parsing.hxx>" << endl; @@ -3670,7 +4070,7 @@ namespace CXX ctx.os << endl; } - if (ctx.options.value<CLI::generate_serialization> ()) + if (ctx.options.generate_serialization ()) { ctx.os << "#include <xsd/cxx/xml/dom/serialization-header.hxx>" << endl << "#include <xsd/cxx/tree/serialization.hxx>" << endl; @@ -3692,16 +4092,17 @@ namespace CXX ctx.os << endl; } - if (ctx.options.value<CLI::generate_ostream> ()) + if (ctx.options.generate_ostream ()) { ctx.os << "#include <xsd/cxx/tree/std-ostream-operators.hxx>" << endl << endl; } - Streams const& ist (ctx.options.value<CLI::generate_insertion> ()); + NarrowStrings const& ist (ctx.options.generate_insertion ()); if (!ist.empty ()) { - for (Streams::ConstIterator i (ist.begin ()); i != ist.end (); ++i) + for (NarrowStrings::const_iterator i (ist.begin ()); i != ist.end (); + ++i) { if (*i == "ACE_OutputCDR") ctx.os << "#include <xsd/cxx/tree/ace-cdr-stream-insertion.hxx>" @@ -3715,10 +4116,11 @@ namespace CXX << endl; } - Streams const& est (ctx.options.value<CLI::generate_extraction> ()); + NarrowStrings const& est (ctx.options.generate_extraction ()); if (!est.empty ()) { - for (Streams::ConstIterator i (est.begin ()); i != est.end (); ++i) + for (NarrowStrings::const_iterator i (est.begin ()); i != est.end (); + ++i) { if (*i == "ACE_InputCDR") ctx.os << "#include <xsd/cxx/tree/ace-cdr-stream-extraction.hxx>" @@ -3746,12 +4148,25 @@ namespace CXX } else { - Boolean inline_ (ctx.options.value<CLI::generate_inline> ()); + bool inline_ (ctx.options.generate_inline ()); - ctx.os << "#include <memory> // std::auto_ptr" << endl + ctx.os << "#include <memory> // " << ctx.auto_ptr << endl << "#include <limits> // std::numeric_limits" << endl - << "#include <algorithm> // std::binary_search" << endl - << endl; + << "#include <algorithm> // std::binary_search" << endl; + + if (ctx.std >= cxx_version::cxx11) + ctx.os << "#include <utility> // std::move" << endl; + + if (!ctx.options.ordered_type ().empty () || + ctx.options.ordered_type_all ()) + { + ctx.os << "#include <cstddef> // std::size_t" << endl; + + if (!ctx.options.order_container_specified ()) + ctx.os << "#include <vector>" << endl; + } + + ctx.os << endl; if (ctx.char_type == L"char" && ctx.char_encoding != L"custom") { @@ -3766,23 +4181,23 @@ namespace CXX << "#include <xsd/cxx/tree/list.hxx>" << endl << endl; - if (!ctx.options.value<CLI::suppress_parsing> ()) + if (!ctx.options.suppress_parsing ()) { ctx.os << "#include <xsd/cxx/xml/dom/parsing-header.hxx>" << endl << endl; } - if (ctx.options.value<CLI::generate_wildcard> ()) + if (ctx.options.generate_wildcard ()) { - if (ctx.options.value<CLI::suppress_parsing> () || - !ctx.options.value<CLI::generate_serialization> ()) + if (ctx.options.suppress_parsing () || + !ctx.options.generate_serialization ()) ctx.os << "#include <xsd/cxx/xml/dom/auto-ptr.hxx>" << endl; ctx.os << "#include <xsd/cxx/tree/containers-wildcard.hxx>" << endl << endl; } - if (!ctx.options.value<CLI::generate_extraction> ().empty ()) + if (!ctx.options.generate_extraction ().empty ()) ctx.os << "#include <xsd/cxx/tree/istream-fwd.hxx>" << endl << endl; @@ -3820,7 +4235,7 @@ namespace CXX { Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; DocumentedNamespace ns (ctx); @@ -3839,7 +4254,7 @@ namespace CXX names >> complex; names >> enumeration; - if (ctx.options.value<CLI::generate_element_type> ()) + if (ctx.options.generate_element_type ()) names >> element; schema.dispatch (ctx.schema_root); diff --git a/xsd/xsd/cxx/tree/tree-header.hxx b/xsd/xsd/cxx/tree/tree-header.hxx index bb3b417..7c97364 100644 --- a/xsd/xsd/cxx/tree/tree-header.hxx +++ b/xsd/xsd/cxx/tree/tree-header.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-header.hxx -// 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 #ifndef CXX_TREE_TREE_HEADER_HXX @@ -12,7 +11,7 @@ namespace CXX { namespace Tree { - Void + void generate_tree_header (Context&); } } diff --git a/xsd/xsd/cxx/tree/tree-inline.cxx b/xsd/xsd/cxx/tree/tree-inline.cxx index 5bf309b..500ee73 100644 --- a/xsd/xsd/cxx/tree/tree-inline.cxx +++ b/xsd/xsd/cxx/tree/tree-inline.cxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-inline.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 <xsd-frontend/semantic-graph.hxx> @@ -22,7 +21,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -54,7 +53,7 @@ namespace CXX os << inl << name << "::" << endl << name << " ()" << endl - << ": " << base_type << " ( " << flags_type << " (0), this)" + << ": " << base_type << " (this)" << "{" << "}"; @@ -83,6 +82,28 @@ namespace CXX << " " << base_type << " (o, f, this)" << "{" << "}"; + + // Comparison operators. + // + if (options.generate_comparison ()) + { + os << inl + << "bool" << endl + << "operator== (const " << name << "& x, " << + "const " << name << "& y)" + << "{" + << "const " << base_type << "& bx (x);" + << "return bx == y;" + << "}"; + + os << inl + << "bool" << endl + << "operator!= (const " << name << "& x, " << + "const " << name << "& y)" + << "{" + << "return !(x == y);" + << "}"; + } } private: @@ -106,7 +127,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -123,7 +144,7 @@ namespace CXX << "//" << endl << endl; - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { // c-tor () // @@ -182,7 +203,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { // This type should be ultimately string based. @@ -196,7 +217,7 @@ namespace CXX os << ")"; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Type& t) { base_type_name_.dispatch (t); @@ -217,7 +238,7 @@ namespace CXX inherits_member_ >> member_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -228,13 +249,13 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } - Boolean enum_based (false); + bool enum_based (false); if (string_based) { SemanticGraph::Enumeration* be (0); @@ -250,7 +271,7 @@ namespace CXX // Get to the ultimate base and see if is a fundamental type. // - Boolean fund_based (false); + bool fund_based (false); SemanticGraph::Type& ult_base (ultimate_base (e)); { IsFundamentalType t (fund_based); @@ -276,7 +297,7 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { os << inl << name << "::" << endl @@ -427,7 +448,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) @@ -437,13 +458,13 @@ namespace CXX String const& mname (emname (m)); String const& member (emember (m)); - Boolean fund (false); + bool fund (false); { IsFundamentalType t (fund); t.dispatch (m.type ()); } - Boolean def_attr (m.default_p () && + bool def_attr (m.default_p () && m.is_a<SemanticGraph::Attribute> ()); if (max (m) != 1) @@ -537,9 +558,10 @@ namespace CXX if (!fund) os << inl << "void " << scope_ << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > x)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "this->" << member << ".set (x);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; } else @@ -589,9 +611,10 @@ namespace CXX if (!fund) os << inl << "void " << scope_ << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > x)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "this->" << member << ".set (x);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; // auto_ptr<type> @@ -599,7 +622,7 @@ namespace CXX // if (detach && !fund) os << inl - << "::std::auto_ptr< " << q_type << " > " << + << auto_ptr << "< " << q_type << " > " << scope_ << "::" << endl << edname (m) << " ()" << "{" @@ -613,7 +636,7 @@ namespace CXX // if (m.default_p ()) { - Boolean simple (true); + bool simple (true); if (m.is_a<SemanticGraph::Element> ()) { @@ -660,7 +683,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& aname (eaname (a)); @@ -810,7 +833,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& aname (eaname (a)); @@ -862,7 +885,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { String name (ename (c)); @@ -883,13 +906,48 @@ namespace CXX Member member (*this, name); Traversal::Names names; - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) names >> any; names >> member; Complex::names (c, names); + // Mixed text content. + // + if (mixed_p (c) && !c.context ().count ("mixed-in-base")) + { + SemanticGraph::Context& ctx (c.context ()); + + String const& cont (ctx.get<String> ("mixed-container")); + String const& memb (ctx.get<String> ("mixed-member")); + + String const& aname (ctx.get<String> ("mixed-aname")); + String const& mname (ctx.get<String> ("mixed-mname")); + + os << inl + << "const " << name << "::" << cont << "& " << + name << "::" << endl + << aname << " () const" + << "{" + << "return this->" << memb << ";" + << "}"; + + os << inl + << name << "::" << cont << "& " << name << "::" << endl + << aname << " ()" + << "{" + << "return this->" << memb << ";" + << "}"; + + os << inl + << "void " << name << "::" << endl + << mname << " (const " << cont << "& s)" + << "{" + << "this->" << memb << " = s;" + << "}"; + } + // dom_document accessors. // if (edom_document_member_p (c)) @@ -899,14 +957,49 @@ namespace CXX name << "::" << endl << edom_document (c) << " () const" << "{" - << "return *" << edom_document_member (c) << ";" + << "return *this->" << edom_document_member (c) << ";" << "}"; os << inl << xerces_ns << "::DOMDocument& " << name << "::" << endl << edom_document (c) << " ()" << "{" - << "return *" << edom_document_member (c) << ";" + << "return *this->" << edom_document_member (c) << ";" + << "}"; + } + + // Order container. + // + if (ordered_p (c) && !c.context ().count ("order-in-base")) + { + SemanticGraph::Context& ctx (c.context ()); + + String const& cont (ctx.get<String> ("order-container")); + String const& memb (ctx.get<String> ("order-member")); + + String const& aname (ctx.get<String> ("order-aname")); + String const& mname (ctx.get<String> ("order-mname")); + + os << inl + << "const " << name << "::" << cont << "& " << + name << "::" << endl + << aname << " () const" + << "{" + << "return this->" << memb << ";" + << "}"; + + os << inl + << name << "::" << cont << "& " << name << "::" << endl + << aname << " ()" + << "{" + << "return this->" << memb << ";" + << "}"; + + os << inl + << "void " << name << "::" << endl + << mname << " (const " << cont << "& s)" + << "{" + << "this->" << memb << " = s;" << "}"; } @@ -924,13 +1017,13 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (!doc_root_p (e)) return; - Boolean fund (false); + bool fund (false); { IsFundamentalType test (fund); test.dispatch (e.type ()); @@ -976,7 +1069,7 @@ namespace CXX << "void " << name << "::" << endl << mname << " (const " << type << "& x)" << "{" - << "return this->" << member << ".set (x);" + << "this->" << member << ".set (x);" << "}"; // void @@ -986,9 +1079,10 @@ namespace CXX { os << inl << "void " << name << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > p)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "return this->" << member << ".set (p);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; } @@ -997,7 +1091,7 @@ namespace CXX // if (detach && !fund) os << inl - << "::std::auto_ptr< " << name << "::" << type << " > " << + << auto_ptr << "< " << name << "::" << type << " > " << name << "::" << endl << edname (e) << " ()" << "{" @@ -1007,12 +1101,12 @@ namespace CXX }; } - Void - generate_tree_inline (Context& ctx, UnsignedLong first, UnsignedLong last) + void + generate_tree_inline (Context& ctx, size_t first, size_t last) { // Generate includes. // - if (ctx.options.value<CLI::generate_inline> ()) + if (ctx.options.generate_inline ()) { Traversal::Schema schema; Includes includes (ctx, Includes::inline_); @@ -1035,7 +1129,7 @@ namespace CXX } Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx, first, last); @@ -1053,7 +1147,7 @@ namespace CXX names >> complex; names >> enumeration; - if (ctx.options.value<CLI::generate_element_type> ()) + if (ctx.options.generate_element_type ()) names >> element; schema.dispatch (ctx.schema_root); diff --git a/xsd/xsd/cxx/tree/tree-inline.hxx b/xsd/xsd/cxx/tree/tree-inline.hxx index ffe4341..351ab38 100644 --- a/xsd/xsd/cxx/tree/tree-inline.hxx +++ b/xsd/xsd/cxx/tree/tree-inline.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-inline.hxx -// 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 #ifndef CXX_TREE_TREE_INLINE_HXX @@ -12,8 +11,8 @@ namespace CXX { namespace Tree { - Void - generate_tree_inline (Context&, UnsignedLong first, UnsignedLong last); + void + generate_tree_inline (Context&, size_t first, size_t last); } } diff --git a/xsd/xsd/cxx/tree/tree-source.cxx b/xsd/xsd/cxx/tree/tree-source.cxx index 4a17b00..8a01c5a 100644 --- a/xsd/xsd/cxx/tree/tree-source.cxx +++ b/xsd/xsd/cxx/tree/tree-source.cxx @@ -1,9 +1,9 @@ // file : xsd/cxx/tree/tree-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 <cult/containers/list.hxx> +#include <map> +#include <list> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> @@ -11,6 +11,8 @@ #include <cxx/tree/tree-source.hxx> #include <cxx/tree/default-value.hxx> +using namespace std; + namespace CXX { namespace Tree @@ -24,7 +26,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& l) { String name (ename (l)); @@ -39,7 +41,7 @@ namespace CXX << "//" << endl << endl; - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { SemanticGraph::Type& item_type (l.argumented ().type ()); String base (L"::xsd::cxx::tree::list< " + @@ -105,27 +107,35 @@ namespace CXX // Register with type factory map. // - if (polymorphic && polymorphic_p (l) && !anonymous_p (l)) + if (polymorphic && polymorphic_p (l)) { // Note that we are using the original type name. // String const& name (ename (l)); - if (!options.value<CLI::suppress_parsing> ()) + // If this type is anonymous but substitutes, then it will + // be registered as part of the substitution registration. + // + if (!anonymous_p (l) && !options.suppress_parsing ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::type_factory_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_factory_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_factory_init (" << endl << strlit (l.name ()) << "," << endl << strlit (xml_ns_name (l)) << ");" << endl; + } - if (options.value<CLI::generate_comparison> ()) + if ((!anonymous_p (l) || anonymous_substitutes_p (l)) && + options.generate_comparison ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::comparison_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::comparison_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_comparison_init;" << endl; + } } } @@ -150,7 +160,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& u) { String name (ename (u)); @@ -167,7 +177,7 @@ namespace CXX << "//" << endl << endl; - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -212,27 +222,35 @@ namespace CXX // Register with type factory map. // - if (polymorphic && polymorphic_p (u) && !anonymous_p (u)) + if (polymorphic && polymorphic_p (u)) { // Note that we are using the original type name. // String const& name (ename (u)); - if (!options.value<CLI::suppress_parsing> ()) + // If this type is anonymous but substitutes, then it will + // be registered as part of the substitution registration. + // + if (!anonymous_p (u) && !options.suppress_parsing ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::type_factory_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_factory_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_factory_init (" << endl << strlit (u.name ()) << "," << endl << strlit (xml_ns_name (u)) << ");" << endl; + } - if (options.value<CLI::generate_comparison> ()) + if ((!anonymous_p (u) || anonymous_substitutes_p (u)) && + options.generate_comparison ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::comparison_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::comparison_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_comparison_init;" << endl; + } } } }; @@ -248,7 +266,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { os << strlit (e.name ()); @@ -269,13 +287,13 @@ namespace CXX String name_; }; - Boolean + bool operator< (LiteralInfo const& x, LiteralInfo const& y) { return x.value_ < y.value_; } - typedef Cult::Containers::List<LiteralInfo> LiteralInfoList; + typedef list<LiteralInfo> LiteralInfoList; // Populate LiteralInfoList @@ -288,7 +306,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { list_.push_back (LiteralInfo (e.name (), ename (e))); @@ -307,7 +325,7 @@ namespace CXX names_enumerator_literal_ >> enumerator_literal_; } - virtual Void + virtual void traverse (Type& e) { String name (ename (e)); @@ -318,14 +336,14 @@ namespace CXX if (renamed_type (e, name) && !name) return; - Boolean string_based (false); + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (e); } SemanticGraph::Enumeration* be (0); - Boolean enum_based (false); + bool enum_based (false); if (string_based) { IsEnumBasedType t (be); @@ -338,7 +356,7 @@ namespace CXX if (string_based) value = evalue (e); - UnsignedLong enum_count (0); + size_t enum_count (0); for (Type::NamesIterator i (e.names_begin ()), end (e.names_end ()); i != end; ++i) @@ -359,7 +377,7 @@ namespace CXX << "//" << endl << endl; - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -490,7 +508,7 @@ namespace CXX String fq_name (ns_scope + L"::" + name); - for (LiteralInfoList::Iterator + for (LiteralInfoList::iterator b (l.begin ()), i (b), end (l.end ()); i != end; ++i) { if (i != b) @@ -504,31 +522,39 @@ namespace CXX // Register with type factory map. // - if (polymorphic && polymorphic_p (e) && !anonymous_p (e)) + if (polymorphic && polymorphic_p (e)) { // Note that we are using the original type name. // String const& name (ename (e)); - if (!options.value<CLI::suppress_parsing> ()) + // If this type is anonymous but substitutes, then it will + // be registered as part of the substitution registration. + // + if (!anonymous_p (e) && !options.suppress_parsing ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::type_factory_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_factory_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_factory_init (" << endl << strlit (e.name ()) << "," << endl << strlit (xml_ns_name (e)) << ");" << endl; + } - if (options.value<CLI::generate_comparison> ()) + if ((!anonymous_p (e) || anonymous_substitutes_p (e)) && + options.generate_comparison ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::comparison_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::comparison_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_comparison_init;" << endl; + } } } - virtual Void + virtual void comma (Type&) { os << "," << endl; @@ -549,7 +575,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) @@ -560,7 +586,7 @@ namespace CXX if (m.default_p ()) { SemanticGraph::Type& t (m.type ()); - Boolean simple (true); + bool simple (true); if (m.is_a<SemanticGraph::Element> ()) { @@ -570,7 +596,7 @@ namespace CXX if (simple) { - Boolean lit (false); + bool lit (false); { IsLiteralValue test (lit); test.dispatch (t); @@ -661,12 +687,15 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) return; + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (e.scope ())); + String const& member (emember (e)); String tr (etraits (e)); // traits type name @@ -674,7 +703,7 @@ namespace CXX SemanticGraph::Type& t (e.type ()); - Boolean fund (false); + bool fund (false); { IsFundamentalType traverser (fund); traverser.dispatch (t); @@ -686,23 +715,17 @@ namespace CXX // derived 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)); os << "// " << comment (e.name ()) << endl << "//" << endl; if (poly) { - // aCC cannot handle an inline call to type_factory_map_instance. - // os << "{" - << "::xsd::cxx::tree::type_factory_map< " << char_type << - " >& tfm (" << endl - << "::xsd::cxx::tree::type_factory_map_instance< 0, " << - char_type << " > ());" - << endl - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl - << "tfm.create (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl + << "::xsd::cxx::tree::type_factory_map_instance< " << + poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl << (e.qualified_p () ? strlit (e.namespace_ ().name ()) @@ -732,8 +755,14 @@ namespace CXX if (!fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl - << tr << "::create (i, f, this));" + os << auto_ptr << "< " << type << " > r (" << endl + << tr << "::create (i, f"; + + if (t.is_a<SemanticGraph::AnyType> () && + options.generate_any_type ()) + os << " | " << flags_type << "::extract_content"; + + os << ", this));" << endl; } } @@ -772,7 +801,7 @@ namespace CXX { // Cast to static type. // - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl @@ -783,23 +812,25 @@ namespace CXX << endl; } + char const* r (std >= cxx_version::cxx11 ? "::std::move (r)" : "r"); + if (max (e) != 1) { // sequence // - os << "this->" << member << ".push_back (r);"; + os << "this->" << member << ".push_back (" << r << ");"; } else if (min (e) == 0) { // optional // - os << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << r << ");"; } else { // one // - os << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << r << ");"; } } else @@ -827,6 +858,27 @@ namespace CXX } } + // Capture order. + // + if (ordered_p (c)) + { + SemanticGraph::Context& ctx (c.context ()); + + String const& t (ctx.get<String> ("order-type")); + String const& m (ctx.get<String> ("order-member")); + + os << "this->" << m << ".push_back (" << endl + << t << " (" << + e.context ().get<String> ("ordered-id-name"); + + // sequence + // + if (max (e) != 1) + os << ", " << "this->" << member << ".size () - 1"; + + os << "));"; + } + os << "continue;"; // End of check block. @@ -863,7 +915,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& e) { if (skip (e)) @@ -893,15 +945,16 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& member (emember (a)); + SemanticGraph::Complex& c ( + dynamic_cast<SemanticGraph::Complex&> (a.scope ())); + String const& ns (a.definition_namespace ().name ()); - String const& dom_doc ( - edom_document ( - dynamic_cast<SemanticGraph::Complex&> (a.scope ()))); + String const& dom_doc (edom_document (c)); os << "// " << ename (a) << endl << "//" << endl @@ -982,7 +1035,7 @@ namespace CXX { // sequence // - os << "this->" << member << " .push_back (r);"; + os << "this->" << member << ".push_back (r);"; } else if (min (a) == 0) { @@ -997,6 +1050,31 @@ namespace CXX os << "this->" << member << ".set (r);"; } + // Capture order. + // + if (ordered_p (c)) + { + SemanticGraph::Context& ctx (c.context ()); + + String const& t (ctx.get<String> ("order-type")); + String const& m (ctx.get<String> ("order-member")); + + os << "this->" << m << ".push_back (" << endl + << t << " (" << + a.context ().get<String> ("ordered-id-name") << ", "; + + if (max (a) != 1) + // sequence + // + os << "this->" << member << ".size () - 1"; + else + // optional & one + // + os << "0"; + + os << "));"; + } + os << "continue;"; // End of check block. @@ -1030,7 +1108,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { if (max (a) == 1 && min (a) == 1) @@ -1055,7 +1133,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& member (emember (a)); @@ -1075,26 +1153,8 @@ namespace CXX << "{"; } - Boolean fund (false); - { - IsFundamentalType traverser (fund); - traverser.dispatch (a.type ()); - } - - if (fund) - { - os << "this->" << member << ".set (" << tr << - "::create (i, f, this));"; - } - else - { - String type (etype (a)); - - os << "::std::auto_ptr< " << type << " > r (" << endl - << tr << "::create (i, f, this));" - << endl - << "this->" << member << ".set (r);"; - } + os << "this->" << member << ".set (" << tr << + "::create (i, f, this));"; os << "continue;" << "}"; @@ -1109,7 +1169,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& member (emember (a)); @@ -1202,7 +1262,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& a) { String const& member (emember (a)); @@ -1238,33 +1298,31 @@ namespace CXX Traversal::Type, Context { - // If base_arg is empty then no base argument is - // generated. + // If base_arg is empty then no base argument is generated. // - CtorBase (Context& c, String const& base_arg) - : Context (c), base_arg_ (base_arg) + CtorBase (Context& c, CtorArgType at, String const& base_arg) + : Context (c), args_ (c, at, base_arg) { } - virtual Void + virtual void traverse (SemanticGraph::Type&) { - if (base_arg_) - os << base_arg_; + if (args_.base_arg_) + os << args_.base_arg_; } - virtual Void + virtual void traverse (SemanticGraph::Enumeration&) { - if (base_arg_) - os << base_arg_; + if (args_.base_arg_) + os << args_.base_arg_; } - Void + void traverse (SemanticGraph::Complex& c) { - Args args (*this, base_arg_); - args.traverse (c); + args_.traverse (c); } private: @@ -1279,31 +1337,32 @@ namespace CXX Traversal::Attribute, Context { - Args (Context& c, String const& base_arg) - : Context (c), base_arg_ (base_arg), first_ (true) + Args (Context& c, CtorArgType at, String const& base_arg) + : Context (c), + arg_type_ (at), base_arg_ (base_arg), first_ (true) { *this >> inherits_ >> *this; *this >> names_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Type&) { if (base_arg_) os << comma () << base_arg_; } - virtual Void + virtual void traverse (SemanticGraph::Enumeration&) { if (base_arg_) os << comma () << base_arg_; } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { - if (!options.value<CLI::generate_wildcard> ()) + if (!options.generate_wildcard ()) return; if (min (a) == 1 && max (a) == 1) @@ -1314,18 +1373,43 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (!skip (e) && min (e) == 1 && max (e) == 1) { // one // - os << comma () << ename (e); + bool move (false); + + if (std >= cxx_version::cxx11) + { + switch (arg_type_) + { + case CtorArgType::complex_auto_ptr: + { + bool simple (true); + IsSimpleType t (simple); + t.dispatch (e.type ()); + move = !simple; + break; + } + case CtorArgType::poly_auto_ptr: + { + move = polymorphic && polymorphic_p (e.type ()); + break; + } + case CtorArgType::type: + break; + } + } + + os << comma () << (move ? "std::move (" : "") << ename (e) << + (move ? ")" : ""); } } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { // Note that we are not including attributes with default @@ -1345,20 +1429,23 @@ namespace CXX String comma () { - Boolean tmp (first_); + bool tmp (first_); first_ = false; return tmp ? "" : ",\n"; } - private: + public: + CtorArgType arg_type_; String base_arg_; - Boolean first_; + + private: + bool first_; Traversal::Inherits inherits_; Traversal::Names names_; }; - String base_arg_; + Args args_; }; @@ -1366,12 +1453,12 @@ namespace CXX Traversal::Attribute, Context { - CtorMember (Context& c) - : Context (c) + CtorMember (Context& c, CtorArgType at) + : Context (c), arg_type_ (at) { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -1384,38 +1471,62 @@ namespace CXX // sequence // os << "," << endl - << " " << member << " (" << flags_type << " (), this)"; + << " " << member << " (this)"; } else if (min (e) == 0) { // optional // os << "," << endl - << " " << member << " (" << flags_type << " (), this)"; + << " " << member << " (this)"; } else { // one // + bool move (false); + + if (std >= cxx_version::cxx11) + { + switch (arg_type_) + { + case CtorArgType::complex_auto_ptr: + { + bool simple (true); + IsSimpleType t (simple); + t.dispatch (e.type ()); + move = !simple; + break; + } + case CtorArgType::poly_auto_ptr: + { + move = polymorphic && polymorphic_p (e.type ()); + break; + } + case CtorArgType::type: + break; + } + } + os << "," << endl - << " " << member << " (" << ename (e) << ", " << - flags_type << " (), this)"; + << " " << member << " (" << (move ? "std::move (" : "") << + ename (e) << (move ? ")" : "") << ", this)"; } } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { String const& member (emember (a)); - Boolean def (a.default_p ()); + bool def (a.default_p ()); if (min (a) == 0 && !def) { // optional // os << "," << endl - << " " << member << " (" << flags_type << " (), this)"; + << " " << member << " (this)"; } else { @@ -1429,16 +1540,18 @@ namespace CXX // os << "," << endl << " " << member << " (" << - edefault_value (a) << " (), " << flags_type << " (), this)"; + edefault_value (a) << " (), this)"; } else { os << "," << endl - << " " << member << " (" << ename (a) << ", " << - flags_type << " (), this)"; + << " " << member << " (" << ename (a) << ", this)"; } } } + + private: + CtorArgType arg_type_; }; struct CtorAny: Traversal::Any, @@ -1450,7 +1563,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -1482,7 +1595,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& dom_doc ( @@ -1502,7 +1615,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Member& m) { if (skip (m)) @@ -1528,7 +1641,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -1541,7 +1654,7 @@ namespace CXX arg_name << "." << member << ", this->" << dom_doc << " ())"; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& member (emember (a)); @@ -1558,6 +1671,48 @@ namespace CXX String arg_name; }; + struct AssignMember: Traversal::Member, Context + { + AssignMember (Context& c) + : Context (c) + { + } + + virtual void + traverse (SemanticGraph::Member& m) + { + if (skip (m)) + return; + + String const& member (emember (m)); + os << "this->" << member << " = x." << member << ";"; + } + }; + + struct AssignAny: Traversal::Any, + Traversal::AnyAttribute, + Context + { + AssignAny (Context& c) + : Context (c) + { + } + + virtual void + traverse (SemanticGraph::Any& a) + { + String const& member (emember (a)); + os << "this->" << member << " = x." << member << ";"; + } + + virtual void + traverse (SemanticGraph::AnyAttribute& a) + { + String const& member (emember (a)); + os << "this->" << member << " = x." << member << ";"; + } + }; + // Element parsing c-tor initializers. // @@ -1568,7 +1723,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (skip (m)) @@ -1577,7 +1732,7 @@ namespace CXX String const& member (emember (m)); os << "," << endl - << " " << member << " (f, this)"; + << " " << member << " (this)"; } }; @@ -1590,7 +1745,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -1602,7 +1757,7 @@ namespace CXX << " " << member << " (this->" << dom_doc << " ())"; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& member (emember (a)); @@ -1627,7 +1782,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -1636,10 +1791,10 @@ namespace CXX String const& member (emember (e)); os << "," << endl - << " " << member << " (" << flags_type << " (), this)"; + << " " << member << " (this)"; } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { String const& member (emember (a)); @@ -1651,11 +1806,11 @@ namespace CXX // os << "," << endl << " " << member << " (" << - edefault_value (a) << " (), " << flags_type << " (), this)"; + edefault_value (a) << " (), this)"; } else os << "," << endl - << " " << member << " (" << flags_type << " (), this)"; + << " " << member << " (this)"; } }; @@ -1668,7 +1823,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& member (emember (a)); @@ -1680,7 +1835,7 @@ namespace CXX << " " << member << " (this->" << dom_doc << " ())"; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& member (emember (a)); @@ -1707,39 +1862,39 @@ namespace CXX { // generate should initially be false. // - HasComparisonOperator (Context& c, Boolean& generate) + HasComparisonOperator (Context& c, bool& generate) : Context (c), generate_ (generate) { *this >> inherits_ >> *this; *this >> names_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Type&) { // All built-in types are comparable. generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::List&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Union&) { generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Enumeration& e) { Traversal::Enumeration::inherits (e); } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { Complex::names (c); @@ -1748,29 +1903,29 @@ namespace CXX Complex::inherits (c); } - virtual Void + virtual void traverse (SemanticGraph::Member& m) { if (!skip (m)) generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Any&) { - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) generate_ = true; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute&) { - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) generate_ = true; } private: - Boolean& generate_; + bool& generate_; Traversal::Inherits inherits_; Traversal::Names names_; @@ -1787,7 +1942,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -1802,7 +1957,7 @@ namespace CXX // dynamically-type with xsi:type. // SemanticGraph::Type& t (e.type ()); - Boolean poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); if (!poly) { @@ -1812,13 +1967,11 @@ namespace CXX } else { - // aCC cannot handle an inline call to comparison_map_instance. - // os << "{" << "::xsd::cxx::tree::comparison_map< " << char_type << " >& cm (" << endl - << "::xsd::cxx::tree::comparison_map_instance< 0, " << - char_type << " > ());" + << "::xsd::cxx::tree::comparison_map_instance< " << + poly_plate << ", " << char_type << " > ());" << endl; if (max (e) != 1) @@ -1878,7 +2031,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { String const& aname (eaname (a)); @@ -1898,7 +2051,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Any& a) { String const& aname (eaname (a)); @@ -1914,7 +2067,7 @@ namespace CXX << endl; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute& a) { String const& aname (eaname (a)); @@ -1935,50 +2088,53 @@ namespace CXX Traversal::AnyAttribute, Context { - HasParseFunction (Context& c, Boolean& has_el, Boolean& has_at) + HasParseFunction (Context& c, bool& has_el, bool& has_at) : Context (c), has_el_ (has_el), has_at_ (has_at) { *this >> names_ >> *this; *this >> inherits_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { + if (mixed_p (c) && !c.context ().count ("mixed-in-base")) + has_el_ = true; + names (c); if (!(has_el_ && has_at_)) inherits (c); } - virtual Void + virtual void traverse (SemanticGraph::Element&) { has_el_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Any&) { has_el_ = true; } - virtual Void + virtual void traverse (SemanticGraph::Attribute&) { has_at_ = true; } - virtual Void + virtual void traverse (SemanticGraph::AnyAttribute&) { - if (options.value<CLI::generate_wildcard> ()) + if (options.generate_wildcard ()) has_at_ = true; } private: - Boolean& has_el_; - Boolean& has_at_; + bool& has_el_; + bool& has_at_; Traversal::Names names_; Traversal::Inherits inherits_; @@ -1993,14 +2149,14 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { Facets f; FacetCollector col (f); col.traverse (c); - for (Facets::ConstIterator i (f.begin ()); i != f.end (); ++i) + for (Facets::const_iterator i (f.begin ()); i != f.end (); ++i) { if (i->first == L"fractionDigits") os << "{::xsd::cxx::tree::facet::fraction_digits, " << @@ -2012,7 +2168,7 @@ namespace CXX } private: - typedef Cult::Containers::Map<String, String> Facets; + typedef map<String, String> Facets; struct FacetCollector: Traversal::Complex { @@ -2022,7 +2178,7 @@ namespace CXX *this >> inherits_ >> *this; } - virtual Void + virtual void traverse (Type& c) { if (c.inherits_p ()) @@ -2075,21 +2231,25 @@ namespace CXX default_ctor_any_init_ (c), default_ctor_member_init_ (c), ctor_any_ (c), - ctor_member_ (c), + ctor_member_ (c, CtorArgType::type), element_ctor_any_ (c), element_ctor_member_ (c), + assign_any_ (c), + assign_member_ (c), comparison_any_ (c), comparison_member_ (c), facet_array_ (c) { + bool gen_wildcard (options.generate_wildcard ()); + inherits_member_ >> member_name_; names_element_ >> element_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) names_element_ >> any_; names_element_test_ >> element_test_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) names_element_test_ >> any_test_; names_attribute_ >> attribute_; @@ -2097,26 +2257,32 @@ namespace CXX names_any_attribute_ >> any_attribute_; default_ctor_init_names_ >> default_ctor_member_init_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) default_ctor_init_names_ >> default_ctor_any_init_; ctor_names_ >> ctor_member_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) ctor_names_ >> ctor_any_; element_ctor_names_ >> element_ctor_member_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) element_ctor_names_ >> element_ctor_any_; + assign_names_ >> assign_member_; + if (gen_wildcard) + assign_names_ >> assign_any_; + comparison_names_ >> comparison_member_; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) comparison_names_ >> comparison_any_; } - virtual Void + virtual void traverse (Type& c) { + bool gen_wildcard (options.generate_wildcard ()); + String name (ename (c)); // If renamed name is empty then we do not need to generate @@ -2125,7 +2291,12 @@ namespace CXX if (renamed_type (c, name) && !name) return; - Boolean string_based (false); + SemanticGraph::Context& ctx (c.context ()); + + bool mixed (mixed_p (c) && !ctx.count ("mixed-in-base")); + bool ordered (ordered_p (c) && !ctx.count ("order-in-base")); + + bool string_based (false); { IsStringBasedType t (string_based); t.dispatch (c); @@ -2137,7 +2308,7 @@ namespace CXX t.dispatch (c); } - Boolean facets (false); + bool facets (false); String base; // base type name if (c.inherits_p ()) { @@ -2200,15 +2371,15 @@ namespace CXX // c-tors // - Boolean generate_no_base_ctor (false); + bool generate_no_base_ctor (false); { GenerateWithoutBaseCtor t (generate_no_base_ctor); t.traverse (c); } - Boolean has_complex_non_op_args (false); - Boolean has_poly_non_op_args (false); - Boolean complex_poly_args_clash (true); + bool has_complex_non_op_args (false); + bool has_poly_non_op_args (false); + bool complex_poly_args_clash (true); { HasComplexPolyNonOptArgs t (*this, true, has_complex_non_op_args, @@ -2219,9 +2390,9 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { - Boolean generate (false); + bool generate (false); { GenerateDefaultCtor t (*this, generate, generate_no_base_ctor); t.traverse (c); @@ -2241,6 +2412,12 @@ namespace CXX " > ())"; } + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + names (c, default_ctor_init_names_); os << "{"; @@ -2252,9 +2429,9 @@ namespace CXX // c-tor (base, all-non-optional-members) // - if (options.value<CLI::generate_from_base_ctor> ()) + if (options.generate_from_base_ctor ()) { - Boolean generate (false); + bool generate (false); { GenerateFromBaseCtor t (*this, generate); t.traverse (c); @@ -2262,9 +2439,9 @@ namespace CXX if (generate) { - Boolean has_complex_non_op_args (false); - Boolean has_poly_non_op_args (false); - Boolean complex_poly_args_clash (true); + bool has_complex_non_op_args (false); + bool has_poly_non_op_args (false); + bool complex_poly_args_clash (true); { HasComplexPolyNonOptArgs t (*this, false, has_complex_non_op_args, @@ -2281,7 +2458,7 @@ namespace CXX inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args (*this, FromBaseCtorArg::arg_type, true); + FromBaseCtorArg args (*this, CtorArgType::type, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2296,6 +2473,12 @@ namespace CXX " > ())"; } + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + names (c, ctor_names_); os << "{"; @@ -2308,13 +2491,14 @@ namespace CXX // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + os << name << "::" << endl << name << " (const "; inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_complex_auto_ptr, true); + FromBaseCtorArg args (*this, at, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2329,7 +2513,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2343,13 +2541,14 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + os << name << "::" << endl << name << " (const "; inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_poly_auto_ptr, true); + FromBaseCtorArg args (*this, at, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2364,7 +2563,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2378,17 +2591,18 @@ namespace CXX // if (generate_no_base_ctor) { + CtorArgType const at (CtorArgType::type); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2403,6 +2617,12 @@ namespace CXX " > ())"; } + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + names (c, ctor_names_); os << "{"; @@ -2416,17 +2636,18 @@ namespace CXX // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_complex_auto_ptr, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2441,7 +2662,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2455,17 +2690,18 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_poly_auto_ptr, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2480,7 +2716,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2497,6 +2747,7 @@ namespace CXX { // c-tor (enum-value, all-non-optional-members) // + CtorArgType const at (CtorArgType::type); String base_arg (L"_xsd_" + ename (*enum_base) + L"_base"); os << name << "::" << endl @@ -2504,8 +2755,7 @@ namespace CXX evalue (*enum_base) << " " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2513,7 +2763,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2529,6 +2779,8 @@ namespace CXX " > ())"; } + // Cannot be mixed. + names (c, ctor_names_); os << "{"; @@ -2537,6 +2789,7 @@ namespace CXX os << "}"; } + CtorArgType const at (CtorArgType::type); String base_arg (L"_xsd_" + ename (ultimate_base (c)) + L"_base"); // c-tor (const char*, all-non-optional-members) @@ -2545,8 +2798,7 @@ namespace CXX << name << " (const " << char_type << "* " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2554,7 +2806,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2570,6 +2822,8 @@ namespace CXX " > ())"; } + // Cannot be mixed. + names (c, ctor_names_); os << "{"; @@ -2584,8 +2838,7 @@ namespace CXX << name << " (const " << string_type << "& " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2593,7 +2846,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2609,6 +2862,8 @@ namespace CXX " > ())"; } + // Cannot be mixed. + names (c, ctor_names_); os << "{"; @@ -2619,57 +2874,66 @@ namespace CXX // c-tor (ultimate-base, all-non-optional-members) // + { + CtorArgType const at (CtorArgType::type); - os << name << "::" << endl - << name << " ("; + os << name << "::" << endl + << name << " ("; - String base_arg; + String base_arg; - { - CtorArgs ctor_args (*this, CtorArgs::arg_type, base_arg); - ctor_args.dispatch (c); - } + { + CtorArgs ctor_args (*this, at, base_arg); + ctor_args.dispatch (c); + } - os << ")" << endl - << ": " << base << " ("; + os << ")" << endl + << ": " << base << " ("; - { - CtorBase base (*this, base_arg); - Traversal::Inherits inherits_base (base); + { + CtorBase base (*this, at, base_arg); + Traversal::Inherits inherits_base (base); - inherits (c, inherits_base); - } + inherits (c, inherits_base); + } - os << ")"; + os << ")"; - if (edom_document_member_p (c)) - { - os << "," << endl - << " " << edom_document_member (c) << " (" << - "::xsd::cxx::xml::dom::create_document< " << char_type << - " > ())"; - } + if (edom_document_member_p (c)) + { + os << "," << endl + << " " << edom_document_member (c) << " (" << + "::xsd::cxx::xml::dom::create_document< " << char_type << + " > ())"; + } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } - os << "{"; - if (facets) - os << "this->_facet_table (_xsd_" << name << "_facet_table);"; - os << "}"; + names (c, ctor_names_); + + os << "{"; + if (facets) + os << "this->_facet_table (_xsd_" << name << "_facet_table);"; + os << "}"; + } // If we have any complex arguments in the previous c-tor // then also generate the auto_ptr version. // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + String base_arg; + os << name << "::" << endl << name << " ("; - String base_arg; - { - CtorArgs ctor_args ( - *this, CtorArgs::arg_complex_auto_ptr, base_arg); + CtorArgs ctor_args (*this, at, base_arg); ctor_args.dispatch (c); } @@ -2677,7 +2941,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2693,7 +2957,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2707,14 +2985,14 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + String base_arg; + os << name << "::" << endl << name << " ("; - String base_arg; - { - CtorArgs ctor_args ( - *this, CtorArgs::arg_poly_auto_ptr, base_arg); + CtorArgs ctor_args (*this, at, base_arg); ctor_args.dispatch (c); } @@ -2722,7 +3000,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2738,7 +3016,21 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2764,6 +3056,20 @@ namespace CXX " > ())"; } + if (mixed) + { + String const& m (ctx.get<String> ("mixed-member")); + os << "," << endl + << " " << m << " (x." << m << ", f, this)"; + } + + if (ordered) + { + String const& m (ctx.get<String> ("order-member")); + os << "," << endl + << " " << m << " (x." << m << ")"; + } + { CopyAny copy_any (*this, "x"); CopyMember copy_member (*this, "x"); @@ -2771,7 +3077,7 @@ namespace CXX names >> copy_member; - if (options.value<CLI::generate_wildcard> ()) + if (gen_wildcard) names >> copy_any; Complex::names (c, names); @@ -2784,17 +3090,15 @@ namespace CXX // // - Boolean he (has<Traversal::Element> (c)); - Boolean hae (has<Traversal::Any> (c)); + bool he (has<Traversal::Element> (c)); + bool hae (has<Traversal::Any> (c)); - Boolean ha (has<Traversal::Attribute> (c)); - Boolean haa (has<Traversal::AnyAttribute> (c)); - - Boolean gen_wildcard (options.value<CLI::generate_wildcard> ()); + bool ha (has<Traversal::Attribute> (c)); + bool haa (has<Traversal::AnyAttribute> (c)); // // - if (!options.value<CLI::suppress_parsing> ()) + if (!options.suppress_parsing ()) { // c-tor (xercesc::DOMElement) // @@ -2804,7 +3108,7 @@ namespace CXX << container << "* c)" << endl << ": " << base << " (e, f"; - if (he || ha || hae || (haa && gen_wildcard)) + if (he || ha || hae || (haa && gen_wildcard) || mixed) os << " | " << flags_type << "::base"; os << ", c)"; @@ -2817,6 +3121,12 @@ namespace CXX " > ())"; } + if (mixed) + { + os << "," << endl + << " " << ctx.get<String> ("mixed-member") << " (this)"; + } + names (c, element_ctor_names_); os << "{"; @@ -2825,12 +3135,12 @@ namespace CXX os << "this->_facet_table (_xsd_" << name << "_facet_table);" << endl; - Boolean base_has_el (false), base_has_at (false); + bool base_has_el (false), base_has_at (false); // We are only interested in this information if we are - // generating out own parse(). + // generating our own parse(). // - if (he || ha || hae || (haa && gen_wildcard)) + if (he || ha || hae || (haa && gen_wildcard) || mixed) { if (c.inherits_p ()) { @@ -2839,13 +3149,14 @@ namespace CXX } } - //@@ throw if p is no exhausted at the end. + //@@ Throw if p is not exhausted at the end. // - if (he || ha || hae || (haa && gen_wildcard)) + if (he || ha || hae || (haa && gen_wildcard) || mixed) os << "if ((f & " << flags_type << "::base) == 0)" << "{" << parser_type << " p (e, " << - (he || hae || base_has_el ? "true, " : "false, ") << + (he || hae || base_has_el || mixed_p (c) ? "true, " : "false, ") << + (mixed_p (c) ? "true, " : "false, ") << (ha || (haa && gen_wildcard) || base_has_at ? "true" : "false") << ");" << "this->" << unclash (name, "parse") << " (p, f);" @@ -2853,7 +3164,7 @@ namespace CXX os << "}"; - Boolean simple (true); + bool simple (true); { IsSimpleType t (simple); t.dispatch (c); @@ -2891,7 +3202,7 @@ namespace CXX os << "}"; } - if (he || ha || hae || (haa && gen_wildcard)) + if (he || ha || hae || (haa && gen_wildcard) || mixed) { os << "void " << name << "::" << endl << unclash (name, "parse") << " (" << @@ -2906,17 +3217,45 @@ namespace CXX os << "this->" << base << "::parse (p, f);" << endl; - if (he || hae) + if (he || hae || mixed_p (c)) { - os << "for (; p.more_elements (); p.next_element ())" - << "{" - << "const " << xerces_ns << "::DOMElement& i (" << - "p.cur_element ());" - << "const " << qname_type << " n (" << endl - << "::xsd::cxx::xml::dom::name< " << char_type << " > (i));" - << endl; + bool m (mixed_p (c)); + + os << "for (; p.more_content (); p.next_content (" << + (m ? "true" : "false") << "))" + << "{"; - names (c, names_element_); + if (m) + { + String const& ma (ctx.get<String> ("mixed-aname")); + String const& mi (ctx.get<String> ("mixed-ordered-id-name")); + String const& oa (ctx.get<String> ("order-aname")); + String const& ot (ctx.get<String> ("order-type")); + + os << "if (p.cur_is_text ())" + << "{" + << "const " << xerces_ns << "::DOMText& t (" << + "p.cur_text ());" + << "this->" << ma << " ().push_back (" << endl + << "::xsd::cxx::xml::transcode< " << char_type << " > (" << + "t.getData (), t.getLength ()));" + << "this->" << oa << " ().push_back (" << endl + << ot << " (" << mi << "," << endl + << "this->" << ma << " ().size () - 1));" + << "continue;" + << "}"; + } + + if (he || hae) + { + os << "const " << xerces_ns << "::DOMElement& i (" << + "p.cur_element ());" + << "const " << qname_type << " n (" << endl + << "::xsd::cxx::xml::dom::name< " << char_type << " > (i));" + << endl; + + names (c, names_element_); + } os << "break;" << "}"; @@ -2977,6 +3316,45 @@ namespace CXX << "return new class " << name << " (*this, f, c);" << "}"; + // operator= + // + if (!options.suppress_assignment () && + (he || ha || (gen_wildcard && (hae || haa)))) + { + os << name << "& " << name << "::" << endl + << "operator= (const " << name << "& x)" + << "{" + << "if (this != &x)" + << "{" + << "static_cast< " << base << "& > (*this) = x;"; + + // Note that here we don't assign the DOMDocument that is + // used to hold wildcard fragments. Each document has its + // own copy. + + // Mixed text content. + // + if (mixed) + { + String const& m (ctx.get<String> ("mixed-member")); + os << "this->" << m << " = x." << m << ";"; + } + + // Order container. + // + if (ordered) + { + String const& m (ctx.get<String> ("order-member")); + os << "this->" << m << " = x." << m << ";"; + } + + names (c, assign_names_); + + os << "}" + << "return *this;" + << "}"; + } + // d-tor // os << name << "::" << endl @@ -2986,36 +3364,44 @@ namespace CXX // Register with type factory map. // - if (polymorphic && polymorphic_p (c) && !anonymous_p (c)) + if (polymorphic && polymorphic_p (c)) { // Note that we are using the original type name. // String const& name (ename (c)); - if (!options.value<CLI::suppress_parsing> ()) + // If this type is anonymous but substitutes, then it will + // be registered as part of the substitution registration. + // + if (!anonymous_p (c) && !options.suppress_parsing ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::type_factory_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::type_factory_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_type_factory_init (" << endl << strlit (c.name ()) << "," << endl << strlit (xml_ns_name (c)) << ");" << endl; + } - if (options.value<CLI::generate_comparison> ()) + if ((!anonymous_p (c) || anonymous_substitutes_p (c)) && + options.generate_comparison ()) + { os << "static" << endl - << "const ::xsd::cxx::tree::comparison_initializer< 0, " << - char_type << ", " << name << " >" << endl + << "const ::xsd::cxx::tree::comparison_initializer< " << + poly_plate << ", " << char_type << ", " << name << " >" << endl << "_xsd_" << name << "_comparison_init;" << endl; + } } // Comparison operators. // - if (options.value<CLI::generate_comparison> () && - (he || ha || !c.inherits_p () || + if (options.generate_comparison () && + (he || ha || mixed || ordered || !c.inherits_p () || ((hae || haa) && gen_wildcard))) { - Boolean base_comp (false); + bool base_comp (false); if (c.inherits_p ()) { @@ -3023,8 +3409,8 @@ namespace CXX test.dispatch (c.inherits ().base ()); } - Boolean has_body (he || ha || base_comp || - ((hae || haa) && gen_wildcard)); + bool has_body (he || ha || ordered || mixed || base_comp || + ((hae || haa) && gen_wildcard)); os << "bool" << endl << "operator== (const " << name << "&" << @@ -3042,6 +3428,22 @@ namespace CXX Complex::names (c, comparison_names_); } + if (mixed) + { + String const& an (ctx.get<String> ("mixed-aname")); + os << "if (!(x." << an << " () == y." << an << " ()))" << endl + << "return false;" + << endl; + } + + if (ordered) + { + String const& an (ctx.get<String> ("order-aname")); + os << "if (!(x." << an << " () == y." << an << " ()))" << endl + << "return false;" + << endl; + } + os << "return true;" << "}"; @@ -3088,6 +3490,10 @@ namespace CXX ElementCtorMember element_ctor_member_; Traversal::Names element_ctor_names_; + AssignAny assign_any_; + AssignMember assign_member_; + Traversal::Names assign_names_; + AnyComparison comparison_any_; MemberComparison comparison_member_; Traversal::Names comparison_names_; @@ -3105,27 +3511,27 @@ namespace CXX GlobalElement (Context& c) : GlobalElementBase (c), Context (c), - element_type_ (c.options.value<CLI::generate_element_type> ()), - element_map_ (c.options.value<CLI::generate_element_map> ()), + element_type_ (c.options.generate_element_type ()), + element_map_ (c.options.generate_element_map ()), type_name_ (c) { belongs_ >> type_name_; } - virtual Void + virtual void traverse (Type& e) { if (element_type_ && doc_root_p (e)) { SemanticGraph::Type& t (e.type ()); - Boolean fund (false); + bool fund (false); { IsFundamentalType test (fund); test.dispatch (t); } - Boolean simple (true); + bool simple (true); if (!fund) { IsSimpleType test (simple); @@ -3166,11 +3572,11 @@ namespace CXX // default c-tor // - if (options.value<CLI::generate_default_ctor> ()) + if (options.generate_default_ctor ()) { os << name << "::" << endl << name << " ()" << endl - << ": " << member << " (0, 0)" + << ": " << member << " (0)" << "{" << "}"; } @@ -3179,7 +3585,7 @@ namespace CXX // os << name << "::" << endl << name << " (const " << type << "& x)" << endl - << ": " << member << " (x, 0, 0)" + << ": " << member << " (x, 0)" << "{" << "}"; @@ -3189,8 +3595,8 @@ namespace CXX if (!simple || (polymorphic && polymorphic_p (t))) { os << name << "::" << endl - << name << " (::std::auto_ptr< " << type << " > p)" << endl - << ": " << member << " (p, 0, 0)" + << name << " (" << auto_ptr << "< " << type << " > p)" << endl + << ": " << member << " (p, 0)" << "{" << "}"; } @@ -3201,7 +3607,7 @@ namespace CXX String const& name_member (ec.get<String> ("element-name-member")); String const& ns_member (ec.get<String> ("element-ns-member")); - Boolean parsing (!options.value<CLI::suppress_parsing> ()); + bool parsing (!options.suppress_parsing ()); if (parsing) { String const& tr (etraits (e)); @@ -3209,7 +3615,7 @@ namespace CXX os << name << "::" << endl << name << " (const " << xerces_ns << "::DOMElement& e, " << flags_type << " f)" << endl - << ": " << member << " (f, 0)" + << ": " << member << " (0)" << "{" << "const " << qname_type << " n (" << endl << "::xsd::cxx::xml::dom::name< " << char_type << " > (e));" @@ -3302,14 +3708,14 @@ namespace CXX } if (polymorphic && e.substitutes_p () && - !options.value<CLI::suppress_parsing> ()) + !options.suppress_parsing ()) { String const& name (ename (e)); Type& r (e.substitutes ().root ()); os << "static" << endl - << "const ::xsd::cxx::tree::element_factory_initializer< 0, " << - char_type << ", "; + << "const ::xsd::cxx::tree::element_factory_initializer< " << + poly_plate << ", " << char_type << ", "; belongs (e, belongs_); @@ -3325,32 +3731,30 @@ namespace CXX } private: - Boolean element_type_; - Boolean element_map_; + bool element_type_; + bool element_map_; Traversal::Belongs belongs_; MemberTypeName type_name_; }; } - Void - generate_tree_source (Context& ctx, - UnsignedLong first, - UnsignedLong last) + void + generate_tree_source (Context& ctx, size_t first, size_t last) { - if (ctx.options.value<CLI::generate_wildcard> ()) + if (ctx.options.generate_wildcard ()) { ctx.os << "#include <xsd/cxx/xml/dom/wildcard-source.hxx>" << endl << endl; } - if (!ctx.options.value<CLI::suppress_parsing> ()) + if (!ctx.options.suppress_parsing ()) ctx.os << "#include <xsd/cxx/xml/dom/parsing-source.hxx>" << endl << endl; if (ctx.polymorphic) { - Boolean parsing (!ctx.options.value<CLI::suppress_parsing> ()); - Boolean comparison (ctx.options.value<CLI::generate_comparison> ()); + bool parsing (!ctx.options.suppress_parsing ()); + bool comparison (ctx.options.generate_comparison ()); if (parsing) ctx.os << "#include <xsd/cxx/tree/type-factory-map.hxx>" << endl @@ -3362,8 +3766,8 @@ namespace CXX if (parsing || comparison) { - 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) { @@ -3379,39 +3783,47 @@ namespace CXX if (parsing && export_maps) ctx.os << "template struct __declspec (dllexport) " << - "type_factory_plate< 0, " << ctx.char_type << " >;"; + "type_factory_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (parsing && import_maps) ctx.os << "template struct __declspec (dllimport) " << - "type_factory_plate< 0, " << ctx.char_type << " >;"; + "type_factory_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (comparison && export_maps) ctx.os << "template struct __declspec (dllexport) " << - "comparison_plate< 0, " << ctx.char_type << " >;"; + "comparison_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (comparison && import_maps) ctx.os << "template struct __declspec (dllimport) " << - "comparison_plate< 0, " << ctx.char_type << " >;"; + "comparison_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#elif defined(__GNUC__) && __GNUC__ >= 4" << endl; if (parsing) ctx.os << "template struct __attribute__ ((visibility(\"default\"))) " << - "type_factory_plate< 0, " << ctx.char_type << " >;"; + "type_factory_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (comparison) ctx.os << "template struct __attribute__ ((visibility(\"default\"))) " << - "comparison_plate< 0, " << ctx.char_type << " >;"; + "comparison_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#elif defined(XSD_MAP_VISIBILITY)" << endl; if (parsing) ctx.os << "template struct XSD_MAP_VISIBILITY " << - "type_factory_plate< 0, " << ctx.char_type << " >;"; + "type_factory_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; if (comparison) ctx.os << "template struct XSD_MAP_VISIBILITY " << - "comparison_plate< 0, " << ctx.char_type << " >;"; + "comparison_plate< " << ctx.poly_plate << ", " << + ctx.char_type << " >;"; ctx.os << "#endif" << endl << "}" // tree @@ -3426,15 +3838,15 @@ namespace CXX if (parsing) ctx.os << "static" << endl - << "const ::xsd::cxx::tree::type_factory_plate< 0, " << - ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::type_factory_plate< " << + ctx.poly_plate << ", " << ctx.char_type << " >" << endl << "type_factory_plate_init;" << endl; if (comparison) ctx.os << "static" << endl - << "const ::xsd::cxx::tree::comparison_plate< 0, " << - ctx.char_type << " >" << endl + << "const ::xsd::cxx::tree::comparison_plate< " << + ctx.poly_plate << ", " << ctx.char_type << " >" << endl << "comparison_plate_init;" << endl; @@ -3443,7 +3855,7 @@ namespace CXX } Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; Traversal::Names names_ns, names; Namespace ns (ctx, first, last); diff --git a/xsd/xsd/cxx/tree/tree-source.hxx b/xsd/xsd/cxx/tree/tree-source.hxx index a1b4778..b2d96f7 100644 --- a/xsd/xsd/cxx/tree/tree-source.hxx +++ b/xsd/xsd/cxx/tree/tree-source.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/tree-source.hxx -// 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 #ifndef CXX_TREE_TREE_SOURCE_HXX @@ -12,8 +11,8 @@ namespace CXX { namespace Tree { - Void - generate_tree_source (Context&, UnsignedLong first, UnsignedLong last); + void + generate_tree_source (Context&, size_t first, size_t last); } } diff --git a/xsd/xsd/cxx/tree/validator.cxx b/xsd/xsd/cxx/tree/validator.cxx index 88451ba..ce3dcd8 100644 --- a/xsd/xsd/cxx/tree/validator.cxx +++ b/xsd/xsd/cxx/tree/validator.cxx @@ -1,20 +1,18 @@ // file : xsd/cxx/tree/validator.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/validator.hxx> +#include <set> +#include <iostream> -#include <cult/containers/set.hxx> +#include <cxx/tree/validator.hxx> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> #include <cxx/tree/elements.hxx> -#include <iostream> - -using std::wcerr; +using namespace std; namespace CXX { @@ -27,15 +25,15 @@ namespace CXX public: ValidationContext (SemanticGraph::Schema& root, SemanticGraph::Path const& path, - CLI::Options const& options, + Tree::options const& ops, const WarningSet& disabled_warnings, Counts const& counts, - Boolean generate_xml_schema, - Boolean& valid_) + bool generate_xml_schema, + bool& valid_) : Context (std::wcerr, root, path, - options, + ops, counts, generate_xml_schema, 0, @@ -53,8 +51,8 @@ namespace CXX } public: - Boolean - is_disabled (Char const* w) + bool + is_disabled (char const* w) { return disabled_warnings_all_ || disabled_warnings_.find (w) != disabled_warnings_.end (); @@ -95,12 +93,12 @@ namespace CXX protected: const WarningSet& disabled_warnings_; - Boolean disabled_warnings_all_; + bool disabled_warnings_all_; - Boolean& valid; + bool& valid; - Boolean& subst_group_warning_issued; - Boolean subst_group_warning_issued_; + bool& subst_group_warning_issued; + bool subst_group_warning_issued_; }; @@ -122,7 +120,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) @@ -130,13 +128,13 @@ namespace CXX using SemanticGraph::Any; - Boolean q (e.qualified_p ()); + bool q (e.qualified_p ()); String ns (q ? e.namespace_ ().name () : ""); for (Any::NamespaceIterator i (any_.namespace_begin ()); i != any_.namespace_end (); ++i) { - Boolean failed (false); + bool failed (false); if (*i == L"##any") { @@ -205,14 +203,14 @@ namespace CXX { } - virtual Void + virtual void post (Type& c) { // Go down the inheritance hierarchy. // if (down_) { - Boolean up = up_; + bool up = up_; up_ = false; if (c.inherits_p ()) @@ -225,7 +223,7 @@ namespace CXX // if (up_) { - Boolean down = down_; + bool down = down_; down_ = false; for (Type::BegetsIterator i (c.begets_begin ()); @@ -239,10 +237,10 @@ namespace CXX } private: - Boolean up_, down_; + bool up_, down_; }; - virtual Void + virtual void traverse (SemanticGraph::Any& a) { using SemanticGraph::Compositor; @@ -295,7 +293,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { using SemanticGraph::Schema; @@ -341,7 +339,7 @@ namespace CXX Complex::traverse (c); } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { // This is also used to traverse Complex. @@ -352,7 +350,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (is_disabled ("T002")) @@ -379,7 +377,7 @@ namespace CXX // Return true if root sources s. // - Boolean + bool sources_p (SemanticGraph::Schema& root, SemanticGraph::Schema& s) { using SemanticGraph::Schema; @@ -399,9 +397,9 @@ namespace CXX } private: - Containers::Set<String> types_; + set<String> types_; - Traversal::Sources sources_; + Sources sources_; Traversal::Names schema_names_; Traversal::Namespace ns_; @@ -432,7 +430,7 @@ namespace CXX *this >> names_; } - Boolean + bool traverse_common (SemanticGraph::Member& m) { SemanticGraph::Type& t (m.type ()); @@ -461,7 +459,7 @@ namespace CXX << "automatically name them" << endl; - if (!options.value<CLI::show_anonymous> ()) + if (!options.show_anonymous ()) wcerr << t.file () << ": info: use --show-anonymous option to see these " << "types" << endl; @@ -473,14 +471,14 @@ namespace CXX return false; } - virtual Void + virtual void traverse (SemanticGraph::Element& e) { if (skip (e)) return; if (traverse_common (e)) { - if (options.value<CLI::show_anonymous> ()) + if (options.show_anonymous ()) { wcerr << e.file () << ":" << e.line () << ":" << e.column () << ": error: element '" << xpath (e) << "' " @@ -491,12 +489,12 @@ namespace CXX Traversal::Element::traverse (e); } - virtual Void + virtual void traverse (SemanticGraph::Attribute& a) { if (traverse_common (a)) { - if (options.value<CLI::show_anonymous> ()) + if (options.show_anonymous ()) { wcerr << a.file () << ":" << a.line () << ":" << a.column () << ": error: attribute '" << xpath (a) << "' " @@ -508,11 +506,11 @@ namespace CXX } private: - Boolean anonymous_error_issued_; + bool anonymous_error_issued_; - Containers::Set<String> types_; + set<String> types_; - Traversal::Sources sources_; + Sources sources_; Traversal::Names schema_names_; Traversal::Namespace ns_; @@ -521,27 +519,21 @@ namespace CXX }; } - Validator:: - Validator () - { - // Dummy ctor, helps with long symbols on HP-UX. - } - - Boolean Validator:: - validate (CLI::Options const& options, + bool Validator:: + validate (options const& ops, SemanticGraph::Schema& schema, SemanticGraph::Path const& path, const WarningSet& disabled_warnings, Counts const& counts) { - Boolean valid (true); + bool valid (true); ValidationContext ctx ( - schema, path, options, disabled_warnings, counts, false, valid); + schema, path, ops, disabled_warnings, counts, false, valid); // // - Boolean import_maps (options.value<CLI::import_maps> ()); - Boolean export_maps (options.value<CLI::export_maps> ()); + bool import_maps (ops.import_maps ()); + bool export_maps (ops.export_maps ()); if (import_maps && export_maps) { @@ -569,17 +561,17 @@ namespace CXX // // - if (options.value<CLI::char_type> () != "char" && - options.value<CLI::char_type> () != "wchar_t" && + if (ops.char_type () != "char" && + ops.char_type () != "wchar_t" && !ctx.is_disabled ("T003")) { wcerr << "warning T003: unknown base character type '" << - options.value<CLI::char_type> ().c_str () << "'" << endl; + ops.char_type ().c_str () << "'" << endl; } // // - NarrowString tn (options.value<CLI::type_naming> ()); + NarrowString tn (ops.type_naming ()); if (tn != "knr" && tn != "ucc" && tn != "java") { @@ -589,7 +581,7 @@ namespace CXX return false; } - NarrowString fn (options.value<CLI::function_naming> ()); + NarrowString fn (ops.function_naming ()); if (fn != "knr" && fn != "lcc" && fn != "java") { @@ -601,11 +593,11 @@ namespace CXX // // - Boolean element_type (options.value<CLI::generate_element_type> ()); - Boolean par (!options.value<CLI::suppress_parsing> ()); - Boolean ser (options.value<CLI::generate_serialization> ()); + bool element_type (ops.generate_element_type ()); + bool par (!ops.suppress_parsing ()); + bool ser (ops.generate_serialization ()); - if (options.value<CLI::generate_element_map> ()) + if (ops.generate_element_map ()) { if (!element_type) { @@ -631,11 +623,11 @@ namespace CXX if (counts.global_elements > 1 && (element_type || par || ser) && - !options.value<CLI::root_element_first> () && - !options.value<CLI::root_element_last> () && - !options.value<CLI::root_element_all> () && - !options.value<CLI::root_element_none> () && - options.value<CLI::root_element> ().empty () && + !ops.root_element_first () && + !ops.root_element_last () && + !ops.root_element_all () && + !ops.root_element_none () && + ops.root_element ().empty () && !ctx.is_disabled ("T004")) { wcerr << schema.file () << ": warning T004: generating "; diff --git a/xsd/xsd/cxx/tree/validator.hxx b/xsd/xsd/cxx/tree/validator.hxx index da0c441..58ec85e 100644 --- a/xsd/xsd/cxx/tree/validator.hxx +++ b/xsd/xsd/cxx/tree/validator.hxx @@ -1,13 +1,12 @@ // file : xsd/cxx/tree/validator.hxx -// 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 #ifndef CXX_TREE_VALIDATOR_HXX #define CXX_TREE_VALIDATOR_HXX #include <cxx/tree/elements.hxx> -#include <cxx/tree/cli.hxx> +#include <cxx/tree/options.hxx> #include <xsd.hxx> @@ -18,10 +17,8 @@ namespace CXX class Validator { public: - Validator (); // Dummy ctor, helps with long symbols on HP-UX. - - Boolean - validate (CLI::Options const& options, + bool + validate (options const&, SemanticGraph::Schema&, SemanticGraph::Path const& tu, const WarningSet& disabled_warnings, |