summaryrefslogtreecommitdiff
path: root/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx')
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx536
1 files changed, 143 insertions, 393 deletions
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 <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 XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENTS_HXX
#define XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENTS_HXX
+#include <set>
+#include <map>
+#include <list>
+#include <vector>
#include <iosfwd>
+#include <utility> // std::pair
+#include <cstdlib> // abort
+#include <cassert>
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/exception.hpp>
+#include <cutl/container/graph.hxx>
+#include <cutl/container/pointer-iterator.hxx>
+#include <cutl/compiler/context.hxx>
+#include <cutl/fs/path.hxx>
-#include <cult/types.hxx>
-
-#include <cult/rtti/type-info.hxx>
-
-#include <cult/containers/set.hxx>
-#include <cult/containers/map.hxx>
-#include <cult/containers/list.hxx>
-#include <cult/containers/pair.hxx>
-#include <cult/containers/graph.hxx>
-#include <cult/containers/vector.hxx>
-
-#include <frontend-elements/context.hxx>
+#include <xsd-frontend/types.hxx>
namespace XSDFrontend
{
namespace SemanticGraph
{
- using namespace Cult::Types;
-
- namespace Bits
- {
- using Cult::Containers::Graph;
-
- //@@ Should end up in Cult::Meta
- //
- template <typename X>
- struct strip_pointer
- {
- typedef X Type;
- };
-
- template <typename X>
- struct strip_pointer<X*>
- {
- typedef X Type;
- };
-
- template <typename I>
- struct PointerIterator
- {
- typedef
- typename strip_pointer<typename I::Value>::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 <typename I>
- inline
- Boolean
- operator== (PointerIterator<I> const& a, PointerIterator<I> const& b)
- {
- return a.base () == b.base ();
- }
-
- template <typename I>
- inline
- Boolean
- operator!= (PointerIterator<I> const& a, PointerIterator<I> const& b)
- {
- return a.base () != b.base ();
- }
-
- template <typename I>
- inline
- typename PointerIterator<I>::BaseIterator::difference_type
- operator- (PointerIterator<I> const& a, PointerIterator<I> 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<Path> Paths;
- typedef
- Cult::Containers::Vector<Path>
- Paths;
-
- typedef
- FrontendElements::Context
- Context;
+ typedef compiler::context Context;
//
//
@@ -195,24 +65,17 @@ namespace XSDFrontend
public:
template <typename X>
- Boolean
+ bool
is_a () const
{
return dynamic_cast<X const*> (this) != 0;
}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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 <typename X>
- Boolean
+ bool
is_a () const
{
return dynamic_cast<X const*> (this) != 0;
}
public:
-
virtual
- ~Node ()
- {
- }
+ ~Node () {}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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<Node, Edge> graph;
//
//
- typedef WideString Name;
+ typedef String Name;
//
@@ -348,34 +209,29 @@ namespace XSDFrontend
return *named_;
}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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<Nameable*>
- Nameables;
-
+ typedef std::set<Nameable*> Nameables;
//
//
class Scope: public virtual Nameable
{
protected:
- typedef
- Cult::Containers::List<Names*>
- NamesList;
-
- typedef
- Cult::Containers::Map<Names*, NamesList::Iterator>
- ListIteratorMap;
-
- typedef
- Cult::Containers::Map<Name, NamesList>
- NamesMap;
+ typedef std::list<Names*> NamesList;
+ typedef std::map<Names*, NamesList::iterator> ListIteratorMap;
+ typedef std::map<Name, NamesList> NamesMap;
public:
- typedef
- Bits::PointerIterator<NamesList::Iterator>
- NamesIterator;
-
- typedef
- Bits::PointerIterator<NamesList::ConstIterator>
- NamesConstIterator;
+ typedef pointer_iterator<NamesList::iterator> NamesIterator;
+ typedef pointer_iterator<NamesList::const_iterator> NamesConstIterator;
typedef
- Cult::Containers::Pair <NamesConstIterator, NamesConstIterator>
+ std::pair<NamesConstIterator, NamesConstIterator>
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<Node, Edge>;
-
- 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<Belongs*>
- Classifies;
-
- typedef
- Cult::Containers::Vector<Inherits*>
- Begets;
-
- typedef
- Cult::Containers::Set<Arguments*>
- ArgumentsSet;
+ typedef std::vector<Belongs*> Classifies;
+ typedef std::vector<Inherits*> Begets;
+ typedef std::set<Arguments*> ArgumentsSet;
public:
- typedef
- Bits::PointerIterator<Classifies::ConstIterator>
- ClassifiesIterator;
+ typedef pointer_iterator<Classifies::const_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<Begets::ConstIterator>
- BegetsIterator;
+ typedef pointer_iterator<Begets::const_iterator> BegetsIterator;
BegetsIterator
begets_begin () const
@@ -670,9 +483,7 @@ namespace XSDFrontend
//
//
- typedef
- Bits::PointerIterator<ArgumentsSet::ConstIterator>
- ArgumentsIterator;
+ typedef pointer_iterator<ArgumentsSet::const_iterator> ArgumentsIterator;
ArgumentsIterator
arguments_begin () const
@@ -686,21 +497,16 @@ namespace XSDFrontend
return arguments_.end ();
}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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<Node, Edge>;
-
- Extends ()
- {
- }
};
class Restricts: public virtual Inherits
{
- protected:
- typedef
- Cult::Containers::Map<WideString, WideString>
- Facets;
-
public:
- typedef
- Facets::Iterator
- FacetIterator;
+ typedef std::map<String, String> 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<Node, Edge>;
-
- Restricts ()
+ Facets const&
+ facets () const
{
+ return facets_;
}
protected:
@@ -936,21 +710,16 @@ namespace XSDFrontend
return *namespace__;
}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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<Arguments*>
- Argumented;
+ typedef std::vector<Arguments*> Argumented;
public:
+ typedef pointer_iterator<Argumented::iterator> ArgumentedIterator;
typedef
- Bits::PointerIterator<Argumented::Iterator>
- ArgumentedIterator;
-
- typedef
- Bits::PointerIterator<Argumented::ConstIterator>
+ pointer_iterator<Argumented::const_iterator>
ArgumentedConstIterator;
ArgumentedIterator
@@ -1125,32 +887,28 @@ namespace XSDFrontend
return *argumented_[0];
}
- protected:
- friend class Bits::Graph<Node, Edge>;
-
+ 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<Node, Edge>;
-
+ public:
void
set_left_node (Type& n)
{
@@ -1205,17 +961,14 @@ namespace XSDFrontend
//
class AnyType: public virtual Type
{
- protected:
- friend class Bits::Graph<Node, Edge>;
-
- 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<Node, Edge>;
-
- 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.
};
}
}