diff options
Diffstat (limited to 'xsd/xsd/cxx/parser/name-processor.cxx')
-rw-r--r-- | xsd/xsd/cxx/parser/name-processor.cxx | 197 |
1 files changed, 86 insertions, 111 deletions
diff --git a/xsd/xsd/cxx/parser/name-processor.cxx b/xsd/xsd/cxx/parser/name-processor.cxx index d323187..219a3c9 100644 --- a/xsd/xsd/cxx/parser/name-processor.cxx +++ b/xsd/xsd/cxx/parser/name-processor.cxx @@ -1,66 +1,47 @@ // file : xsd/cxx/parser/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 <sstream> +#include <iostream> + #include <cxx/parser/name-processor.hxx> #include <xsd-frontend/semantic-graph.hxx> #include <xsd-frontend/traversal.hxx> -#include <cult/containers/set.hxx> -#include <sstream> -#include <iostream> +using namespace std; namespace CXX { namespace Parser { - 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 CXX::Context { public: - Context (CLI::Options const& ops, + Context (Parser::options const& ops, SemanticGraph::Schema& root, SemanticGraph::Path const& path, StringLiteralMap const* map) - : CXX::Context (std::wcerr, - 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> ()), - skel_suffix_ (ops.value<CLI::skel_type_suffix> ()), - impl_suffix_ (ops.value<CLI::impl_type_suffix> ()), - impl (ops.value<CLI::generate_noop_impl> () || - ops.value<CLI::generate_print_impl> () || - ops.value<CLI::generate_test_driver> ()), + : CXX::Context (std::wcerr, root, path, ops, map), + skel_suffix_ (ops.skel_type_suffix ()), + impl_suffix_ (ops.impl_type_suffix ()), + impl (ops.generate_noop_impl () || + ops.generate_print_impl () || + ops.generate_test_driver ()), skel_suffix (skel_suffix_), impl_suffix (impl_suffix_), global_type_names (global_type_names_), - polymorphic (ops.value<CLI::generate_polymorphic> ()) + polymorphic (ops.generate_polymorphic ()) { } @@ -82,7 +63,7 @@ namespace CXX String base_name (escape (n)); 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; @@ -97,16 +78,16 @@ namespace CXX String const skel_suffix_; String const impl_suffix_; - Cult::Containers::Map<String, NameSet> global_type_names_; + map<String, NameSet> global_type_names_; public: - Boolean const impl; + bool const impl; String const& skel_suffix; String const& impl_suffix; - Cult::Containers::Map<String, NameSet>& global_type_names; + map<String, NameSet>& global_type_names; - Boolean polymorphic; + bool polymorphic; }; @@ -119,7 +100,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Parser::Context::skip (m)) @@ -139,7 +120,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Parser::Context::skip (m)) @@ -156,9 +137,6 @@ namespace CXX !m.type ().context ().count ("anonymous")) { m.context ().set ( - "member-cache", find_name (base + L"_parser_cache_", set_)); - - m.context ().set ( "member-map", find_name (base + L"_parser_map_", set_)); m.context ().set ( @@ -245,7 +223,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Parser::Context::skip (m)) @@ -282,17 +260,17 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& m) { if (Parser::Context::skip (m)) return; - Boolean poly (polymorphic && + bool poly (polymorphic && m.is_a<SemanticGraph::Element> () && !m.type ().context ().count ("anonymous")); - String parser, member, member_cache, member_map, member_map_impl; + String parser, member, member_map, member_map_impl; try { @@ -306,7 +284,6 @@ namespace CXX if (poly) { - member_cache = bm.context ().get<String> ("member-cache"); member_map = bm.context ().get<String> ("member-map"); member_map_impl = bm.context ().get<String> ("member-map-impl"); } @@ -322,7 +299,6 @@ namespace CXX if (poly) { - member_cache = find_name (base + L"_parser_cache_", set_); member_map = find_name (base + L"_parser_map_", set_); member_map_impl = find_name (base + L"_parser_map_impl_", set_); } @@ -333,7 +309,6 @@ namespace CXX if (poly) { - m.context ().set ("member-cache", member_cache); m.context ().set ("member-map", member_map); m.context ().set ("member-map-impl", member_map_impl); } @@ -349,7 +324,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& c) { SemanticGraph::Context& cc (c.context ()); @@ -371,7 +346,7 @@ namespace CXX // inheriting by restriction in which case we need to have // the same names as our base. // - Boolean restriction (false); + bool restriction (false); if (c.inherits_p ()) { @@ -464,7 +439,7 @@ namespace CXX { } - virtual Void + virtual void traverse (SemanticGraph::Type& t) { SemanticGraph::Context& c (t.context ()); @@ -533,7 +508,7 @@ namespace CXX String base_name (escape (L"post_" + n)); String post (base_name); - for (UnsignedLong i (1); set.find (post) != set.end (); ++i) + for (size_t i (1); set.find (post) != set.end (); ++i) { std::wostringstream os; os << i; @@ -556,7 +531,7 @@ namespace CXX { } - virtual Void + virtual void traverse (Type& ns) { NameSet& type_set (global_type_names[ns.name ()]); @@ -634,7 +609,7 @@ namespace CXX // anyType & anySimpleType. // - virtual Void + virtual void traverse (SemanticGraph::AnyType& t) { t.context ().set ("name", make_skel_name ("any_type")); @@ -642,7 +617,7 @@ namespace CXX t.context ().set ("post", String ("post_any_type")); } - virtual Void + virtual void traverse (SemanticGraph::AnySimpleType& t) { t.context ().set ("name", make_skel_name ("any_simple_type")); @@ -652,7 +627,7 @@ namespace CXX // Boolean. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Boolean& t) { t.context ().set ("name", make_skel_name ("boolean")); @@ -662,7 +637,7 @@ namespace CXX // Integral types. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Byte& t) { t.context ().set ("name", make_skel_name ("byte")); @@ -670,7 +645,7 @@ namespace CXX t.context ().set ("post", String ("post_byte")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedByte& t) { t.context ().set ("name", make_skel_name ("unsigned_byte")); @@ -678,7 +653,7 @@ namespace CXX t.context ().set ("post", String ("post_unsigned_byte")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Short& t) { t.context ().set ("name", make_skel_name ("short")); @@ -686,7 +661,7 @@ namespace CXX t.context ().set ("post", String ("post_short")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedShort& t) { t.context ().set ("name", make_skel_name ("unsigned_short")); @@ -694,7 +669,7 @@ namespace CXX t.context ().set ("post", String ("post_unsigned_short")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Int& t) { t.context ().set ("name", make_skel_name ("int")); @@ -702,7 +677,7 @@ namespace CXX t.context ().set ("post", String ("post_int")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedInt& t) { t.context ().set ("name", make_skel_name ("unsigned_int")); @@ -710,7 +685,7 @@ namespace CXX t.context ().set ("post", String ("post_unsigned_int")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Long& t) { t.context ().set ("name", make_skel_name ("long")); @@ -718,7 +693,7 @@ namespace CXX t.context ().set ("post", String ("post_long")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::UnsignedLong& t) { t.context ().set ("name", make_skel_name ("unsigned_long")); @@ -726,7 +701,7 @@ namespace CXX t.context ().set ("post", String ("post_unsigned_long")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Integer& t) { t.context ().set ("name", make_skel_name ("integer")); @@ -734,7 +709,7 @@ namespace CXX t.context ().set ("post", String ("post_integer")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonPositiveInteger& t) { t.context ().set ("name", make_skel_name ("non_positive_integer")); @@ -742,7 +717,7 @@ namespace CXX t.context ().set ("post", String ("post_non_positive_integer")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NonNegativeInteger& t) { t.context ().set ("name", make_skel_name ("non_negative_integer")); @@ -750,7 +725,7 @@ namespace CXX t.context ().set ("post", String ("post_non_negative_integer")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::PositiveInteger& t) { t.context ().set ("name", make_skel_name ("positive_integer")); @@ -758,7 +733,7 @@ namespace CXX t.context ().set ("post", String ("post_positive_integer")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NegativeInteger& t) { t.context ().set ("name", make_skel_name ("negative_integer")); @@ -768,7 +743,7 @@ namespace CXX // Floats. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Float& t) { t.context ().set ("name", make_skel_name ("float")); @@ -776,7 +751,7 @@ namespace CXX t.context ().set ("post", String ("post_float")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Double& t) { t.context ().set ("name", make_skel_name ("double")); @@ -784,7 +759,7 @@ namespace CXX t.context ().set ("post", String ("post_double")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Decimal& t) { t.context ().set ("name", make_skel_name ("decimal")); @@ -794,7 +769,7 @@ namespace CXX // Strings. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::String& t) { t.context ().set ("name", make_skel_name ("string")); @@ -802,7 +777,7 @@ namespace CXX t.context ().set ("post", String ("post_string")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NormalizedString& t) { t.context ().set ("name", make_skel_name ("normalized_string")); @@ -810,7 +785,7 @@ namespace CXX t.context ().set ("post", String ("post_normalized_string")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Token& t) { t.context ().set ("name", make_skel_name ("token")); @@ -818,7 +793,7 @@ namespace CXX t.context ().set ("post", String ("post_token")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameToken& t) { t.context ().set ("name", make_skel_name ("nmtoken")); @@ -826,7 +801,7 @@ namespace CXX t.context ().set ("post", String ("post_nmtoken")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NameTokens& t) { t.context ().set ("name", make_skel_name ("nmtokens")); @@ -834,7 +809,7 @@ namespace CXX t.context ().set ("post", String ("post_nmtokens")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Name& t) { t.context ().set ("name", make_skel_name ("name")); @@ -842,7 +817,7 @@ namespace CXX t.context ().set ("post", String ("post_name")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::NCName& t) { t.context ().set ("name", make_skel_name ("ncname")); @@ -850,7 +825,7 @@ namespace CXX t.context ().set ("post", String ("post_ncname")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Language& t) { t.context ().set ("name", make_skel_name ("language")); @@ -861,7 +836,7 @@ namespace CXX // Qualified name. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::QName& t) { t.context ().set ("name", make_skel_name ("qname")); @@ -872,7 +847,7 @@ namespace CXX // ID/IDREF. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Id& t) { t.context ().set ("name", make_skel_name ("id")); @@ -880,7 +855,7 @@ namespace CXX t.context ().set ("post", String ("post_id")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRef& t) { t.context ().set ("name", make_skel_name ("idref")); @@ -888,7 +863,7 @@ namespace CXX t.context ().set ("post", String ("post_idref")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::IdRefs& t) { t.context ().set ("name", make_skel_name ("idrefs")); @@ -898,7 +873,7 @@ namespace CXX // URI. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::AnyURI& t) { t.context ().set ("name", make_skel_name ("uri")); @@ -908,7 +883,7 @@ namespace CXX // Binary. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { t.context ().set ("name", make_skel_name ("base64_binary")); @@ -916,7 +891,7 @@ namespace CXX t.context ().set ("post", String ("post_base64_binary")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { t.context ().set ("name", make_skel_name ("hex_binary")); @@ -927,7 +902,7 @@ namespace CXX // Date/time. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Date& t) { t.context ().set ("name", make_skel_name ("date")); @@ -935,7 +910,7 @@ namespace CXX t.context ().set ("post", String ("post_date")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::DateTime& t) { t.context ().set ("name", make_skel_name ("date_time")); @@ -943,7 +918,7 @@ namespace CXX t.context ().set ("post", String ("post_date_time")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Duration& t) { t.context ().set ("name", make_skel_name ("duration")); @@ -951,7 +926,7 @@ namespace CXX t.context ().set ("post", String ("post_duration")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Day& t) { t.context ().set ("name", make_skel_name ("gday")); @@ -959,7 +934,7 @@ namespace CXX t.context ().set ("post", String ("post_gday")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Month& t) { t.context ().set ("name", make_skel_name ("gmonth")); @@ -967,7 +942,7 @@ namespace CXX t.context ().set ("post", String ("post_gmonth")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::MonthDay& t) { t.context ().set ("name", make_skel_name ("gmonth_day")); @@ -975,7 +950,7 @@ namespace CXX t.context ().set ("post", String ("post_gmonth_day")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Year& t) { t.context ().set ("name", make_skel_name ("gyear")); @@ -983,7 +958,7 @@ namespace CXX t.context ().set ("post", String ("post_gyear")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::YearMonth& t) { t.context ().set ("name", make_skel_name ("gyear_month")); @@ -991,7 +966,7 @@ namespace CXX t.context ().set ("post", String ("post_gyear_month")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Time& t) { t.context ().set ("name", make_skel_name ("time")); @@ -1001,7 +976,7 @@ namespace CXX // Entity. // - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entity& t) { t.context ().set ("name", make_skel_name ("entity")); @@ -1009,7 +984,7 @@ namespace CXX t.context ().set ("post", String ("post_entity")); } - virtual Void + virtual void traverse (SemanticGraph::Fundamental::Entities& t) { t.context ().set ("name", make_skel_name ("entities")); @@ -1038,7 +1013,7 @@ namespace CXX Traversal::Includes, Traversal::Imports { - virtual Void + virtual void traverse (SemanticGraph::Sources& sr) { SemanticGraph::Schema& s (sr.schema ()); @@ -1050,7 +1025,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Includes& i) { SemanticGraph::Schema& s (i.schema ()); @@ -1062,7 +1037,7 @@ namespace CXX } } - virtual Void + virtual void traverse (SemanticGraph::Imports& i) { SemanticGraph::Schema& s (i.schema ()); @@ -1080,7 +1055,7 @@ namespace CXX // struct Implies: Traversal::Implies { - virtual Void + virtual void traverse (SemanticGraph::Implies& i) { SemanticGraph::Schema& s (i.schema ()); @@ -1093,8 +1068,8 @@ namespace CXX } }; - Void - process_impl (CLI::Options const& ops, + void + process_impl (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& file, StringLiteralMap const& map) @@ -1169,7 +1144,7 @@ namespace CXX // { Traversal::Schema schema; - Traversal::Sources sources; + Sources sources; schema >> sources >> schema; @@ -1189,8 +1164,8 @@ namespace CXX } } - Void NameProcessor:: - process (CLI::Options const& ops, + void NameProcessor:: + process (options const& ops, SemanticGraph::Schema& tu, SemanticGraph::Path const& file, StringLiteralMap const& map) |