summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-19 11:30:09 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-09-19 11:30:09 -0600
commit17f44d57164b123be802b3474f674d2e0df4d216 (patch)
treed992c46f2f2f4933f2af2b71ec06cc0d60cd168c
parentf255f2498da1fd985ad1ed79362580bbf4675723 (diff)
downloadchill-17f44d57164b123be802b3474f674d2e0df4d216.tar.gz
chill-17f44d57164b123be802b3474f674d2e0df4d216.tar.bz2
chill-17f44d57164b123be802b3474f674d2e0df4d216.zip
Template definition back in header files
-rw-r--r--.gitignore3
-rw-r--r--chill/src/ir_rose.cc1
-rw-r--r--omegalib/omega/include/basic/Bag.h328
-rw-r--r--omegalib/omega/include/basic/DynamicArray.h223
-rw-r--r--omegalib/omega/include/basic/List.h151
-rw-r--r--omegalib/omega/include/basic/Map.h67
-rw-r--r--omegalib/omega/include/basic/Section.h83
-rw-r--r--omegalib/omega/include/basic/SimpleList.h109
-rw-r--r--omegalib/omega/include/basic/Tuple.c2
-rw-r--r--omegalib/omega/include/basic/Tuple.h256
10 files changed, 1193 insertions, 30 deletions
diff --git a/.gitignore b/.gitignore
index ba18327..f0d8fa3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,8 @@
# Cmake build directory
/build
+# CLion config directory
+/.idea
+
# Vim swap file
*.swap
diff --git a/chill/src/ir_rose.cc b/chill/src/ir_rose.cc
index 36e2db9..27930e6 100644
--- a/chill/src/ir_rose.cc
+++ b/chill/src/ir_rose.cc
@@ -844,6 +844,7 @@ IR_roseCode::IR_roseCode(const char *filename, const char* proc_name) :
symtab2_ = func->get_definition()->get_symbol_table();
symtab3_ = func->get_definition()->get_body()->get_symbol_table();
// Manu:: added is_fortran_ parameter
+ // TODO Substitute it with a better builder
ocg_ = new omega::CG_roseBuilder(is_fortran_, root, firstScope,
func->get_definition()->get_symbol_table(),
func->get_definition()->get_body()->get_symbol_table(),
diff --git a/omegalib/omega/include/basic/Bag.h b/omegalib/omega/include/basic/Bag.h
index 3bd7143..a3d07a0 100644
--- a/omegalib/omega/include/basic/Bag.h
+++ b/omegalib/omega/include/basic/Bag.h
@@ -5,6 +5,7 @@
#include <basic/Iterator.h>
#include <basic/Collection.h>
#include <basic/Link.h>
+#include <assert.h>
namespace omega {
@@ -71,10 +72,6 @@ public:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/Bag.c>
-#endif
-
#define instantiate_Bag(T) template class Bag<T>; \
instantiate_List_Element(T);
#define instantiate_Ordered_Bag(T) template class Ordered_Bag<T>; \
@@ -82,4 +79,327 @@ public:
#define instantiate_Set(T) template class Set<T>; \
instantiate_Ordered_Bag(T)
+
+namespace omega {
+
+template<class T> Bag<T>::Bag() {
+ contents = new List_Element <T>;
+ contents->tail = 0;
+ }
+template<class T> Bag<T>::~Bag() {
+ delete contents;
+ }
+
+template<class T> Ordered_Bag<T>::Ordered_Bag() {}
+
+template<class T> Set<T>::Set() {}
+
+template<class T> Bag<T>::Bag(const Bag<T> &L) {
+ contents = new List_Element<T>(*L.contents);
+ }
+
+template<class T> Bag<T> & Bag<T>::operator=(const Bag<T> &L) {
+ if (this != &L) {
+ delete contents;
+ contents = new List_Element<T>(*L.contents);
+ }
+ return *this;
+ }
+
+
+
+template<class T> Set<T>::Set(T e) {
+ assert(this->contents);
+ this->contents->tail = new List_Element<T>(e, 0);
+ }
+
+
+/****************************************************************
+ * *
+ * Misc. simple Collection operations *
+ * *
+ ****************************************************************/
+
+template<class T> bool Bag<T>::empty() const {
+ return contents->tail == 0;
+ }
+
+template<class T> Iterator<T> *Bag<T>::new_iterator()
+ {
+ return new List_Element_Iterator<T>(contents->tail);
+ }
+
+
+template<class T> void Bag<T>::clear() {
+ if (contents->tail) delete contents->tail;
+ contents->tail = 0;
+ }
+
+template<class T> int Bag<T>::size() const {
+ int i = 0;
+ List_Element<T> * p = contents->tail;
+ while (p) {
+ p = p->tail;
+ i++;
+ };
+ return i;
+ }
+
+
+/****************************************************************
+ * *
+ * Collection/Element operations (e.g. insert, contains) *
+ * *
+ ****************************************************************/
+
+template<class T> void Bag<T>::remove(T e) {
+ List_Element<T> * p = contents;
+ while (p->tail && p->tail->head != e) p = p->tail;
+ if (p->tail && p->tail->head == e) {
+ List_Element<T> * q = p->tail;
+ p->tail = q->tail;
+ q->tail = 0;
+ delete q;
+ }
+ }
+
+template<class T> T Bag<T>::extract() {
+ List_Element<T> * p = contents->tail;
+ T e = p->head;
+ contents->tail = p->tail;
+ p->tail = 0;
+ delete p;
+ return e;
+ }
+
+
+template<class T> void Bag<T>::insert(T e) {
+ List_Element<T> * q = new List_Element<T>(e,contents->tail);
+ contents->tail = q;
+ }
+
+template<class T> void Ordered_Bag<T>::insert(T e) {
+ List_Element<T> * p = this->contents;
+ while (p->tail && p->tail->head < e) p = p->tail;
+ if (!p->tail || p->tail->head != e) {
+ List_Element<T> * q = new List_Element<T>(e,p->tail);
+ p->tail = q;
+ }
+ }
+
+
+template<class T> bool Bag<T>::contains(T e) const {
+ List_Element<T> * p = contents;
+ while (p->tail && p->tail->head != e) p = p->tail;
+ return (p->tail && p->tail->head == e);
+ }
+
+template<class T> bool Ordered_Bag<T>::contains(T e) const {
+ List_Element<T> * p = this->contents;
+ while (p->tail && p->tail->head < e) p = p->tail;
+ return (p->tail && p->tail->head == e);
+ }
+
+
+template<class T> bool Set<T>::contains (const Set<T>& b) const {
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents;
+ do {
+ /* consume matched elements in p and q */
+ p = p->tail;
+ q = q->tail;
+ if (!q) return 1; /* no more elements to match */
+ if (!p) return 0; /* nothing left in p to match with */
+ if (q->head < p->head) {
+ /* nothing smaller than
+ p->head left in p, so q->head
+ can't be matched */
+ return 0;
+ };
+ while (p && p->head < q->head) {
+ /* toss away some elements from p */
+ p = p->tail;
+ }
+ if (!p || q->head < p->head) return 0;
+ } while (q);
+
+ return 1;
+ }
+
+
+
+/****************************************************************
+ * *
+ * Collection/Collection operations (e.g. |=) *
+ * *
+ ****************************************************************/
+
+template<class T> void Bag<T>::operator |= (const Bag<T> & b) {
+ assert(this != &b);
+ List_Element<T> * q = b.contents->tail;
+
+ while (q) {
+ List_Element<T> * r = new List_Element<T>(q->head,contents->tail);
+ contents->tail = r;
+ q = q->tail;
+ }
+ }
+
+template<class T> void Ordered_Bag<T>::operator |= (const Ordered_Bag<T> & b) {
+ if (this == &b) return;
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents->tail;
+
+ while (q) {
+ while (p->tail && p->tail->head < q->head) p = p->tail;
+ List_Element<T> * r = new List_Element<T>(q->head,p->tail);
+ p->tail = r;
+ q = q->tail;
+ }
+ }
+
+template<class T> void Ordered_Bag<T>::operator |= (const Bag<T> & b) {
+ Ordered_Bag<T> tmp;
+ for (List_Element<T> *p = b.contents; p; p=p->tail) {
+ tmp.insert(p->head);
+ }
+ *this |= tmp;
+}
+
+template<class T> void Set<T>::operator |= (const Set<T> & b) {
+ if (this == &b) return;
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents->tail;
+
+ while (q) {
+ while (p->tail && p->tail->head < q->head) p = p->tail;
+ if (!p->tail || p->tail->head != q->head) {
+ List_Element<T> * r = new List_Element<T>(q->head,p->tail);
+ p->tail = r;
+ }
+ q = q->tail;
+ }
+ }
+
+template<class T> void Set<T>::operator |= (const Ordered_Bag<T> & b) {
+ Set<T> tmp;
+ for (List_Element<T> *p = b.contents; p; p=p->tail) {
+ tmp.insert(p->head);
+ }
+ *this |= tmp;
+}
+
+template<class T> void Set<T>::operator |= (const Bag<T> & b) {
+ Set<T> tmp;
+ for (List_Element<T> *p = b.contents; p; p=p->tail) {
+ tmp.insert(p->head);
+ }
+ *this |= tmp;
+}
+
+
+
+// delete items also in b
+template<class T> void Set<T>::operator -= (const Set<T> & b) {
+ if (this == &b) {
+ this->clear();
+ return;
+ }
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents->tail;
+
+ while (q) {
+ while (p->tail && p->tail->head < q->head) p = p->tail;
+ if (p->tail && p->tail->head == q->head) {
+ List_Element<T> * r = p->tail;
+ p->tail = r->tail;
+ r->tail = 0;
+ delete r;
+ }
+ q = q->tail;
+ }
+ }
+
+
+// delete items not in b
+template<class T> void Set<T>::operator &= (const Set<T> & b)
+ {
+ if (this == &b) return;
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents->tail;
+
+ while (q) {
+ while (p->tail && p->tail->head < q->head) {
+ List_Element<T> * r = p->tail;
+ p->tail = r->tail;
+ r->tail = 0;
+ delete r;
+ };
+ if (p->tail && p->tail->head == q->head) {
+ /* allow p->tail->head into the result */
+ p = p->tail;
+ }
+ /* q->head has matched anything it is going to match */
+ q = q->tail;
+ }
+ if (p->tail) {
+ delete p->tail;
+ p->tail = 0;
+ };
+
+ }
+
+
+template<class T> bool Set<T>::operator & (const Set<T>& b) const {
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents;
+ do {
+ p = p->tail;
+ q = q->tail;
+ while (p && q && p->head != q->head) {
+ while (p && p->head < q->head) p = p->tail;
+ while (p && q && q->head < p->head) q = q->tail;
+ };
+ if (p && q && p->head == q->head) return 1;
+ } while (p && q);
+
+ return 0;
+ }
+
+
+template<class T> bool Ordered_Bag<T>::operator == (const Ordered_Bag<T>& b) const {
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents;
+ while (1) {
+ p = p->tail;
+ q = q->tail;
+ if (!p && !q) return 1;
+ if (!p || !q) return 0;
+ if (p->head != q->head) return 0;
+ };
+
+ }
+
+template<class T> bool Ordered_Bag<T>::operator != (const Ordered_Bag<T>& b) const {
+ return !(*this == b);
+ }
+
+template<class T> bool Ordered_Bag<T>::operator < (const Ordered_Bag<T>& b) const {
+ List_Element<T> * p = this->contents;
+ List_Element<T> * q = b.contents;
+ while (1) {
+ p = p->tail;
+ q = q->tail;
+ if (!p && !q) return 0;
+ if (!p) return 1;
+ if (!q) return 0;
+ if (p->head < q->head) return 1;
+ if (q->head < p->head) return 0;
+ };
+
+ return 1;
+ }
+
+} // namespace
+
#endif
diff --git a/omegalib/omega/include/basic/DynamicArray.h b/omegalib/omega/include/basic/DynamicArray.h
index ac9bae4..08f8b91 100644
--- a/omegalib/omega/include/basic/DynamicArray.h
+++ b/omegalib/omega/include/basic/DynamicArray.h
@@ -1,6 +1,8 @@
#ifndef Already_Included_DynamicArray
#define Already_Included_DynamicArray
+#include <assert.h>
+
namespace omega {
template <class T> class DynamicArray2;
@@ -82,10 +84,6 @@ template <class T> class DynamicArray4 : public DynamicArray<T,4>
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/DynamicArray.c>
-#endif
-
#define instantiate_DynamicArray1(T) template class DynamicArray1<T>; \
template class DynamicArray<T,1>;
@@ -100,4 +98,221 @@ template <class T> class DynamicArray4 : public DynamicArray<T,4>
#define instantiate_DynamicArray4(T) template class DynamicArray4<T>; \
template class DynamicArray<T,4>; \
instantiate_DynamicArray3(T);
+
+namespace omega {
+
+template<class T, int d> void DynamicArray<T,d>::do_constr()
+ {
+// #if ! defined SHUT_UP_ABOUT_STATEMENT_WITH_NO_EFFECT_IN_DYNAMIC_ARRAY_CREATION
+// assert(d > 0);
+// #endif
+ bounds = 0;
+ elements = 0;
+ partial = false;
+ }
+
+
+template<class T> void DynamicArray1<T>::do_construct(int d0)
+ {
+ this->bounds = new int[1];
+ this->bounds[0] = d0;
+ this->elements = new T [d0];
+ this->partial = false;
+ }
+
+template<class T> void DynamicArray2<T>::do_construct(int d0, int d1)
+ {
+ this->bounds = new int[2];
+ this->bounds[0] = d0;
+ this->bounds[1] = d1;
+ this->elements = new T [d0 * d1];
+ this->partial = false;
+ }
+
+template<class T> void DynamicArray3<T>::do_construct(int d0,int d1,int d2)
+ {
+ this->bounds = new int[3];
+ this->bounds[0] = d0;
+ this->bounds[1] = d1;
+ this->bounds[2] = d2;
+ this->elements = new T [d0 * d1 * d2];
+ this->partial = false;
+ }
+
+template<class T> void DynamicArray4<T>::do_construct(int d0,int d1,int d2,int d3)
+ {
+ this->bounds = new int[4];
+ this->bounds[0] = d0;
+ this->bounds[1] = d1;
+ this->bounds[2] = d2;
+ this->bounds[3] = d3;
+ this->elements = new T [d0 * d1 * d2 * d3];
+ this->partial = false;
+ }
+
+template<class T, int d> DynamicArray<T,d>::DynamicArray()
+ {
+ do_constr();
+ }
+
+template<class T> DynamicArray1<T>::DynamicArray1(const char *)
+ {
+ this->do_constr();
+ }
+
+template<class T> DynamicArray2<T>::DynamicArray2(const char *,const char *)
+ {
+ this->do_constr();
+ }
+
+template<class T> DynamicArray3<T>::DynamicArray3(const char *,const char *,const char *)
+ {
+ this->do_constr();
+ }
+
+template<class T> DynamicArray4<T>::DynamicArray4(const char *,const char *,const char *,const char *)
+ {
+ this->do_constr();
+ }
+
+template<class T> DynamicArray1<T>::DynamicArray1(int d0)
+ {
+ do_construct(d0);
+ }
+
+template<class T> DynamicArray2<T>::DynamicArray2(int d0, int d1)
+ {
+ do_construct(d0, d1);
+ }
+
+template<class T> DynamicArray3<T>::DynamicArray3(int d0,int d1,int d2)
+ {
+ do_construct(d0, d1, d2);
+ }
+
+template<class T> DynamicArray4<T>::DynamicArray4(int d0,int d1,int d2,int d3)
+ {
+ do_construct(d0, d1, d2, d3);
+ }
+
+
+template<class T, int d> void DynamicArray<T,d>::do_destruct()
+ {
+ if (! partial)
+ {
+ delete [] bounds;
+ delete [] elements;
+ }
+ }
+
+
+template<class T, int d> DynamicArray<T,d>::~DynamicArray()
+ {
+ do_destruct();
+ }
+
+
+template<class T> void DynamicArray1<T>::resize(int d0)
+ {
+ assert(!this->partial);
+ this->do_destruct();
+ if (d0 == 0)
+ this->do_constr();
+ else
+ do_construct(d0);
+ }
+
+template<class T> void DynamicArray2<T>::resize(int d0, int d1)
+ {
+ assert(!this->partial);
+ this->do_destruct();
+ if (d0 == 0 && d1 == 0)
+ this->do_constr();
+ else
+ do_construct(d0, d1);
+ }
+
+template<class T> void DynamicArray3<T>::resize(int d0, int d1, int d2)
+ {
+ assert(!this->partial);
+ this->do_destruct();
+ if (d0 == 0 && d1 == 0 && d2 == 0)
+ this->do_constr();
+ else
+ do_construct(d0, d1, d2);
+ }
+
+template<class T> void DynamicArray4<T>::resize(int d0, int d1, int d2, int d3)
+ {
+ assert(!this->partial);
+ this->do_destruct();
+ if (d0 == 0 && d1 == 0 && d2 == 0 && d3 == 0)
+ this->do_constr();
+ else
+ do_construct(d0, d1, d2, d3);
+ }
+
+
+template<class T> T& DynamicArray1<T>::operator[](int d0)
+ {
+#if !defined (NDEBUG)
+ assert(this->elements != 0 && "Trying to dereference undefined array");
+ assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds");
+#endif
+
+ return this->elements[d0];
+ }
+
+template<class T> DynamicArray1<T> DynamicArray2<T>::operator[](int d0)
+ {
+#if !defined (NDEBUG)
+ assert(this->elements != 0 && "Trying to dereference undefined array");
+ assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds");
+#endif
+
+ DynamicArray1<T> result;
+ result.bounds = this->bounds+1;
+ result.elements = this->elements + this->bounds[1] * d0;
+ result.partial = true;
+ return result;
+ }
+
+template<class T> DynamicArray2<T> DynamicArray3<T>::operator[](int d0)
+ {
+#if !defined (NDEBUG)
+ assert(this->elements != 0 && "Trying to dereference undefined array");
+ assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds");
+#endif
+ DynamicArray2<T> result;
+ result.bounds = this->bounds+1;
+ result.elements = this->elements + this->bounds[1] * this->bounds[2] * d0;
+ result.partial = true;
+ return result;
+ }
+
+template<class T> DynamicArray3<T> DynamicArray4<T>::operator[](int d0)
+ {
+#if !defined (NDEBUG)
+ assert(this->elements != 0 && "Trying to dereference undefined array");
+ assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds");
+#endif
+
+ DynamicArray3<T> result;
+ result.bounds = this->bounds+1;
+ result.elements = this->elements + this->bounds[1] * this->bounds[2] * this->bounds[3] * d0;
+ result.partial = true;
+ return result;
+ }
+
+
+template<class T, int d>
+ DynamicArray<T,d>::DynamicArray(DynamicArray<T,d> &D)
+ {
+ assert(D.elements != 0 && "Trying to copy an undefined array");
+ partial = true;
+ bounds = D.bounds;
+ elements = D.elements;
+ }
+
+} // namespace
#endif
diff --git a/omegalib/omega/include/basic/List.h b/omegalib/omega/include/basic/List.h
index ee394d9..28ab1d5 100644
--- a/omegalib/omega/include/basic/List.h
+++ b/omegalib/omega/include/basic/List.h
@@ -8,6 +8,7 @@
#include <basic/Iterator.h>
#include <basic/Collection.h>
#include <basic/Link.h>
+#include <assert.h>
namespace omega {
@@ -77,14 +78,156 @@ private:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/List.c>
-#endif
-
#define instantiate_List(T) template class List<T>; \
template class List_Iterator<T>; \
instantiate_Only_List_Element(T) \
instantiate_Sequence(T)
+namespace omega {
+
+template<class T> List_Iterator<T>::List_Iterator(List<T> &l)
+: List_Element_Iterator<T>(l.contents) {}
+
+template<class T> List_Iterator<T>::List_Iterator(const List<T> &l)
+: List_Element_Iterator<T>(l.contents) {}
+
+template<class T> List_Iterator<T>::List_Iterator()
+: List_Element_Iterator<T>(0) {}
+
+template<class T> Iterator<T> *List<T>::new_iterator()
+{
+ return new List_Iterator<T>(*this);
+}
+
+template<class T> const T &List<T>::operator[](int i) const
+{
+ assert(i > 0 && "Subscript out of bounds");
+ List_Iterator<T> p(*this);
+
+ while(--i > 0 && p)
+ p++;
+
+ if (p)
+ return *p;
+ else
+ return *((T *)0);
+}
+
+template<class T> T &List<T>::operator[](int i)
+{
+ assert(i > 0 && "Subscript out of bounds");
+ List_Iterator<T> p(*this);
+
+ while(--i > 0 && p)
+ p++;
+
+ if (p)
+ return *p;
+ else
+ return *((T *)0);
+}
+
+template<class T> int List<T>::index(const T &item) const
+{
+ List_Iterator<T> p(*this);
+ int i = 1;
+
+ while(p && *p != item)
+ {
+ p++;
+ i++;
+ }
+ if (p)
+ return i;
+ else
+ return 0;
+}
+
+template<class T> int List<T>::size() const
+ {
+ int i = 0;
+ List_Element<T> * p = contents;
+ while (p)
+ {
+ p = p->tail;
+ i++;
+ }
+ return i;
+ }
+
+template<class T> T &List<T>::front() const
+ {
+ return contents->head;
+ }
+
+template<class T> T List<T>::remove_front()
+ {
+ List_Element<T> *frunt = contents;
+ contents = contents->tail;
+ T fruntT = frunt->head;
+ frunt->tail = 0;
+ delete frunt;
+ return fruntT;
+ }
+
+template<class T> void List<T>::prepend(const T &item)
+ {
+ contents = new List_Element<T>(item, contents);
+ }
+
+
+template<class T> void List<T>::append(const T &item)
+ {
+ *(end()) = new List_Element<T>(item, 0);
+ }
+
+template<class T> void List<T>::ins_after(List_Iterator<T> i,
+ const T &item)
+ {
+#if ! defined NDEBUG
+ for (List_Element<T> *e = contents; e != &(i.element()); e=e->tail)
+ {
+ assert(e);
+ }
+#endif
+ i.element().tail = new List_Element<T>(item, i.element().tail);
+ }
+
+template<class T> void List<T>::del_front()
+ {
+ List_Element<T> *e = contents;
+ contents = contents->tail;
+ e->tail = 0;
+ delete e;
+ }
+
+template<class T> void List<T>::del_after(List_Iterator<T> i)
+ {
+#if ! defined NDEBUG
+ for (List_Element<T> *e0 = contents; e0 != &(i.element()); e0=e0->tail)
+ {
+ assert(e0);
+ }
+#endif
+ List_Element<T> *e = i.element().tail;
+ i.element().tail = e->tail;
+ e->tail = 0;
+ delete e;
+ }
+
+template<class T> void List<T>::clear()
+ {
+ delete contents;
+ contents = 0;
+ }
+
+template<class T> void List<T>::join(List<T> &consumed)
+ {
+ List_Element<T> *e = consumed.contents;
+ consumed.contents = 0;
+ *(end()) = e;
+ }
+
+} // namespace
#endif
diff --git a/omegalib/omega/include/basic/Map.h b/omegalib/omega/include/basic/Map.h
index f94a10c..25a116d 100644
--- a/omegalib/omega/include/basic/Map.h
+++ b/omegalib/omega/include/basic/Map.h
@@ -55,14 +55,73 @@ private:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/Map.c>
-#endif
-
#define instantiate_Map(T1,T2) template class Map<T1,T2>; \
template class MapElement<T1,T2>; \
template class MapElementIterator<T1,T2>;
#define instantiate_MapElement(T1,T2) instantiate_Map(T1,T2)
#define instantiate_MapElementIterator(T1,T2) instantiate_Map(T1,T2)
+namespace omega {
+
+template<class K, class V> MapElement<K,V>:: MapElement(const MapElement<K,V>& M) {
+ if (M.tail) tail = new MapElement<K,V>(*M.tail);
+ else tail = 0;
+ k = M.k;
+ v = M.v;
+ }
+
+template<class K, class V> MapElement<K,V> &
+ MapElement<K,V>:: operator=(const MapElement<K,V>& M) {
+ if (this != &M) {
+ if (tail) delete tail;
+ if (M.tail) tail = new MapElement<K,V>(*M.tail);
+ else tail = 0;
+ k = M.k;
+ v = M.v;
+ }
+ return *this;
+ }
+
+
+
+
+#if ! defined linux
+template <class K, class V> Map <K,V>::Map(const V &default_value)
+#else
+template <class K, class V> Map <K,V>::Map(V default_value)
+#endif
+ : _default_value(default_value)
+ {
+ contents = 0;
+ }
+
+template <class K, class V> Map <K,V>::~Map()
+ {
+ delete contents;
+ }
+
+template <class K, class V> V Map<K,V>::operator()(K k) const {
+ MapElement <K,V> * P = contents;
+ while (P) {
+ if (P->k == k) return P->v;
+ P = P->tail;
+ };
+ return _default_value;
+ }
+
+template <class K, class V> V & Map<K,V>::operator[](K k) {
+ MapElement <K,V> * P = contents;
+ while (P) {
+ if (P->k == k) return P->v;
+ P = P->tail;
+ };
+ P = new MapElement <K,V>;
+ P->k = k;
+ P->v = _default_value;
+ P->tail = contents;
+ contents = P;
+ return P->v;
+ }
+
+} // namespace
#endif
diff --git a/omegalib/omega/include/basic/Section.h b/omegalib/omega/include/basic/Section.h
index 60821d1..7a4d241 100644
--- a/omegalib/omega/include/basic/Section.h
+++ b/omegalib/omega/include/basic/Section.h
@@ -5,6 +5,7 @@
*/
#include <basic/Collection.h>
+#include <assert.h>
namespace omega {
@@ -51,13 +52,87 @@ private:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/Section.c>
-#endif
-
#define instantiate_Section(T) template class Section<T>; \
template class Section_Iterator<T>; \
instantiate_Sequence(T)
#define instantiate_Section_Iterator(T) instantiate_Section(T)
+
+namespace omega {
+
+template <class T> Section<T>::Section(Sequence<T> *s, int start, int length)
+ {
+ assert(s->size() >= start-1 + length);
+ it = s;
+ _start = start;
+ _length = length;
+ }
+
+template <class T> Iterator<T> *Section<T>::new_iterator()
+ {
+ return new Section_Iterator<T>(*this);
+ }
+
+template <class T> const T &Section<T>::operator[](int i) const
+ {
+ assert(1 <= i && i <= size());
+ return (*it)[i+(_start-1)];
+ }
+
+template <class T> T &Section<T>::operator[](int i)
+ {
+ assert(1 <= i && i <= size());
+ return (*it)[i+(_start-1)];
+ }
+
+template <class T> int Section<T>::index(const T &var) const
+ {
+ int i;
+ for (i=1; i<=size(); i++)
+ if ((*this)[i] == var)
+ return i;
+ return 0;
+ }
+
+template <class T> int Section<T>::size() const
+ {
+ return _length;
+ }
+
+
+template <class T> Section_Iterator<T>::Section_Iterator(Section<T> &sec)
+ {
+ it = sec.it->new_iterator();
+ for (int i = 1; i < sec._start; i++)
+ (*it)++;
+ remaining = sec.size();
+ }
+
+
+template <class T> Section_Iterator<T>::Section_Iterator(const Section_Iterator<T> &si) : it(si.it), remaining(si.remaining) {}
+
+
+template <class T> void Section_Iterator<T>::operator++()
+ { this->operator++(0); }
+
+template <class T> void Section_Iterator<T>::operator++(int)
+ {
+ if (remaining > 0)
+ {
+ (*it)++;
+ remaining--;
+ }
+ }
+
+template <class T> bool Section_Iterator<T>::live() const
+ {
+ return (remaining > 0);
+ }
+
+template <class T> Iterator<T> *Section_Iterator<T>::new_copy() const
+ {
+ return new Section_Iterator<T>(*this);
+ }
+
+} // namespace
#endif
diff --git a/omegalib/omega/include/basic/SimpleList.h b/omegalib/omega/include/basic/SimpleList.h
index a08b307..104390d 100644
--- a/omegalib/omega/include/basic/SimpleList.h
+++ b/omegalib/omega/include/basic/SimpleList.h
@@ -81,13 +81,114 @@ private:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/SimpleList.c>
-#endif
-
#define instantiate_Simple_List(T) template class Simple_List<T>; \
template class Simple_List_Iterator<T>; \
instantiate_Only_List_Element(T) \
instantiate_Sequence(T)
+namespace omega {
+
+template<class T> Simple_List_Iterator<T>::Simple_List_Iterator(Simple_List<T> &l)
+: List_Element_Iterator<T>(l.contents) {}
+
+template<class T> Simple_List_Iterator<T>::Simple_List_Iterator(const Simple_List<T> &l)
+: List_Element_Iterator<T>(l.contents) {}
+
+template<class T> Simple_List_Iterator<T>::Simple_List_Iterator()
+: List_Element_Iterator<T>(0) {}
+
+template<class T> Iterator<T> *Simple_List<T>::new_iterator()
+{
+ return new Simple_List_Iterator<T>(*this);
+}
+
+template<class T> const T &Simple_List<T>::operator[](int i) const
+{
+ Simple_List_Iterator<T> p(*this);
+
+ while(--i > 0 && p)
+ p++;
+
+ if (p)
+ return *p;
+ else
+ return *((T *)0);
+}
+
+template<class T> T &Simple_List<T>::operator[](int i)
+{
+ Simple_List_Iterator<T> p(*this);
+
+ while(--i > 0 && p)
+ p++;
+
+ if (p)
+ return *p;
+ else
+ return *((T *)0);
+}
+
+
+template<class T> int Simple_List<T>::size() const
+ {
+ int i = 0;
+ List_Element<T> * p = contents;
+ while (p)
+ {
+ p = p->tail;
+ i++;
+ }
+ return i;
+ }
+
+template<class T> T &Simple_List<T>::front() const
+ {
+ return contents->head;
+ }
+
+template<class T> T Simple_List<T>::remove_front()
+ {
+ List_Element<T> *frunt = contents;
+ contents = contents->tail;
+ T fruntT = frunt->head;
+ frunt->tail = 0;
+ delete frunt;
+ return fruntT;
+ }
+
+template<class T> void Simple_List<T>::prepend(const T &item)
+ {
+ contents = new List_Element<T>(item, contents);
+ }
+
+
+template<class T> void Simple_List<T>::append(const T &item)
+ {
+ *(end()) = new List_Element<T>(item, 0);
+ }
+
+
+template<class T> void Simple_List<T>::del_front()
+ {
+ List_Element<T> *e = contents;
+ contents = contents->tail;
+ e->tail = 0;
+ delete e;
+ }
+
+
+template<class T> void Simple_List<T>::clear()
+ {
+ delete contents;
+ contents = 0;
+ }
+
+template<class T> void Simple_List<T>::join(Simple_List<T> &consumed)
+ {
+ List_Element<T> *e = consumed.contents;
+ consumed.contents = 0;
+ *(end()) = e;
+ }
+
+} // namespace
#endif
diff --git a/omegalib/omega/include/basic/Tuple.c b/omegalib/omega/include/basic/Tuple.c
index ce99e82..ee6648f 100644
--- a/omegalib/omega/include/basic/Tuple.c
+++ b/omegalib/omega/include/basic/Tuple.c
@@ -149,7 +149,7 @@ template<class T> void Tuple<T>::join(Tuple<T>& t) {
assert(alloc_sz >= sz);
for(int i=0; i<t.sz; i++)
data[i+old_sz] = t.data[i];
- t.clear();
+ t.clear();ation will not fail, it would generate the object file but it won't generate any code for the template class in the object file.
}
template<class T> void Tuple<T>::clear() { if (sz) delete [] data; data = 0; alloc_sz = 0; sz = 0; }
diff --git a/omegalib/omega/include/basic/Tuple.h b/omegalib/omega/include/basic/Tuple.h
index 28e83bd..7bb3c24 100644
--- a/omegalib/omega/include/basic/Tuple.h
+++ b/omegalib/omega/include/basic/Tuple.h
@@ -79,12 +79,258 @@ private:
} // namespace
-#if ! defined DONT_INCLUDE_TEMPLATE_CODE
-#include <basic/Tuple.c>
-#endif
-
#define instantiate_Tuple(T) template class Tuple<T>; \
template class Tuple_Iterator<T>; \
instantiate_Sequence(T)
-
+
+namespace omega {
+
+template<class T> T &Tuple<T>::operator[](int index)
+ {
+ assert(1 <= index && index <= sz); return data[index-1];
+ }
+
+template<class T> const T &Tuple<T>::operator[](int index) const
+ {
+ assert(1 <= index && index <= sz); return data[index-1];
+ }
+
+
+template<class T> Tuple<T>::~Tuple()
+ {
+ if (data)
+ delete [] data;
+ }
+
+template<class T> Tuple<T>::Tuple() : sz(0), alloc_sz(0),
+ prealloc_min(20),prealloc_pad(5), data(0)
+{
+ // nothing needs be done
+ }
+
+template<class T> Tuple<T>::Tuple(int size) : sz(size),
+ prealloc_min(20),prealloc_pad(5)
+{
+ if (sz > 0)
+ {
+ alloc_sz = prealloc_size(sz);
+ data = new T[alloc_sz];
+ assert(alloc_sz >= sz);
+ //Need some handling for out of memory.
+ assert (data!=0);
+ }
+ else {
+ alloc_sz = 0;
+ data = 0;
+ }
+}
+
+
+template<class T> Tuple<T>::Tuple(const Tuple<T>& t)
+ : sz(t.sz), alloc_sz(t.alloc_sz), prealloc_min(20),prealloc_pad(5)
+{
+ if (sz > 0) {
+ data = new T[alloc_sz];
+ assert (data!=0);
+ assert (alloc_sz >= sz);
+ for (int i=0; i<sz; i++)
+ data[i] = t.data[i];
+ } else {
+ data = 0;
+ alloc_sz = 0; // THis might not be 0 if it was a "clear"ed Tuple
+// assert(alloc_sz == 0);
+ }
+}
+
+
+template<class T> Tuple<T>& Tuple<T>::operator=(const Tuple<T>& t)
+{
+ if (this != &t) { // Delete this
+ if (data)
+ delete [] data;
+ sz = t.sz;
+ alloc_sz = t.alloc_sz;
+ assert(alloc_sz >= sz);
+ if (sz > 0) { // Copy old
+ data = new T[alloc_sz];
+ assert (data!=0);
+ for (int i=0; i<sz; i++)
+ data[i] = t.data[i];
+ } else {
+ data=0;
+ alloc_sz = 0; // THis might not be 0 if it was a "clear"ed Tuple
+// assert(alloc_sz == 0);
+ }
+ }
+ return *this;
+}
+
+
+template<class T> void Tuple<T>::reallocate(const int req_size)
+{
+ if (alloc_sz >= req_size) { // if (sz >= req_size), does this.
+ sz = req_size;
+ return;
+ }
+ alloc_sz = prealloc_size(req_size);
+ T* tmp_data = new T[alloc_sz];
+ for(int i=0;i<sz;i++)
+ tmp_data[i] = data[i];
+ delete [] data;
+ data = tmp_data;
+ sz = req_size;
+ assert(alloc_sz >= req_size);
+}
+
+template<class T> void Tuple<T>::delete_last()
+{
+assert(sz > 0);
+sz --;
+}
+
+template<class T> void Tuple<T>::append(const T &v)
+{
+ // Check if reallocation is necessary.
+ if (sz == 0) { // Empty Tuple
+ assert(alloc_sz >= 0); // May be nonzero for cleared tuple
+
+ if(alloc_sz == 0) { // If it's > 1 no allocation is necessary
+ alloc_sz = prealloc_size(1);
+ data = new T[alloc_sz];
+ }
+ assert (alloc_sz > 0 && data != 0);
+ } else {
+ if(sz == alloc_sz) { // Requires new allocation
+ alloc_sz = realloc_size(alloc_sz);
+ T * data_tmp = new T[alloc_sz];
+ assert (data_tmp!=0);
+ assert (alloc_sz > sz);
+ for (int i=0; i<sz; i++)
+ data_tmp[i] = data[i];
+ delete [] data;
+ data=data_tmp;
+ } // Otherwise big enough, no reallocation necessary
+ }
+ // Make assignment
+ assert(alloc_sz >= sz);
+ data[sz++] = v;
+}
+
+template<class T> void Tuple<T>::append(const Tuple<T>& t) {
+ int old_sz = sz;
+ reallocate(t.size()+size());
+ assert(alloc_sz >= sz);
+ for(int i=0; i<t.sz; i++)
+ data[i+old_sz] = t.data[i];
+}
+
+template<class T> void Tuple<T>::join(Tuple<T>& t) {
+ int old_sz = sz;
+ reallocate(t.size()+size());
+ assert(alloc_sz >= sz);
+ for(int i=0; i<t.sz; i++)
+ data[i+old_sz] = t.data[i];
+ t.clear();ation will not fail, it would generate the object file but it won't generate any code for the template class in the object file.
+}
+
+template<class T> void Tuple<T>::clear() { if (sz) delete [] data; data = 0; alloc_sz = 0; sz = 0; }
+
+template<class T> int Tuple<T>::empty() const { return (sz == 0); }
+
+template<class T> Iterator<T> *Tuple<T>::new_iterator()
+{
+ return new Tuple_Iterator<T>(*this);
+}
+
+template<class T> int Tuple<T>::index(const T & var) const
+/* returns index or 0 if var isn't in the tuple */
+{
+ int i;
+ for (i=0; i<sz; i++)
+ if (data[i]== var)
+ return i+1;
+ return 0;
+}
+
+template<class T> bool Tuple<T>::operator == (const Tuple<T>& b) const
+{
+ int i;
+ if (sz != b.size()) return false;
+ for (i=0; i<sz; i++)
+ if (!(data[i] == b[i+1])) return false;
+ return true;
+}
+
+/* class Tuple_Iterator */
+
+template<class T> Tuple_Iterator<T>::Tuple_Iterator(const Tuple<T> &tpl) :
+current(tpl.data), lastptr(tpl.data+tpl.sz-1), firstptr(tpl.data), sz(tpl.sz)
+{
+}
+
+template<class T> Tuple_Iterator<T>::Tuple_Iterator(T * cr, T *frst, T * lst,
+ int insz)
+ : current(cr), lastptr(lst), firstptr(frst), sz(insz)
+{
+}
+
+template<class T> const T & Tuple_Iterator<T>::operator*() const
+{
+ assert (current<=lastptr && current>=firstptr);
+ return *current;
+}
+
+template<class T> T & Tuple_Iterator<T>::operator*()
+{
+ assert (current<=lastptr && current >=firstptr);
+ return *current;
+}
+
+template<class T> void Tuple_Iterator<T>::operator++(int)
+{
+ current++;
+}
+
+template<class T> void Tuple_Iterator<T>::operator++()
+{
+ current++;
+}
+
+template<class T> void Tuple_Iterator<T>::operator--(int)
+{
+ current--;
+}
+
+template<class T> void Tuple_Iterator<T>::operator--()
+{
+ current--;
+}
+
+template<class T> void Tuple_Iterator<T>::set_to_last()
+{
+ current = lastptr;
+}
+
+template<class T> void Tuple_Iterator<T>::set_to_first()
+{
+ current = firstptr;
+}
+
+template<class T> void Tuple_Iterator<T>::set_position(const int req_pos)
+{
+ assert(req_pos <= sz && 1 <= req_pos);
+ current = firstptr + (req_pos - 1);
+}
+
+
+template<class T> bool Tuple_Iterator<T>::live() const
+{
+ return (current !=0 && current<=lastptr && current >= firstptr);
+}
+
+template<class T> Iterator<T> *Tuple_Iterator<T>::new_copy() const {
+ return new Tuple_Iterator<T>(current, firstptr, lastptr, sz);
+}
+
+} // namespace
#endif