diff options
Diffstat (limited to 'xsd/xsd/cxx/parser/driver-source.cxx')
-rw-r--r-- | xsd/xsd/cxx/parser/driver-source.cxx | 164 |
1 files changed, 86 insertions, 78 deletions
diff --git a/xsd/xsd/cxx/parser/driver-source.cxx b/xsd/xsd/cxx/parser/driver-source.cxx index b48b0e0..510c965 100644 --- a/xsd/xsd/cxx/parser/driver-source.cxx +++ b/xsd/xsd/cxx/parser/driver-source.cxx @@ -1,18 +1,18 @@ // file : xsd/cxx/parser/driver-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 <set> +#include <map> +#include <sstream> + #include <cxx/parser/driver-source.hxx> #include <cxx/parser/print-impl-common.hxx> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/map.hxx> -#include <cult/containers/set.hxx> - -#include <sstream> +using namespace std; namespace CXX { @@ -20,23 +20,22 @@ namespace CXX { namespace { - typedef - Cult::Containers::Map<SemanticGraph::Type*, String> - TypeInstanceMap; - - typedef Cult::Containers::Set<String> InstanceSet; + typedef map<SemanticGraph::Type*, String> TypeInstanceMap; + typedef set<String> InstanceSet; // For base types we only want member's types, but not the // base itself. // - struct BaseType: Traversal::Complex, Context + struct BaseType: Traversal::Complex, + Traversal::List, + Context { - BaseType (Context& c) - : Context (c) + BaseType (Context& c, Traversal::NodeBase& def) + : Context (c), def_ (def) { } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { inherits (c); @@ -44,6 +43,15 @@ namespace CXX if (!restriction_p (c)) names (c); } + + virtual void + traverse (SemanticGraph::List& l) + { + def_.dispatch (l.argumented ().type ()); + } + + private: + Traversal::NodeBase& def_; }; struct ParserDef: Traversal::Type, @@ -109,7 +117,7 @@ namespace CXX Context { ParserDef (Context& c, TypeInstanceMap& map, InstanceSet& set) - : Context (c), map_ (map), set_ (set), base_ (c) + : Context (c), map_ (map), set_ (set), base_ (c, *this) { *this >> inherits_ >> base_ >> inherits_; @@ -119,7 +127,7 @@ namespace CXX names_ >> member_ >> belongs_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { if (map_.find (&t) == map_.end ()) @@ -131,7 +139,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::List& l) { if (map_.find (&l) == map_.end ()) @@ -145,7 +153,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { if (map_.find (&c) == map_.end ()) @@ -164,13 +172,13 @@ namespace CXX // anyType & anySimpleType. // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { fund_type (t, "any_type"); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { fund_type (t, "any_simple_type"); @@ -178,7 +186,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { fund_type (t, "boolean"); @@ -186,79 +194,79 @@ namespace CXX // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { fund_type (t, "byte"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { fund_type (t, "unsigned_byte"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { fund_type (t, "short"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { fund_type (t, "unsigned_short"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { fund_type (t, "int"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { fund_type (t, "unsigned_int"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { fund_type (t, "long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { fund_type (t, "unsigned_long"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { fund_type (t, "integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { fund_type (t, "non_positive_integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { fund_type (t, "non_negative_integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { fund_type (t, "positive_integer"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { fund_type (t, "negative_integer"); @@ -266,19 +274,19 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { fund_type (t, "float"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { fund_type (t, "double"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { fund_type (t, "decimal"); @@ -286,49 +294,49 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { fund_type (t, "string"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { fund_type (t, "normalized_string"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { fund_type (t, "token"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { fund_type (t, "nmtoken"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { fund_type (t, "nmtokens"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { fund_type (t, "name"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { fund_type (t, "ncname"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { fund_type (t, "language"); @@ -337,7 +345,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { fund_type (t, "qname"); @@ -346,19 +354,19 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { fund_type (t, "id"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { fund_type (t, "idref"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { fund_type (t, "idrefs"); @@ -366,7 +374,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { fund_type (t, "uri"); @@ -374,13 +382,13 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { fund_type (t, "base64_binary"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { fund_type (t, "hex_binary"); @@ -389,55 +397,55 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { fund_type (t, "date"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { fund_type (t, "date_time"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { fund_type (t, "duration"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { fund_type (t, "day"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { fund_type (t, "month"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { fund_type (t, "month_day"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { fund_type (t, "year"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { fund_type (t, "year_month"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { fund_type (t, "time"); @@ -445,20 +453,20 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { fund_type (t, "entity"); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { fund_type (t, "entities"); } private: - virtual Void + virtual void fund_type (SemanticGraph::Type& t, String const& name) { if (map_.find (&t) == map_.end ()) @@ -476,7 +484,7 @@ namespace CXX String base_name (escape (raw_name + L"_p")); 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; @@ -516,7 +524,7 @@ namespace CXX names_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { inherits (c, inherits_); @@ -525,7 +533,7 @@ namespace CXX names (c, names_); } - virtual Void + virtual void traverse (SemanticGraph::List& l) { if (!first_) @@ -536,7 +544,7 @@ namespace CXX os << map_[&l.argumented ().type ()]; } - virtual Void + virtual void traverse (SemanticGraph::Member& m) { if (skip (m)) @@ -556,7 +564,7 @@ namespace CXX Traversal::Inherits inherits_; Traversal::Names names_; - Boolean first_; + bool first_; }; struct ParserConnect: Traversal::List, @@ -564,7 +572,7 @@ namespace CXX Context { ParserConnect (Context& c, TypeInstanceMap& map) - : Context (c), map_ (map), base_ (c) + : Context (c), map_ (map), base_ (c, *this) { *this >> inherits_ >> base_ >> inherits_; @@ -574,7 +582,7 @@ namespace CXX names_ >> member_ >> belongs_ >> *this; } - virtual Void + virtual void traverse (SemanticGraph::List& l) { if (type_set_.find (&l) == type_set_.end ()) @@ -587,7 +595,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Complex& c) { if (type_set_.find (&c) == type_set_.end ()) @@ -613,7 +621,7 @@ namespace CXX } private: - Boolean + bool has_members (SemanticGraph::Complex& c) { using SemanticGraph::Complex; @@ -636,7 +644,7 @@ namespace CXX private: TypeInstanceMap& map_; - Cult::Containers::Set<SemanticGraph::Type*> type_set_; + set<SemanticGraph::Type*> type_set_; BaseType base_; Traversal::Inherits inherits_; @@ -647,7 +655,7 @@ namespace CXX }; } - Void + void generate_driver_source (Context& ctx) { // Figure out the root element. Validator should have made sure @@ -656,7 +664,7 @@ namespace CXX SemanticGraph::Element* root (0); { Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; @@ -740,7 +748,7 @@ namespace CXX root_p << "." << post << " ());" << endl; - if (ctx.options.value<CLI::generate_print_impl> ()) + if (ctx.options.generate_print_impl ()) { PrintCall t (ctx, root->name (), "v"); t.dispatch (root_type); |