From: levill_r <levill_r@4aad255d-cdde-0310-9447-f3009e2ae8c0>
* src/data.erb.hh: Rename as...
* src/data.hh: ...this.
* src/Makefile.am (dyn_light_hh_deps, dyn_all_hh_deps):
s|data.hh|$(srcdir)/data.hh|.
(BUILT_SOURCES): Remove data.hh.
git-svn-id:
https://svn.lrde.epita.fr/svn/oln/trunk@4654
4aad255d-cdde-0310-9447-f3009e2ae8c0
---
dynamic-use-of-static-c++/ChangeLog | 10 +
dynamic-use-of-static-c++/src/Makefile.am | 5 +-
dynamic-use-of-static-c++/src/data.erb.hh | 418 -----------------------------
dynamic-use-of-static-c++/src/data.hh | 416 ++++++++++++++++++++++++++++
4 files changed, 428 insertions(+), 421 deletions(-)
delete mode 100644 dynamic-use-of-static-c++/src/data.erb.hh
create mode 100644 dynamic-use-of-static-c++/src/data.hh
diff --git a/dynamic-use-of-static-c++/ChangeLog b/dynamic-use-of-static-c++/ChangeLog
index a8c3708..fc90b57 100644
--- a/dynamic-use-of-static-c++/ChangeLog
+++ b/dynamic-use-of-static-c++/ChangeLog
@@ -1,5 +1,15 @@
2009-10-20 Roland Levillain <roland(a)lrde.epita.fr>
+ Rename src/data.erb.hh as src/data.hh and stop generating the latter.
+
+ * src/data.erb.hh: Rename as...
+ * src/data.hh: ...this.
+ * src/Makefile.am (dyn_light_hh_deps, dyn_all_hh_deps):
+ s|data.hh|$(srcdir)/data.hh|.
+ (BUILT_SOURCES): Remove data.hh.
+
+2009-10-20 Roland Levillain <roland(a)lrde.epita.fr>
+
Various fixes in src/Makefile.am.
* src/Makefile.am: Aesthetic changes.
diff --git a/dynamic-use-of-static-c++/src/Makefile.am
b/dynamic-use-of-static-c++/src/Makefile.am
index 0bb8cea..7d62edf 100644
--- a/dynamic-use-of-static-c++/src/Makefile.am
+++ b/dynamic-use-of-static-c++/src/Makefile.am
@@ -7,7 +7,7 @@ dyn_light_hh_deps = \
$(srcdir)/name_of.hh \
function.hh \
all_methods.hh \
- data.hh \
+ $(srcdir)/data.hh \
$(srcdir)/policy.hh
dyn_all_hh_deps = \
@@ -15,7 +15,7 @@ dyn_all_hh_deps = \
$(srcdir)/name_of.hh \
function.hh \
all_methods.hh \
- data.hh \
+ $(srcdir)/data.hh \
$(srcdir)/data.hxx \
$(srcdir)/function_loader.hh \
$(srcdir)/dyn.hh
@@ -24,7 +24,6 @@ dyn_all_hh_deps = \
BUILT_SOURCES = \
all_methods.hh \
function.hh \
- data.hh \
config.hh
# Clean generated files.
diff --git a/dynamic-use-of-static-c++/src/data.erb.hh
b/dynamic-use-of-static-c++/src/data.erb.hh
deleted file mode 100644
index b4c14e1..0000000
--- a/dynamic-use-of-static-c++/src/data.erb.hh
+++ /dev/null
@@ -1,418 +0,0 @@
-#ifndef DYN_DATA_HH
-# define DYN_DATA_HH
-
-// FIXME: rename me without the .erb
-
-# include <string>
-# include <cassert>
-# include "function.hh"
-# include "name_of.hh"
-# include "all_methods.hh"
-
-namespace dyn {
-
- extern std::ostream& logger;
-
- namespace language
- {
- struct val;
- struct var;
- }
-
- namespace policy
- {
- enum type
- {
- none = 0,
- is_const = 1,
- is_ref = 2,
- is_ptr = 4,
- is_pod = 8,
- is_void = 16
- };
- }
- struct proxy_tag;
-
- // data --> abstract_data
- // ^
- // |
- // data_proxy<T> --> T
-
-
- // abstract_data
-
- struct abstract_data
- {
- virtual abstract_data* clone() const = 0;
- virtual abstract_data* const_clone() const { return clone(); }
- virtual std::string proxy_type() const = 0;
- virtual std::string type() const = 0;
- virtual ~abstract_data() {}
- };
-
- // data_proxy<T>
-
- template <class T>
- struct data_proxy : public abstract_data
- {
-# define gen_ctor \
- data_proxy() \
- { \
- logger << "ctor: " << proxy_type() << std::endl; \
- }
-
-# define gen_proxy_type \
- virtual std::string proxy_type() const \
- { \
- return mlc_name_of(*this); \
- }
-
- gen_proxy_type
-
- template <typename V>
- operator V() const
- {
- V ret(const_ref());
- return ret;
- }
-
- virtual std::string type() const
- {
- return mlc_name_of(const_ref());
- }
-
- virtual const T& const_ref() const = 0;
- };
-
-
- // FIXME Perhaps we can use smart pointers here.
- template <class T>
- struct data_proxy_by_ptr : public data_proxy<T>
- {
- data_proxy_by_ptr(T* obj) : p_obj_(obj) { logger << "ctor: " <<
proxy_type() << std::endl; }
-
- virtual data_proxy_by_ptr<T>* clone() const
- {
- return new data_proxy_by_ptr<T>(p_obj_);
- }
-
- virtual data_proxy_by_ptr<const T>* const_clone() const
- {
- return new data_proxy_by_ptr<const T>(p_obj_);
- }
-
- gen_proxy_type
-
- T& obj()
- {
- assert(p_obj_);
- return *p_obj_;
- }
-
- const T& obj() const
- {
- assert(p_obj_);
- return *p_obj_;
- }
-
- virtual const T& const_ref() const { return obj(); }
-
- protected:
- T* p_obj_;
- };
-
-
- template <class T>
- struct data_proxy_by_ref : public data_proxy<T>
- {
- data_proxy_by_ref(T& obj) : obj_(obj) { logger << "ctor: "
<< proxy_type() << std::endl; }
-
- virtual data_proxy_by_ref<T>* clone() const
- {
- return new data_proxy_by_ref<T>(obj_);
- }
-
- virtual data_proxy_by_ref<const T>* const_clone() const
- {
- return new data_proxy_by_ref<const T>(obj_);
- }
-
- virtual const T& const_ref() const { return obj_; }
- const T& obj() const { return obj_; }
- T& obj() { return obj_; }
-
- gen_proxy_type
-
- protected:
- T& obj_;
- };
-
-
- template <class T>
- struct data_proxy_by_cpy : public data_proxy<T>
- {
- data_proxy_by_cpy(const T obj) : obj_(T(obj)) { logger << "ctor: "
<< proxy_type() << std::endl; }
-
- virtual data_proxy_by_cpy<T>* clone() const
- {
- return new data_proxy_by_cpy<T>(obj_);
- }
-
- virtual data_proxy_by_cpy<const T>* const_clone() const
- {
- return new data_proxy_by_cpy<const T>(obj_);
- }
-
- virtual const T& const_ref() const { return obj_; }
- const T& obj() const { return obj_; }
- T& obj() { return obj_; }
-
- gen_proxy_type
-
- protected:
- T obj_;
- };
-
-
- struct NilClass
- {
- NilClass(int) {}
- };
-
- struct data_nil : public data_proxy<NilClass>
- {
- data_nil() : nil_object_(NilClass(0)) { logger << "ctor: " <<
proxy_type() << std::endl; }
- data_nil(const NilClass& nil_object) : nil_object_(nil_object) {}
- const NilClass& const_ref() const { return nil_object_; }
- const NilClass& obj() const { return nil_object_; }
- virtual data_nil* clone() const { return new data_nil; }
- gen_proxy_type
- const NilClass nil_object_;
- };
-
- extern const NilClass nil_object;
- extern data_nil* nil_proxy;
-
- template <typename T1, typename T2>
- T2
- data_cast(const T1& src)
- {
- T2 tmp(src);
- return tmp;
- }
-
- template <typename T1, typename T2>
- void
- data_assign(T1& lhs, const T2& rhs)
- {
- lhs = rhs;
- }
-
- // data
-
- struct data : public all_methods
- {
-
- virtual const data& self() const
- {
- return *this;
- }
-
- virtual data& self()
- {
- return *this;
- }
-
- data& assign(const data& rhs)
- {
- if (&rhs == this) return *this;
- if (rhs.proxy_ == 0)
- {
- logger << "assign(const data& rhs) [ rhs.proxy_ == 0 ]"
<< std::endl;
- proxy_ = nil_proxy;
- }
- else
- {
- assert(rhs.proxy_ != proxy_);
- // if (proxy_ != 0)
- // delete proxy_;
- proxy_ = rhs.proxy_->clone();
- }
- return *this;
- }
-
- data& const_assign(const data& rhs)
- {
- if (&rhs == this) return *this;
- if (rhs.proxy_ == 0)
- {
- logger << "const_assign(const data& rhs) [ rhs.proxy_ == 0 ]"
<< std::endl;
- proxy_ = nil_proxy;
- }
- else
- {
- assert(rhs.proxy_ != proxy_);
- // if (proxy_ != 0)
- // delete proxy_;
- proxy_ = rhs.proxy_->const_clone();
- }
- return *this;
- }
-
- data& operator=(const data& rhs) { return assign(rhs); }
-
- data& operator=(data& rhs) { return assign(rhs); }
-
-
- template <typename T>
- data& operator=(const T& rhs);
-
-
- template <typename T>
- T convert_to() const;
-
-
- template <typename T>
- T& get_ref_on();
-
- template <typename T>
- const T& get_ref_on() const;
-
- std::string& const_stripping(std::string& str) const
- {
- size_t pos;
- while ((pos = str.find("const ")) != std::string::npos)
- str.erase(pos, 6);
- while ((pos = str.find(" const")) != std::string::npos)
- str.erase(pos, 6);
- return str;
- }
-
- template <typename T>
- operator T() const
- {
- std::string src_type(proxy()->type());
- std::string dest_type(mlc_name<T>::of());
- if (const_stripping(src_type) == const_stripping(dest_type))
- return get_ref_on<T>();
- else
- return convert_to<T>();
- }
-
-
- ~data()
- {
- if (proxy_ != nil_proxy)
- {
- logger << "~data [ type() = " << type() << "
]" << std::endl;
- delete proxy_;
- proxy_ = nil_proxy;
- }
- }
-
-
- std::string type() const
- {
- return proxy()->proxy_type();
- }
-
-
- data operator[](const data&);
- const data& operator[](const data&) const;
- data operator*();
- const data& operator*() const;
-
-
- abstract_data* proxy() const
- {
- assert(proxy_);
- return proxy_;
- }
-
- bool is_const()
- {
- std::string type_(type());
- return type_.find("dyn::data_proxy_by_ref<") == 0
- && type_.rfind("const>") == type_.length() - 6;
- }
-
- meth method(const std::string& method_name);
-
- data() : proxy_(nil_proxy) {}
-
- data(abstract_data* proxy, proxy_tag*) : all_methods(), proxy_(proxy) {}
-
- template <class T>
- data(T& obj) : all_methods()
- {
- logger << "data(T& obj) [ T = " <<
mlc_name<T>::of() << " ]" << std::endl;
- proxy_ = new data_proxy_by_ref<T>(obj);
- }
-
- template <class T>
- data(const T& obj) : all_methods()
- {
- logger << "data(const T& obj) [ T = " <<
mlc_name<T>::of() << " ]" << std::endl;
- proxy_ = new data_proxy_by_ref<const T>(obj);
- }
-
- data(language::var& rhs);
- data(language::val& rhs);
- data(const language::var& rhs);
- data(const language::val& rhs);
-
- data(data& rhs) : all_methods(), proxy_(0)
- {
- logger << "data(data& rhs) [ rhs.type() = " << rhs.type()
<< " ]" << std::endl;
- assign(rhs);
- }
-
- data(const data& rhs) : all_methods(), proxy_(0)
- {
- logger << "data(const data& rhs) [ rhs.type() = " <<
rhs.type() << " ]" << std::endl;
- assign(rhs);
- }
-
- protected:
- abstract_data* proxy_;
- };
-
- extern const data nil;
-
- namespace internal {
- extern op operator_push;
- extern op operator_pop;
- extern op operator_incr;
- extern op operator_decr;
- extern op operator_plus;
- extern op operator_star;
- extern op operator_equal;
- extern op operator_not_equal;
- extern meth operator_square_brackets;
- }
-
-}
-
-template <typename T, dyn::policy::type policy>
-struct dyn_choose_data_proxy
-{
- typedef dyn::data_proxy_by_cpy<T> ret;
-};
-
-template <typename T>
-struct dyn_choose_data_proxy<T, dyn::policy::is_ref>
-{
- typedef dyn::data_proxy_by_ref<T> ret;
-};
-
-template <typename T>
-struct dyn_choose_data_proxy<T, (dyn::policy::type)(dyn::policy::is_ref +
dyn::policy::is_const)>
-{
- typedef dyn::data_proxy_by_ref<const T> ret;
-};
-
-# ifdef DYN_FULL_IMPLEMENTATION
-# include "data.hxx"
-# endif
-
-#endif
diff --git a/dynamic-use-of-static-c++/src/data.hh
b/dynamic-use-of-static-c++/src/data.hh
new file mode 100644
index 0000000..f0e1812
--- /dev/null
+++ b/dynamic-use-of-static-c++/src/data.hh
@@ -0,0 +1,416 @@
+#ifndef DYN_DATA_HH
+# define DYN_DATA_HH
+
+# include <string>
+# include <cassert>
+# include "function.hh"
+# include "name_of.hh"
+# include "all_methods.hh"
+
+namespace dyn {
+
+ extern std::ostream& logger;
+
+ namespace language
+ {
+ struct val;
+ struct var;
+ }
+
+ namespace policy
+ {
+ enum type
+ {
+ none = 0,
+ is_const = 1,
+ is_ref = 2,
+ is_ptr = 4,
+ is_pod = 8,
+ is_void = 16
+ };
+ }
+ struct proxy_tag;
+
+ // data --> abstract_data
+ // ^
+ // |
+ // data_proxy<T> --> T
+
+
+ // abstract_data
+
+ struct abstract_data
+ {
+ virtual abstract_data* clone() const = 0;
+ virtual abstract_data* const_clone() const { return clone(); }
+ virtual std::string proxy_type() const = 0;
+ virtual std::string type() const = 0;
+ virtual ~abstract_data() {}
+ };
+
+ // data_proxy<T>
+
+ template <class T>
+ struct data_proxy : public abstract_data
+ {
+# define gen_ctor \
+ data_proxy() \
+ { \
+ logger << "ctor: " << proxy_type() << std::endl; \
+ }
+
+# define gen_proxy_type \
+ virtual std::string proxy_type() const \
+ { \
+ return mlc_name_of(*this); \
+ }
+
+ gen_proxy_type
+
+ template <typename V>
+ operator V() const
+ {
+ V ret(const_ref());
+ return ret;
+ }
+
+ virtual std::string type() const
+ {
+ return mlc_name_of(const_ref());
+ }
+
+ virtual const T& const_ref() const = 0;
+ };
+
+
+ // FIXME Perhaps we can use smart pointers here.
+ template <class T>
+ struct data_proxy_by_ptr : public data_proxy<T>
+ {
+ data_proxy_by_ptr(T* obj) : p_obj_(obj) { logger << "ctor: " <<
proxy_type() << std::endl; }
+
+ virtual data_proxy_by_ptr<T>* clone() const
+ {
+ return new data_proxy_by_ptr<T>(p_obj_);
+ }
+
+ virtual data_proxy_by_ptr<const T>* const_clone() const
+ {
+ return new data_proxy_by_ptr<const T>(p_obj_);
+ }
+
+ gen_proxy_type
+
+ T& obj()
+ {
+ assert(p_obj_);
+ return *p_obj_;
+ }
+
+ const T& obj() const
+ {
+ assert(p_obj_);
+ return *p_obj_;
+ }
+
+ virtual const T& const_ref() const { return obj(); }
+
+ protected:
+ T* p_obj_;
+ };
+
+
+ template <class T>
+ struct data_proxy_by_ref : public data_proxy<T>
+ {
+ data_proxy_by_ref(T& obj) : obj_(obj) { logger << "ctor: "
<< proxy_type() << std::endl; }
+
+ virtual data_proxy_by_ref<T>* clone() const
+ {
+ return new data_proxy_by_ref<T>(obj_);
+ }
+
+ virtual data_proxy_by_ref<const T>* const_clone() const
+ {
+ return new data_proxy_by_ref<const T>(obj_);
+ }
+
+ virtual const T& const_ref() const { return obj_; }
+ const T& obj() const { return obj_; }
+ T& obj() { return obj_; }
+
+ gen_proxy_type
+
+ protected:
+ T& obj_;
+ };
+
+
+ template <class T>
+ struct data_proxy_by_cpy : public data_proxy<T>
+ {
+ data_proxy_by_cpy(const T obj) : obj_(T(obj)) { logger << "ctor: "
<< proxy_type() << std::endl; }
+
+ virtual data_proxy_by_cpy<T>* clone() const
+ {
+ return new data_proxy_by_cpy<T>(obj_);
+ }
+
+ virtual data_proxy_by_cpy<const T>* const_clone() const
+ {
+ return new data_proxy_by_cpy<const T>(obj_);
+ }
+
+ virtual const T& const_ref() const { return obj_; }
+ const T& obj() const { return obj_; }
+ T& obj() { return obj_; }
+
+ gen_proxy_type
+
+ protected:
+ T obj_;
+ };
+
+
+ struct NilClass
+ {
+ NilClass(int) {}
+ };
+
+ struct data_nil : public data_proxy<NilClass>
+ {
+ data_nil() : nil_object_(NilClass(0)) { logger << "ctor: " <<
proxy_type() << std::endl; }
+ data_nil(const NilClass& nil_object) : nil_object_(nil_object) {}
+ const NilClass& const_ref() const { return nil_object_; }
+ const NilClass& obj() const { return nil_object_; }
+ virtual data_nil* clone() const { return new data_nil; }
+ gen_proxy_type
+ const NilClass nil_object_;
+ };
+
+ extern const NilClass nil_object;
+ extern data_nil* nil_proxy;
+
+ template <typename T1, typename T2>
+ T2
+ data_cast(const T1& src)
+ {
+ T2 tmp(src);
+ return tmp;
+ }
+
+ template <typename T1, typename T2>
+ void
+ data_assign(T1& lhs, const T2& rhs)
+ {
+ lhs = rhs;
+ }
+
+ // data
+
+ struct data : public all_methods
+ {
+
+ virtual const data& self() const
+ {
+ return *this;
+ }
+
+ virtual data& self()
+ {
+ return *this;
+ }
+
+ data& assign(const data& rhs)
+ {
+ if (&rhs == this) return *this;
+ if (rhs.proxy_ == 0)
+ {
+ logger << "assign(const data& rhs) [ rhs.proxy_ == 0 ]"
<< std::endl;
+ proxy_ = nil_proxy;
+ }
+ else
+ {
+ assert(rhs.proxy_ != proxy_);
+ // if (proxy_ != 0)
+ // delete proxy_;
+ proxy_ = rhs.proxy_->clone();
+ }
+ return *this;
+ }
+
+ data& const_assign(const data& rhs)
+ {
+ if (&rhs == this) return *this;
+ if (rhs.proxy_ == 0)
+ {
+ logger << "const_assign(const data& rhs) [ rhs.proxy_ == 0 ]"
<< std::endl;
+ proxy_ = nil_proxy;
+ }
+ else
+ {
+ assert(rhs.proxy_ != proxy_);
+ // if (proxy_ != 0)
+ // delete proxy_;
+ proxy_ = rhs.proxy_->const_clone();
+ }
+ return *this;
+ }
+
+ data& operator=(const data& rhs) { return assign(rhs); }
+
+ data& operator=(data& rhs) { return assign(rhs); }
+
+
+ template <typename T>
+ data& operator=(const T& rhs);
+
+
+ template <typename T>
+ T convert_to() const;
+
+
+ template <typename T>
+ T& get_ref_on();
+
+ template <typename T>
+ const T& get_ref_on() const;
+
+ std::string& const_stripping(std::string& str) const
+ {
+ size_t pos;
+ while ((pos = str.find("const ")) != std::string::npos)
+ str.erase(pos, 6);
+ while ((pos = str.find(" const")) != std::string::npos)
+ str.erase(pos, 6);
+ return str;
+ }
+
+ template <typename T>
+ operator T() const
+ {
+ std::string src_type(proxy()->type());
+ std::string dest_type(mlc_name<T>::of());
+ if (const_stripping(src_type) == const_stripping(dest_type))
+ return get_ref_on<T>();
+ else
+ return convert_to<T>();
+ }
+
+
+ ~data()
+ {
+ if (proxy_ != nil_proxy)
+ {
+ logger << "~data [ type() = " << type() << "
]" << std::endl;
+ delete proxy_;
+ proxy_ = nil_proxy;
+ }
+ }
+
+
+ std::string type() const
+ {
+ return proxy()->proxy_type();
+ }
+
+
+ data operator[](const data&);
+ const data& operator[](const data&) const;
+ data operator*();
+ const data& operator*() const;
+
+
+ abstract_data* proxy() const
+ {
+ assert(proxy_);
+ return proxy_;
+ }
+
+ bool is_const()
+ {
+ std::string type_(type());
+ return type_.find("dyn::data_proxy_by_ref<") == 0
+ && type_.rfind("const>") == type_.length() - 6;
+ }
+
+ meth method(const std::string& method_name);
+
+ data() : proxy_(nil_proxy) {}
+
+ data(abstract_data* proxy, proxy_tag*) : all_methods(), proxy_(proxy) {}
+
+ template <class T>
+ data(T& obj) : all_methods()
+ {
+ logger << "data(T& obj) [ T = " <<
mlc_name<T>::of() << " ]" << std::endl;
+ proxy_ = new data_proxy_by_ref<T>(obj);
+ }
+
+ template <class T>
+ data(const T& obj) : all_methods()
+ {
+ logger << "data(const T& obj) [ T = " <<
mlc_name<T>::of() << " ]" << std::endl;
+ proxy_ = new data_proxy_by_ref<const T>(obj);
+ }
+
+ data(language::var& rhs);
+ data(language::val& rhs);
+ data(const language::var& rhs);
+ data(const language::val& rhs);
+
+ data(data& rhs) : all_methods(), proxy_(0)
+ {
+ logger << "data(data& rhs) [ rhs.type() = " << rhs.type()
<< " ]" << std::endl;
+ assign(rhs);
+ }
+
+ data(const data& rhs) : all_methods(), proxy_(0)
+ {
+ logger << "data(const data& rhs) [ rhs.type() = " <<
rhs.type() << " ]" << std::endl;
+ assign(rhs);
+ }
+
+ protected:
+ abstract_data* proxy_;
+ };
+
+ extern const data nil;
+
+ namespace internal {
+ extern op operator_push;
+ extern op operator_pop;
+ extern op operator_incr;
+ extern op operator_decr;
+ extern op operator_plus;
+ extern op operator_star;
+ extern op operator_equal;
+ extern op operator_not_equal;
+ extern meth operator_square_brackets;
+ }
+
+}
+
+template <typename T, dyn::policy::type policy>
+struct dyn_choose_data_proxy
+{
+ typedef dyn::data_proxy_by_cpy<T> ret;
+};
+
+template <typename T>
+struct dyn_choose_data_proxy<T, dyn::policy::is_ref>
+{
+ typedef dyn::data_proxy_by_ref<T> ret;
+};
+
+template <typename T>
+struct dyn_choose_data_proxy<T, (dyn::policy::type)(dyn::policy::is_ref +
dyn::policy::is_const)>
+{
+ typedef dyn::data_proxy_by_ref<const T> ret;
+};
+
+# ifdef DYN_FULL_IMPLEMENTATION
+# include "data.hxx"
+# endif
+
+#endif
--
1.6.5