aboutsummaryrefslogtreecommitdiff
path: root/odb/semantics
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-03-25 13:47:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-03-25 13:47:43 +0200
commit01f77f6d38283b4efbe2b55fc9c7c837fd6498dc (patch)
tree12059fa0c514a3f2b9da2a9419593e3596cc6f5d /odb/semantics
parentad637abaa62a26461b276769c35dd1b67036b54b (diff)
Add support for union, enum, class/union template
Diffstat (limited to 'odb/semantics')
-rw-r--r--odb/semantics/class-template.cxx42
-rw-r--r--odb/semantics/class-template.hxx76
-rw-r--r--odb/semantics/class.cxx10
-rw-r--r--odb/semantics/class.hxx20
-rw-r--r--odb/semantics/elements.cxx17
-rw-r--r--odb/semantics/elements.hxx35
-rw-r--r--odb/semantics/enum.cxx48
-rw-r--r--odb/semantics/enum.hxx133
-rw-r--r--odb/semantics/template.cxx66
-rw-r--r--odb/semantics/template.hxx158
-rw-r--r--odb/semantics/union-template.cxx42
-rw-r--r--odb/semantics/union-template.hxx41
-rw-r--r--odb/semantics/union.cxx33
-rw-r--r--odb/semantics/union.hxx32
14 files changed, 730 insertions, 23 deletions
diff --git a/odb/semantics/class-template.cxx b/odb/semantics/class-template.cxx
new file mode 100644
index 0000000..05deef8
--- /dev/null
+++ b/odb/semantics/class-template.cxx
@@ -0,0 +1,42 @@
+// file : odb/semantics/class-template.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+
+#include <semantics/class-template.hxx>
+
+namespace semantics
+{
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ // class_template
+ //
+ {
+ type_info ti (typeid (class_template));
+ ti.add_base (typeid (type_template));
+ ti.add_base (typeid (scope));
+ insert (ti);
+ }
+
+ // class_instantiation
+ //
+ {
+ type_info ti (typeid (class_instantiation));
+ ti.add_base (typeid (class_));
+ ti.add_base (typeid (type_instantiation));
+ insert (ti);
+ }
+ }
+ } init_;
+ }
+}
diff --git a/odb/semantics/class-template.hxx b/odb/semantics/class-template.hxx
new file mode 100644
index 0000000..6443a19
--- /dev/null
+++ b/odb/semantics/class-template.hxx
@@ -0,0 +1,76 @@
+// file : odb/semantics/class-template.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_CLASS_TEMPLATE_HXX
+#define ODB_SEMANTICS_CLASS_TEMPLATE_HXX
+
+#include <semantics/elements.hxx>
+#include <semantics/class.hxx>
+#include <semantics/template.hxx>
+
+namespace semantics
+{
+ class class_template: public type_template, public scope
+ {
+ private:
+ typedef std::vector<inherits*> inherits_list;
+
+ public:
+ typedef inherits_list::const_iterator inherits_iterator;
+
+ inherits_iterator
+ inherits_begin () const
+ {
+ return inherits_.begin ();
+ }
+
+ inherits_iterator
+ inherits_end () const
+ {
+ return inherits_.end ();
+ }
+
+ public:
+ class_template (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ void
+ add_edge_left (inherits& e)
+ {
+ inherits_.push_back (&e);
+ }
+
+ void
+ add_edge_right (inherits&)
+ {
+ }
+
+ using scope::add_edge_left;
+ using scope::add_edge_right;
+
+ // Resolve conflict between scope::scope and nameable::scope.
+ //
+ using nameable::scope;
+
+ private:
+ inherits_list inherits_;
+ };
+
+ class class_instantiation: public class_, public type_instantiation
+ {
+ public:
+ class_instantiation (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ using class_::add_edge_left;
+ using type_instantiation::add_edge_left;
+ };
+}
+
+#endif // ODB_SEMANTICS_CLASS_TEMPLATE_HXX
diff --git a/odb/semantics/class.cxx b/odb/semantics/class.cxx
index 5575745..7462d7c 100644
--- a/odb/semantics/class.cxx
+++ b/odb/semantics/class.cxx
@@ -19,15 +19,6 @@ namespace semantics
{
using compiler::type_info;
- // data_member
- //
- {
- type_info ti (typeid (data_member));
- ti.add_base (typeid (nameable));
- ti.add_base (typeid (instance));
- insert (ti);
- }
-
// inherits
//
{
@@ -40,6 +31,7 @@ namespace semantics
//
{
type_info ti (typeid (class_));
+ ti.add_base (typeid (type));
ti.add_base (typeid (scope));
insert (ti);
}
diff --git a/odb/semantics/class.hxx b/odb/semantics/class.hxx
index d4a0900..bbe4687 100644
--- a/odb/semantics/class.hxx
+++ b/odb/semantics/class.hxx
@@ -13,19 +13,6 @@ namespace semantics
{
class class_;
- //
- //
- class data_member: public nameable, public instance
- {
- public:
- data_member (path const& file, size_t line, size_t column)
- : node (file, line, column)
- {
- }
- };
-
- //
- //
class inherits: public edge
{
public:
@@ -83,7 +70,7 @@ namespace semantics
//
//
- class class_: public type, public scope
+ class class_: public virtual type, public scope
{
private:
typedef std::vector<inherits*> inherits_list;
@@ -127,6 +114,11 @@ namespace semantics
//
using nameable::scope;
+ protected:
+ class_ ()
+ {
+ }
+
private:
inherits_list inherits_;
};
diff --git a/odb/semantics/elements.cxx b/odb/semantics/elements.cxx
index d14835c..caed01e 100644
--- a/odb/semantics/elements.cxx
+++ b/odb/semantics/elements.cxx
@@ -149,6 +149,23 @@ namespace semantics
ti.add_base (typeid (node));
insert (ti);
}
+
+ // data_member
+ //
+ {
+ type_info ti (typeid (data_member));
+ ti.add_base (typeid (nameable));
+ ti.add_base (typeid (instance));
+ insert (ti);
+ }
+
+ // unsupported_type
+ //
+ {
+ type_info ti (typeid (unsupported_type));
+ ti.add_base (typeid (type));
+ insert (ti);
+ }
}
} init_;
}
diff --git a/odb/semantics/elements.hxx b/odb/semantics/elements.hxx
index 0b89831..97f386f 100644
--- a/odb/semantics/elements.hxx
+++ b/odb/semantics/elements.hxx
@@ -543,6 +543,41 @@ namespace semantics
private:
belongs_type* belongs_;
};
+
+ // Data member for class and union types.
+ //
+ class data_member: public nameable, public instance
+ {
+ public:
+ data_member (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+ };
+
+ // Unsupported type.
+ //
+ class unsupported_type: public type
+ {
+ public:
+ string const&
+ type_name () const
+ {
+ return type_name_;
+ }
+
+ public:
+ unsupported_type (path const& file,
+ size_t line,
+ size_t column,
+ string const& type_name)
+ : node (file, line, column), type_name_ (type_name)
+ {
+ }
+
+ private:
+ string const type_name_;
+ };
}
#include <semantics/elements.ixx>
diff --git a/odb/semantics/enum.cxx b/odb/semantics/enum.cxx
new file mode 100644
index 0000000..ab19c70
--- /dev/null
+++ b/odb/semantics/enum.cxx
@@ -0,0 +1,48 @@
+// file : odb/semantics/enum.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+
+#include <semantics/enum.hxx>
+
+namespace semantics
+{
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ // enumerates
+ //
+ {
+ type_info ti (typeid (enumerates));
+ ti.add_base (typeid (edge));
+ insert (ti);
+ }
+
+ // enumerator
+ //
+ {
+ type_info ti (typeid (enumerator));
+ ti.add_base (typeid (instance));
+ insert (ti);
+ }
+
+ // enum_
+ //
+ {
+ type_info ti (typeid (enum_));
+ ti.add_base (typeid (type));
+ insert (ti);
+ }
+ }
+ } init_;
+ }
+}
diff --git a/odb/semantics/enum.hxx b/odb/semantics/enum.hxx
new file mode 100644
index 0000000..e628ad9
--- /dev/null
+++ b/odb/semantics/enum.hxx
@@ -0,0 +1,133 @@
+// file : odb/semantics/enum.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_ENUM_HXX
+#define ODB_SEMANTICS_ENUM_HXX
+
+#include <vector>
+#include <semantics/elements.hxx>
+
+namespace semantics
+{
+ class enum_;
+ class enumerator;
+
+ class enumerates: public edge
+ {
+ public:
+ typedef semantics::enum_ enum_type;
+ typedef semantics::enumerator enumerator_type;
+
+ enum_type&
+ enum_ () const
+ {
+ return *enum__;
+ }
+
+ enumerator_type&
+ enumerator () const
+ {
+ return *enumerator_;
+ }
+
+ public:
+ enumerates ()
+ {
+ }
+
+ void
+ set_left_node (enum_type& n)
+ {
+ enum__ = &n;
+ }
+
+ void
+ set_right_node (enumerator_type& n)
+ {
+ enumerator_ = &n;
+ }
+
+ protected:
+ enum_type* enum__;
+ enumerator_type* enumerator_;
+ };
+
+ //
+ //
+ class enumerator: public instance
+ {
+ public:
+ typedef semantics::enum_ enum_type;
+
+ enum_type&
+ enum_ () const
+ {
+ return enumerated_->enum_ ();
+ }
+
+ enumerates&
+ enumerated () const
+ {
+ return *enumerated_;
+ }
+
+ public:
+ enumerator (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ void
+ add_edge_right (enumerates& e)
+ {
+ enumerated_ = &e;
+ }
+
+ using instance::add_edge_right;
+
+ private:
+ enumerates* enumerated_;
+ };
+
+ //
+ //
+ class enum_: public type
+ {
+ private:
+ typedef std::vector<enumerates*> enumerates_list;
+
+ public:
+ typedef enumerates_list::const_iterator enumerates_iterator;
+
+ enumerates_iterator
+ enumerates_begin () const
+ {
+ return enumerates_.begin ();
+ }
+
+ enumerates_iterator
+ enumerates_end () const
+ {
+ return enumerates_.end ();
+ }
+
+ public:
+ enum_ (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ void
+ add_edge_left (enumerates& e)
+ {
+ enumerates_.push_back (&e);
+ }
+
+ private:
+ enumerates_list enumerates_;
+ };
+}
+
+#endif // ODB_SEMANTICS_ENUM_HXX
diff --git a/odb/semantics/template.cxx b/odb/semantics/template.cxx
new file mode 100644
index 0000000..4882aa3
--- /dev/null
+++ b/odb/semantics/template.cxx
@@ -0,0 +1,66 @@
+// file : odb/semantics/template.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+
+#include <semantics/template.hxx>
+
+namespace semantics
+{
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ // template_
+ //
+ {
+ type_info ti (typeid (template_));
+ ti.add_base (typeid (nameable));
+ insert (ti);
+ }
+
+ // instantiates
+ //
+ {
+ type_info ti (typeid (instantiates));
+ ti.add_base (typeid (edge));
+ insert (ti);
+ }
+
+ // instantiation
+ //
+ {
+ type_info ti (typeid (instantiation));
+ ti.add_base (typeid (node));
+ insert (ti);
+ }
+
+ // type_template
+ //
+ {
+ type_info ti (typeid (type_template));
+ ti.add_base (typeid (template_));
+ insert (ti);
+ }
+
+ // type_instantiation
+ //
+ {
+ type_info ti (typeid (type_instantiation));
+ ti.add_base (typeid (type));
+ ti.add_base (typeid (instantiation));
+ insert (ti);
+ }
+
+ }
+ } init_;
+ }
+}
diff --git a/odb/semantics/template.hxx b/odb/semantics/template.hxx
new file mode 100644
index 0000000..1357dbf
--- /dev/null
+++ b/odb/semantics/template.hxx
@@ -0,0 +1,158 @@
+// file : odb/semantics/template.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_TEMPLATE_HXX
+#define ODB_SEMANTICS_TEMPLATE_HXX
+
+#include <vector>
+#include <semantics/elements.hxx>
+
+namespace semantics
+{
+ //
+ //
+ class instantiates;
+
+ class template_: public virtual nameable
+ {
+ typedef std::vector<instantiates*> instantiated;
+
+ public:
+ typedef
+ pointer_iterator<instantiated::const_iterator>
+ instantiated_iterator;
+
+ instantiated_iterator
+ instantiated_begin () const
+ {
+ return instantiated_.begin ();
+ }
+
+ instantiated_iterator
+ instantiated_end () const
+ {
+ return instantiated_.end ();
+ }
+
+ public:
+ void
+ add_edge_right (instantiates& e)
+ {
+ instantiated_.push_back (&e);
+ }
+
+ using nameable::add_edge_right;
+
+ protected:
+ template_ ()
+ {
+ }
+
+ private:
+ instantiated instantiated_;
+ };
+
+ //
+ //
+ class instantiation;
+
+ class instantiates: public edge
+ {
+ public:
+ typedef semantics::template_ template_type;
+ typedef semantics::instantiation instantiation_type;
+
+ template_type&
+ template_ () const
+ {
+ return *template__;
+ }
+
+ instantiation_type&
+ instantiation () const
+ {
+ return *instantiation_;
+ }
+
+ public:
+ instantiates ()
+ {
+ }
+
+ void
+ set_left_node (instantiation_type& n)
+ {
+ instantiation_ = &n;
+ }
+
+ void
+ set_right_node (template_type& n)
+ {
+ template__ = &n;
+ }
+
+ private:
+ template_type* template__;
+ instantiation_type* instantiation_;
+ };
+
+ //
+ //
+ class instantiation: public virtual node
+ {
+ public:
+ typedef semantics::template_ template_type;
+ typedef semantics::instantiates instantiates_type;
+
+ template_type&
+ template_ () const
+ {
+ return instantiates_->template_ ();
+ }
+
+ instantiates_type&
+ instantiates () const
+ {
+ return *instantiates_;
+ }
+
+ public:
+ void
+ add_edge_left (instantiates_type& e)
+ {
+ instantiates_ = &e;
+ }
+
+ protected:
+ instantiation ()
+ {
+ }
+
+ private:
+ instantiates_type* instantiates_;
+ };
+
+ //
+ // Type template and instantiation.
+ //
+
+ class type_template: public template_
+ {
+ protected:
+ type_template ()
+ {
+ }
+ };
+
+ class type_instantiation: public virtual type, public instantiation
+ {
+ protected:
+ type_instantiation ()
+ {
+ }
+ };
+}
+
+#endif // ODB_SEMANTICS_TEMPLATE_HXX
diff --git a/odb/semantics/union-template.cxx b/odb/semantics/union-template.cxx
new file mode 100644
index 0000000..a83748f
--- /dev/null
+++ b/odb/semantics/union-template.cxx
@@ -0,0 +1,42 @@
+// file : odb/semantics/union-template.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+
+#include <semantics/union-template.hxx>
+
+namespace semantics
+{
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ // union_template
+ //
+ {
+ type_info ti (typeid (union_template));
+ ti.add_base (typeid (type_template));
+ ti.add_base (typeid (scope));
+ insert (ti);
+ }
+
+ // union_instantiation
+ //
+ {
+ type_info ti (typeid (union_instantiation));
+ ti.add_base (typeid (union_));
+ ti.add_base (typeid (type_instantiation));
+ insert (ti);
+ }
+ }
+ } init_;
+ }
+}
diff --git a/odb/semantics/union-template.hxx b/odb/semantics/union-template.hxx
new file mode 100644
index 0000000..1aaadb7
--- /dev/null
+++ b/odb/semantics/union-template.hxx
@@ -0,0 +1,41 @@
+// file : odb/semantics/union-template.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_UNION_TEMPLATE_HXX
+#define ODB_SEMANTICS_UNION_TEMPLATE_HXX
+
+#include <semantics/elements.hxx>
+#include <semantics/union.hxx>
+#include <semantics/template.hxx>
+
+namespace semantics
+{
+ class union_template: public type_template, public scope
+ {
+ public:
+ union_template (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ // Resolve conflict between scope::scope and nameable::scope.
+ //
+ using nameable::scope;
+ };
+
+ class union_instantiation: public union_, public type_instantiation
+ {
+ public:
+ union_instantiation (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ using union_::add_edge_left;
+ using type_instantiation::add_edge_left;
+ };
+}
+
+#endif // ODB_SEMANTICS_UNION_TEMPLATE_HXX
diff --git a/odb/semantics/union.cxx b/odb/semantics/union.cxx
new file mode 100644
index 0000000..a4e62a1
--- /dev/null
+++ b/odb/semantics/union.cxx
@@ -0,0 +1,33 @@
+// file : odb/semantics/union.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cutl/compiler/type-info.hxx>
+
+#include <semantics/union.hxx>
+
+namespace semantics
+{
+ // type info
+ //
+ namespace
+ {
+ struct init
+ {
+ init ()
+ {
+ using compiler::type_info;
+
+ // union_
+ //
+ {
+ type_info ti (typeid (union_));
+ ti.add_base (typeid (type));
+ ti.add_base (typeid (scope));
+ insert (ti);
+ }
+ }
+ } init_;
+ }
+}
diff --git a/odb/semantics/union.hxx b/odb/semantics/union.hxx
new file mode 100644
index 0000000..2873d97
--- /dev/null
+++ b/odb/semantics/union.hxx
@@ -0,0 +1,32 @@
+// file : odb/semantics/union.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_SEMANTICS_UNION_HXX
+#define ODB_SEMANTICS_UNION_HXX
+
+#include <semantics/elements.hxx>
+
+namespace semantics
+{
+ class union_: public virtual type, public scope
+ {
+ public:
+ union_ (path const& file, size_t line, size_t column)
+ : node (file, line, column)
+ {
+ }
+
+ // Resolve conflict between scope::scope and nameable::scope.
+ //
+ using nameable::scope;
+
+ protected:
+ union_ ()
+ {
+ }
+ };
+}
+
+#endif // ODB_SEMANTICS_UNION_HXX