From bada6666c70977a058755ccf232e7d67b24adeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:21:29 +0200 Subject: New upstream release --- .../xsd-frontend/semantic-graph/elements.hxx | 536 ++++++--------------- 1 file changed, 143 insertions(+), 393 deletions(-) (limited to 'libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx') diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx index 78b6615..98fb180 100644 --- a/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx +++ b/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx @@ -1,171 +1,41 @@ // file : xsd-frontend/semantic-graph/elements.hxx -// author : Boris Kolpackov -// 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 XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENTS_HXX #define XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENTS_HXX +#include +#include +#include +#include #include +#include // std::pair +#include // abort +#include -#include -#include -#include +#include +#include +#include +#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include +#include namespace XSDFrontend { namespace SemanticGraph { - using namespace Cult::Types; - - namespace Bits - { - using Cult::Containers::Graph; - - //@@ Should end up in Cult::Meta - // - template - struct strip_pointer - { - typedef X Type; - }; - - template - struct strip_pointer - { - typedef X Type; - }; - - template - struct PointerIterator - { - typedef - typename strip_pointer::Type - Value; - - typedef I BaseIterator; - typedef Value& Reference; - typedef Value* Pointer; - - PointerIterator () - : i_ () // i_ can be of a pointer type. - { - } - - PointerIterator (I const& i) - : i_ (i) - { - } - - public: - Reference - operator* () const - { - return **i_; - } - - Pointer - operator-> () const - { - return *i_; - } - - I const& - base () const - { - return i_; - } - - public: - PointerIterator& - operator++ () - { - ++i_; - return *this; - } - - PointerIterator - operator++ (Int) - { - PointerIterator r (*this); - ++i_; - return r; - } - - PointerIterator& - operator-- () - { - --i_; - return *this; - } + using namespace cutl; - PointerIterator - operator-- (Int) - { - PointerIterator r (*this); - --i_; - return r; - } - - private: - I i_; - }; - - template - inline - Boolean - operator== (PointerIterator const& a, PointerIterator const& b) - { - return a.base () == b.base (); - } - - template - inline - Boolean - operator!= (PointerIterator const& a, PointerIterator const& b) - { - return a.base () != b.base (); - } - - template - inline - typename PointerIterator::BaseIterator::difference_type - operator- (PointerIterator const& a, PointerIterator const& b) - { - return a.base () - b.base (); - } - } + using container::pointer_iterator; // // - typedef - boost::filesystem::filesystem_error - InvalidPath; - - typedef - boost::filesystem::path - Path; + typedef fs::path Path; + typedef fs::invalid_path InvalidPath; + typedef std::vector Paths; - typedef - Cult::Containers::Vector - Paths; - - typedef - FrontendElements::Context - Context; + typedef compiler::context Context; // // @@ -195,24 +65,17 @@ namespace XSDFrontend public: template - Boolean + bool is_a () const { return dynamic_cast (this) != 0; } - protected: - friend class Bits::Graph; - - Edge () - { - } - private: mutable Context context_; }; - inline Boolean + inline bool operator== (Edge const& x, Edge const& y) { return &x == &y; @@ -237,20 +100,20 @@ namespace XSDFrontend return file_; } - UnsignedLong + unsigned long line () const { return line_; } - UnsignedLong + unsigned long column () const { return column_; } public: - Boolean + bool annotated_p () const { return annotates_ != 0; @@ -267,56 +130,54 @@ namespace XSDFrontend public: template - Boolean + bool is_a () const { return dynamic_cast (this) != 0; } public: - virtual - ~Node () - { - } + ~Node () {} - protected: - friend class Bits::Graph; - - Node (Path const& file, UnsignedLong line, UnsignedLong column) + Node (Path const& file, unsigned long line, unsigned long column) : annotates_ (0), file_ (file), line_ (line), column_ (column) { } - Node () // For virtual inheritance. + void + add_edge_right (Annotates& a) { - abort (); // Told you so! + annotates_ = &a; } - Void - add_edge_right (Annotates& a) + protected: + Node () // For virtual inheritance. { - annotates_ = &a; + abort (); // Told you so! } private: mutable Context context_; Annotates* annotates_; Path file_; - UnsignedLong line_; - UnsignedLong column_; + unsigned long line_; + unsigned long column_; }; - inline Boolean + inline bool operator== (Node const& x, Node const& y) { return &x == &y; } + // + // + typedef container::graph graph; // // - typedef WideString Name; + typedef String Name; // @@ -348,34 +209,29 @@ namespace XSDFrontend return *named_; } - protected: - friend class Bits::Graph; - - Names (Name const& name) - : name_ (name) - { - } + public: + Names (Name const& name): name_ (name) {} - Void + void set_left_node (Scope& n) { scope_ = &n; } - Void + void set_right_node (Nameable& n) { named_ = &n; } - Void + void clear_left_node (Scope& n) { assert (scope_ == &n); scope_ = 0; } - Void + void clear_right_node (Nameable& n) { assert (named_ == &n); @@ -392,7 +248,7 @@ namespace XSDFrontend class Nameable: public virtual Node { public: - Boolean + bool named_p () const { return named_ != 0; @@ -419,21 +275,16 @@ namespace XSDFrontend return *named_; } - protected: - friend class Bits::Graph; - - Nameable () - : named_ (0) - { - } + public: + Nameable (): named_ (0) {} - Void + void add_edge_right (Names& e) { named_ = &e; } - Void + void remove_edge_right (Names& e) { assert (named_ == &e); @@ -446,42 +297,25 @@ namespace XSDFrontend Names* named_; }; - // // - typedef - Cult::Containers::Set - Nameables; - + typedef std::set Nameables; // // class Scope: public virtual Nameable { protected: - typedef - Cult::Containers::List - NamesList; - - typedef - Cult::Containers::Map - ListIteratorMap; - - typedef - Cult::Containers::Map - NamesMap; + typedef std::list NamesList; + typedef std::map ListIteratorMap; + typedef std::map NamesMap; public: - typedef - Bits::PointerIterator - NamesIterator; - - typedef - Bits::PointerIterator - NamesConstIterator; + typedef pointer_iterator NamesIterator; + typedef pointer_iterator NamesConstIterator; typedef - Cult::Containers::Pair + std::pair NamesIteratorPair; NamesIterator @@ -511,7 +345,7 @@ namespace XSDFrontend virtual NamesIteratorPair find (Name const& name) const { - NamesMap::ConstIterator i (names_map_.find (name)); + NamesMap::const_iterator i (names_map_.find (name)); if (i == names_map_.end ()) return NamesIteratorPair (names_.end (), names_.end ()); @@ -522,42 +356,36 @@ namespace XSDFrontend NamesIterator find (Names& e) { - ListIteratorMap::Iterator i (iterator_map_.find (&e)); + ListIteratorMap::iterator i (iterator_map_.find (&e)); return i != iterator_map_.end () ? i->second : names_.end (); } - protected: - friend class Bits::Graph; - - Scope (Path const& file, UnsignedLong line, UnsignedLong column) + public: + Scope (Path const& file, unsigned long line, unsigned long column) : Node (file, line, column) { } - Scope () - { - } - - Void + void add_edge_left (Names& e) { - NamesList::Iterator i (names_.insert (names_.end (), &e)); + NamesList::iterator i (names_.insert (names_.end (), &e)); iterator_map_[&e] = i; names_map_[e.name ()].push_back (&e); } - Void + void remove_edge_left (Names& e) { - ListIteratorMap::Iterator i (iterator_map_.find (&e)); + ListIteratorMap::iterator i (iterator_map_.find (&e)); assert (i != iterator_map_.end ()); names_.erase (i->second); iterator_map_.erase (i); - NamesMap::Iterator j (names_map_.find (e.name ())); + NamesMap::iterator j (names_map_.find (e.name ())); - for (NamesList::Iterator i (j->second.begin ()); + for (NamesList::iterator i (j->second.begin ()); i != j->second.end (); ++i) { if (*i == &e) @@ -565,21 +393,16 @@ namespace XSDFrontend } } - //@@ Ideally should be protected but then NodeArg has no way to - // access it. Maybe when (if) I move NodeArg into Grpah I can - // resolve this. - // - public: - Void + void add_edge_left (Names& e, NamesIterator const& after) { - NamesList::Iterator i; + NamesList::iterator i; if (after.base () == names_.end ()) i = names_.insert (names_.begin (), &e); else { - NamesList::Iterator j (after.base ()); + NamesList::iterator j (after.base ()); i = names_.insert (++j, &e); } @@ -587,9 +410,11 @@ namespace XSDFrontend names_map_[e.name ()].push_back (&e); } - protected: using Nameable::add_edge_right; + protected: + Scope () {} + private: NamesList names_; ListIteratorMap iterator_map_; @@ -606,22 +431,12 @@ namespace XSDFrontend class Type: public virtual Nameable { protected: - typedef - Cult::Containers::Vector - Classifies; - - typedef - Cult::Containers::Vector - Begets; - - typedef - Cult::Containers::Set - ArgumentsSet; + typedef std::vector Classifies; + typedef std::vector Begets; + typedef std::set ArgumentsSet; public: - typedef - Bits::PointerIterator - ClassifiesIterator; + typedef pointer_iterator ClassifiesIterator; ClassifiesIterator classifies_begin () const @@ -637,7 +452,7 @@ namespace XSDFrontend // // - Boolean + bool inherits_p () const { return inherits_ != 0; @@ -652,9 +467,7 @@ namespace XSDFrontend // // - typedef - Bits::PointerIterator - BegetsIterator; + typedef pointer_iterator BegetsIterator; BegetsIterator begets_begin () const @@ -670,9 +483,7 @@ namespace XSDFrontend // // - typedef - Bits::PointerIterator - ArgumentsIterator; + typedef pointer_iterator ArgumentsIterator; ArgumentsIterator arguments_begin () const @@ -686,21 +497,16 @@ namespace XSDFrontend return arguments_.end (); } - protected: - friend class Bits::Graph; - - Type () - : inherits_ (0) - { - } + public: + Type (): inherits_ (0) {} - Void + void add_edge_right (Belongs& e) { classifies_.push_back (&e); } - Void + void add_edge_right (Inherits& e) { begets_.push_back (&e); @@ -708,16 +514,16 @@ namespace XSDFrontend using Nameable::add_edge_right; - Void + void add_edge_left (Arguments& a) { arguments_.insert (&a); } - Void + void remove_edge_left (Arguments&); - Void + void add_edge_left (Inherits& e) { inherits_ = &e; @@ -730,7 +536,6 @@ namespace XSDFrontend ArgumentsSet arguments_; }; - class Instance: public virtual Nameable { public: @@ -743,21 +548,16 @@ namespace XSDFrontend Type& type () const; - Boolean + bool typed_p () const { return belongs_ != 0; } - protected: - friend class Bits::Graph; - - Instance () - : belongs_ (0) - { - } + public: + Instance (): belongs_ (0) {} - Void + void add_edge_left (Belongs& e) { belongs_ = &e; @@ -783,20 +583,14 @@ namespace XSDFrontend return *type_; } - protected: - friend class Bits::Graph; - - Belongs () - { - } - - Void + public: + void set_left_node (Instance& n) { instance_ = &n; } - Void + void set_right_node (Type& n) { type_ = &n; @@ -825,20 +619,14 @@ namespace XSDFrontend return *derived_; } - protected: - friend class Bits::Graph; - - Inherits () - { - } - - Void + public: + void set_left_node (Type& n) { derived_ = &n; } - Void + void set_right_node (Type& n) { base_ = &n; @@ -849,30 +637,17 @@ namespace XSDFrontend Type* derived_; }; - class Extends: public virtual Inherits { - protected: - friend class Bits::Graph; - - Extends () - { - } }; class Restricts: public virtual Inherits { - protected: - typedef - Cult::Containers::Map - Facets; - public: - typedef - Facets::Iterator - FacetIterator; + typedef std::map Facets; + typedef Facets::iterator FacetIterator; - Boolean + bool facet_empty () { return facets_.empty (); @@ -891,22 +666,21 @@ namespace XSDFrontend } FacetIterator - facet_find (WideString const& name) + facet_find (String const& name) { return facets_.find (name); } - Void + void facet_insert (String const& name, String const& value) { facets_[name] = value; } - protected: - friend class Bits::Graph; - - Restricts () + Facets const& + facets () const { + return facets_; } protected: @@ -936,21 +710,16 @@ namespace XSDFrontend return *namespace__; } - protected: - friend class Bits::Graph; - - BelongsToNamespace () - : member_ (0), namespace__ (0) - { - } + public: + BelongsToNamespace (): member_ (0), namespace__ (0) {} - Void + void set_left_node (Member& n) { member_ = &n; } - Void + void set_right_node (Namespace& n) { namespace__ = &n; @@ -969,13 +738,13 @@ namespace XSDFrontend // Member is global either if it is defined outside any type // or it is a ref="" of a global member. // - Boolean + bool global_p () const { return global_; } - Boolean + bool qualified_p () const { return qualified_; @@ -995,13 +764,13 @@ namespace XSDFrontend // is a superset of the default value semantics. As such setting the // fixed value appears as if the default value was also set. // - Boolean + bool default_p () const { return value_type_ != ValueType::none; } - Boolean + bool fixed_p () const { return value_type_ == ValueType::fixed; @@ -1009,7 +778,7 @@ namespace XSDFrontend struct NoValue {}; - WideString + String value () const { if (value_type_ != ValueType::none) @@ -1020,24 +789,22 @@ namespace XSDFrontend // // - Void - default_ (WideString const& v) + void + default_ (String const& v) { value_ = v; value_type_ = ValueType::default_; } - Void - fixed (WideString const& v) + void + fixed (String const& v) { value_ = v; value_type_ = ValueType::fixed; } - protected: - friend class Bits::Graph; - - Member (Boolean global, Boolean qualified) + public: + Member (bool global, bool qualified) : global_ (global), qualified_ (qualified), belongs_to_namespace_ (0), @@ -1045,7 +812,7 @@ namespace XSDFrontend { } - Void + void add_edge_left (BelongsToNamespace& e) { // In the parser we sometimes re-add the same adge. @@ -1056,8 +823,8 @@ namespace XSDFrontend using Instance::add_edge_left; private: - Boolean global_; - Boolean qualified_; + bool global_; + bool qualified_; BelongsToNamespace* belongs_to_namespace_; struct ValueType @@ -1070,7 +837,7 @@ namespace XSDFrontend }; }; - WideString value_; + String value_; ValueType::Value value_type_; }; @@ -1080,17 +847,12 @@ namespace XSDFrontend class Specialization: public virtual Type { - typedef - Cult::Containers::Vector - Argumented; + typedef std::vector Argumented; public: + typedef pointer_iterator ArgumentedIterator; typedef - Bits::PointerIterator - ArgumentedIterator; - - typedef - Bits::PointerIterator + pointer_iterator ArgumentedConstIterator; ArgumentedIterator @@ -1125,32 +887,28 @@ namespace XSDFrontend return *argumented_[0]; } - protected: - friend class Bits::Graph; - + public: using Type::add_edge_right; - Void + void add_edge_right (Arguments& a) { argumented_.push_back (&a); } - Void - remove_edge_right (Arguments&); - - public: - Void + void add_edge_right (Arguments& a, ArgumentedIterator const& pos) { argumented_.insert (pos.base (), &a); } + void + remove_edge_right (Arguments&); + private: Argumented argumented_; }; - class Arguments: public virtual Edge { public: @@ -1166,9 +924,7 @@ namespace XSDFrontend return *specialization_; } - protected: - friend class Bits::Graph; - + public: void set_left_node (Type& n) { @@ -1205,17 +961,14 @@ namespace XSDFrontend // class AnyType: public virtual Type { - protected: - friend class Bits::Graph; - - AnyType (Path const& file, UnsignedLong line, UnsignedLong column) + public: + AnyType (Path const& file, unsigned long line, unsigned long column) : Node (file, line, column) { } - AnyType () // For virtual inheritance. - { - } + protected: + AnyType () {} // For virtual inheritance. }; @@ -1223,17 +976,14 @@ namespace XSDFrontend // class AnySimpleType: public virtual Type { - protected: - friend class Bits::Graph; - - AnySimpleType (Path const& file, UnsignedLong line, UnsignedLong column) + public: + AnySimpleType (Path const& file, unsigned long line, unsigned long column) : Node (file, line, column) { } - AnySimpleType () // For virtual inheritance. - { - } + protected: + AnySimpleType () {} // For virtual inheritance. }; } } -- cgit v1.2.3