summaryrefslogtreecommitdiff
path: root/libxsd-frontend/xsd-frontend/semantic-graph
diff options
context:
space:
mode:
Diffstat (limited to 'libxsd-frontend/xsd-frontend/semantic-graph')
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/annotation.cxx50
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/annotation.hxx89
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.cxx114
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.hxx85
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/any.cxx125
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/any.hxx90
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.cxx39
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.hxx27
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/attribute.cxx44
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/attribute.hxx39
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/complex.cxx45
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/complex.hxx78
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/compositors.cxx124
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/compositors.hxx263
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/element-group.cxx38
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/element-group.hxx45
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/element.cxx63
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/element.hxx105
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/elements.cxx350
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx1247
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/enumeration.cxx67
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/enumeration.hxx35
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/fundamental.cxx.m4216
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/fundamental.hxx.m4165
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/fundamental.m418
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/list.cxx37
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/list.hxx25
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/namespace.cxx37
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/namespace.hxx32
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/particle.cxx61
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/particle.hxx145
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/schema.cxx139
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/schema.hxx281
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/union.cxx37
-rw-r--r--libxsd-frontend/xsd-frontend/semantic-graph/union.hxx25
35 files changed, 4380 insertions, 0 deletions
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/annotation.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/annotation.cxx
new file mode 100644
index 0000000..22793f7
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/annotation.cxx
@@ -0,0 +1,50 @@
+// file : xsd-frontend/semantic-graph/annotation.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/annotation.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ // Annotates
+ //
+ namespace
+ {
+ struct AnnotatesInit
+ {
+ AnnotatesInit ()
+ {
+ TypeInfo ti (typeid (Annotates));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } annotates_init_;
+ }
+
+ // Annotation
+ //
+ namespace
+ {
+ struct AnnotationInit
+ {
+ AnnotationInit ()
+ {
+ TypeInfo ti (typeid (Annotation));
+ ti.add_base (Access::public_, true, typeid (Node));
+ RTTI::insert (ti);
+ }
+
+ } annotation_init_;
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/annotation.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/annotation.hxx
new file mode 100644
index 0000000..661ac72
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/annotation.hxx
@@ -0,0 +1,89 @@
+// file : xsd-frontend/semantic-graph/annotation.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ANNOTATION_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ANNOTATION_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ //
+ //
+ class Annotation;
+
+ class Annotates: public virtual Edge
+ {
+ public:
+ Annotation&
+ annotation ()
+ {
+ return *annotation_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Annotates ()
+ : annotation_ (0)
+ {
+ }
+
+ Void
+ set_left_node (Annotation& a)
+ {
+ annotation_ = &a;
+ }
+
+ Void
+ set_right_node (Node&)
+ {
+ }
+
+ Void
+ set_right_node (Edge&)
+ {
+ }
+
+ private:
+ Annotation* annotation_;
+ };
+
+ //
+ //
+ class Annotation: public virtual Node
+ {
+ public:
+ WideString const&
+ documentation () const
+ {
+ return documentation_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Annotation (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ WideString const& documentation)
+ : Node (file, line, column), documentation_ (documentation)
+ {
+ }
+
+ Void
+ add_edge_left (Annotates&)
+ {
+ }
+
+ private:
+ WideString documentation_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ANNOTATION_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.cxx
new file mode 100644
index 0000000..e25e742
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.cxx
@@ -0,0 +1,114 @@
+// file : xsd-frontend/semantic-graph/any-attribute.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/any-attribute.hxx>
+#include <xsd-frontend/semantic-graph/compositors.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct AnyAttributeInit
+ {
+ AnyAttributeInit ()
+ {
+ TypeInfo ti (typeid (AnyAttribute));
+ ti.add_base (Access::public_, true, typeid (Nameable));
+ RTTI::insert (ti);
+ }
+
+ } any_attribute_init_;
+ }
+
+ AnyAttribute::
+ AnyAttribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ WideString const& namespaces)
+ : Node (file, line, column),
+ prototype_ (0)
+ {
+ // Not sure if the separator is just space or any white-space
+ // chararcter.
+ //
+
+ for (Size i (0), j (namespaces.find (L' '));;)
+ {
+ if (j != WideString::npos)
+ {
+ namespaces_.push_back (WideString (namespaces, i, j - i));
+
+ i = j + 1;
+ j = namespaces.find (L' ', i);
+ }
+ else
+ {
+ // Last element.
+ //
+ namespaces_.push_back (WideString (namespaces, i));
+ break;
+ }
+ }
+ }
+
+ AnyAttribute::
+ AnyAttribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ NamespaceIterator begin,
+ NamespaceIterator end)
+ : Node (file, line, column),
+ prototype_ (0)
+ {
+ for (; begin != end; ++begin)
+ namespaces_.push_back (*begin);
+ }
+
+ namespace
+ {
+ Namespace&
+ namespace_ (Nameable& n)
+ {
+ // The basic idea goes like this: go up Names edges until you
+ // reach Namespace. There are, however, anonymous types which
+ // need special handling. In the case of an anonymous type we
+ // will go up the first Belongs edge (because the first edge
+ // is where the type was defined.
+ //
+
+ if (n.named_p ())
+ {
+ Scope& s (n.scope ());
+ Namespace* ns (dynamic_cast<Namespace*> (&n));
+
+ return ns ? *ns : namespace_ (s);
+ }
+ else
+ {
+ Type& t (dynamic_cast<Type&> (n));
+ Belongs& b (*t.classifies_begin ());
+
+ return namespace_ (b.instance ());
+ }
+ }
+ }
+
+ Namespace& AnyAttribute::
+ definition_namespace ()
+ {
+ if (prototype_p ())
+ return prototype ().definition_namespace ();
+
+ return namespace_ (scope ());
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.hxx
new file mode 100644
index 0000000..bc8c512
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/any-attribute.hxx
@@ -0,0 +1,85 @@
+// file : xsd-frontend/semantic-graph/any-attribute.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ANY_ATTRIBUTE_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ANY_ATTRIBUTE_HXX
+
+#include <cult/containers/vector.hxx>
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/namespace.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class AnyAttribute: public virtual Nameable
+ {
+ typedef
+ Cult::Containers::Vector<WideString>
+ Namespaces;
+
+ public:
+ typedef Namespaces::ConstIterator NamespaceIterator;
+
+ NamespaceIterator
+ namespace_begin () const
+ {
+ return namespaces_.begin ();
+ }
+
+ NamespaceIterator
+ namespace_end () const
+ {
+ return namespaces_.end ();
+ }
+
+ public:
+ Boolean
+ prototype_p ()
+ {
+ return prototype_ != 0;
+ }
+
+ AnyAttribute&
+ prototype ()
+ {
+ assert (prototype_ != 0);
+ return *prototype_;
+ }
+
+ Void
+ prototype (AnyAttribute& a)
+ {
+ assert (prototype_ == 0);
+ prototype_ = &a;
+ }
+
+ public:
+ Namespace&
+ definition_namespace ();
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ AnyAttribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ WideString const& namespaces);
+
+ AnyAttribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ NamespaceIterator begin,
+ NamespaceIterator end);
+
+ private:
+ AnyAttribute* prototype_;
+ Namespaces namespaces_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ANY_ATTRIBUTE_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/any.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/any.cxx
new file mode 100644
index 0000000..a6c9e72
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/any.cxx
@@ -0,0 +1,125 @@
+// file : xsd-frontend/semantic-graph/any.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/any.hxx>
+#include <xsd-frontend/semantic-graph/compositors.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct AnyInit
+ {
+ AnyInit ()
+ {
+ TypeInfo ti (typeid (Any));
+ ti.add_base (Access::public_, true, typeid (Nameable));
+ ti.add_base (Access::public_, true, typeid (Particle));
+ RTTI::insert (ti);
+ }
+
+ } any_init_;
+ }
+
+ Any::
+ Any (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ WideString const& namespaces)
+ : Node (file, line, column),
+ prototype_ (0)
+ {
+ // Not sure if the separator is just space or any white-space
+ // chararcter.
+ //
+
+ for (Size i (0), j (namespaces.find (L' '));;)
+ {
+ if (j != WideString::npos)
+ {
+ namespaces_.push_back (WideString (namespaces, i, j - i));
+
+ i = j + 1;
+ j = namespaces.find (L' ', i);
+ }
+ else
+ {
+ // Last element.
+ //
+ namespaces_.push_back (WideString (namespaces, i));
+ break;
+ }
+ }
+ }
+
+ Any::
+ Any (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ NamespaceIterator begin,
+ NamespaceIterator end)
+ : Node (file, line, column),
+ prototype_ (0)
+ {
+ for (; begin != end; ++begin)
+ namespaces_.push_back (*begin);
+ }
+
+ namespace
+ {
+ Namespace&
+ namespace_ (Nameable& n)
+ {
+ // The basic idea goes like this: go up Names edges until you
+ // reach Namespace. There are, however, anonymous types which
+ // need special handling. In the case of an anonymous type we
+ // will go up the first Belongs edge (because the first edge
+ // is where the type was defined.
+ //
+
+ if (n.named_p ())
+ {
+ Scope& s (n.scope ());
+ Namespace* ns (dynamic_cast<Namespace*> (&n));
+
+ return ns ? *ns : namespace_ (s);
+ }
+ else
+ {
+ Type& t (dynamic_cast<Type&> (n));
+ Belongs& b (*t.classifies_begin ());
+
+ return namespace_ (b.instance ());
+ }
+ }
+ }
+
+ Namespace& Any::
+ definition_namespace ()
+ {
+ if (prototype_p ())
+ return prototype ().definition_namespace ();
+
+ // Get to our scope.
+ //
+ Compositor* c (&contained_particle ().compositor ());
+
+ while(!c->contained_compositor_p ())
+ c = &c->contained_particle ().compositor ();
+
+ Scope& scope (
+ dynamic_cast<Scope&> (c->contained_compositor ().container ()));
+
+ return namespace_ (scope);
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/any.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/any.hxx
new file mode 100644
index 0000000..ded9bd8
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/any.hxx
@@ -0,0 +1,90 @@
+// file : xsd-frontend/semantic-graph/any.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ANY_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ANY_HXX
+
+#include <cult/containers/vector.hxx>
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/particle.hxx>
+#include <xsd-frontend/semantic-graph/namespace.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Any: public virtual Nameable,
+ public virtual Particle
+ {
+ typedef
+ Cult::Containers::Vector<WideString>
+ Namespaces;
+
+ public:
+ typedef Namespaces::ConstIterator NamespaceIterator;
+
+ NamespaceIterator
+ namespace_begin () const
+ {
+ return namespaces_.begin ();
+ }
+
+ NamespaceIterator
+ namespace_end () const
+ {
+ return namespaces_.end ();
+ }
+
+ public:
+ Boolean
+ prototype_p ()
+ {
+ return prototype_ != 0;
+ }
+
+ Any&
+ prototype ()
+ {
+ assert (prototype_ != 0);
+ return *prototype_;
+ }
+
+ Void
+ prototype (Any& a)
+ {
+ assert (prototype_ == 0);
+ prototype_ = &a;
+ }
+
+ public:
+ Namespace&
+ definition_namespace ();
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Any (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ WideString const& namespaces);
+
+ Any (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ NamespaceIterator begin,
+ NamespaceIterator end);
+
+ using Nameable::add_edge_right;
+ using Particle::add_edge_right;
+
+ private:
+ Any* prototype_;
+ Namespaces namespaces_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ANY_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.cxx
new file mode 100644
index 0000000..54bb5df
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.cxx
@@ -0,0 +1,39 @@
+// file : xsd-frontend/semantic-graph/attribute-group.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/attribute-group.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ namespace
+ {
+ struct AttributeGroupInit
+ {
+ AttributeGroupInit ()
+ {
+ TypeInfo ti (typeid (AttributeGroup));
+ ti.add_base (Access::public_, true, typeid (Scope));
+ RTTI::insert (ti);
+ }
+
+ } attribute_group_init_;
+ }
+
+ AttributeGroup::
+ AttributeGroup (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.hxx
new file mode 100644
index 0000000..44739f2
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/attribute-group.hxx
@@ -0,0 +1,27 @@
+// file : xsd-frontend/semantic-graph/attribute-group.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_GROUP_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_GROUP_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class AttributeGroup: public virtual Scope
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ AttributeGroup (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_GROUP_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/attribute.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/attribute.cxx
new file mode 100644
index 0000000..2e30d4e
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/attribute.cxx
@@ -0,0 +1,44 @@
+// file : xsd-frontend/semantic-graph/attribute.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/attribute.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct AttributeInit
+ {
+ AttributeInit ()
+ {
+ TypeInfo ti (typeid (Attribute));
+ ti.add_base (Access::public_, true, typeid (Member));
+ RTTI::insert (ti);
+ }
+
+ } attribute_init_;
+ }
+
+ Attribute::
+ Attribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ Boolean optional,
+ Boolean global,
+ Boolean qualified)
+ : Node (file, line, column),
+ Member (global, qualified),
+ optional_ (optional)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/attribute.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/attribute.hxx
new file mode 100644
index 0000000..f7a516d
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/attribute.hxx
@@ -0,0 +1,39 @@
+// file : xsd-frontend/semantic-graph/attribute.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Attribute: public virtual Member
+ {
+ public:
+ Boolean
+ optional_p () const
+ {
+ return optional_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Attribute (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ Boolean optional,
+ Boolean global,
+ Boolean qualified);
+ private:
+ Boolean optional_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ATTRIBUTE_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/complex.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/complex.cxx
new file mode 100644
index 0000000..0cc265f
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/complex.cxx
@@ -0,0 +1,45 @@
+// file : xsd-frontend/semantic-graph/complex.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/complex.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct ComplexInit
+ {
+ ComplexInit ()
+ {
+ TypeInfo ti (typeid (Complex));
+ ti.add_base (Access::public_, true, typeid (Type));
+ ti.add_base (Access::public_, true, typeid (Scope));
+ RTTI::insert (ti);
+ }
+
+ } complex_init_;
+ }
+
+ Complex::
+ Complex ()
+ : mixed_ (false), contains_compositor_ (0)
+ {
+ }
+
+ Complex::
+ Complex (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column),
+ mixed_ (false), contains_compositor_ (0)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/complex.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/complex.hxx
new file mode 100644
index 0000000..40327bc
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/complex.hxx
@@ -0,0 +1,78 @@
+// file : xsd-frontend/semantic-graph/complex.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_COMPLEX_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_COMPLEX_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/compositors.hxx>
+
+#include <cult/containers/vector.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Complex: public virtual Type, public virtual Scope
+ {
+ public:
+ Boolean
+ mixed_p () const
+ {
+ return mixed_;
+ }
+
+ public:
+ Boolean
+ contains_compositor_p ()
+ {
+ return contains_compositor_ != 0;
+ }
+
+ ContainsCompositor&
+ contains_compositor ()
+ {
+ assert (contains_compositor_ != 0);
+ return *contains_compositor_;
+ }
+
+ public:
+ Void
+ mixed_p (Boolean m)
+ {
+ mixed_ = m;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Complex (); // Virtual inheritance (Enumeration).
+ Complex (Path const& file, UnsignedLong line, UnsignedLong column);
+
+ using Type::add_edge_right;
+ using Type::add_edge_left;
+ using Scope::add_edge_left;
+
+ Void
+ add_edge_left (ContainsCompositor& e)
+ {
+ contains_compositor_ = &e;
+ }
+
+ Void
+ remove_edge_left (ContainsCompositor& e)
+ {
+ assert (contains_compositor_ == &e);
+ contains_compositor_ = 0;
+ }
+
+ private:
+ Boolean mixed_;
+ ContainsCompositor* contains_compositor_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_COMPLEX_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/compositors.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/compositors.cxx
new file mode 100644
index 0000000..08953bc
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/compositors.cxx
@@ -0,0 +1,124 @@
+// file : xsd-frontend/semantic-graph/compositor.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/compositors.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ // ContainsCompositor
+ //
+ namespace
+ {
+ struct ContainsCompositorInit
+ {
+ ContainsCompositorInit ()
+ {
+ TypeInfo ti (typeid (ContainsCompositor));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } contains_compositor_init_;
+ }
+
+ ContainsCompositor::
+ ContainsCompositor (UnsignedLong min, UnsignedLong max)
+ : compositor_ (0), container_ (0), min_ (min), max_ (max)
+ {
+ }
+
+ // Compositor
+ //
+ namespace
+ {
+ struct CompositorInit
+ {
+ CompositorInit ()
+ {
+ TypeInfo ti (typeid (Compositor));
+ ti.add_base (Access::public_, true, typeid (Particle));
+ RTTI::insert (ti);
+ }
+
+ } compositor_init_;
+ }
+
+
+ // All
+ //
+ namespace
+ {
+ struct AllInit
+ {
+ AllInit ()
+ {
+ TypeInfo ti (typeid (All));
+ ti.add_base (Access::public_, true, typeid (Compositor));
+ RTTI::insert (ti);
+ }
+
+ } all_init_;
+ }
+
+ All::
+ All (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+
+ // Choice
+ //
+ namespace
+ {
+ struct ChoiceInit
+ {
+ ChoiceInit ()
+ {
+ TypeInfo ti (typeid (Choice));
+ ti.add_base (Access::public_, true, typeid (Compositor));
+ RTTI::insert (ti);
+ }
+
+ } choice_init_;
+ }
+
+ Choice::
+ Choice (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+ // Sequence
+ //
+ namespace
+ {
+ struct SequenceInit
+ {
+ SequenceInit ()
+ {
+ TypeInfo ti (typeid (Sequence));
+ ti.add_base (Access::public_, true, typeid (Compositor));
+ RTTI::insert (ti);
+ }
+
+ } sequence_init_;
+ }
+
+ Sequence::
+ Sequence (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/compositors.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/compositors.hxx
new file mode 100644
index 0000000..c82d8a4
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/compositors.hxx
@@ -0,0 +1,263 @@
+// file : xsd-frontend/semantic-graph/compositors.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_COMPOSITORS_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_COMPOSITORS_HXX
+
+#include <cult/containers/list.hxx>
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/particle.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ //
+ //
+ class ContainsCompositor: public virtual Edge
+ {
+ public:
+ Compositor&
+ compositor () const
+ {
+ return *compositor_;
+ }
+
+ Node&
+ container () const
+ {
+ return *container_;
+ }
+
+ public:
+ UnsignedLong
+ min () const
+ {
+ return min_;
+ }
+
+ UnsignedLong
+ max () const
+ {
+ return max_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ ContainsCompositor (UnsignedLong min, UnsignedLong max);
+
+ Void
+ set_left_node (Node& n)
+ {
+ container_ = &n;
+ }
+
+ Void
+ set_right_node (Compositor& n)
+ {
+ compositor_ = &n;
+ }
+
+ Void
+ clear_left_node (Node& n)
+ {
+ assert (container_ == &n);
+ container_ = 0;
+ }
+
+ Void
+ clear_right_node (Compositor& n)
+ {
+ assert (compositor_ == &n);
+ compositor_ = 0;
+ }
+
+ private:
+ Compositor* compositor_;
+ Node* container_;
+ UnsignedLong min_, max_;
+ };
+
+
+ //
+ //
+ class Compositor: public virtual Particle
+ {
+ typedef
+ Cult::Containers::List<ContainsParticle*>
+ ContainsList;
+
+ public:
+ typedef
+ Bits::PointerIterator<ContainsList::Iterator>
+ ContainsIterator;
+
+ typedef
+ Bits::PointerIterator<ContainsList::ConstIterator>
+ ContainsConstIterator;
+
+ ContainsIterator
+ contains_begin ()
+ {
+ return contains_.begin ();
+ }
+
+ ContainsIterator
+ contains_end ()
+ {
+ return contains_.end ();
+ }
+
+ ContainsConstIterator
+ contains_begin () const
+ {
+ return contains_.begin ();
+ }
+
+ ContainsConstIterator
+ contains_end () const
+ {
+ return contains_.end ();
+ }
+
+ public:
+ Boolean
+ contained_compositor_p ()
+ {
+ return contained_compositor_ != 0;
+ }
+
+ ContainsCompositor&
+ contained_compositor ()
+ {
+ assert (contained_compositor_ != 0);
+ return *contained_compositor_;
+ }
+
+ public:
+ UnsignedLong
+ min () const
+ {
+ if (contained_compositor_ != 0)
+ return contained_compositor_->min ();
+ else
+ return Particle::min ();
+ }
+
+ UnsignedLong
+ max () const
+ {
+ if (contained_compositor_ != 0)
+ return contained_compositor_->max ();
+ else
+ return Particle::max ();
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Compositor ()
+ : contained_compositor_ (0)
+ {
+ }
+
+ Void
+ add_edge_left (ContainsParticle& e)
+ {
+ contains_.push_back (&e);
+ }
+
+ Void
+ remove_edge_left (ContainsParticle& e)
+ {
+ for (ContainsList::Iterator i (contains_.begin ());
+ i != contains_.end (); ++i)
+ {
+ if (*i == &e)
+ {
+ contains_.erase (i);
+ break;
+ }
+ }
+ }
+
+ //@@ 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
+ add_edge_left (ContainsParticle& e, ContainsIterator const& after)
+ {
+ if (after.base () == contains_.end ())
+ contains_.push_front (&e);
+ else
+ {
+ ContainsList::Iterator i (after.base ());
+ contains_.insert (++i, &e);
+ }
+ }
+
+ protected:
+ using Node::add_edge_right;
+ using Particle::add_edge_right;
+ using Particle::remove_edge_right;
+
+ Void
+ add_edge_right (ContainsCompositor& e)
+ {
+ contained_compositor_ = &e;
+ }
+
+ Void
+ remove_edge_right (ContainsCompositor& e)
+ {
+ assert (contained_compositor_ == &e);
+ contained_compositor_ = 0;
+ }
+
+ private:
+ ContainsList contains_;
+ ContainsCompositor* contained_compositor_;
+ };
+
+
+ //
+ //
+ class All: public virtual Compositor
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ All (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+
+
+ //
+ //
+ class Choice: public virtual Compositor
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Choice (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+
+
+ //
+ //
+ class Sequence: public virtual Compositor
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Sequence (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_COMPOSITORS_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/element-group.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/element-group.cxx
new file mode 100644
index 0000000..0e71aa6
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/element-group.cxx
@@ -0,0 +1,38 @@
+// file : xsd-frontend/semantic-graph/element-group.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/element-group.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ namespace
+ {
+ struct ElementGroupInit
+ {
+ ElementGroupInit ()
+ {
+ TypeInfo ti (typeid (ElementGroup));
+ ti.add_base (Access::public_, true, typeid (Scope));
+ RTTI::insert (ti);
+ }
+
+ } element_group_init_;
+ }
+
+ ElementGroup::
+ ElementGroup (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column), contains_compositor_ (0)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/element-group.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/element-group.hxx
new file mode 100644
index 0000000..23514b5
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/element-group.hxx
@@ -0,0 +1,45 @@
+// file : xsd-frontend/semantic-graph/element-group.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_GROUP_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_GROUP_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/compositors.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class ElementGroup: public virtual Scope
+ {
+ public:
+ ContainsCompositor&
+ contains_compositor ()
+ {
+ assert (contains_compositor_ != 0);
+ return *contains_compositor_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ ElementGroup (Path const& file, UnsignedLong line, UnsignedLong column);
+
+ using Scope::add_edge_left;
+
+ Void
+ add_edge_left (ContainsCompositor& e)
+ {
+ contains_compositor_ = &e;
+ }
+
+ private:
+ ContainsCompositor* contains_compositor_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_GROUP_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/element.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/element.cxx
new file mode 100644
index 0000000..1d8cda5
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/element.cxx
@@ -0,0 +1,63 @@
+// file : xsd-frontend/semantic-graph/element.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/element.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ // Substitutes
+ //
+ namespace
+ {
+ struct SubstitutesInit
+ {
+ SubstitutesInit ()
+ {
+ TypeInfo ti (typeid (Substitutes));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } substitutes_init_;
+ }
+
+ // Element
+ //
+ namespace
+ {
+ struct ElementInit
+ {
+ ElementInit ()
+ {
+ TypeInfo ti (typeid (Element));
+ ti.add_base (Access::public_, true, typeid (Member));
+ ti.add_base (Access::public_, true, typeid (Particle));
+ RTTI::insert (ti);
+ }
+
+ } element_init_;
+ }
+
+ Element::
+ Element (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ Boolean global,
+ Boolean qualified)
+ : Node (file, line, column),
+ Member (global, qualified),
+ substitutes_ (0)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/element.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/element.hxx
new file mode 100644
index 0000000..e7046e4
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/element.hxx
@@ -0,0 +1,105 @@
+// file : xsd-frontend/semantic-graph/element.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/particle.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Element;
+
+ class Substitutes: public virtual Edge
+ {
+ public:
+ Element&
+ substitution () const
+ {
+ return *substitution_;
+ }
+
+ Element&
+ root () const
+ {
+ return *root_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Substitutes ()
+ {
+ }
+
+ Void
+ set_left_node (Element& n)
+ {
+ substitution_ = &n;
+ }
+
+ Void
+ set_right_node (Element& n)
+ {
+ root_ = &n;
+ }
+
+ private:
+ Element* root_;
+ Element* substitution_;
+ };
+
+
+ class Element: public virtual Member,
+ public virtual Particle
+ {
+ public:
+ Boolean
+ substitutes_p () const
+ {
+ return substitutes_ != 0;
+ }
+
+ Substitutes&
+ substitutes () const
+ {
+ assert (substitutes_ != 0);
+ return *substitutes_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Element (Path const& file,
+ UnsignedLong line,
+ UnsignedLong column,
+ Boolean global,
+ Boolean qualified);
+
+ Void
+ add_edge_left (Substitutes& e)
+ {
+ substitutes_ = &e;
+ }
+
+ Void
+ add_edge_right (Substitutes&)
+ {
+ }
+
+ using Member::add_edge_left;
+ using Member::add_edge_right;
+ using Particle::add_edge_right;
+
+ private:
+ Substitutes* substitutes_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENT_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/elements.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/elements.cxx
new file mode 100644
index 0000000..6a2addf
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/elements.cxx
@@ -0,0 +1,350 @@
+// file : xsd-frontend/semantic-graph/elements.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <algorithm>
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/annotation.hxx>
+
+using namespace std;
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ // Node
+ //
+ Annotation& Node::
+ annotation ()
+ {
+ return annotates_->annotation ();
+ }
+
+ // Type
+ //
+ Void Type::
+ remove_edge_left (Arguments& a)
+ {
+ ArgumentsSet::Iterator i (arguments_.find (&a));
+ assert (i != arguments_.end ());
+ arguments_.erase (i);
+ }
+
+ // Specialization
+ //
+ Void Specialization::
+ remove_edge_right (Arguments& a)
+ {
+ // The number of entries should be small so linear search will do.
+ //
+ Argumented::Iterator i (
+ std::find (argumented_.begin (), argumented_.end (), &a));
+
+ assert (i != argumented_.end ());
+ argumented_.erase (i);
+ }
+
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ // Edge
+ //
+ struct EdgeInit
+ {
+ EdgeInit ()
+ {
+ TypeInfo ti (typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } edge_init_;
+
+
+ // Node
+ //
+ struct NodeInit
+ {
+ NodeInit ()
+ {
+ TypeInfo ti (typeid (Node));
+ RTTI::insert (ti);
+ }
+
+ } node_init_;
+
+
+ // Names
+ //
+ struct NamesInit
+ {
+ NamesInit ()
+ {
+ TypeInfo ti (typeid (Names));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } names_init_;
+
+
+ // Nameable
+ //
+ struct NameableInit
+ {
+ NameableInit ()
+ {
+ TypeInfo ti (typeid (Nameable));
+ ti.add_base (Access::public_, true, typeid (Node));
+ RTTI::insert (ti);
+ }
+
+ } nameable_init_;
+
+
+ // Scope
+ //
+ struct ScopeInit
+ {
+ ScopeInit ()
+ {
+ TypeInfo ti (typeid (Scope));
+ ti.add_base (Access::public_, true, typeid (Nameable));
+ RTTI::insert (ti);
+ }
+
+ } scope_init_;
+
+
+ // Type
+ //
+ struct TypeInit
+ {
+ TypeInit ()
+ {
+ TypeInfo ti (typeid (Type));
+ ti.add_base (Access::public_, true, typeid (Nameable));
+ RTTI::insert (ti);
+ }
+
+ } type_init_;
+
+
+ // Instance
+ //
+ struct InstanceInit
+ {
+ InstanceInit ()
+ {
+ TypeInfo ti (typeid (Instance));
+ ti.add_base (Access::public_, true, typeid (Nameable));
+ RTTI::insert (ti);
+ }
+
+ } instance_init_;
+
+
+ // Belongs
+ //
+ struct BelongsInit
+ {
+ BelongsInit ()
+ {
+ TypeInfo ti (typeid (Belongs));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } belongs_init_;
+
+
+
+ // Inherits
+ //
+ struct InheritsInit
+ {
+ InheritsInit ()
+ {
+ TypeInfo ti (typeid (Inherits));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } inherits_init_;
+
+
+ // Extends
+ //
+ struct ExtendsInit
+ {
+ ExtendsInit ()
+ {
+ TypeInfo ti (typeid (Extends));
+ ti.add_base (Access::public_, true, typeid (Inherits));
+ RTTI::insert (ti);
+ }
+
+ } extends_init_;
+
+
+ // Restricts
+ //
+ struct RestrictsInit
+ {
+ RestrictsInit ()
+ {
+ TypeInfo ti (typeid (Restricts));
+ ti.add_base (Access::public_, true, typeid (Inherits));
+ RTTI::insert (ti);
+ }
+
+ } restricts_init_;
+
+
+ // BelongsToNamespace
+ //
+ struct BelongsToNamespaceInit
+ {
+ BelongsToNamespaceInit ()
+ {
+ TypeInfo ti (typeid (BelongsToNamespace));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } belongs_to_namespace_init_;
+
+
+ // Member
+ //
+ struct MemberInit
+ {
+ MemberInit ()
+ {
+ TypeInfo ti (typeid (Member));
+ ti.add_base (Access::public_, true, typeid (Instance));
+ RTTI::insert (ti);
+ }
+
+ } member_init_;
+
+
+ // Specialization
+ //
+ struct SpecializationInit
+ {
+ SpecializationInit ()
+ {
+ TypeInfo ti (typeid (Specialization));
+ ti.add_base (Access::public_, true, typeid (Type));
+ RTTI::insert (ti);
+ }
+
+ } specialization_init_;
+
+
+ // Arguments
+ //
+ struct ArgumentsInit
+ {
+ ArgumentsInit ()
+ {
+ TypeInfo ti (typeid (Arguments));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } arguments_init_;
+
+
+ /*
+ // Contains
+ //
+ struct ContainsInit
+ {
+ ContainsInit ()
+ {
+ TypeInfo ti (typeid (Contains));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } contains_init_;
+
+
+ // Container
+ //
+ struct ContainerInit
+ {
+ ContainerInit ()
+ {
+ TypeInfo ti (typeid (Container));
+ ti.add_base (Access::public_, true, typeid (Node));
+ RTTI::insert (ti);
+ }
+
+ } container_init_;
+ */
+
+
+ // AnyType
+ //
+ namespace
+ {
+ struct AnyTypeInit
+ {
+ AnyTypeInit ()
+ {
+ TypeInfo ti (typeid (AnyType));
+ ti.add_base (Access::public_, true, typeid (SemanticGraph::Type));
+ RTTI::insert (ti);
+ }
+
+ } any_type_init_;
+ }
+
+
+ // AnySimpleType
+ //
+ namespace
+ {
+ struct AnySimpleTypeInit
+ {
+ AnySimpleTypeInit ()
+ {
+ TypeInfo ti (typeid (AnySimpleType));
+ ti.add_base (Access::public_, true, typeid (Type));
+ RTTI::insert (ti);
+ }
+
+ } any_simple_type_init_;
+ }
+ }
+
+
+ // Instance
+ //
+ Type& Instance::
+ type () const
+ {
+ return belongs ().type ();
+ }
+ }
+}
+
+// Path
+//
+std::wostream&
+operator<< (std::wostream& os, XSDFrontend::SemanticGraph::Path const& path)
+{
+#if !defined(BOOST_FILESYSTEM_VERSION) || BOOST_FILESYSTEM_VERSION == 2
+ return os << path.native_file_string ().c_str ();
+#else
+ return os << path.string ().c_str ();
+#endif
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx
new file mode 100644
index 0000000..78b6615
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/elements.hxx
@@ -0,0 +1,1247 @@
+// file : xsd-frontend/semantic-graph/elements.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 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 <iosfwd>
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/exception.hpp>
+
+#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>
+
+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;
+ }
+
+ 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 ();
+ }
+ }
+
+ //
+ //
+ typedef
+ boost::filesystem::filesystem_error
+ InvalidPath;
+
+ typedef
+ boost::filesystem::path
+ Path;
+
+ typedef
+ Cult::Containers::Vector<Path>
+ Paths;
+
+ typedef
+ FrontendElements::Context
+ Context;
+
+ //
+ //
+ class Node;
+ class Edge;
+
+ //
+ //
+ class Annotates;
+ class Annotation;
+
+ //
+ //
+ class Edge
+ {
+ public:
+ Context&
+ context () const
+ {
+ return context_;
+ }
+
+ virtual
+ ~Edge ()
+ {
+ }
+
+ public:
+ template <typename X>
+ Boolean
+ is_a () const
+ {
+ return dynamic_cast<X const*> (this) != 0;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Edge ()
+ {
+ }
+
+ private:
+ mutable Context context_;
+ };
+
+ inline Boolean
+ operator== (Edge const& x, Edge const& y)
+ {
+ return &x == &y;
+ }
+
+
+ //
+ //
+ class Node
+ {
+ public:
+ Context&
+ context () const
+ {
+ return context_;
+ }
+
+ public:
+ Path const&
+ file () const
+ {
+ return file_;
+ }
+
+ UnsignedLong
+ line () const
+ {
+ return line_;
+ }
+
+ UnsignedLong
+ column () const
+ {
+ return column_;
+ }
+
+ public:
+ Boolean
+ annotated_p () const
+ {
+ return annotates_ != 0;
+ }
+
+ Annotates&
+ annotated () const
+ {
+ return *annotates_;
+ }
+
+ Annotation&
+ annotation ();
+
+ public:
+ template <typename X>
+ Boolean
+ is_a () const
+ {
+ return dynamic_cast<X const*> (this) != 0;
+ }
+
+ public:
+
+ virtual
+ ~Node ()
+ {
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Node (Path const& file, UnsignedLong line, UnsignedLong column)
+ : annotates_ (0), file_ (file), line_ (line), column_ (column)
+ {
+ }
+
+ Node () // For virtual inheritance.
+ {
+ abort (); // Told you so!
+ }
+
+ Void
+ add_edge_right (Annotates& a)
+ {
+ annotates_ = &a;
+ }
+
+ private:
+ mutable Context context_;
+ Annotates* annotates_;
+ Path file_;
+ UnsignedLong line_;
+ UnsignedLong column_;
+ };
+
+ inline Boolean
+ operator== (Node const& x, Node const& y)
+ {
+ return &x == &y;
+ }
+
+
+ //
+ //
+ typedef WideString Name;
+
+
+ //
+ //
+ class Scope;
+ class Nameable;
+
+
+ //
+ //
+ class Names: public virtual Edge
+ {
+ public:
+ Name
+ name () const
+ {
+ return name_;
+ }
+
+ Scope&
+ scope () const
+ {
+ return *scope_;
+ }
+
+ Nameable&
+ named () const
+ {
+ return *named_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Names (Name const& name)
+ : name_ (name)
+ {
+ }
+
+ Void
+ set_left_node (Scope& n)
+ {
+ scope_ = &n;
+ }
+
+ Void
+ set_right_node (Nameable& n)
+ {
+ named_ = &n;
+ }
+
+ Void
+ clear_left_node (Scope& n)
+ {
+ assert (scope_ == &n);
+ scope_ = 0;
+ }
+
+ Void
+ clear_right_node (Nameable& n)
+ {
+ assert (named_ == &n);
+ named_ = 0;
+ }
+
+ private:
+ Scope* scope_;
+ Nameable* named_;
+ Name name_;
+ };
+
+
+ class Nameable: public virtual Node
+ {
+ public:
+ Boolean
+ named_p () const
+ {
+ return named_ != 0;
+ }
+
+ Name
+ name () const
+ {
+ assert (named_p ());
+ return named_->name ();
+ }
+
+ Scope&
+ scope ()
+ {
+ assert (named_p ());
+ return named_->scope ();
+ }
+
+ Names&
+ named ()
+ {
+ assert (named_p ());
+ return *named_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Nameable ()
+ : named_ (0)
+ {
+ }
+
+ Void
+ add_edge_right (Names& e)
+ {
+ named_ = &e;
+ }
+
+ Void
+ remove_edge_right (Names& e)
+ {
+ assert (named_ == &e);
+ named_ = 0;
+ }
+
+ using Node::add_edge_right;
+
+ private:
+ Names* named_;
+ };
+
+
+ //
+ //
+ typedef
+ Cult::Containers::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;
+
+ public:
+ typedef
+ Bits::PointerIterator<NamesList::Iterator>
+ NamesIterator;
+
+ typedef
+ Bits::PointerIterator<NamesList::ConstIterator>
+ NamesConstIterator;
+
+ typedef
+ Cult::Containers::Pair <NamesConstIterator, NamesConstIterator>
+ NamesIteratorPair;
+
+ NamesIterator
+ names_begin ()
+ {
+ return names_.begin ();
+ }
+
+ NamesIterator
+ names_end ()
+ {
+ return names_.end ();
+ }
+
+ NamesConstIterator
+ names_begin () const
+ {
+ return names_.begin ();
+ }
+
+ NamesConstIterator
+ names_end () const
+ {
+ return names_.end ();
+ }
+
+ virtual NamesIteratorPair
+ find (Name const& name) const
+ {
+ NamesMap::ConstIterator i (names_map_.find (name));
+
+ if (i == names_map_.end ())
+ return NamesIteratorPair (names_.end (), names_.end ());
+ else
+ return NamesIteratorPair (i->second.begin (), i->second.end ());
+ }
+
+ NamesIterator
+ find (Names& 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)
+ : Node (file, line, column)
+ {
+ }
+
+ Scope ()
+ {
+ }
+
+ Void
+ add_edge_left (Names& e)
+ {
+ NamesList::Iterator i (names_.insert (names_.end (), &e));
+ iterator_map_[&e] = i;
+ names_map_[e.name ()].push_back (&e);
+ }
+
+ Void
+ remove_edge_left (Names& 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 ()));
+
+ for (NamesList::Iterator i (j->second.begin ());
+ i != j->second.end (); ++i)
+ {
+ if (*i == &e)
+ i = j->second.erase (i);
+ }
+ }
+
+ //@@ 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
+ add_edge_left (Names& e, NamesIterator const& after)
+ {
+ NamesList::Iterator i;
+
+ if (after.base () == names_.end ())
+ i = names_.insert (names_.begin (), &e);
+ else
+ {
+ NamesList::Iterator j (after.base ());
+ i = names_.insert (++j, &e);
+ }
+
+ iterator_map_[&e] = i;
+ names_map_[e.name ()].push_back (&e);
+ }
+
+ protected:
+ using Nameable::add_edge_right;
+
+ private:
+ NamesList names_;
+ ListIteratorMap iterator_map_;
+ NamesMap names_map_;
+ };
+
+
+ //
+ //
+ class Belongs;
+ class Inherits;
+ class Arguments;
+
+ class Type: public virtual Nameable
+ {
+ protected:
+ typedef
+ Cult::Containers::Vector<Belongs*>
+ Classifies;
+
+ typedef
+ Cult::Containers::Vector<Inherits*>
+ Begets;
+
+ typedef
+ Cult::Containers::Set<Arguments*>
+ ArgumentsSet;
+
+ public:
+ typedef
+ Bits::PointerIterator<Classifies::ConstIterator>
+ ClassifiesIterator;
+
+ ClassifiesIterator
+ classifies_begin () const
+ {
+ return classifies_.begin ();
+ }
+
+ ClassifiesIterator
+ classifies_end () const
+ {
+ return classifies_.end ();
+ }
+
+ //
+ //
+ Boolean
+ inherits_p () const
+ {
+ return inherits_ != 0;
+ }
+
+ Inherits&
+ inherits () const
+ {
+ assert (inherits_ != 0);
+ return *inherits_;
+ }
+
+ //
+ //
+ typedef
+ Bits::PointerIterator<Begets::ConstIterator>
+ BegetsIterator;
+
+ BegetsIterator
+ begets_begin () const
+ {
+ return begets_.begin ();
+ }
+
+ BegetsIterator
+ begets_end () const
+ {
+ return begets_.end ();
+ }
+
+ //
+ //
+ typedef
+ Bits::PointerIterator<ArgumentsSet::ConstIterator>
+ ArgumentsIterator;
+
+ ArgumentsIterator
+ arguments_begin () const
+ {
+ return arguments_.begin ();
+ }
+
+ ArgumentsIterator
+ arguments_end () const
+ {
+ return arguments_.end ();
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Type ()
+ : inherits_ (0)
+ {
+ }
+
+ Void
+ add_edge_right (Belongs& e)
+ {
+ classifies_.push_back (&e);
+ }
+
+ Void
+ add_edge_right (Inherits& e)
+ {
+ begets_.push_back (&e);
+ }
+
+ using Nameable::add_edge_right;
+
+ Void
+ add_edge_left (Arguments& a)
+ {
+ arguments_.insert (&a);
+ }
+
+ Void
+ remove_edge_left (Arguments&);
+
+ Void
+ add_edge_left (Inherits& e)
+ {
+ inherits_ = &e;
+ }
+
+ private:
+ Inherits* inherits_;
+ Begets begets_;
+ Classifies classifies_;
+ ArgumentsSet arguments_;
+ };
+
+
+ class Instance: public virtual Nameable
+ {
+ public:
+ Belongs&
+ belongs () const
+ {
+ return *belongs_;
+ }
+
+ Type&
+ type () const;
+
+ Boolean
+ typed_p () const
+ {
+ return belongs_ != 0;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Instance ()
+ : belongs_ (0)
+ {
+ }
+
+ Void
+ add_edge_left (Belongs& e)
+ {
+ belongs_ = &e;
+ }
+
+ private:
+ Belongs* belongs_;
+ };
+
+
+ class Belongs: public virtual Edge
+ {
+ public:
+ Instance&
+ instance () const
+ {
+ return *instance_;
+ }
+
+ Type&
+ type () const
+ {
+ return *type_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Belongs ()
+ {
+ }
+
+ Void
+ set_left_node (Instance& n)
+ {
+ instance_ = &n;
+ }
+
+ Void
+ set_right_node (Type& n)
+ {
+ type_ = &n;
+ }
+
+ private:
+ Instance* instance_;
+ Type* type_;
+ };
+
+
+ //
+ //
+ class Inherits: public virtual Edge
+ {
+ public:
+ Type&
+ base () const
+ {
+ return *base_;
+ }
+
+ Type&
+ derived () const
+ {
+ return *derived_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Inherits ()
+ {
+ }
+
+ Void
+ set_left_node (Type& n)
+ {
+ derived_ = &n;
+ }
+
+ Void
+ set_right_node (Type& n)
+ {
+ base_ = &n;
+ }
+
+ private:
+ Type* base_;
+ 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;
+
+ Boolean
+ facet_empty ()
+ {
+ return facets_.empty ();
+ }
+
+ FacetIterator
+ facet_begin ()
+ {
+ return facets_.begin ();
+ }
+
+ FacetIterator
+ facet_end ()
+ {
+ return facets_.end ();
+ }
+
+ FacetIterator
+ facet_find (WideString const& name)
+ {
+ return facets_.find (name);
+ }
+
+ Void
+ facet_insert (String const& name, String const& value)
+ {
+ facets_[name] = value;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Restricts ()
+ {
+ }
+
+ protected:
+ Facets facets_;
+ };
+
+
+ //
+ //
+ class Member;
+ class Namespace;
+
+ class BelongsToNamespace: public virtual Edge
+ {
+ public:
+ Member&
+ member () const
+ {
+ assert (member_ != 0);
+ return *member_;
+ }
+
+ Namespace&
+ namespace_ () const
+ {
+ assert (namespace__ != 0);
+ return *namespace__;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ BelongsToNamespace ()
+ : member_ (0), namespace__ (0)
+ {
+ }
+
+ Void
+ set_left_node (Member& n)
+ {
+ member_ = &n;
+ }
+
+ Void
+ set_right_node (Namespace& n)
+ {
+ namespace__ = &n;
+ }
+
+ private:
+ Member* member_;
+ Namespace* namespace__;
+ };
+
+ //
+ //
+ class Member: public virtual Instance
+ {
+ public:
+ // Member is global either if it is defined outside any type
+ // or it is a ref="" of a global member.
+ //
+ Boolean
+ global_p () const
+ {
+ return global_;
+ }
+
+ Boolean
+ qualified_p () const
+ {
+ return qualified_;
+ }
+
+ // Note that only qualified members belong to a namespace.
+ //
+ Namespace&
+ namespace_ () const
+ {
+ assert (belongs_to_namespace_ != 0);
+ return belongs_to_namespace_->namespace_ ();
+ }
+
+
+ // Default and fixed value API. Note that the fixed value semantics
+ // is a superset of the default value semantics. As such setting the
+ // fixed value appears as if the default value was also set.
+ //
+ Boolean
+ default_p () const
+ {
+ return value_type_ != ValueType::none;
+ }
+
+ Boolean
+ fixed_p () const
+ {
+ return value_type_ == ValueType::fixed;
+ }
+
+ struct NoValue {};
+
+ WideString
+ value () const
+ {
+ if (value_type_ != ValueType::none)
+ return value_;
+ else
+ throw NoValue ();
+ }
+
+ //
+ //
+ Void
+ default_ (WideString const& v)
+ {
+ value_ = v;
+ value_type_ = ValueType::default_;
+ }
+
+ Void
+ fixed (WideString const& v)
+ {
+ value_ = v;
+ value_type_ = ValueType::fixed;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Member (Boolean global, Boolean qualified)
+ : global_ (global),
+ qualified_ (qualified),
+ belongs_to_namespace_ (0),
+ value_type_ (ValueType::none)
+ {
+ }
+
+ Void
+ add_edge_left (BelongsToNamespace& e)
+ {
+ // In the parser we sometimes re-add the same adge.
+ //
+ belongs_to_namespace_ = &e;
+ }
+
+ using Instance::add_edge_left;
+
+ private:
+ Boolean global_;
+ Boolean qualified_;
+ BelongsToNamespace* belongs_to_namespace_;
+
+ struct ValueType
+ {
+ enum Value
+ {
+ none,
+ default_,
+ fixed
+ };
+ };
+
+ WideString value_;
+ ValueType::Value value_type_;
+ };
+
+
+ // Parametric types.
+ //
+
+ class Specialization: public virtual Type
+ {
+ typedef
+ Cult::Containers::Vector<Arguments*>
+ Argumented;
+
+ public:
+ typedef
+ Bits::PointerIterator<Argumented::Iterator>
+ ArgumentedIterator;
+
+ typedef
+ Bits::PointerIterator<Argumented::ConstIterator>
+ ArgumentedConstIterator;
+
+ ArgumentedIterator
+ argumented_begin ()
+ {
+ return argumented_.begin ();
+ }
+
+ ArgumentedConstIterator
+ argumented_begin () const
+ {
+ return argumented_.begin ();
+ }
+
+ ArgumentedIterator
+ argumented_end ()
+ {
+ return argumented_.end ();
+ }
+
+ ArgumentedConstIterator
+ argumented_end () const
+ {
+ return argumented_.end ();
+ }
+
+ // Shortcut for one-argument specializations.
+ //
+ Arguments&
+ argumented () const
+ {
+ return *argumented_[0];
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ using Type::add_edge_right;
+
+ Void
+ add_edge_right (Arguments& a)
+ {
+ argumented_.push_back (&a);
+ }
+
+ Void
+ remove_edge_right (Arguments&);
+
+ public:
+ Void
+ add_edge_right (Arguments& a, ArgumentedIterator const& pos)
+ {
+ argumented_.insert (pos.base (), &a);
+ }
+
+ private:
+ Argumented argumented_;
+ };
+
+
+ class Arguments: public virtual Edge
+ {
+ public:
+ Type&
+ type () const
+ {
+ return *type_;
+ }
+
+ Specialization&
+ specialization () const
+ {
+ return *specialization_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ void
+ set_left_node (Type& n)
+ {
+ type_ = &n;
+ }
+
+ void
+ clear_left_node (Type& n)
+ {
+ assert (type_ == &n);
+ type_ = 0;
+ }
+
+ void
+ set_right_node (Specialization& s)
+ {
+ specialization_ = &s;
+ }
+
+ void
+ clear_right_node (Specialization& s)
+ {
+ assert (specialization_ == &s);
+ specialization_ = 0;
+ }
+
+ private:
+ Type* type_;
+ Specialization* specialization_;
+ };
+
+
+ //
+ //
+ class AnyType: public virtual Type
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ AnyType (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+ AnyType () // For virtual inheritance.
+ {
+ }
+ };
+
+
+ //
+ //
+ class AnySimpleType: public virtual Type
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ AnySimpleType (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+ AnySimpleType () // For virtual inheritance.
+ {
+ }
+ };
+ }
+}
+
+// ADL won't find it because Path is a typedef. Note that this
+// function prints in native format.
+//
+std::wostream&
+operator<< (std::wostream& os, XSDFrontend::SemanticGraph::Path const& path);
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ELEMENTS_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.cxx
new file mode 100644
index 0000000..adcf71e
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.cxx
@@ -0,0 +1,67 @@
+// file : xsd-frontend/semantic-graph/enumeration.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/enumeration.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ // Enumeration
+ //
+ struct EnumerationInit
+ {
+ EnumerationInit ()
+ {
+ TypeInfo ti (typeid (Enumeration));
+ ti.add_base (Access::public_, true, typeid (Complex));
+ RTTI::insert (ti);
+ }
+
+ } enumeration_init_;
+
+
+ // Enumerator
+ //
+ struct EnumeratorInit
+ {
+ EnumeratorInit ()
+ {
+ TypeInfo ti (typeid (Enumerator));
+ ti.add_base (Access::public_, true, typeid (Instance));
+ RTTI::insert (ti);
+ }
+
+ } enumerator_init_;
+ }
+
+
+ // Enumeration
+ //
+
+ Enumeration::
+ Enumeration (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+
+ // Enumerator
+ //
+
+ Enumerator::
+ Enumerator (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.hxx
new file mode 100644
index 0000000..a21e8f3
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/enumeration.hxx
@@ -0,0 +1,35 @@
+// file : xsd-frontend/semantic-graph/enumeration.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_ENUMERATION_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_ENUMERATION_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/complex.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Enumeration: public virtual Complex
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Enumeration (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+
+
+ class Enumerator: public virtual Instance
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Enumerator (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_ENUMERATION_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.cxx.m4 b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.cxx.m4
new file mode 100644
index 0000000..cc1316c
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.cxx.m4
@@ -0,0 +1,216 @@
+divert(-1)
+
+# file : xsd-frontend/semantic-graph/fundamental.cxx.m4
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include(`fundamental.m4')
+
+define(`fundamental_type',
+ `fundamental_type_impl(`make_class_name(`$1')', `make_var_name(`$1')')')
+
+
+define(`fundamental_type_impl', `
+
+ // $1
+ //
+ namespace
+ {
+ struct $1Init
+ {
+ $1Init ()
+ {
+ TypeInfo ti (typeid ($1));
+ ti.add_base (Access::public_, true, typeid (Type));
+ RTTI::insert (ti);
+ }
+
+ } $2_init_;
+ }
+
+ $1::
+ $1 (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }')
+
+divert(0)dnl
+dnl
+dnl
+dnl
+// file : xsd-frontend/semantic-graph/fundamental.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Note, that this file is automatically generated!
+//
+
+#include <xsd-frontend/semantic-graph/fundamental.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace Fundamental
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+
+ // Type
+ //
+ namespace
+ {
+ struct TypeInit
+ {
+ TypeInit ()
+ {
+ TypeInfo ti (typeid (Type));
+ ti.add_base (Access::public_, true, typeid (SemanticGraph::Type));
+ RTTI::insert (ti);
+ }
+
+ } any_type_init_;
+ }
+
+ Type::
+ Type ()
+ {
+ }
+dnl
+dnl Integers.
+dnl
+fundamental_type(`byte')
+fundamental_type(`unsigned byte')
+fundamental_type(`short')
+fundamental_type(`unsigned short')
+fundamental_type(`int')
+fundamental_type(`unsigned int')
+fundamental_type(`long')
+fundamental_type(`unsigned long')
+fundamental_type(`integer')
+fundamental_type(`non positive integer')
+fundamental_type(`non negative integer')
+fundamental_type(`positive integer')
+fundamental_type(`negative integer')
+dnl
+dnl Boolean.
+dnl
+fundamental_type(`boolean')
+dnl
+dnl Floats.
+dnl
+fundamental_type(`float')
+fundamental_type(`double')
+fundamental_type(`decimal')
+dnl
+dnl Strings.
+dnl
+fundamental_type(`string')
+fundamental_type(`normalized string')
+fundamental_type(`token')
+fundamental_type(`name')
+fundamental_type(`name token')
+fundamental_type(`name tokens')
+fundamental_type(`NC name')
+fundamental_type(`language')
+dnl
+dnl Qualified name.
+dnl
+fundamental_type(`q name')
+dnl
+dnl ID/IDREF.
+dnl
+fundamental_type(`id')
+
+
+ // IdRef
+ //
+ namespace
+ {
+ struct IdRefInit
+ {
+ IdRefInit ()
+ {
+ TypeInfo ti (typeid (IdRef));
+ ti.add_base (Access::public_, true, typeid (Type));
+ ti.add_base (Access::public_, true, typeid (Specialization));
+ RTTI::insert (ti);
+ }
+
+ } id_ref_init_;
+ }
+
+ IdRef::
+ IdRef (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+
+
+ // IdRefs
+ //
+ namespace
+ {
+ struct IdRefsInit
+ {
+ IdRefsInit ()
+ {
+ TypeInfo ti (typeid (IdRefs));
+ ti.add_base (Access::public_, true, typeid (Type));
+ ti.add_base (Access::public_, true, typeid (Specialization));
+ RTTI::insert (ti);
+ }
+
+ } id_refs_init_;
+ }
+
+ IdRefs::
+ IdRefs (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+dnl
+dnl URI.
+dnl
+fundamental_type(`any URI')
+dnl
+dnl Binary.
+dnl
+fundamental_type(`base 64 binary')
+fundamental_type(`hex binary')
+dnl
+dnl Date/time.
+dnl
+fundamental_type(`date')
+fundamental_type(`date time')
+fundamental_type(`duration')
+fundamental_type(`day')
+fundamental_type(`month')
+fundamental_type(`month day')
+fundamental_type(`year')
+fundamental_type(`year month')
+fundamental_type(`time')
+dnl
+dnl Entity.
+dnl
+fundamental_type(`entity')
+fundamental_type(`entities')
+dnl
+dnl Notation.
+dnl
+fundamental_type(`notation')
+dnl
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.hxx.m4 b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.hxx.m4
new file mode 100644
index 0000000..f5a88a9
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.hxx.m4
@@ -0,0 +1,165 @@
+divert(-1)
+
+# file : xsd-frontend/semantic-graph/fundamental.hxx.m4
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include(`fundamental.m4')
+
+define(`fundamental_type', `fundamental_type_impl(`make_class_name(`$1')', `$1')')
+
+define(`fundamental_type_impl', `
+
+ //
+ //
+ class $1: public virtual Type
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ $1 (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column);
+ };')
+divert(0)dnl
+dnl
+dnl
+dnl
+// file : xsd-frontend/semantic-graph/fundamental.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Note, that this file is automatically generated!
+//
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_FUNDAMENTAL_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_FUNDAMENTAL_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace Fundamental
+ {
+ //
+ //
+ class Type: public virtual SemanticGraph::Type
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Type ();
+ };
+dnl
+dnl Integers.
+dnl
+fundamental_type(`byte')
+fundamental_type(`unsigned byte')
+fundamental_type(`short')
+fundamental_type(`unsigned short')
+fundamental_type(`int')
+fundamental_type(`unsigned int')
+fundamental_type(`long')
+fundamental_type(`unsigned long')
+fundamental_type(`integer')
+fundamental_type(`non positive integer')
+fundamental_type(`non negative integer')
+fundamental_type(`positive integer')
+fundamental_type(`negative integer')
+dnl
+dnl Boolean.
+dnl
+fundamental_type(`boolean')
+dnl
+dnl Floats.
+dnl
+fundamental_type(`float')
+fundamental_type(`double')
+fundamental_type(`decimal')
+dnl
+dnl Strings.
+dnl
+fundamental_type(`string')
+fundamental_type(`normalized string')
+fundamental_type(`token')
+fundamental_type(`name')
+fundamental_type(`name token')
+fundamental_type(`name tokens')
+fundamental_type(`NC name')
+fundamental_type(`language')
+dnl
+dnl Qualified name.
+dnl
+fundamental_type(`q name')
+dnl
+dnl ID/IDREF.
+dnl
+fundamental_type(`id')
+
+
+ //
+ //
+ class IdRef: public virtual Type,
+ public virtual Specialization
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ IdRef (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column);
+ };
+
+
+ //
+ //
+ class IdRefs: public virtual Type,
+ public virtual Specialization
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ IdRefs (Path const& file,
+ SemanticGraph::UnsignedLong line,
+ SemanticGraph::UnsignedLong column);
+ };
+dnl
+dnl URI.
+dnl
+fundamental_type(`any URI')
+dnl
+dnl Binary.
+dnl
+fundamental_type(`base 64 binary')
+fundamental_type(`hex binary')
+dnl
+dnl Date/time.
+dnl
+fundamental_type(`date')
+fundamental_type(`date time')
+fundamental_type(`duration')
+fundamental_type(`day')
+fundamental_type(`month')
+fundamental_type(`month day')
+fundamental_type(`year')
+fundamental_type(`year month')
+fundamental_type(`time')
+dnl
+dnl Entity.
+dnl
+fundamental_type(`entity')
+fundamental_type(`entities')
+dnl
+dnl Notation.
+dnl
+fundamental_type(`notation')
+dnl
+ }
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_FUNDAMENTAL_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.m4 b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.m4
new file mode 100644
index 0000000..735b35d
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/fundamental.m4
@@ -0,0 +1,18 @@
+# file : xsd-frontend/semantic-graph/fundamental.m4
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+define(`upcase', `translit(`$*', `a-z', `A-Z')')
+
+
+define(`capitalize_word',
+ `regexp(`$1', `^\(.\)\(.*\)', `upcase(`\1')`\2'')')
+
+
+define(`capitalize',
+ `patsubst(`$1', `\w+', `capitalize_word(`\&')')')
+
+define(`make_class_name', `patsubst(capitalize(`$1'), ` ')')
+
+define(`make_var_name', `patsubst(`$1', ` ', `_')')
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/list.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/list.cxx
new file mode 100644
index 0000000..3184041
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/list.cxx
@@ -0,0 +1,37 @@
+// file : xsd-frontend/semantic-graph/list.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/list.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct ListInit
+ {
+ ListInit ()
+ {
+ TypeInfo ti (typeid (List));
+ ti.add_base (Access::public_, true, typeid (Specialization));
+ RTTI::insert (ti);
+ }
+
+ } list_init_;
+ }
+
+ List::
+ List (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/list.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/list.hxx
new file mode 100644
index 0000000..3ba0c02
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/list.hxx
@@ -0,0 +1,25 @@
+// file : xsd-frontend/semantic-graph/list.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_LIST_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_LIST_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class List: public virtual Specialization
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ List (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_LIST_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/namespace.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/namespace.cxx
new file mode 100644
index 0000000..789b5d8
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/namespace.cxx
@@ -0,0 +1,37 @@
+// file : xsd-frontend/semantic-graph/namespace.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/namespace.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct NamespaceInit
+ {
+ NamespaceInit ()
+ {
+ TypeInfo ti (typeid (Namespace));
+ ti.add_base (Access::public_, true, typeid (Scope));
+ RTTI::insert (ti);
+ }
+
+ } namespace_init_;
+ }
+
+ Namespace::
+ Namespace (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/namespace.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/namespace.hxx
new file mode 100644
index 0000000..25bd1c0
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/namespace.hxx
@@ -0,0 +1,32 @@
+// file : xsd-frontend/semantic-graph/namespace.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_NAMESPACE_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_NAMESPACE_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Namespace : public virtual Scope
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Namespace (Path const& file, UnsignedLong line, UnsignedLong column);
+
+ Void
+ add_edge_right (BelongsToNamespace&)
+ {
+ }
+
+ using Scope::add_edge_right;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_NAMESPACE_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/particle.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/particle.cxx
new file mode 100644
index 0000000..f8c93de
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/particle.cxx
@@ -0,0 +1,61 @@
+// file : xsd-frontend/semantic-graph/particle.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/particle.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ // ContainsParticle
+ //
+ namespace
+ {
+ struct ContainsParticleInit
+ {
+ ContainsParticleInit ()
+ {
+ TypeInfo ti (typeid (ContainsParticle));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } contains_particle_init_;
+ }
+
+ ContainsParticle::
+ ContainsParticle (UnsignedLong min, UnsignedLong max)
+ : particle_ (0), compositor_ (0), min_ (min), max_ (max)
+ {
+ }
+
+ // Particle
+ //
+ namespace
+ {
+ struct ParticleInit
+ {
+ ParticleInit ()
+ {
+ TypeInfo ti (typeid (Particle));
+ ti.add_base (Access::public_, true, typeid (Node));
+ RTTI::insert (ti);
+ }
+
+ } particle_init_;
+ }
+
+ Particle::
+ Particle ()
+ : contained_particle_ (0)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/particle.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/particle.hxx
new file mode 100644
index 0000000..df48de4
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/particle.hxx
@@ -0,0 +1,145 @@
+// file : xsd-frontend/semantic-graph/particle.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_PARTICLE_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_PARTICLE_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ //
+ //
+ class Particle;
+ class Compositor;
+
+
+ //
+ //
+ class ContainsParticle: public virtual Edge
+ {
+ public:
+ Particle&
+ particle () const
+ {
+ return *particle_;
+ }
+
+ Compositor&
+ compositor () const
+ {
+ return *compositor_;
+ }
+
+ public:
+ UnsignedLong
+ min () const
+ {
+ return min_;
+ }
+
+ UnsignedLong
+ max () const
+ {
+ return max_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ ContainsParticle (UnsignedLong min, UnsignedLong max);
+
+ Void
+ set_left_node (Compositor& n)
+ {
+ compositor_ = &n;
+ }
+
+ Void
+ set_right_node (Particle& n)
+ {
+ particle_ = &n;
+ }
+
+ Void
+ clear_left_node (Compositor& n)
+ {
+ assert (compositor_ == &n);
+ compositor_ = 0;
+ }
+
+ Void
+ clear_right_node (Particle& n)
+ {
+ assert (particle_ == &n);
+ particle_ = 0;
+ }
+
+ private:
+ Particle* particle_;
+ Compositor* compositor_;
+ UnsignedLong min_, max_;
+ };
+
+ //
+ //
+ class Particle: public virtual Node
+ {
+ public:
+ Boolean
+ contained_particle_p ()
+ {
+ return contained_particle_ != 0;
+ }
+
+ ContainsParticle&
+ contained_particle ()
+ {
+ assert (contained_particle_ != 0);
+ return *contained_particle_;
+ }
+
+ public:
+ UnsignedLong
+ min () const
+ {
+ assert (contained_particle_ != 0);
+ return contained_particle_->min ();
+ }
+
+ UnsignedLong
+ max () const
+ {
+ assert (contained_particle_ != 0);
+ return contained_particle_->max ();
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Particle ();
+
+ Void
+ add_edge_right (ContainsParticle& e)
+ {
+ contained_particle_ = &e;
+ }
+
+ Void
+ remove_edge_right (ContainsParticle& e)
+ {
+ assert (contained_particle_ == &e);
+ contained_particle_ = 0;
+ }
+
+ private:
+ ContainsParticle* contained_particle_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_PARTICLE_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/schema.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/schema.cxx
new file mode 100644
index 0000000..f812797
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/schema.cxx
@@ -0,0 +1,139 @@
+// file : xsd-frontend/semantic-graph/schema.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/schema.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ // Uses
+ //
+ struct UsesInit
+ {
+ UsesInit ()
+ {
+ TypeInfo ti (typeid (Uses));
+ ti.add_base (Access::public_, true, typeid (Edge));
+ RTTI::insert (ti);
+ }
+
+ } uses_init_;
+
+
+ // Implies
+ //
+ struct ImpliesInit
+ {
+ ImpliesInit ()
+ {
+ TypeInfo ti (typeid (Implies));
+ ti.add_base (Access::public_, true, typeid (Uses));
+ RTTI::insert (ti);
+ }
+
+ } implies_init_;
+
+
+ // Sources
+ //
+ struct SourcesInit
+ {
+ SourcesInit ()
+ {
+ TypeInfo ti (typeid (Sources));
+ ti.add_base (Access::public_, true, typeid (Uses));
+ RTTI::insert (ti);
+ }
+
+ } sources_init_;
+
+
+ // Includes
+ //
+ struct IncludesInit
+ {
+ IncludesInit ()
+ {
+ TypeInfo ti (typeid (Includes));
+ ti.add_base (Access::public_, true, typeid (Uses));
+ RTTI::insert (ti);
+ }
+
+ } includes_init_;
+
+
+ // Imports
+ //
+ struct ImportsInit
+ {
+ ImportsInit ()
+ {
+ TypeInfo ti (typeid (Imports));
+ ti.add_base (Access::public_, true, typeid (Uses));
+ RTTI::insert (ti);
+ }
+
+ } imports_init_;
+
+
+ // Schema
+ //
+ struct SchemaInit
+ {
+ SchemaInit ()
+ {
+ TypeInfo ti (typeid (Schema));
+ ti.add_base (Access::public_, true, typeid (Scope));
+ RTTI::insert (ti);
+ }
+
+ } schema_init_;
+ }
+
+
+ // Schema
+ //
+ Schema::NamesIteratorPair Schema::
+ find (Name const& name) const
+ {
+ // Here we are going to create an illusion that the namespace
+ // hierarchy is flat.
+ names_.clear ();
+ schemas_.clear ();
+
+ find_ (name, names_, schemas_);
+
+ return NamesIteratorPair (NamesConstIterator (names_.begin ()),
+ NamesConstIterator (names_.end ()));
+ }
+
+ Void Schema::
+ find_ (Name const& name, NamesList& names, SchemaSet& set) const
+ {
+ set.insert (this);
+
+ // Check our own namespace first so it will end up first in the list.
+ //
+ NamesIteratorPair pair (Scope::find (name));
+ names.insert (names.end (), pair.first.base (), pair.second.base ());
+
+ for (UsesIterator i (uses_begin ()), end (uses_end ()); i != end; ++i)
+ {
+ Schema& s (i->schema ());
+
+ if (set.find (&s) == set.end ())
+ s.find_ (name, names, set);
+ }
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/schema.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/schema.hxx
new file mode 100644
index 0000000..10d2f75
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/schema.hxx
@@ -0,0 +1,281 @@
+// file : xsd-frontend/semantic-graph/schema.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_SCHEMA_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_SCHEMA_HXX
+
+#include <cult/containers/set.hxx>
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+#include <xsd-frontend/semantic-graph/namespace.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ //
+ //
+ class Schema;
+
+
+ class Uses: public virtual Edge
+ {
+ public:
+ Schema&
+ user () const
+ {
+ return *user_;
+ }
+
+ Schema&
+ schema () const
+ {
+ return *schema_;
+ }
+
+ Path
+ path () const
+ {
+ return path_;
+ }
+
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Uses (Path const& path)
+ : path_ (path)
+ {
+ }
+
+ Void
+ set_left_node (Schema& s)
+ {
+ user_ = &s;
+ }
+
+ Void
+ set_right_node (Schema& s)
+ {
+ schema_ = &s;
+ }
+
+ private:
+ Path path_;
+ Schema* user_;
+ Schema* schema_;
+ };
+
+
+ //
+ //
+ class Implies: public virtual Uses
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Implies (Path const& path)
+ : Uses (path)
+ {
+ }
+ };
+
+
+ //
+ //
+ class Sources: public virtual Uses
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Sources (Path const& path)
+ : Uses (path)
+ {
+ }
+ };
+
+
+ //
+ //
+ class Includes: public virtual Uses
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Includes (Path const& path)
+ : Uses (path)
+ {
+ }
+ };
+
+
+ //
+ //
+ class Imports: public virtual Uses
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Imports (Path const& path)
+ : Uses (path)
+ {
+ }
+ };
+
+
+ //
+ //
+ class Schema: public virtual Scope,
+ private Bits::Graph<Node, Edge>,
+ public NonCopyable
+ {
+ typedef
+ Cult::Containers::Vector<Uses*>
+ UsesList;
+
+ typedef
+ Cult::Containers::Vector<Uses*>
+ UsedList;
+
+ public:
+ Schema (Path const& file, UnsignedLong line, UnsignedLong column)
+ : SemanticGraph::Node (file, line, column)
+ {
+ }
+
+ public:
+ typedef
+ Bits::PointerIterator<UsesList::ConstIterator>
+ UsesIterator;
+
+ UsesIterator
+ uses_begin () const
+ {
+ return uses_.begin ();
+ }
+
+ UsesIterator
+ uses_end () const
+ {
+ return uses_.end ();
+ }
+
+ typedef
+ Bits::PointerIterator<UsedList::ConstIterator>
+ UsedIterator;
+
+ UsedIterator
+ used_begin () const
+ {
+ return used_.begin ();
+ }
+
+ UsedIterator
+ used_end () const
+ {
+ return used_.end ();
+ }
+
+ Boolean
+ used_p () const
+ {
+ return used_begin () != used_end ();
+ }
+
+ virtual NamesIteratorPair
+ find (Name const& name) const;
+
+ public:
+ using Bits::Graph<SemanticGraph::Node, Edge>::new_edge;
+ using Bits::Graph<SemanticGraph::Node, Edge>::reset_left_node;
+ using Bits::Graph<SemanticGraph::Node, Edge>::reset_right_node;
+ using Bits::Graph<SemanticGraph::Node, Edge>::add_edge_left;
+ using Bits::Graph<SemanticGraph::Node, Edge>::add_edge_right;
+ using Bits::Graph<SemanticGraph::Node, Edge>::delete_node;
+ using Bits::Graph<SemanticGraph::Node, Edge>::delete_edge;
+
+ template <typename T>
+ T&
+ new_node (Path const& file, UnsignedLong line, UnsignedLong column)
+ {
+ return graph ().new_node<T> (file, line, column);
+ }
+
+ template <typename T, typename A0>
+ T&
+ new_node (Path const& file, UnsignedLong line, UnsignedLong column,
+ A0 const& a0)
+ {
+ return graph ().new_node<T> (file, line, column, a0);
+ }
+
+ template <typename T, typename A0, typename A1>
+ T&
+ new_node (Path const& file, UnsignedLong line, UnsignedLong column,
+ A0 const& a0, A1 const& a1)
+ {
+ return graph ().new_node<T> (file, line, column, a0, a1);
+ }
+
+ template <typename T, typename A0, typename A1, typename A2>
+ T&
+ new_node (Path const& file, UnsignedLong line, UnsignedLong column,
+ A0 const& a0, A1 const& a1, A2 const& a2)
+ {
+ return graph ().new_node<T> (file, line, column, a0, a1, a2);
+ }
+
+ template <typename T, typename A0, typename A1, typename A2,
+ typename A3>
+ T&
+ new_node (Path const& file, UnsignedLong line, UnsignedLong column,
+ A0 const& a0, A1 const& a1, A2 const& a2, A3 const& a3)
+ {
+ return graph ().new_node<T> (file, line, column, a0, a1, a2, a3);
+ }
+
+ protected:
+ //@@ gcc bug #21146
+ //
+ friend class Bits::Graph<SemanticGraph::Node, Edge>;
+
+ using Scope::add_edge_left;
+ using Node::add_edge_right;
+
+ Void
+ add_edge_left (Uses& e)
+ {
+ uses_.push_back (&e);
+ }
+
+ Void
+ add_edge_right (Uses& e)
+ {
+ used_.push_back (&e);
+ }
+
+ private:
+ Bits::Graph<SemanticGraph::Node, Edge>&
+ graph ()
+ {
+ return *this;
+ }
+
+ private:
+ UsesList uses_;
+ UsedList used_;
+
+ private:
+ typedef Cult::Containers::Set<Schema const*> SchemaSet;
+
+ Void
+ find_ (Name const& name, NamesList&, SchemaSet&) const;
+
+ mutable NamesList names_;
+ mutable SchemaSet schemas_;
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_SCHEMA_HXX
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/union.cxx b/libxsd-frontend/xsd-frontend/semantic-graph/union.cxx
new file mode 100644
index 0000000..b4b4cf0
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/union.cxx
@@ -0,0 +1,37 @@
+// file : xsd-frontend/semantic-graph/union.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <xsd-frontend/semantic-graph/union.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ namespace RTTI = Cult::RTTI;
+
+ using RTTI::Access;
+ using RTTI::TypeInfo;
+
+ namespace
+ {
+ struct UnionInit
+ {
+ UnionInit ()
+ {
+ TypeInfo ti (typeid (Union));
+ ti.add_base (Access::public_, true, typeid (Specialization));
+ RTTI::insert (ti);
+ }
+
+ } union_init_;
+ }
+
+ Union::
+ Union (Path const& file, UnsignedLong line, UnsignedLong column)
+ : Node (file, line, column)
+ {
+ }
+ }
+}
diff --git a/libxsd-frontend/xsd-frontend/semantic-graph/union.hxx b/libxsd-frontend/xsd-frontend/semantic-graph/union.hxx
new file mode 100644
index 0000000..62df730
--- /dev/null
+++ b/libxsd-frontend/xsd-frontend/semantic-graph/union.hxx
@@ -0,0 +1,25 @@
+// file : xsd-frontend/semantic-graph/union.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#ifndef XSD_FRONTEND_SEMANTIC_GRAPH_UNION_HXX
+#define XSD_FRONTEND_SEMANTIC_GRAPH_UNION_HXX
+
+#include <xsd-frontend/semantic-graph/elements.hxx>
+
+namespace XSDFrontend
+{
+ namespace SemanticGraph
+ {
+ class Union: public virtual Specialization
+ {
+ protected:
+ friend class Bits::Graph<Node, Edge>;
+
+ Union (Path const& file, UnsignedLong line, UnsignedLong column);
+ };
+ }
+}
+
+#endif // XSD_FRONTEND_SEMANTIC_GRAPH_UNION_HXX