diff options
Diffstat (limited to 'xsd/xsd/cxx/tree/polymorphism-processor.cxx')
-rw-r--r-- | xsd/xsd/cxx/tree/polymorphism-processor.cxx | 216 |
1 files changed, 83 insertions, 133 deletions
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) |