aurelia-svn Mailing List for Aurelia
Status: Alpha
Brought to you by:
valentindavid
You can subscribe to this list here.
| 2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(8) |
Jul
(30) |
Aug
(5) |
Sep
(6) |
Oct
(13) |
Nov
(2) |
Dec
(5) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2011 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(2) |
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
|
From: SEAnews <ne...@se...> - 2014-12-23 04:28:29
|
【SEAnews:India Front Line Report】 =============================================== First published March 06, 1992 MCI (P) 066/05/2013 Published once a week =============================================== [Latest Report ] Category : MISC **************************************************** Review:The baptism of the Holy Spirit (The Lord is come!) (vol.141215) **************************************************** Please see the HTML version. http://seanewsonline.com/seanews/misc/141215e.htm [Contents] 【Review】He is not the God of the dead, but of the living, for to him all are alive.(Luke20:38) * The God of the living * A UN Security Council vote to end Israeli occupation is scheduled?! * The resolution largely adopts principles of the French draft * U.S. Secretary rushs to meet with PM Netanyahu * EU Parliament backs Palestine statehood 'in principle' * Abbas expresses his retirement * What is needed now is political will and courage: UN Secretary-General Ban * What is "Baptism with The Holy Spirit"? =============================================== Please let us know your feedback and comments. https://docs.google.com/spreadsheet/viewform?formkey=dC1lZmNDVEM1QW12aUxubFktc3B5eEE6MQ#gid=0 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Publisher : SEA Research sea...@gm... http://www.seanewsonline.com TEL:67520308 FAX:67567147 BLK 758 Yishun Street 72 #09-444 Singapore 760758 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ |
|
From: James <hu...@ta...> - 2012-07-27 05:58:04
|
Hey. How are things? We may be getting down there to your neck of the woods soon so maybe we can all go grab a bite to eat or something. I'll keep you posted. Talk to you soon, James |
|
From: <val...@us...> - 2011-05-16 12:54:51
|
Revision: 159
http://aurelia.svn.sourceforge.net/aurelia/?rev=159&view=rev
Author: valentindavid
Date: 2011-05-16 12:54:44 +0000 (Mon, 16 May 2011)
Log Message:
-----------
* doc/header.html: Insert "<div>" as work-around for Doxygen bug.
Modified Paths:
--------------
trunk/ChangeLog
trunk/doc/header.html
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-05-13 20:21:08 UTC (rev 158)
+++ trunk/ChangeLog 2011-05-16 12:54:44 UTC (rev 159)
@@ -1,3 +1,7 @@
+2011-05-16 Valentin David <val...@ii...>
+
+ * doc/header.html: Insert "<div>" as work-around for Doxygen bug.
+
2011-05-13 Valentin David <val...@ii...>
Fix for GCC-4.6.0.
Modified: trunk/doc/header.html
===================================================================
--- trunk/doc/header.html 2011-05-13 20:21:08 UTC (rev 158)
+++ trunk/doc/header.html 2011-05-16 12:54:44 UTC (rev 159)
@@ -42,3 +42,4 @@
</div>
</div>
<div class="cont">
+<div>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-05-13 20:21:14
|
Revision: 158
http://aurelia.svn.sourceforge.net/aurelia/?rev=158&view=rev
Author: valentindavid
Date: 2011-05-13 20:21:08 +0000 (Fri, 13 May 2011)
Log Message:
-----------
* demos-from-stratego/01-constant-folding-rules.cc (main):
Fix main strategy (missing some sub-strategies).
* src/lockfree/unordered_set.hh,
* src/lockfree/tests/test_sorted_forward_list.cc,
* src/llstack/queue.hh: Remove unused variable.
* src/lockfree/marked_pointer.hh: Fix includes.
* src/memory/pool_allocator.hh: Hack around Valgrind and
GCC warnings.
Modified Paths:
--------------
trunk/ChangeLog
trunk/demos-from-stratego/01-constant-folding-rules.cc
trunk/src/llstack/queue.hh
trunk/src/lockfree/marked_pointer.hh
trunk/src/lockfree/tests/test_sorted_forward_list.cc
trunk/src/lockfree/unordered_set.hh
trunk/src/memory/pool_allocator.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/ChangeLog 2011-05-13 20:21:08 UTC (rev 158)
@@ -1,3 +1,19 @@
+2011-05-13 Valentin David <val...@ii...>
+
+ Fix for GCC-4.6.0.
+
+ * src/memory/pool_allocator.hh: Hack around Valgrind and
+ GCC warnings.
+
+ * demos-from-stratego/01-constant-folding-rules.cc (main):
+ Fix main strategy (missing some sub-strategies).
+
+ * src/lockfree/unordered_set.hh,
+ * src/lockfree/tests/test_sorted_forward_list.cc,
+ * src/llstack/queue.hh: Remove unused variable.
+
+ * src/lockfree/marked_pointer.hh: Fix includes.
+
2011-05-12 Valentin David <val...@ii...>
* configure.ac: Distribute .xz archive. Use libtool. Make
Modified: trunk/demos-from-stratego/01-constant-folding-rules.cc
===================================================================
--- trunk/demos-from-stratego/01-constant-folding-rules.cc 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/demos-from-stratego/01-constant-folding-rules.cc 2011-05-13 20:21:08 UTC (rev 158)
@@ -245,7 +245,7 @@
return (~Div[Int[i], Int[j]] < !p(i, j) < divS < ~k < !Int[k])(t);
};
- auto EvalMode = [] (const T& t) {
+ auto EvalMod = [] (const T& t) {
V i, j, k;
return (~Mod[Int[i], Int[j]] < !p(i, j) < modS < ~k < !Int[k])(t);
};
@@ -366,6 +366,9 @@
auto til_simplify = innermost(ForToWhile + IfThenToIfElse
+ AddZero + MulOne
+ EvalAdd + EvalMul + EvalSub + EvalDiv
+ + EvalMod + EvalLt + EvalGt + EvalOr
+ + EvalAnd + EvalS2I + EvalI2S + EvalIf
+ + EvalWhile
+ EvalLeq + EvalGeq + EvalEqu + EvalNeq
+ DefaultDeclaration
+ ReadInt + WriteInt
Modified: trunk/src/llstack/queue.hh
===================================================================
--- trunk/src/llstack/queue.hh 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/src/llstack/queue.hh 2011-05-13 20:21:08 UTC (rev 158)
@@ -112,8 +112,7 @@
rj_t::frame_set_t::iterator f = (*j).second.begin();
frame fr = *f;
rj_t::ln p = (*j).first;
- std::pair<rj_t::frame_set_t::iterator, bool> k =
- (*i).second.done[(*j).first].insert(*f);
+ (*i).second.done[(*j).first].insert(*f);
(*j).second.erase(*f);
if ((*j).second.empty()) {
(*i).second.pending.erase(j);
Modified: trunk/src/lockfree/marked_pointer.hh
===================================================================
--- trunk/src/lockfree/marked_pointer.hh 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/src/lockfree/marked_pointer.hh 2011-05-13 20:21:08 UTC (rev 158)
@@ -19,6 +19,7 @@
# define __MARKED_POINTER_HH
# include <type_traits>
+# include <memory>
namespace lockfree {
namespace details {
Modified: trunk/src/lockfree/tests/test_sorted_forward_list.cc
===================================================================
--- trunk/src/lockfree/tests/test_sorted_forward_list.cc 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/src/lockfree/tests/test_sorted_forward_list.cc 2011-05-13 20:21:08 UTC (rev 158)
@@ -33,7 +33,6 @@
insert_random(const insert_random&) = default;
void operator()() {
- L::iterator last_to_remove = l.end();
std::uniform_int_distribution<> r(0, 4096);
for (unsigned i = 0; i < 1000; ++i) {
l.insert(r(engine));
@@ -51,7 +50,6 @@
erase_random(const erase_random&) = default;
void operator()() {
- L::iterator last_to_remove = l.end();
std::uniform_int_distribution<> r(0, 4096);
for (unsigned i = 0; i < 1000; ++i) {
l.erase(l.find(r(engine)));
Modified: trunk/src/lockfree/unordered_set.hh
===================================================================
--- trunk/src/lockfree/unordered_set.hh 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/src/lockfree/unordered_set.hh 2011-05-13 20:21:08 UTC (rev 158)
@@ -228,7 +228,6 @@
size_t h = hash(elt);
typename list_t::const_iterator i = get_bucket(h);
size_t inv = get_invert(h);
- typename list_t::const_iterator was_found = i;
size_t f = 0;
for (;
i != list.end(); ++i) {
Modified: trunk/src/memory/pool_allocator.hh
===================================================================
--- trunk/src/memory/pool_allocator.hh 2011-05-13 16:57:22 UTC (rev 157)
+++ trunk/src/memory/pool_allocator.hh 2011-05-13 20:21:08 UTC (rev 158)
@@ -24,6 +24,9 @@
# include "../lockfree/simple_stack.hh"
# ifdef HAVE_VALGRIND_VALGRIND_H
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+# pragma GCC diagnostic ignored "-Wunused-value"
# include <valgrind/valgrind.h>
# include <valgrind/memcheck.h>
# else
@@ -179,4 +182,8 @@
}
+# ifdef HAVE_VALGRIND_VALGRIND_H
+# pragma GCC diagnostic pop
+# endif
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-05-13 16:57:33
|
Revision: 157
http://aurelia.svn.sourceforge.net/aurelia/?rev=157&view=rev
Author: valentindavid
Date: 2011-05-13 16:57:22 +0000 (Fri, 13 May 2011)
Log Message:
-----------
* configure.ac: Distribute .xz archive. Use libtool. Make
sure that cross-compilation does not try to bootstrap the
distribution. Fix bootstrap with VPATH. Use Catsfoot library.
* src/streams/buf_stream.hh: Clean up interface style.
* src/relations/relations.hh: Improve move operations.
* src/max_shared/max_shared_ptr.hh: Make it generic to the
set type used (or nearly).
* src/type_traits/overloading_priority.hh,
* src/type_traits/is_callable_with.hh,
* src/type_traits/has_member_hash.hh,
* src/type_traits/has_constructor.hh:
Remove. Those are now provided by Catsfoot.
* src/hash/mhash.hh, src/terms/constructor.hh: Use Catsfoot.
* src/terms/Makefile.am (type_traits_HEADERS): Update.
* src/terms/Makefile.am: Fix VPATH compilation.
Modified Paths:
--------------
trunk/ChangeLog
trunk/configure.ac
trunk/doc/Makefile.am
trunk/src/hash/mhash.hh
trunk/src/max_shared/max_shared_ptr.hh
trunk/src/relations/relations.hh
trunk/src/streams/buf_stream.hh
trunk/src/terms/constructor.hh
trunk/src/terms/term.hh
trunk/src/type_traits/Makefile.am
Removed Paths:
-------------
trunk/src/type_traits/has_constructor.hh
trunk/src/type_traits/has_member_hash.hh
trunk/src/type_traits/has_model.hh
trunk/src/type_traits/is_callable_with.hh
trunk/src/type_traits/overloading_priority.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/ChangeLog 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,3 +1,28 @@
+2011-05-12 Valentin David <val...@ii...>
+
+ * configure.ac: Distribute .xz archive. Use libtool. Make
+ sure that cross-compilation does not try to bootstrap the
+ distribution. Fix bootstrap with VPATH. Use Catsfoot library.
+
+ * src/streams/buf_stream.hh: Clean up interface style.
+
+ * src/relations/relations.hh: Improve move operations.
+
+ * src/max_shared/max_shared_ptr.hh: Make it generic to the
+ set type used (or nearly).
+
+ * src/type_traits/overloading_priority.hh,
+ * src/type_traits/is_callable_with.hh,
+ * src/type_traits/has_member_hash.hh,
+ * src/type_traits/has_constructor.hh:
+ Remove. Those are now provided by Catsfoot.
+
+ * src/hash/mhash.hh, src/terms/constructor.hh: Use Catsfoot.
+
+ * src/terms/Makefile.am (type_traits_HEADERS): Update.
+
+ * src/terms/Makefile.am: Fix VPATH compilation.
+
2011-01-20 Valentin David <val...@ii...>
* src/parser_generator/syntax.csf:
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/configure.ac 2011-05-13 16:57:22 UTC (rev 157)
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-AC_PREREQ([2.67])
+AC_PREREQ([2.68])
AC_INIT([aurelia], [0.1],dnl
[aur...@li...],dnl
@@ -29,7 +29,7 @@
AC_CONFIG_HEADERS([config/config.h src/aurelia-config.hh])
AM_INIT_AUTOMAKE([1.11a foreign
- dist-bzip2 tar-pax
+ dist-xz no-dist-gzip tar-pax
color-tests parallel-tests
-W -Wall])
AM_SILENT_RULES([yes])
@@ -44,7 +44,7 @@
AC_PROG_INSTALL
AC_PROG_SED
-
+AC_PROG_LIBTOOL
AC_C_BIGENDIAN
CXX0X_FLAG
@@ -83,6 +83,10 @@
AC_ARG_ENABLE([bootstrap],[AS_HELP_STRING([--enable-bootstrap],dnl
[bootstrap when checked out from SVN.])],[dnl
+ if test -n "$host_alias"; then
+ AC_MSG_ERROR([Cannot cross-compile while bootstrapping. Use a source tarball.])
+ fi
+
AC_ARG_VAR([PARSER_GEN], [Aurelia parser generator])
AC_ARG_VAR([DOXYGEN], [Doxygen documentation generation tool])
AC_ARG_VAR([SVN], [svn command])
@@ -96,7 +100,7 @@
AC_CHECK_PROGS([DOXYGEN], [doxygen], [dnl
AC_MSG_ERROR([doxygen not found. Please set variable DOXYGEN.])])
BOOTSTRAP=true
- svnrev=`$SVN info 2>/dev/null | sed "/Revision: /{;s///;q;};d"`
+ svnrev=`$SVN info $srcdir 2>/dev/null | sed "/Revision: /{;s///;q;};d"`
if test -z "$svnrev"
then
svnrev=`cat $srcdir/svnrev`
@@ -153,6 +157,12 @@
PACKAGE_VERSION
VERSION])
+PKG_CHECK_MODULES([catsfoot], [
+ catsfoot >= 0.1
+])
+AC_SUBST([AM_CXXFLAGS], ["$catsfoot_CFLAGS"])
+AC_SUBST([AM_LDFLAGS], ["$catsfoot_LIBS"])
+
AC_CONFIG_COMMANDS([docdeps], [dnl
AS_MKDIR_P([doc/$DOCDEPDIR])
test -f doc/$DOCDEPDIR/doc.deps || echo '# Dummy' >doc/$DOCDEPDIR/doc.deps
Modified: trunk/doc/Makefile.am
===================================================================
--- trunk/doc/Makefile.am 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/doc/Makefile.am 2011-05-13 16:57:22 UTC (rev 157)
@@ -29,10 +29,10 @@
header-exp.html: header.html
$(AM_V_GEN)if test x"$(ONLINE)" = xyes; then \
- cp header.html header-exp.html; \
+ cp $< $@; \
else \
$(SED) "/<!--online only begin-->/{;:l;/<!--online only end-->/d;N;bl;}" \
- header.html >header-exp.html; \
+ $< >$@; \
fi
html: html.stamp
@@ -89,6 +89,8 @@
-rm -rf ./$(DEPDIR)
.doc.in.doc:
+ @for i in pages pages/manual pages/tutorial; do \
+ $(MKDIR_P) $$i; done
$(AM_V_GEN)if $(SED) -f $(srcdir)/makemenu.sed $< | \
$(SED) "/^<ul>$$/{;N;/<\/ul>$$/d;}" >"$@.tmp"; then \
mv "$@.tmp" "$@"; \
Modified: trunk/src/hash/mhash.hh
===================================================================
--- trunk/src/hash/mhash.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/hash/mhash.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -17,19 +17,15 @@
#ifndef __MHASH_HH
# define __MHASH_HH
-# include "../type_traits/has_member_hash.hh"
# include <functional>
+# include <concept/concept_tools.hh>
+# include <type_traits/is_callable.hh>
+# include <wrappers/members.hh>
+# include <memory>
namespace aurelia {
- /*! \brief Functor calling a hash method as member.
- */
- template <typename T>
- struct member_hash: public std::unary_function<T, size_t> {
- size_t operator()(const T& t) const {
- return t.hash();
- }
- };
+ DEF_MEMBER_WRAPPER(hash);
/*! \brief Helper traits for mhash
*/
@@ -41,15 +37,16 @@
};
template <typename T>
- struct try_member_hash<T, true>: public member_hash<T> {
+ struct try_member_hash<T, true>: public member_hash {
};
/*! \brief Functor calling a hash method as member if present, or the
* std::hash functor otherwise.
*/
template <typename T>
- struct mhash: public try_member_hash<T, type_traits::
- has_member_hash<T>::value> {
+ struct mhash:
+ public try_member_hash
+ <T, IF(catsfoot::is_callable<member_hash(const T)>)> {
};
}
Modified: trunk/src/max_shared/max_shared_ptr.hh
===================================================================
--- trunk/src/max_shared/max_shared_ptr.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/max_shared/max_shared_ptr.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -19,13 +19,16 @@
# define __MAX_SHARED_PTR_HH
# include "../lockfree/unordered_set.hh"
+# include <unordered_set>
+# include "../memory/pool_allocator.hh"
# include <memory>
# include <atomic>
-# include "../type_traits/has_constructor.hh"
# include "../type_traits/is_same_ellipsis.hh"
+# include <type_traits/is_constructible.hh>
# include "deref.hh"
# include "../hash/mhash.hh"
+# include <wrappers/members.hh>
namespace aurelia {
@@ -44,16 +47,15 @@
}
~virt_ptr() {
-
}
protected:
- virt_ptr(const virt_ptr& other): _count() {
+ virt_ptr(const virt_ptr& other): _count(0) {
_count.store(other._count.load());
}
public:
- virt_ptr(virt_ptr&& other): _count() {
+ virt_ptr(virt_ptr&& other): _count(0) {
_count.store(other._count.load());
}
@@ -65,19 +67,41 @@
}
};
+ DEF_MEMBER_WRAPPER(collect);
+ template <typename T,
+ bool = IF(catsfoot::is_callable<member_collect(T&)>)>
+ struct collector {
+ static bool collect(T&) {
+ return false;
+ }
+ };
+
+ template <typename T>
+ struct collector<T, true> {
+ static bool collect(T& t) {
+ return t.collect();
+ }
+ };
+
/*! \brief Provides a maximally shared allocated pointer.
*
*/
template <typename T, typename Hash = mhash<T>,
typename EqnFunc = std::equal_to<T>,
- typename Alloc = std::allocator<T> >
+ typename Alloc = pool_allocator<T>,
+ bool lockfree = true>
struct max_shared_ptr {
protected:
struct ptr;
- typedef lockfree::unordered_set<ptr, deref_op<Hash>,
- deref_op<EqnFunc>,
- Alloc> set_t;
+ typedef typename
+ std::conditional<lockfree,
+ lockfree::unordered_set<ptr, deref_op<Hash>,
+ deref_op<EqnFunc>,
+ Alloc>,
+ std::unordered_set<ptr, deref_op<Hash>,
+ deref_op<EqnFunc>,
+ Alloc> >::type set_t;
struct ptr: public virt_ptr {
private:
typedef virt_ptr super;
@@ -93,7 +117,7 @@
//cleanup of allocators.
_set.insert(ptr(T()));
_set.clear();
- while (_set.collect()) ;
+ while (collector<set_t>::collect(_set)) ;
atexit(collect);
}
@@ -146,7 +170,7 @@
public:
static void collect() {
- while (set().collect()) ;
+ while (collector<set_t>::collect(set())) ;
}
private:
@@ -201,15 +225,12 @@
}
template <typename... Args,
- typename =
- typename std::enable_if<!type_traits::
- is_same_ellipsis<max_shared_ptr,
- Args...>::
- value>::type,
- typename =
- typename std::enable_if<type_traits::
- has_constructor<T, Args...>::value>::type>
- max_shared_ptr(Args... args...): _ptr(ptr::create(T(std::forward<Args>(args)...))) {
+ ENABLE_IF_NOT(type_traits::
+ is_same_ellipsis<max_shared_ptr,
+ Args...>),
+ ENABLE_IF(catsfoot::is_constructible<T(Args...)>)>
+ max_shared_ptr(Args... args...):
+ _ptr(ptr::create(T(std::forward<Args>(args)...))) {
}
max_shared_ptr(): _ptr(set().end()) {
@@ -235,6 +256,7 @@
return *get();
}
};
+
}
Modified: trunk/src/relations/relations.hh
===================================================================
--- trunk/src/relations/relations.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/relations/relations.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -33,6 +33,11 @@
this->insert(t);
}
+ set(const set&) = default;
+ set(set&&) = default;
+ set& operator=(const set&) = default;
+ set& operator=(set&& other) = default;
+
set operator|(const set& other) const {
set ret = *this;
ret.insert(other.begin(), other.end());
@@ -58,6 +63,11 @@
this->insert(t);
}
+ rel_set(const rel_set&) = default;
+ rel_set(rel_set&&) = default;
+ rel_set& operator=(const rel_set&) = default;
+ rel_set& operator=(rel_set&& other) = default;
+
typename std::unordered_multimap<T,U>::iterator
insert(const typename std::unordered_multimap<T,U>::value_type& v) {
typename std::unordered_multimap<T,U>::iterator i = this->find(v.first);
@@ -152,7 +162,7 @@
ret.insert(in.first);
ret.insert(in.second);
});
- return ret;
+ return std::move(ret);
}
template <typename Stream, typename T, typename U>
@@ -200,7 +210,7 @@
[&ret](const std::pair<T, T>& in) {
ret.erase(in.second);
});
- return ret;
+ return std::move(ret);
}
template <typename T>
@@ -211,7 +221,7 @@
if (m.find(in.second) == m.end())
ret.insert(in.second);
});
- return ret;
+ return std::move(ret);
}
template <typename T, typename U, typename V>
@@ -229,7 +239,7 @@
}
}
- return ret;
+ return std::move(ret);
}
template <typename T, typename U>
@@ -244,7 +254,7 @@
}
}
- return ret;
+ return std::move(ret);
}
template <typename T, typename U>
@@ -254,7 +264,7 @@
[&ret](const std::pair<T, U>& p) {
ret.insert(p.first);
});
- return ret;
+ return std::move(ret);
}
template <typename T>
@@ -265,7 +275,7 @@
if (b.find(t) == b.end())
ret.insert(t);
});
- return ret;
+ return std::move(ret);
}
template <typename T>
@@ -277,7 +287,7 @@
[&direct_reach, &G, &Excl](const T& in) {
direct_reach |= G[in] - Excl;
});
- return Start | reachX(G, direct_reach, Excl | Start);
+ return Start | reachX(G, std::move(direct_reach), Excl | Start);
}
}
Modified: trunk/src/streams/buf_stream.hh
===================================================================
--- trunk/src/streams/buf_stream.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/streams/buf_stream.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -40,6 +40,10 @@
std::forward_list<rc_char>::iterator i;
int pos;
+ friend class buf_stream;
+ explicit buf_stream_iterator(buf_stream* s,
+ const std::forward_list<rc_char>::iterator& i,
+ int pos);
public:
unsigned hash() const;
@@ -57,15 +61,12 @@
return pos < other.pos;
}
- explicit buf_stream_iterator(buf_stream* s,
- const std::forward_list<rc_char>::iterator& i,
- int pos);
-
~buf_stream_iterator();
buf_stream_iterator& operator++();
- buf_stream_iterator(const buf_stream_iterator& other);
+ buf_stream_iterator(const buf_stream_iterator&);
+ buf_stream_iterator(buf_stream_iterator&&);
char operator*() const {
return (*i).c;
@@ -73,12 +74,11 @@
bool eof() const;
- buf_stream_iterator& operator=(buf_stream_iterator other) {
- this->swap(other);
- return *this;
+ buf_stream_iterator& operator=(const buf_stream_iterator& other) {
+ return *this = buf_stream_iterator(other);
}
- void swap(buf_stream_iterator& other);
+ buf_stream_iterator& operator=(buf_stream_iterator&& other);
bool eat(const std::string& s) {
std::string::const_iterator i = s.begin();
@@ -106,13 +106,9 @@
int size;
#endif
- //FORBIDDEN!
- explicit buf_stream(const buf_stream&): real_stream(NULL),
- buf(),
- start(0)
- {}
-
public:
+ buf_stream(const buf_stream&) = delete;
+ buf_stream(buf_stream&&) = delete;
#ifndef NDEBUG
int buffer_start() const {
@@ -138,18 +134,9 @@
return _hash;
}
- buf_stream& operator=(buf_stream other) {
- this->swap(other);
- return *this;
- }
+ buf_stream& operator=(const buf_stream&) = delete;
+ buf_stream& operator=(buf_stream&&) = delete;
- void swap(buf_stream& other) {
- std::istream* os = other.real_stream;
- other.real_stream = real_stream;
- real_stream = os;
- std::swap(buf, other.buf);
- }
-
buf_stream_iterator begin() {
std::forward_list<rc_char>::iterator i = buf.begin();
if (i == buf.end()) {
@@ -167,6 +154,10 @@
return buf_stream_iterator(this, i, -1);
}
+ std::forward_list<rc_char>::iterator buf_end() {
+ return buf.end();
+ }
+
void cleanup () {
std::forward_list<rc_char>::iterator i = buf.begin();
while (i != buf.end()) {
@@ -218,6 +209,12 @@
(*i).refs++;
}
+ buf_stream_iterator::buf_stream_iterator(buf_stream_iterator&& other)
+ : s(other.s), i(s->buf_end()), pos(other.pos) {
+ std::swap(i, other.i);
+ other.pos = -1;
+ }
+
buf_stream_iterator::~buf_stream_iterator()
{
if (!s->is_end(i)) {
@@ -242,13 +239,13 @@
return (s->is_end(i));
}
-void buf_stream_iterator::swap(buf_stream_iterator& other) {
- buf_stream* os = other.s;
- other.s = s;
- s = os;
- std::swap(pos, other.pos);
- std::swap(i, other.i);
-}
+ buf_stream_iterator& buf_stream_iterator::operator=
+ (buf_stream_iterator&& other) {
+ std::swap(s, other.s);
+ std::swap(pos, other.pos);
+ std::swap(i, other.i);
+ return *this;
+ }
unsigned buf_stream_iterator::hash() const {
//!FIXME: -1 should have the same hash as EOF
Modified: trunk/src/terms/constructor.hh
===================================================================
--- trunk/src/terms/constructor.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/terms/constructor.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -127,11 +127,11 @@
template <typename Pool>
struct untyped_constructor:
public max_shared_ptr<untyped_constructor_core,
- member_hash<untyped_constructor_core>,
+ member_hash,
std::equal_to<untyped_constructor_core>,
pool_allocator<untyped_constructor_core> > {
typedef max_shared_ptr<untyped_constructor_core,
- member_hash<untyped_constructor_core>,
+ member_hash,
std::equal_to<untyped_constructor_core>,
pool_allocator<untyped_constructor_core> > super;
Modified: trunk/src/terms/term.hh
===================================================================
--- trunk/src/terms/term.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/terms/term.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -197,12 +197,12 @@
template <typename Pool>
struct untyped_term:
public max_shared_ptr<untyped_term_core<Pool>,
- member_hash<untyped_term_core<Pool> >,
+ member_hash,
std::equal_to<untyped_term_core<Pool> >,
pool_allocator<untyped_term_core<Pool> > > {
public:
typedef max_shared_ptr<untyped_term_core<Pool>,
- member_hash<untyped_term_core<Pool> >,
+ member_hash,
std::equal_to<untyped_term_core<Pool> >,
pool_allocator<untyped_term_core<Pool> > > super;
Modified: trunk/src/type_traits/Makefile.am
===================================================================
--- trunk/src/type_traits/Makefile.am 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/Makefile.am 2011-05-13 16:57:22 UTC (rev 157)
@@ -16,12 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
type_traits_HEADERS= \
- is_callable_with.hh \
- overloading_priority.hh \
- has_model.hh \
itself.hh \
- has_constructor.hh \
- has_member_hash.hh \
is_same_ellipsis.hh
type_traitsdir=$(includedir)/type_traits
Deleted: trunk/src/type_traits/has_constructor.hh
===================================================================
--- trunk/src/type_traits/has_constructor.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/has_constructor.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,48 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __HAS_CONSTRUCTOR_HH
-# define __HAS_CONSTRUCTOR_HH
-
-# include "itself.hh"
-# include "overloading_priority.hh"
-# include <type_traits>
-
-namespace aurelia {
- namespace type_traits {
-
- template <typename T, typename... Args,
- typename = typename
- itself<decltype(T(std::declval<Args>()...))>::type>
- std::true_type has_constructor_helper(try_first, T, Args...);
-
- template <typename T, typename... Args>
- std::false_type has_constructor_helper(try_second, T, Args...);
-
- /*! \brief Tells if a type has a constructor with arguments Args...
- */
- template <typename T, typename... Args>
- struct has_constructor:
- public itself<decltype(has_constructor_helper(try_first(),
- std::declval<T>(),
- std::declval<Args>()...))>
- ::type
- {
- };
- }
-}
-
-#endif
Deleted: trunk/src/type_traits/has_member_hash.hh
===================================================================
--- trunk/src/type_traits/has_member_hash.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/has_member_hash.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,56 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __HAS_MEMBER_HASH_HH
-# define __HAS_MEMBER_HASH_HH
-
-# include <type_traits>
-# include "itself.hh"
-# include "overloading_priority.hh"
-
-namespace aurelia {
- namespace type_traits {
-
- /*! \brief Helper for hash_member_hash
- */
- template <typename T,
- typename = decltype(std::declval<const T>().hash())>
- std::true_type has_member_hash_helper(try_first, T) {
- return 0;
- }
-
- /*! \brief Helper for hash_member_hash
- */
- template <typename T>
- std::false_type has_member_hash_helper(try_second, T) {
- return 0;
- }
-
- /*! \brief Type traits telling wether a type has a hash method.
- */
- template <typename T>
- struct has_member_hash {
- typedef
- typename itself<
- decltype(has_member_hash_helper(try_first(),
- std::declval<const T>()))>::type type;
- enum { value = type::value };
- };
-
- }
-}
-
-#endif
Deleted: trunk/src/type_traits/has_model.hh
===================================================================
--- trunk/src/type_traits/has_model.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/has_model.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,47 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __HAS_MODEL_HH
-# define __HAS_MODEL_HH
-
-# include <type_traits>
-# include "itself.hh"
-
-namespace aurelia {
- namespace type_traits {
-
- template <typename T,
- typename = typename T::model>
- std::true_type has_model_helper(const T&) {
- assert(false);
- return std::true_type();
- }
-
- template <typename T,
- typename = typename T::no_model>
- std::false_type has_model_helper(const T&) {
- assert(false);
- return std::false_type();
- }
-
- template <typename T>
- struct has_model:
- public itself<decltype(has_model_helper(std::declval<T>()))>::type {
- };
- }
-}
-
-#endif
Deleted: trunk/src/type_traits/is_callable_with.hh
===================================================================
--- trunk/src/type_traits/is_callable_with.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/is_callable_with.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,56 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __IS_CALLABLE_WITH_HH
-# define __IS_CALLABLE_WITH_HH
-
-# include <type_traits>
-# include "overloading_priority.hh"
-# include "itself.hh"
-
-namespace aurelia {
- namespace type_traits {
-
- template <typename T, typename U>
- std::false_type is_callable_helper(try_second, T, U) {
- return 0;
- }
-
- template <typename T, typename U,
- typename =
- decltype(std::declval<T&>()(std::declval<U>()))>
- std::true_type is_callable_helper(try_first, T&, U&&) {
- return 0;
- }
-
- template <typename T, typename U,
- typename =
- decltype(std::declval<const T&>()(std::declval<U>()))>
- std::true_type is_callable_helper(try_first, const T&, U&&) {
- return 0;
- }
-
- template <typename T, typename U>
- struct is_callable_with:
- public itself<decltype(is_callable_helper(try_first(),
- std::declval<T>(),
- std::declval<U>()))>::type {
- };
-
- }
-}
-
-#endif
Deleted: trunk/src/type_traits/overloading_priority.hh
===================================================================
--- trunk/src/type_traits/overloading_priority.hh 2011-01-20 19:02:16 UTC (rev 156)
+++ trunk/src/type_traits/overloading_priority.hh 2011-05-13 16:57:22 UTC (rev 157)
@@ -1,32 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __OVERLOADING_PRIORITY_HH
-# define __OVERLOADING_PRIORITY_HH
-
-namespace aurelia {
- namespace type_traits {
-
- struct try_first {};
-
- struct try_second {
- try_second(const try_first&) {}
- };
-
- }
-}
-
-#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-01-20 19:02:22
|
Revision: 156
http://aurelia.svn.sourceforge.net/aurelia/?rev=156&view=rev
Author: valentindavid
Date: 2011-01-20 19:02:16 +0000 (Thu, 20 Jan 2011)
Log Message:
-----------
2011-01-20 Valentin David <val...@ii...>
* src/parser_generator/syntax.csf:
Use lexical restrictions.
* src/parser_generator/parser_gen.cc:
Evaluate lexical restrictions before executing attribute code
on end of rule. Remove conditional when rule is always LL.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/parser_generator/parser_gen.cc
trunk/src/parser_generator/syntax.csf
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-01-20 18:22:18 UTC (rev 155)
+++ trunk/ChangeLog 2011-01-20 19:02:16 UTC (rev 156)
@@ -1,6 +1,15 @@
2011-01-20 Valentin David <val...@ii...>
+ * src/parser_generator/syntax.csf:
+ Use lexical restrictions.
+
* src/parser_generator/parser_gen.cc:
+ Evaluate lexical restrictions before executing attribute code
+ on end of rule. Remove conditional when rule is always LL.
+
+2011-01-20 Valentin David <val...@ii...>
+
+ * src/parser_generator/parser_gen.cc:
Handle attribute code on character classes.
2011-01-19 Valentin David <val...@ii...>
Modified: trunk/src/parser_generator/parser_gen.cc
===================================================================
--- trunk/src/parser_generator/parser_gen.cc 2011-01-20 18:22:18 UTC (rev 155)
+++ trunk/src/parser_generator/parser_gen.cc 2011-01-20 19:02:16 UTC (rev 156)
@@ -434,9 +434,9 @@
std::cout << "#pragma GCC diagnostic ignored \"-Wunused-parameter\"" << std::endl;
std::cout << " void operator()(r_t& R, const frame& f, stream& s, const node& cu) const {" << std::endl;
- std::cout << ((get_cons_name < undouble_quote)(*attrcode)) << std::endl;
std::cout << " if (nofollow<"<<nt_name<<">::check(s))" << std::endl;
std::cout << " return ;" << std::endl;
+ std::cout << ((get_cons_name < undouble_quote)(*attrcode)) << std::endl;
std::cout << " cu.pop(R, ret, s);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
@@ -961,7 +961,9 @@
)(in);
};
- std::bitset<256> nonll = ((*build_first)[*nt]) & ((*build_follow)[*nt]);
+ std::bitset<256> nonll;
+ if ((*build_empty)[*nt])
+ nonll = ((*build_first)[*nt]) & ((*build_follow)[*nt]);
std::bitset<256> hastestfor;
V attr, chain;
@@ -972,29 +974,30 @@
hastestfor |= bs;
return bs;
}))))(*l);
- std::cout << " static const unsigned char nonll[] = {";
- print_bin(std::cout, nonll);
- std::cout << "};" << std::endl;
- std::cout << " bool nll;" << std::endl;
- std::cout << " if (s.eof()) nll = true;" << std::endl;
- std::cout << " else nll = nonll[*s >> 3]&(1 << (*s%8));" << std::endl;
- std::cout << " if (nll) {" << std::endl;
- map([&i, nt_name](const T& t) {
- std::cout << " if (test(s, NT_"<<nt_name<<", "<<nt_name<<"_"
- <<i<<"_0))" << std::endl;
- std::cout << " R.add(branch<"<<nt_name<<", "<<i
- <<", 0>::res(), f, cu, s);" << std::endl;
- ++i;
- return t;
- })(*l);
+ if (nonll != std::bitset<256>()) {
+ std::cout << " static const unsigned char nonll[] = {";
+ print_bin(std::cout, nonll);
+ std::cout << "};" << std::endl;
+ std::cout << " bool nll;" << std::endl;
+ std::cout << " if (s.eof()) nll = true;" << std::endl;
+ std::cout << " else nll = nonll[*s >> 3]&(1 << (*s%8));" << std::endl;
+ std::cout << " if (nll) {" << std::endl;
+ map([&i, nt_name](const T& t) {
+ std::cout << " if (test(s, NT_"<<nt_name<<", "<<nt_name<<"_"
+ <<i<<"_0))" << std::endl;
+ std::cout << " R.add(branch<"<<nt_name<<", "<<i
+ <<", 0>::res(), f, cu, s);" << std::endl;
+ ++i;
+ return t;
+ })(*l);
// std::cout << " if (test(s, NT_"<<nt_name<<", "<<nt_name<<"_"
// <<i<<"_0)) {" << std::endl;
//std::cout << " branch<"<<nt_name<<", "<<i<<", 0>::res n;"
// << std::endl;
// std::cout << " return n(R, f, s, cu);" << std::endl;
// std::cout << " }" << std::endl;
-
- std::cout << " } else {" << std::endl;
+ std::cout << " } else {" << std::endl;
+ }
i = 0;
map([&i, nt_name](const T& t) {
std::cout << " if (test(s, NT_"<<nt_name<<", "<<nt_name
@@ -1006,7 +1009,9 @@
++i;
return t;
})(*l);
- std::cout << " }" << std::endl;
+ if (nonll != std::bitset<256>()) {
+ std::cout << " }" << std::endl;
+ }
std::cout << " }" << std::endl;
std::cout << "};" << std::endl;
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2011-01-20 18:22:18 UTC (rev 155)
+++ trunk/src/parser_generator/syntax.csf 2011-01-20 19:02:16 UTC (rev 156)
@@ -1,44 +1,4 @@
- LAYOUT? ::= LAYOUT+
- $ if (!s.eof()) {
- switch (*s) {
- case ' ':
- case '\r':
- case '\n':
- case '\t':
- return ;
- case '/':
- {
- buf_stream_iterator next = s;
- ++next;
- if (!next.eof()) {
- if (*next == '/')
- return ;
- }
- }
- }
- }
- void_return ret;
- $ |
- $ if (!s.eof()) {
- switch (*s) {
- case ' ':
- case '\r':
- case '\n':
- case '\t':
- return ;
- case '/':
- {
- buf_stream_iterator next = s;
- ++next;
- if (!next.eof()) {
- if (*next == '/')
- return ;
- }
- }
- }
- }
- void_return ret;
- $
+ LAYOUT? ::= LAYOUT+ | -/- [ \r\n\t] , [/].[/]
LAYOUT+ ::= LAYOUT LAYOUT?
LAYOUT ::=
@@ -66,24 +26,11 @@
SymbolChar ::= [A-Z] | [a-z] | "*" | "?" | "+" | "-" | "_"
SymbolChar+ ::= SymbolChar SymbolChar*
SymbolChar* ::= SymbolChar+ |
- Symbol ::= $ ret_frame<stream> next_frame(f, s); $ SymbolChar+ $
- if (!s.eof()) {
- switch (*s) {
- case '*':
- case '?':
- case '+':
- case '-':
- case '_':
- return ;
- }
- if (((*s) >= 'A') && (*s) <= 'Z')
- return ;
- if (((*s) >= 'a') && (*s) <= 'z')
- return ;
- }
+ Symbol ::= $ ret_frame<stream> next_frame(f, s); $ SymbolChar+
+ $
ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
- $
+ $ -/- [a-zA-Z*?+_\-]
StringChar ::= [^\"\\] | "\\" SpecialChar
StringChar+ ::= StringChar StringChar*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-01-20 18:22:24
|
Revision: 155
http://aurelia.svn.sourceforge.net/aurelia/?rev=155&view=rev
Author: valentindavid
Date: 2011-01-20 18:22:18 +0000 (Thu, 20 Jan 2011)
Log Message:
-----------
2011-01-20 Valentin David <val...@ii...>
* src/parser_generator/parser_gen.cc:
Handle attribute code on character classes.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/parser_generator/parser_gen.cc
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-01-19 21:14:13 UTC (rev 154)
+++ trunk/ChangeLog 2011-01-20 18:22:18 UTC (rev 155)
@@ -1,3 +1,8 @@
+2011-01-20 Valentin David <val...@ii...>
+
+ * src/parser_generator/parser_gen.cc:
+ Handle attribute code on character classes.
+
2011-01-19 Valentin David <val...@ii...>
* src/hash/hash_addr.hh: New.
Modified: trunk/src/parser_generator/parser_gen.cc
===================================================================
--- trunk/src/parser_generator/parser_gen.cc 2011-01-19 21:14:13 UTC (rev 154)
+++ trunk/src/parser_generator/parser_gen.cc 2011-01-20 18:22:18 UTC (rev 155)
@@ -1,6 +1,7 @@
// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010, 2011 Valentin David
// Copyright (C) 2010 University of Bergen
+// Copyright (C) 2011 Uni Research
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -369,11 +370,37 @@
std::cout << "struct branch<" << nt_name << ","
<< index << "," << index_l
<< "> {" << std::endl;
- std::cout << " typedef ";
- std::cout << "parse_set<set_" << num << ", branch<"
- << nt_name << ", " << index << ", " << index_l+1
- << "> > ";
- std::cout << "res;" << std::endl;
+ try {
+ V attrcode;
+ V params;
+ static C Some("Some", 1);
+ static C AttrRule("AttrRule", 2);
+
+ Some[AttrRule[params, attrcode]] = *attr;
+ std::cout << " struct res {" << std::endl;
+ std::cout << "#pragma GCC diagnostic ignored \"-Wunused-parameter\"" << std::endl;
+ std::cout << " void operator()(r_t& R, const frame& f, stream& s, const node& cu) const {" << std::endl;
+
+ std::cout << ((get_cons_name < undouble_quote)(*attrcode)) << std::endl;
+ std::cout << " parse_set<set_"
+ << num << ", branch<" << nt_name
+ << "," << index << "," << index_l + 1
+ << "> > next;" << std::endl;
+ std::cout << " next(R, next_frame, s, cu);" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << " unsigned hash() const {" << std::endl;
+ std::cout << " return hash_addr(typeid(res));" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << " };" << std::endl;
+ } catch (failure) {
+ std::cout << " typedef ";
+ std::cout << "parse_set<set_" << num << ", branch<"
+ << nt_name << ", " << index << ", " << index_l+1
+ << "> > ";
+ std::cout << "res;" << std::endl;
+ }
+
+
std::cout << "};" << std::endl;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-01-19 21:14:20
|
Revision: 154
http://aurelia.svn.sourceforge.net/aurelia/?rev=154&view=rev
Author: valentindavid
Date: 2011-01-19 21:14:13 +0000 (Wed, 19 Jan 2011)
Log Message:
-----------
2011-01-19 Valentin David <val...@ii...>
* src/llstack/label.hh: Fix for non 32 bits addresses.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/llstack/label.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-01-19 20:41:43 UTC (rev 153)
+++ trunk/ChangeLog 2011-01-19 21:14:13 UTC (rev 154)
@@ -3,6 +3,7 @@
* src/hash/hash_addr.hh: New.
* src/hash/Makefile.am: Update.
+ * src/llstack/label.hh,
* src/parser_generator/parser_gen.cc,
* src/parser_generator/syntax.cc,
* src/streams/buf_stream.hh: Fix for non 32 bits addresses.
Modified: trunk/src/llstack/label.hh
===================================================================
--- trunk/src/llstack/label.hh 2011-01-19 20:41:43 UTC (rev 153)
+++ trunk/src/llstack/label.hh 2011-01-19 21:14:13 UTC (rev 154)
@@ -20,6 +20,7 @@
# include <cassert>
# include "frame.hh"
# include "../streams/buf_stream.hh"
+# include "../hash/hash_addr.hh"
namespace aurelia {
namespace llstack {
@@ -30,11 +31,11 @@
struct label {
private:
std::function<void(r_t&, const frame&, stream&, const node&)> fun;
- unsigned type;
+ size_t type;
public:
template <typename T>
- label(const T& in): fun(in), type((unsigned)&typeid(T)) {}
+ label(const T& in): fun(in), type((size_t)&typeid(T)) {}
label(const label& other): fun(other.fun), type(other.type) {
}
@@ -49,7 +50,7 @@
}
unsigned hash() const {
- return type;
+ return std::hash<size_t>()(type);
}
label& operator=(const label& other) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-01-19 20:41:49
|
Revision: 153
http://aurelia.svn.sourceforge.net/aurelia/?rev=153&view=rev
Author: valentindavid
Date: 2011-01-19 20:41:43 +0000 (Wed, 19 Jan 2011)
Log Message:
-----------
2011-01-19 Valentin David <val...@ii...>
* src/hash/hash_addr.hh: New.
* src/hash/Makefile.am: Update.
* src/parser_generator/parser_gen.cc,
* src/parser_generator/syntax.cc,
* src/streams/buf_stream.hh: Fix for non 32 bits addresses.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/hash/Makefile.am
trunk/src/parser_generator/parser_gen.cc
trunk/src/parser_generator/syntax.cc
trunk/src/streams/buf_stream.hh
Added Paths:
-----------
trunk/src/hash/hash_addr.hh
Property Changed:
----------------
trunk/doc/pages/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2011-01-18 23:47:17 UTC (rev 152)
+++ trunk/ChangeLog 2011-01-19 20:41:43 UTC (rev 153)
@@ -1,3 +1,12 @@
+2011-01-19 Valentin David <val...@ii...>
+
+ * src/hash/hash_addr.hh: New.
+ * src/hash/Makefile.am: Update.
+
+ * src/parser_generator/parser_gen.cc,
+ * src/parser_generator/syntax.cc,
+ * src/streams/buf_stream.hh: Fix for non 32 bits addresses.
+
2011-01-18 Valentin David <val...@ii...>
* doc/pages/401.doc, doc/pages/403.doc, doc/pages/404.doc,
Property changes on: trunk/doc/pages
___________________________________________________________________
Modified: svn:ignore
- tutorial.doc
references.doc
rationale.doc
papers.doc
parser_generator.doc
+ tutorial.doc
references.doc
rationale.doc
papers.doc
parser_generator.doc
401.doc
403.doc
404.doc
500.doc
download.doc
mainpage.doc
manual.doc
papers.doc
parser_generator.doc
rationale.doc
references.doc
strategies.doc
support.doc
tutorial.doc
Modified: trunk/src/hash/Makefile.am
===================================================================
--- trunk/src/hash/Makefile.am 2011-01-18 23:47:17 UTC (rev 152)
+++ trunk/src/hash/Makefile.am 2011-01-19 20:41:43 UTC (rev 153)
@@ -18,6 +18,7 @@
hashdir=$(aureliadir)/hash
hash_HEADERS= \
mhash.hh \
- tuple_hash.hh
+ tuple_hash.hh \
+ hash_addr.hh
SUBDIRS=tests
Added: trunk/src/hash/hash_addr.hh
===================================================================
--- trunk/src/hash/hash_addr.hh (rev 0)
+++ trunk/src/hash/hash_addr.hh 2011-01-19 20:41:43 UTC (rev 153)
@@ -0,0 +1,30 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2011 Valentin David
+// Copyright (C) 2011 Uni Research
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __HASH_ADDR_HH
+# define __HASH_ADDR_HH
+
+# include <functional>
+
+namespace aurelia {
+ template <typename T>
+ unsigned hash_addr(T& addr) {
+ static std::hash<size_t> hasher;
+ return hasher((size_t)&addr);
+ }
+}
+
+#endif
Modified: trunk/src/parser_generator/parser_gen.cc
===================================================================
--- trunk/src/parser_generator/parser_gen.cc 2011-01-18 23:47:17 UTC (rev 152)
+++ trunk/src/parser_generator/parser_gen.cc 2011-01-19 20:41:43 UTC (rev 153)
@@ -49,7 +49,7 @@
typedef untyped_constructor<Main> C;
typedef variable<untyped_term<Main> > V;
-template <typename Stream, unsigned N>
+template <typename Stream, size_t N>
void print_bin(Stream& s, const std::bitset<N>& set) {
int l = 0;
int k = 0;
@@ -219,7 +219,9 @@
last_c = '-';
has_char = true;
} else {
- if ((i+1) == c.end()) {
+ std::string::iterator next = i;
+ ++next;
+ if (next == c.end()) {
chars['-'] = true;
break ;
} else {
@@ -287,7 +289,7 @@
std::cout << " next(R, next_frame, s, cu);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
- std::cout << " return (unsigned)&typeid(res);" << std::endl;
+ std::cout << " return hash_addr(typeid(res));" << std::endl;
std::cout << " }" << std::endl;
std::cout << " };" << std::endl;
} catch (failure) {
@@ -338,7 +340,7 @@
std::cout << " next(R, next_frame, s, cu);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
- std::cout << " return (unsigned)&typeid(res);" << std::endl;
+ std::cout << " return hash_addr(typeid(res));" << std::endl;
std::cout << " }" << std::endl;
std::cout << " };" << std::endl;
} catch (failure) {
@@ -411,7 +413,7 @@
std::cout << " cu.pop(R, ret, s);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
- std::cout << " return (unsigned)&typeid(res);" << std::endl;
+ std::cout << " return hash_addr(typeid(res));" << std::endl;
std::cout << " }" << std::endl;
std::cout << " };" << std::endl;
} catch (failure) {
@@ -423,7 +425,7 @@
std::cout << " cu.pop(R, void_return(), s);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
- std::cout << " return (unsigned)&typeid(res);" << std::endl;
+ std::cout << " return hash_addr(typeid(res));" << std::endl;
std::cout << " }" << std::endl;
std::cout << " };" << std::endl;
}
Modified: trunk/src/parser_generator/syntax.cc
===================================================================
--- trunk/src/parser_generator/syntax.cc 2011-01-18 23:47:17 UTC (rev 152)
+++ trunk/src/parser_generator/syntax.cc 2011-01-19 20:41:43 UTC (rev 153)
@@ -28,6 +28,7 @@
#include "patterns/term_pattern.hh"
#include "strategies/patterns/scope.hh"
#include "strategies/lists/const_map.hh"
+#include "hash/hash_addr.hh"
using namespace aurelia;
using namespace llstack;
Modified: trunk/src/streams/buf_stream.hh
===================================================================
--- trunk/src/streams/buf_stream.hh 2011-01-18 23:47:17 UTC (rev 152)
+++ trunk/src/streams/buf_stream.hh 2011-01-19 20:41:43 UTC (rev 153)
@@ -21,6 +21,7 @@
# include <forward_list>
# include <istream>
# include <sstream>
+# include "hash/hash_addr.hh"
namespace aurelia {
@@ -130,7 +131,7 @@
, size(0)
#endif
{
- _hash = (unsigned)&s;
+ _hash = hash_addr(s);
}
unsigned hash() const {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2011-01-18 23:47:26
|
Revision: 152
http://aurelia.svn.sourceforge.net/aurelia/?rev=152&view=rev
Author: valentindavid
Date: 2011-01-18 23:47:17 +0000 (Tue, 18 Jan 2011)
Log Message:
-----------
2011-01-18 Valentin David <val...@ii...>
* doc/pages/401.doc, doc/pages/403.doc, doc/pages/404.doc,
* doc/pages/500.doc, doc/pages/concept_howto.doc,
* doc/pages/mainpage.doc, doc/pages/manual.doc,
* doc/pages/download.doc,
* doc/pages/strategies.doc, doc/pages/support.doc: Rename as...
* doc/pages/401.doc.in, doc/pages/403.doc.in,
* doc/pages/404.doc.in, doc/pages/500.doc.in,
* doc/pages/concept_howto.doc.in, doc/pages/mainpage.doc.in,
* doc/pages/manual.doc.in, doc/pages/download.doc.in
* doc/pages/strategies.doc.in, doc/pages/support.doc.in: Those.
* doc/pages/download.doc.in: Link to tarballs sorted by date of
modification.
* doc/pages/manual.doc.in: Add parser_generator subpage.
* doc/pages/papers.doc.in,
* doc/pages/parser_generator.doc.in,
* doc/pages/rationale.doc.in,
* doc/pages/references.doc.in,
* doc/pages/tutorial.doc.in,
* doc/pages/tutorial/tuto_ast.doc.in,
* doc/pages/tutorial/tuto_parsing.doc.in,
* doc/pages/tutorial/tuto_pp.doc.in,
* doc/pages/tutorial/tuto_trans.doc.in:
New.
* doc/gendeps.sh.in: Change absolute pathes to relative.
* doc/makemenu.sed: New.
* doc/Makefile.am: Fix verbosity for genrating header-exp.html.
Add dependencies to the pages.
Generate pages with table of content. Update $(PAGES).
* doc/header.html: Add new pages.
* configure.ac: Check for sed.
Modified Paths:
--------------
trunk/ChangeLog
trunk/configure.ac
trunk/doc/Makefile.am
trunk/doc/gendeps.sh.in
trunk/doc/header.html
Added Paths:
-----------
trunk/doc/makemenu.sed
trunk/doc/pages/401.doc.in
trunk/doc/pages/403.doc.in
trunk/doc/pages/404.doc.in
trunk/doc/pages/500.doc.in
trunk/doc/pages/download.doc.in
trunk/doc/pages/mainpage.doc.in
trunk/doc/pages/manual/
trunk/doc/pages/manual/concept_howto.doc.in
trunk/doc/pages/manual.doc.in
trunk/doc/pages/papers.doc.in
trunk/doc/pages/parser_generator.doc.in
trunk/doc/pages/rationale.doc.in
trunk/doc/pages/references.doc.in
trunk/doc/pages/strategies.doc.in
trunk/doc/pages/support.doc.in
trunk/doc/pages/tutorial/
trunk/doc/pages/tutorial/tuto_ast.doc.in
trunk/doc/pages/tutorial/tuto_parsing.doc.in
trunk/doc/pages/tutorial/tuto_pp.doc.in
trunk/doc/pages/tutorial/tuto_trans.doc.in
trunk/doc/pages/tutorial.doc.in
Removed Paths:
-------------
trunk/doc/pages/401.doc
trunk/doc/pages/403.doc
trunk/doc/pages/404.doc
trunk/doc/pages/500.doc
trunk/doc/pages/concept_howto.doc
trunk/doc/pages/download.doc
trunk/doc/pages/mainpage.doc
trunk/doc/pages/manual.doc
trunk/doc/pages/strategies.doc
trunk/doc/pages/support.doc
Property Changed:
----------------
trunk/doc/pages/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/ChangeLog 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,3 +1,44 @@
+2011-01-18 Valentin David <val...@ii...>
+
+ * doc/pages/401.doc, doc/pages/403.doc, doc/pages/404.doc,
+ * doc/pages/500.doc, doc/pages/concept_howto.doc,
+ * doc/pages/mainpage.doc, doc/pages/manual.doc,
+ * doc/pages/download.doc,
+ * doc/pages/strategies.doc, doc/pages/support.doc: Rename as...
+
+ * doc/pages/401.doc.in, doc/pages/403.doc.in,
+ * doc/pages/404.doc.in, doc/pages/500.doc.in,
+ * doc/pages/concept_howto.doc.in, doc/pages/mainpage.doc.in,
+ * doc/pages/manual.doc.in, doc/pages/download.doc.in
+ * doc/pages/strategies.doc.in, doc/pages/support.doc.in: Those.
+
+ * doc/pages/download.doc.in: Link to tarballs sorted by date of
+ modification.
+
+ * doc/pages/manual.doc.in: Add parser_generator subpage.
+ * doc/pages/papers.doc.in,
+ * doc/pages/parser_generator.doc.in,
+ * doc/pages/rationale.doc.in,
+ * doc/pages/references.doc.in,
+ * doc/pages/tutorial.doc.in,
+ * doc/pages/tutorial/tuto_ast.doc.in,
+ * doc/pages/tutorial/tuto_parsing.doc.in,
+ * doc/pages/tutorial/tuto_pp.doc.in,
+ * doc/pages/tutorial/tuto_trans.doc.in:
+ New.
+
+ * doc/gendeps.sh.in: Change absolute pathes to relative.
+
+ * doc/makemenu.sed: New.
+
+ * doc/Makefile.am: Fix verbosity for genrating header-exp.html.
+ Add dependencies to the pages.
+ Generate pages with table of content. Update $(PAGES).
+
+ * doc/header.html: Add new pages.
+
+ * configure.ac: Check for sed.
+
2010-12-14 Valentin David <val...@ii...>
* demos/07-strategies.cc, demos/10-int.cc:
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/configure.ac 2011-01-18 23:47:17 UTC (rev 152)
@@ -28,7 +28,10 @@
AC_CONFIG_MACRO_DIR([config])
AC_CONFIG_HEADERS([config/config.h src/aurelia-config.hh])
-AM_INIT_AUTOMAKE([1.11a foreign dist-bzip2 tar-pax color-tests parallel-tests])
+AM_INIT_AUTOMAKE([1.11a foreign
+ dist-bzip2 tar-pax
+ color-tests parallel-tests
+ -W -Wall])
AM_SILENT_RULES([yes])
AC_LANG_CPLUSPLUS
@@ -40,7 +43,7 @@
dnl CXX_WERROR
AC_PROG_INSTALL
-AC_PROG_LIBTOOL
+AC_PROG_SED
AC_C_BIGENDIAN
@@ -75,7 +78,8 @@
AC_CHECK_HEADERS([cxxabi.h])
AC_SUBST([EXTRACPPFLAGS])
-AC_SUBST([AM_CPPFLAGS], ['-I$(top_srcdir)/src -I$(top_builddir)/src '"$EXTRACPPFLAGS"])
+AC_SUBST([AM_CPPFLAGS],
+ ['-I$(top_srcdir)/src -I$(top_builddir)/src '"$EXTRACPPFLAGS"])
AC_ARG_ENABLE([bootstrap],[AS_HELP_STRING([--enable-bootstrap],dnl
[bootstrap when checked out from SVN.])],[dnl
Modified: trunk/doc/Makefile.am
===================================================================
--- trunk/doc/Makefile.am 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/Makefile.am 2011-01-18 23:47:17 UTC (rev 152)
@@ -28,16 +28,16 @@
if BOOTSTRAP
header-exp.html: header.html
- @if test x"$(ONLINE)" = xyes; then \
+ $(AM_V_GEN)if test x"$(ONLINE)" = xyes; then \
cp header.html header-exp.html; \
else \
- sed "/<!--online only begin-->/{;:l;/<!--online only end-->/d;N;bl;}" \
+ $(SED) "/<!--online only begin-->/{;:l;/<!--online only end-->/d;N;bl;}" \
header.html >header-exp.html; \
fi
html: html.stamp
-html.stamp: $(DOCFILES)
+html.stamp: $(DOCFILES) $(PAGES)
@-rm -rf output.tmp
@$(MAKE) $(AM_MAKEFLAGS) Doxyfile gendeps.sh
@echo "html.stamp: \\" >$(DEPDIR)/doc.Tdeps
@@ -64,7 +64,7 @@
clean-local:
rm -rf html
-CLEANFILES=html.stamp header-exp.html doxygen.log
+CLEANFILES=html.stamp header-exp.html doxygen.log $(PAGES)
else
CLEANFILES=
endif
@@ -88,21 +88,47 @@
maintainer-clean-local:
-rm -rf ./$(DEPDIR)
-EXTRA_DIST= \
- html \
- html.stamp \
- pages/mainpage.doc \
+.doc.in.doc:
+ $(AM_V_GEN)if $(SED) -f $(srcdir)/makemenu.sed $< | \
+ $(SED) "/^<ul>$$/{;N;/<\/ul>$$/d;}" >"$@.tmp"; then \
+ mv "$@.tmp" "$@"; \
+ else \
+ rm -f "$@.tmp"; \
+ exit 1; \
+ fi
+
+SUFFIXES=.doc.in .doc
+
+PAGES= \
pages/401.doc \
pages/403.doc \
pages/404.doc \
pages/500.doc \
pages/download.doc \
+ pages/mainpage.doc \
pages/manual.doc \
+ pages/manual/concept_howto.doc \
+ pages/papers.doc \
+ pages/parser_generator.doc \
+ pages/rationale.doc \
+ pages/references.doc \
+ pages/strategies.doc \
pages/support.doc \
- pages/strategies.doc \
+ pages/tutorial.doc \
+ pages/tutorial/tuto_ast.doc \
+ pages/tutorial/tuto_parsing.doc \
+ pages/tutorial/tuto_pp.doc \
+ pages/tutorial/tuto_trans.doc
+
+PAGE_TEMPLATES=$(PAGES:.doc=.doc.in)
+
+EXTRA_DIST= \
+ html \
+ html.stamp \
footer.html \
header.html \
header-exp.html \
stylesheet.css \
bldl-mini.png \
- doxygen.png
+ doxygen.png \
+ makemenu.sed
Modified: trunk/doc/gendeps.sh.in
===================================================================
--- trunk/doc/gendeps.sh.in 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/gendeps.sh.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,8 +1,8 @@
#! @SHELL@
-if test -f @DEPDIR@/doc.Tdeps
+if test -f @DEPDIR@/doc.Tdeps && test -w @DEPDIR@/doc.Tdeps
then
- echo " $1 \\" >>@DEPDIR@/doc.Tdeps
+ echo "$1" | @SED@ 's,@abs_srcdir@,@srcdir@,;s,^, ,;s,$, \\,' >>@DEPDIR@/doc.Tdeps
else
echo "Cannot write to @DEPDIR@/doc.Tdeps" 1>&2
fi
Modified: trunk/doc/header.html
===================================================================
--- trunk/doc/header.html 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/header.html 2011-01-18 23:47:17 UTC (rev 152)
@@ -11,7 +11,11 @@
<li><a href="index.html"><span>Main page</span></a></li>
<li><a href="download.html"><span>Download</span></a></li>
<li><a href="manual.html"><span>Manual</span></a></li>
+<li><a href="tutorial.html"><span>Tutorial</span></a></li>
+<li><a href="papers.html"><span>Research papers</span></a></li>
<li><a href="support.html"><span>Support</span></a></li>
+<li><a href="rationale.html"><span>Rationale</span></a></li>
+<li><a href="references.html"><span>References</span></a></li>
</ul>
<div class="buttons">
Added: trunk/doc/makemenu.sed
===================================================================
--- trunk/doc/makemenu.sed (rev 0)
+++ trunk/doc/makemenu.sed 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,46 @@
+1{
+ n
+ i<ul>
+}
+:sec
+/^\\section /{
+ H
+ s///
+ s/ .*//g
+ s,\(.*\),<li>\\ref \1</li>,
+ n
+ bsec
+}
+/^\\subsection /{
+ i<ul>
+ :subsec
+ /^\\section /{
+ i</ul>
+ bsec
+ }
+ H
+ /^\\subsection /{
+ s///
+ s/ .*//g
+ s,\(.*\),<li>\\ref \1</li>,
+ n
+ bsubsec
+ }
+ ${
+ i</ul>
+ i</ul>
+ x
+ q
+ }
+ N
+ s/^.*\n//g
+ bsubsec
+}
+${
+ H
+ i</ul>
+ x
+ q
+}
+H
+d
Property changes on: trunk/doc/pages
___________________________________________________________________
Added: svn:ignore
+ tutorial.doc
references.doc
rationale.doc
papers.doc
parser_generator.doc
Deleted: trunk/doc/pages/401.doc
===================================================================
--- trunk/doc/pages/401.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/401.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,5 +0,0 @@
-/*! \page 401 Error 401: Unauthorized
-
-Please contact me on val...@ii... .
-
-*/
Copied: trunk/doc/pages/401.doc.in (from rev 134, trunk/doc/pages/401.doc)
===================================================================
--- trunk/doc/pages/401.doc.in (rev 0)
+++ trunk/doc/pages/401.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page 401 Error 401: Unauthorized
+
+Please contact me on val...@ii... .
+
+*/
Deleted: trunk/doc/pages/403.doc
===================================================================
--- trunk/doc/pages/403.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/403.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,5 +0,0 @@
-/*! \page 403 Error 403: Forbidden
-
-Please contact me on val...@ii... .
-
-*/
Copied: trunk/doc/pages/403.doc.in (from rev 134, trunk/doc/pages/403.doc)
===================================================================
--- trunk/doc/pages/403.doc.in (rev 0)
+++ trunk/doc/pages/403.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page 403 Error 403: Forbidden
+
+Please contact me on val...@ii... .
+
+*/
Deleted: trunk/doc/pages/404.doc
===================================================================
--- trunk/doc/pages/404.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/404.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,5 +0,0 @@
-/*! \page 404 Error 404: Document not found.
-
-Please contact me on val...@ii... .
-
-*/
Copied: trunk/doc/pages/404.doc.in (from rev 134, trunk/doc/pages/404.doc)
===================================================================
--- trunk/doc/pages/404.doc.in (rev 0)
+++ trunk/doc/pages/404.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page 404 Error 404: Document not found.
+
+Please contact me on val...@ii... .
+
+*/
Deleted: trunk/doc/pages/500.doc
===================================================================
--- trunk/doc/pages/500.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/500.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,5 +0,0 @@
-/*! \page 500 Error 500: Internal server error.
-
-Please contact me on val...@ii... .
-
-*/
Copied: trunk/doc/pages/500.doc.in (from rev 134, trunk/doc/pages/500.doc)
===================================================================
--- trunk/doc/pages/500.doc.in (rev 0)
+++ trunk/doc/pages/500.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page 500 Error 500: Internal server error.
+
+Please contact me on val...@ii... .
+
+*/
Deleted: trunk/doc/pages/concept_howto.doc
===================================================================
--- trunk/doc/pages/concept_howto.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/concept_howto.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,99 +0,0 @@
-/*! \page concept_howto Concept HOWTO
-
-\section concept Defining a concept
-
-\code
-template <typename Model>
-struct MyConcept {
- // We declare a type.
- typedef typename Model::SomeType SomeType;
- typedef typename Model::ReturnType ReturnType;
-
-#ifdef GEN_DOC
- //We declare the needed functions
- ReturnType operator()(SomeType&, int);
-#else
- typedef void static_check;
-
- static_assert(std::is_same<ReturnType,
- std::declval<SomeType&>()(0)>::value,
- "operator()(SomeType&, int) does not return ReturnType");
-#endif
-};
-
-template <typename T>
-struct MyModel {
- typedef void NoModel;
-};
-\endcode
-
-\section models Defining models
-
-\code
-struct A {
- int operator()(int) {
- return 0;
- }
-};
-
-template <>
-struct MyModel<A> {
- struct Model {
- typedef A SomeType;
- typedef int RetType;
- };
-};
-\endcode
-
-\section requirement Requiring a model
-
-\code
-template <typename T,
- typename Model = MyModel<T>::Model>
-void foo(T) {
- //We have a model, but we need to require this model to check.
- typedef typename Model::static_check require;
-
- //...
-}
-\endcode
-
-Or for a class:
-
-\code
-template <typename T>
-struct Foo {
- typedef typename MyModel<T>::Model::static_check require;
-
- //...
-};
-\endcode
-
-\section auto Making automatic models
-
-In case it is possible to know automatically a model, then we can do as follow.
-
-\code
-template <typename T,
- bool = is_callable_with<T&, int>::value>
-struct MyModel;
-
-template <typename T>
-struct MyModel<T, false> {
- typedef void NoModel;
-};
-
-template <typename T>
-struct MyModel<T, true> {
- struct Model {
- typedef A SomeType;
- typedef decltype(std::declval<T&>()(std::declval<int>())) RetType;
- };
-};
-\endcode
-
-\section archetype Writing an archetype
-
-TODO
-
-*/
Deleted: trunk/doc/pages/download.doc
===================================================================
--- trunk/doc/pages/download.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/download.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,14 +0,0 @@
-/*! \page download Download
-
-There is no release yet of Aurelia.
-
-However it can be downloaded as a source tarball from the
-<a href="http://aurelia.cx/nightly">nightly tarball repository</a>.
-
-The second option is to use the svn repository
-https://svn.aurelia.cx/svnroot/aurelia/trunk . You will need recent
-versions of GNU Autoconf, Automake, Stratego/XT, and Doxygen. Do not
-forget to pass "--enable-bootstrap". Those requirements are not needed
-for compiling a nightly tarball.
-
-*/
Copied: trunk/doc/pages/download.doc.in (from rev 134, trunk/doc/pages/download.doc)
===================================================================
--- trunk/doc/pages/download.doc.in (rev 0)
+++ trunk/doc/pages/download.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,14 @@
+/*! \page download Download
+
+There is no release yet of Aurelia.
+
+However it can be downloaded as a source tarball from the
+<a href="http://aurelia.cx/nightly/?C=M;O=D">nightly tarball repository</a>.
+
+The second option is to use the svn repository
+https://svn.aurelia.cx/svnroot/aurelia/trunk . You will need recent
+versions of GNU Autoconf, Automake, Stratego/XT, and Doxygen. Do not
+forget to pass "--enable-bootstrap". Those requirements are not needed
+for compiling a nightly tarball.
+
+*/
Deleted: trunk/doc/pages/mainpage.doc
===================================================================
--- trunk/doc/pages/mainpage.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/mainpage.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,18 +0,0 @@
-/*! \page index Aurelia
-
-Aurelia is a framework for language-independant program transformation in C++.
-It provides:
-
-\li A maximally shared reference counted term library
-\li A generic strategic programming infrastructure, using expression templates
-\li A typed term hierachy generator from a signature definition
-\li A scannerless generalized LL parser generator
-
-Aurelia is developed <a href="http://bldl.ii.uib.no/">Bergen Language
-Design Laboratory</a>.
-
-The project is licensed in GPL-3 (see \ref COPYING). It is hosted <a
-href="http://sourceforge.net">sourceforge.net</a> (<a
-href="http://sf.net/projects/aurelia">visit the project page</a>).
-
-*/
Copied: trunk/doc/pages/mainpage.doc.in (from rev 134, trunk/doc/pages/mainpage.doc)
===================================================================
--- trunk/doc/pages/mainpage.doc.in (rev 0)
+++ trunk/doc/pages/mainpage.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,18 @@
+/*! \page index Aurelia
+
+Aurelia is a framework for language-independant program transformation in C++.
+It provides:
+
+\li A maximally shared reference counted term library
+\li A generic strategic programming infrastructure, using expression templates
+\li A typed term hierachy generator from a signature definition
+\li A scannerless generalized LL parser generator
+
+Aurelia is developed <a href="http://bldl.ii.uib.no/">Bergen Language
+Design Laboratory</a>.
+
+The project is licensed in GPL-3 (see \ref COPYING). It is hosted <a
+href="http://sourceforge.net">sourceforge.net</a> (<a
+href="http://sf.net/projects/aurelia">visit the project page</a>).
+
+*/
Property changes on: trunk/doc/pages/manual
___________________________________________________________________
Added: svn:ignore
+ concept_howto.doc
Copied: trunk/doc/pages/manual/concept_howto.doc.in (from rev 134, trunk/doc/pages/concept_howto.doc)
===================================================================
--- trunk/doc/pages/manual/concept_howto.doc.in (rev 0)
+++ trunk/doc/pages/manual/concept_howto.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,99 @@
+/*! \page concept_howto Concept HOWTO
+
+\section concept Defining a concept
+
+\code
+template <typename Model>
+struct MyConcept {
+ // We declare a type.
+ typedef typename Model::SomeType SomeType;
+ typedef typename Model::ReturnType ReturnType;
+
+#ifdef GEN_DOC
+ //We declare the needed functions
+ ReturnType operator()(SomeType&, int);
+#else
+ typedef void static_check;
+
+ static_assert(std::is_same<ReturnType,
+ std::declval<SomeType&>()(0)>::value,
+ "operator()(SomeType&, int) does not return ReturnType");
+#endif
+};
+
+template <typename T>
+struct MyModel {
+ typedef void NoModel;
+};
+\endcode
+
+\section models Defining models
+
+\code
+struct A {
+ int operator()(int) {
+ return 0;
+ }
+};
+
+template <>
+struct MyModel<A> {
+ struct Model {
+ typedef A SomeType;
+ typedef int RetType;
+ };
+};
+\endcode
+
+\section requirement Requiring a model
+
+\code
+template <typename T,
+ typename Model = MyModel<T>::Model>
+void foo(T) {
+ //We have a model, but we need to require this model to check.
+ typedef typename Model::static_check require;
+
+ //...
+}
+\endcode
+
+Or for a class:
+
+\code
+template <typename T>
+struct Foo {
+ typedef typename MyModel<T>::Model::static_check require;
+
+ //...
+};
+\endcode
+
+\section auto Making automatic models
+
+In case it is possible to know automatically a model, then we can do as follow.
+
+\code
+template <typename T,
+ bool = is_callable_with<T&, int>::value>
+struct MyModel;
+
+template <typename T>
+struct MyModel<T, false> {
+ typedef void NoModel;
+};
+
+template <typename T>
+struct MyModel<T, true> {
+ struct Model {
+ typedef A SomeType;
+ typedef decltype(std::declval<T&>()(std::declval<int>())) RetType;
+ };
+};
+\endcode
+
+\section archetype Writing an archetype
+
+TODO
+
+*/
Deleted: trunk/doc/pages/manual.doc
===================================================================
--- trunk/doc/pages/manual.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/manual.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,23 +0,0 @@
-/*! \page manual User manual
-
-\section api API documentation
-
-\li <a href="group__Concepts.html">Concepts</a>
-\li \subpage strategies
-\li <a href="namespaces.html">Namespaces</a>
-\li <a href="classes.html">Classes</a>
-
-\section hacking Hacking
-
-\li \subpage concept_howto
-
-\section package Package documentation
-
-\li \subpage README
-\li \subpage INSTALL
-\li \subpage HACKING
-\li \subpage NEWS
-\li \subpage COPYING
-\li \subpage AUTHORS
-
-*/
Copied: trunk/doc/pages/manual.doc.in (from rev 134, trunk/doc/pages/manual.doc)
===================================================================
--- trunk/doc/pages/manual.doc.in (rev 0)
+++ trunk/doc/pages/manual.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,27 @@
+/*! \page manual User manual
+
+\section api API documentation
+
+\li <a href="group__Concepts.html">Concepts</a>
+\li \subpage strategies
+\li <a href="namespaces.html">Namespaces</a>
+\li <a href="classes.html">Classes</a>
+
+\section parsing_sec Parsing
+
+\li \subpage parser_generator
+
+\section hacking Hacking
+
+\li \subpage concept_howto
+
+\section package Package documentation
+
+\li \subpage README
+\li \subpage INSTALL
+\li \subpage HACKING
+\li \subpage NEWS
+\li \subpage COPYING
+\li \subpage AUTHORS
+
+*/
Added: trunk/doc/pages/papers.doc.in
===================================================================
--- trunk/doc/pages/papers.doc.in (rev 0)
+++ trunk/doc/pages/papers.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page papers Publications
+
+Nothing yet.
+
+*/
Added: trunk/doc/pages/parser_generator.doc.in
===================================================================
--- trunk/doc/pages/parser_generator.doc.in (rev 0)
+++ trunk/doc/pages/parser_generator.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,141 @@
+/*! \page parser_generator Parser generator
+
+\section invocation Invocation
+
+Tool \p parser_gen transform the syntax definition as standard input into a
+a C++ generated code onto the standard output.
+
+\verbatim
+parser_gen <syntax_def.csf >syntax.hh
+\endverbatim
+
+\subsection automake Using GNU Automake
+
+TODO.
+
+\section grammar Grammar
+
+\subsection lexical_part Lexical part
+
+Space, horizontal tabulation, new line, carriage return characters are
+ignored. Also double slash ("//") ignores the end of the line.
+
+\verbatim
+SpecialChar ::= "\\" | "n" | "r" | "t" | "\"" | "-" | "]"
+
+Char ::= [^\]\\\-] | "\\" SpecialChar
+Range ::= Char "-" Char
+CharClass ::= "[" (Range | Char)+ "]"
+ | "[" "^" (Range | Char)+ "]"
+
+StringChar ::= [^\"\\] | "\\" SpecialChar
+String ::= "\"" StringChar* "\""
+
+Symbol ::= ([A-Z] | [a-z] | "*" | "?" | "+" | "-" | "_")+
+
+AttrRule ::= "$" CxxCode "$"
+\endverbatim
+
+\subsection syntactic_part Syntactic part
+
+A syntax definition consists on a list of rules. Rules are defined as such:
+
+\verbatim
+Rule ::=
+ ("<" AttrChainElt ">")? Symbol "::=" ListOfChains Filtering?
+
+ListOfChains ::= {(AttrChainElt* AttrRule?) "|"}+
+
+AttrChainElt ::= AttrRule? ChainElt
+
+ChainElt ::= Symbol | String | CharClass
+\endverbatim
+
+\section layout Layout
+
+\section lexical_restrictions Lexical restrictions
+
+\verbatim
+Filtering ::= "-/-" LookAhead+
+\endverbatim
+
+\section user_code User code
+
+The attribute rules (AttrRule) on the left of a parsing element
+(symbol, string, or character class) are prior to the descent onto
+parsing this element.
+
+It must define \p next_frame of type convertible to type \ref
+aurelia::llstack::frame.
+
+The default copies the current frame:
+
+\verbatim
+$ frame next_frame(f); $
+\endverbatim
+
+The frame should never be modified in case of left recursion, otherwise
+it breaks the parsing algorithm and does not halt.
+
+The last attribute rule must define \p ret. If there is no return value,
+it must define it as type \ref aurelia::llstack::void_return.
+
+\verbatim
+void_return ret;
+\endverbatim
+
+If the code decides to reject the current parsing, then the code must return.
+
+\subsection frames Frames
+
+Aurelia provides template \ref aurelia::llstack::ret_frame to stack
+easily data to pass through rules. The data must be hash-able and
+movable or copyable.
+
+\subsection local_vars Local variables available
+
+\li \p f is the current frame.
+\li \p s is the current stream.
+
+\section parsing_types Types
+
+Type \p stream must provide operators "++" and "*". Aurelia
+provides \ref aurelia::buf_stream_iterator.
+
+\section parser_loop Writing a parser
+
+\code
+// We first check that the stream has the right first character.
+if (s.eof()) {
+ if (!is_empty_first(S_0_0))
+ throw error();
+}
+else if (!is_first(s, S_0_0)) {
+ throw error();
+}
+
+// We then define the boundary nodes of the graph.
+// end is the end iterator of the stream.
+node u1 = node::boundary(start_label(), end);
+node u0 = node::boundary(end_label(), end);
+u1.parents().insert(u0);
+
+// We define a queue of parsing contexts.
+r_t R;
+
+// We then add the start symbol in the queue.
+S start;
+start(R, empty_frame(), s, u1);
+
+// We then loop requesting descriptors from the queue, then calling
+// them.
+try {
+ while (true) {
+ descriptor d = R.pop();
+ d.L.call(R, d.f, d.s, d.n);
+ }
+} catch (r_t::eof) {
+}
+\endcode
+
+*/
Added: trunk/doc/pages/rationale.doc.in
===================================================================
--- trunk/doc/pages/rationale.doc.in (rev 0)
+++ trunk/doc/pages/rationale.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,85 @@
+/*! \page rationale Rationale
+
+There are already several projects providing a language-independant
+program transformation environment. However we needed some features
+that were not all provided by the existing projects.
+See section \ref difference.
+
+\section related_projects Related projects
+
+\subsection tom Tom
+
+http://tom.loria.fr/
+
+Tom is an extension of Java providing a term library and pattern matching.
+
+\subsection asfsdf ASF+SDF
+
+http://www.meta-environment.org/
+
+ASF+SDF provides parsing tools and a high-level semantic language.
+
+\subsection strategoxt Stratego/XT
+
+Stratego is a programming language turned towards program transformation.
+
+http://strategoxt.org/
+
+\subsection spoofax Spoofax
+
+http://www.spoofax.org/
+
+Spoofax is a Stratego environment for Eclipse. Spoofax can generate
+code able to run on a Java virtual machine.
+
+\subsection rascal Rascal
+
+http://www.rascal-mpl.org/
+
+Rascal is still in alpha state. It is available as binary. The source
+is not accessible. The license is not stated.
+
+\subsection txl TXL
+
+http://www.txl.ca/
+
+\subsection dms Semantic Designs' DMS®
+
+http://www.semdesigns.com/
+
+\section difference What makes Aurelia different?
+
+Aurelia is born from the fact that most of generic meta-programming
+environment do not scale well for analysing programs written in
+C++. For instance, while developing projects Transformers, efficiency
+(in memory like in run time) was a problem.
+
+http://transformers.lrde.epita.fr/
+
+The different other environment move towards providing complete IDE
+for the transformed language. DMS® lead the way, Rascal and
+Spoofax/IMP are following. However, they forget the problems of
+efficiency, prorbably because nobody wants to touch C++.
+
+Aurelia has for goals:
+\li Efficiency in memory and run-time:
+\li Static type-checking: a majority of projects on the page have dynamic
+ types, or no types at all.
+\li Portability: Aurelia is generic, and is intended to work on any
+ architecture where a standard compiler and library for C++ is
+ available.
+\li Parallelism: In Transformers, parrallelism was missing. Parsing
+ non deterministic and ambiguous grammars can profit of
+ multi-core architecture. Attribute grammar evaluation as well.
+
+\subsection whynotjava Why not Java (or .Net)?
+
+It appears that the JVM made improvements and it is often a better choice to
+use Java than C++. However C++ provides fine tuning. Aurelia is responsible
+of this tuning, not . In Java, it is not possible to explicitely differentiate
+between virtual and non virtual calls. But to ensure optimization, Aurelia
+needs to be able to decide between those. Aurelia also is heavily
+based on meta-programming to provide efficient genericity. This
+is not possible in Java.
+
+*/
Added: trunk/doc/pages/references.doc.in
===================================================================
--- trunk/doc/pages/references.doc.in (rev 0)
+++ trunk/doc/pages/references.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,40 @@
+/*! \page references References
+
+This page is intended to provide acknowledgement.
+
+\section ref_papers Papers
+
+The implementation of Aurelia has been using different algorithsm from
+the state of art of research. Those algorithms are originally presented
+in the following papers.
+
+\subsection parsing Parsing
+
+The parser generator is based on:
+
+\li Elizabeth Scott, Adrian Johnstone, <b>GLL Parsing</b>, Electronic
+Notes in Theoretical Computer Science, Volume 253, Issue 7,
+Proceedings of the Ninth Workshop on Language Descriptions Tools and
+Applications (LDTA 2009), 17 September 2010, Pages 177-189, ISSN
+1571-0661, DOI: <a
+href="http://dx.doi.org/10.1016/j.entcs.2010.08.041">10.1016/j.entcs.2010.08.041</a>.
+
+There are few optimization that were made. However some are breaking the
+worst case complexity, but appear to be useful for Aurelia.
+
+\subsection lockfree Lock-free data structures
+
+The generic lock-free hash map implementation, which is used in the maximally
+shared terms and in GLL parsing, is based from the algorithms from those
+two papers:
+
+\li Ori Shalev and Nir Shavit, <b>Split-ordered lists: Lock-free
+extensible hash tables</b>, J. ACM 53, 3 (May. 2006), 379-405, DOI: <a
+href="http://doi.acm.org/10.1145/1147954.1147958">10.1145/1147954.1147958</a>.
+\li Timothy L. Harris, <b>A Pragmatic Implementation of Non-blocking
+Linked-Lists</b>, In Proceedings of the 15th international Conference
+on Distributed Computing (October 03 - 05, 2001). J. L. Welch,
+Ed. Lecture Notes In Computer Science, vol. 2180. Springer-Verlag,
+London, 300-314.
+
+*/
Deleted: trunk/doc/pages/strategies.doc
===================================================================
--- trunk/doc/pages/strategies.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/strategies.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,11 +0,0 @@
-/*! \page strategies Strategies
-
-\li \ref Generic
-\li \ref Strings
-\li \ref Terms
-\li \ref Patterns
-\li \ref Lists
-\li \ref Traversals
-\li \ref Strings
-
-*/
Copied: trunk/doc/pages/strategies.doc.in (from rev 134, trunk/doc/pages/strategies.doc)
===================================================================
--- trunk/doc/pages/strategies.doc.in (rev 0)
+++ trunk/doc/pages/strategies.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,11 @@
+/*! \page strategies Strategies
+
+\li \ref Generic
+\li \ref Strings
+\li \ref Terms
+\li \ref Patterns
+\li \ref Lists
+\li \ref Traversals
+\li \ref Strings
+
+*/
Deleted: trunk/doc/pages/support.doc
===================================================================
--- trunk/doc/pages/support.doc 2010-12-14 10:55:39 UTC (rev 151)
+++ trunk/doc/pages/support.doc 2011-01-18 23:47:17 UTC (rev 152)
@@ -1,17 +0,0 @@
-/*! \page support Support
-
-\section mailing-lists Mailing-lists
-
-To subscribe to any of those mailing lists, just send
-
-\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-announce">aur...@li...</a>
-\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-bugs">aur...@li...</a>
-\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-svn">aur...@li...</a>
-\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-users">aur...@li...</a>
-
-\section tracker Bug tracker
-
-Please send bug reports on the sourceforge page (<a href="http://sourceforge.net/tracker/?func=add&group_id=330861&atid=1387810">quick link</a>).
-
-
-*/
\ No newline at end of file
Copied: trunk/doc/pages/support.doc.in (from rev 134, trunk/doc/pages/support.doc)
===================================================================
--- trunk/doc/pages/support.doc.in (rev 0)
+++ trunk/doc/pages/support.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,17 @@
+/*! \page support Support
+
+\section mailing-lists Mailing-lists
+
+To subscribe to any of those mailing lists, just send
+
+\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-announce">aur...@li...</a>
+\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-bugs">aur...@li...</a>
+\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-svn">aur...@li...</a>
+\li <a href="https://lists.sourceforge.net/lists/listinfo/aurelia-users">aur...@li...</a>
+
+\section tracker Bug tracker
+
+Please send bug reports on the sourceforge page (<a href="http://sourceforge.net/tracker/?func=add&group_id=330861&atid=1387810">quick link</a>).
+
+
+*/
\ No newline at end of file
Property changes on: trunk/doc/pages/tutorial
___________________________________________________________________
Added: svn:ignore
+ tuto_ast.doc
tuto_parsing.doc
tuto_pp.doc
tuto_trans.doc
Added: trunk/doc/pages/tutorial/tuto_ast.doc.in
===================================================================
--- trunk/doc/pages/tutorial/tuto_ast.doc.in (rev 0)
+++ trunk/doc/pages/tutorial/tuto_ast.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,5 @@
+/*! \page tuto_ast Tutorial: abstract syntax definition
+
+
+
+*/
Added: trunk/doc/pages/tutorial/tuto_parsing.doc.in
===================================================================
--- trunk/doc/pages/tutorial/tuto_parsing.doc.in (rev 0)
+++ trunk/doc/pages/tutorial/tuto_parsing.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,6 @@
+/*! \page tuto_parsing Tutorial: parser
+
+
+
+
+*/
\ No newline at end of file
Added: trunk/doc/pages/tutorial/tuto_pp.doc.in
===================================================================
--- trunk/doc/pages/tutorial/tuto_pp.doc.in (rev 0)
+++ trunk/doc/pages/tutorial/tuto_pp.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,3 @@
+/*! \page tuto_pp Tutorial: pretty-printer
+
+*/
Added: trunk/doc/pages/tutorial/tuto_trans.doc.in
===================================================================
--- trunk/doc/pages/tutorial/tuto_trans.doc.in (rev 0)
+++ trunk/doc/pages/tutorial/tuto_trans.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,7 @@
+/*! \page tuto_trans Tutorial: transformations
+
+\section pattern_matching Pattern matching
+
+\section strategies Strategies
+
+*/
Added: trunk/doc/pages/tutorial.doc.in
===================================================================
--- trunk/doc/pages/tutorial.doc.in (rev 0)
+++ trunk/doc/pages/tutorial.doc.in 2011-01-18 23:47:17 UTC (rev 152)
@@ -0,0 +1,8 @@
+/*! \page tutorial Tutorial
+
+\li \subpage tuto_ast
+\li \subpage tuto_parsing
+\li \subpage tuto_pp
+\li \subpage tuto_trans
+
+*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-12-14 10:55:45
|
Revision: 151
http://aurelia.svn.sourceforge.net/aurelia/?rev=151&view=rev
Author: valentindavid
Date: 2010-12-14 10:55:39 +0000 (Tue, 14 Dec 2010)
Log Message:
-----------
2010-12-14 Valentin David <val...@ii...>
* demos/07-strategies.cc, demos/10-int.cc:
Include missing header.
Modified Paths:
--------------
trunk/ChangeLog
trunk/demos/07-strategies.cc
trunk/demos/10-int.cc
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-12-14 10:38:22 UTC (rev 150)
+++ trunk/ChangeLog 2010-12-14 10:55:39 UTC (rev 151)
@@ -1,5 +1,10 @@
2010-12-14 Valentin David <val...@ii...>
+ * demos/07-strategies.cc, demos/10-int.cc:
+ Include missing header.
+
+2010-12-14 Valentin David <val...@ii...>
+
Fix lexical filtering generation.
* src/llstack/queue.hh: Fix possible seg fault when popping
Modified: trunk/demos/07-strategies.cc
===================================================================
--- trunk/demos/07-strategies.cc 2010-12-14 10:38:22 UTC (rev 150)
+++ trunk/demos/07-strategies.cc 2010-12-14 10:55:39 UTC (rev 151)
@@ -18,6 +18,7 @@
#include <iostream>
#include <terms/term.hh>
#include <strategies/strategies.hh>
+#include <strategies/generic/try.hh>
#include <strategies/generic/debug.hh>
#include <strategies/traversals/topdown.hh>
#include <strategies/traversals/one.hh>
Modified: trunk/demos/10-int.cc
===================================================================
--- trunk/demos/10-int.cc 2010-12-14 10:38:22 UTC (rev 150)
+++ trunk/demos/10-int.cc 2010-12-14 10:55:39 UTC (rev 151)
@@ -22,6 +22,7 @@
#include <strategies/strategies.hh>
#include <strategies/traversals/topdown.hh>
#include <strategies/generic/debug.hh>
+#include <strategies/generic/try.hh>
#include <terms/baf_read.hh>
#include <iostream>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-12-14 10:38:28
|
Revision: 150
http://aurelia.svn.sourceforge.net/aurelia/?rev=150&view=rev
Author: valentindavid
Date: 2010-12-14 10:38:22 +0000 (Tue, 14 Dec 2010)
Log Message:
-----------
2010-12-14 Valentin David <val...@ii...>
Fix lexical filtering generation.
* src/llstack/queue.hh: Fix possible seg fault when popping
context.
* src/parser_generator/parser_gen.cc:
Fix priorities in some generated expressions related to
lexical filtering.
* src/parser_generator/parser_gen_main.cc:
Define some needed definitions of -O0. This has to be fixed.
* src/parser_generator/syntax.csf:
Remove useless debug message.
* src/strategies/strategies.hh, src/strategies/generic/try.hh:
Fix include order.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/llstack/queue.hh
trunk/src/parser_generator/parser_gen.cc
trunk/src/parser_generator/parser_gen_main.cc
trunk/src/parser_generator/syntax.csf
trunk/src/strategies/generic/try.hh
trunk/src/strategies/strategies.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/ChangeLog 2010-12-14 10:38:22 UTC (rev 150)
@@ -1,3 +1,23 @@
+2010-12-14 Valentin David <val...@ii...>
+
+ Fix lexical filtering generation.
+
+ * src/llstack/queue.hh: Fix possible seg fault when popping
+ context.
+
+ * src/parser_generator/parser_gen.cc:
+ Fix priorities in some generated expressions related to
+ lexical filtering.
+
+ * src/parser_generator/parser_gen_main.cc:
+ Define some needed definitions of -O0. This has to be fixed.
+
+ * src/parser_generator/syntax.csf:
+ Remove useless debug message.
+
+ * src/strategies/strategies.hh, src/strategies/generic/try.hh:
+ Fix include order.
+
2010-12-06 Valentin David <val...@ii...>
Add lexical restrictions in the parser generator in the fashion
Modified: trunk/src/llstack/queue.hh
===================================================================
--- trunk/src/llstack/queue.hh 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/llstack/queue.hh 2010-12-14 10:38:22 UTC (rev 150)
@@ -96,6 +96,9 @@
descriptor pop() {
map_t::iterator i = m.begin();
+ if (i == m.end()) {
+ throw eof();
+ }
while ((*i).second.pending.empty()) {
stream s = (*i).first;
m.erase(i);
Modified: trunk/src/parser_generator/parser_gen.cc
===================================================================
--- trunk/src/parser_generator/parser_gen.cc 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/parser_generator/parser_gen.cc 2010-12-14 10:38:22 UTC (rev 150)
@@ -1354,7 +1354,7 @@
std::cout << " static const unsigned char set[] = {";
print_bin(std::cout, chars);
std::cout << "};" << std::endl;
- std::cout << " if (!set[*current >> 3]&(1 << (*current%8)))" << std::endl;
+ std::cout << " if (!(set[(*current) >> 3]&(1 << ((*current)%8))))" << std::endl;
std::cout << " break ;" << std::endl;
std::cout << " }" << std::endl;
std::cout << " ++current;" << std::endl;
Modified: trunk/src/parser_generator/parser_gen_main.cc
===================================================================
--- trunk/src/parser_generator/parser_gen_main.cc 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/parser_generator/parser_gen_main.cc 2010-12-14 10:38:22 UTC (rev 150)
@@ -18,6 +18,7 @@
#include <iostream>
#include <fstream>
#include "terms/term.hh"
+#include "strategies/generic/id.hh"
using namespace aurelia;
struct Main {};
@@ -26,6 +27,10 @@
void parser_generator(T input);
T parse_syntax(std::istream& in);
+namespace aurelia {
+ id_strategy id;
+}
+
int main(){
try {
parser_generator(parse_syntax(std::cin));
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/parser_generator/syntax.csf 2010-12-14 10:38:22 UTC (rev 150)
@@ -349,7 +349,6 @@
| $ T ret(C::AS_EMPTY_LIST); $
<LAYOUT?> LookAhead ::= CharClass LookAhead?
$
- std::cerr << "a" << std::endl;
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C::AS_LIST, (T(C("Class", 1), rf1.t), rf0.t));
Modified: trunk/src/strategies/generic/try.hh
===================================================================
--- trunk/src/strategies/generic/try.hh 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/strategies/generic/try.hh 2010-12-14 10:38:22 UTC (rev 150)
@@ -17,9 +17,9 @@
#ifndef __TRY_HH
# define __TRY_HH
-# include "../strategies.hh"
# include "id.hh"
# include "choice.hh"
+# include "../strategies.hh"
namespace aurelia {
Modified: trunk/src/strategies/strategies.hh
===================================================================
--- trunk/src/strategies/strategies.hh 2010-12-07 18:49:36 UTC (rev 149)
+++ trunk/src/strategies/strategies.hh 2010-12-14 10:38:22 UTC (rev 150)
@@ -99,7 +99,6 @@
# include "patterns/build.hh"
# include "generic/not.hh"
# include "generic/where.hh"
-# include "generic/try.hh"
/*! \defgroup Strategies
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-12-07 18:49:43
|
Revision: 149
http://aurelia.svn.sourceforge.net/aurelia/?rev=149&view=rev
Author: valentindavid
Date: 2010-12-07 18:49:36 +0000 (Tue, 07 Dec 2010)
Log Message:
-----------
2010-12-06 Valentin David <val...@ii...>
Add lexical restrictions in the parser generator in the fashion
of SDF.
* src/parser_generator/parser_gen.cc,
* src/parser_generator/syntax.csf: Support lexical restrictions.
* src/llstack/utils.hh: Declare a required template "nofollow".
* src/parser_generator/tests/nofollow.csf,
* src/parser_generator/tests/input_nofollow.txt: New.
* src/parser_generator/tests/Makefile.am: Update.
* src/parser_generator/Makefile.am: Make sure the parser
generator is compiled before going to the testing subdirectory.
* amlib/am/csf.am: Do not create file on error.
Modified Paths:
--------------
trunk/ChangeLog
trunk/amlib/am/csf.am
trunk/src/llstack/utils.hh
trunk/src/parser_generator/Makefile.am
trunk/src/parser_generator/parser_gen.cc
trunk/src/parser_generator/syntax.csf
trunk/src/parser_generator/tests/Makefile.am
Added Paths:
-----------
trunk/src/parser_generator/tests/input_nofollow.txt
trunk/src/parser_generator/tests/nofollow.csf
Property Changed:
----------------
trunk/src/parser_generator/tests/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/ChangeLog 2010-12-07 18:49:36 UTC (rev 149)
@@ -1,5 +1,23 @@
2010-12-06 Valentin David <val...@ii...>
+ Add lexical restrictions in the parser generator in the fashion
+ of SDF.
+
+ * src/parser_generator/parser_gen.cc,
+ * src/parser_generator/syntax.csf: Support lexical restrictions.
+ * src/llstack/utils.hh: Declare a required template "nofollow".
+
+ * src/parser_generator/tests/nofollow.csf,
+ * src/parser_generator/tests/input_nofollow.txt: New.
+ * src/parser_generator/tests/Makefile.am: Update.
+
+ * src/parser_generator/Makefile.am: Make sure the parser
+ generator is compiled before going to the testing subdirectory.
+
+ * amlib/am/csf.am: Do not create file on error.
+
+2010-12-06 Valentin David <val...@ii...>
+
* src/parser_generator/syntax.csf: Use layout sugar.
2010-12-06 Valentin David <val...@ii...>
Modified: trunk/amlib/am/csf.am
===================================================================
--- trunk/amlib/am/csf.am 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/amlib/am/csf.am 2010-12-07 18:49:36 UTC (rev 149)
@@ -1,4 +1,5 @@
?GENERIC?%EXT%%DERIVED-EXT%:
?!GENERIC?%OBJ%: %SOURCE%
-?GENERIC? %VERBOSE%%COMPILE% <%SOURCE% >%OBJ%
-?!GENERIC? %VERBOSE%%COMPILE% <`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% >%OBJ%
+?GENERIC? %VERBOSE%%COMPILE% <%SOURCE% >%OBJ%.tmp && \
+?!GENERIC? %VERBOSE%%COMPILE% <`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% >%OBJ%.tmp && \
+ $(am__mv) %OBJ%.tmp %OBJ%
Modified: trunk/src/llstack/utils.hh
===================================================================
--- trunk/src/llstack/utils.hh 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/src/llstack/utils.hh 2010-12-07 18:49:36 UTC (rev 149)
@@ -100,6 +100,13 @@
}
};
+template <typename NT>
+struct nofollow {
+ static bool check(stream&) {
+ return false;
+ }
+};
+
template <typename S>
struct pop {
void operator()(r_t& R, const frame&, stream& s, const node& cu) const {
Modified: trunk/src/parser_generator/Makefile.am
===================================================================
--- trunk/src/parser_generator/Makefile.am 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/src/parser_generator/Makefile.am 2010-12-07 18:49:36 UTC (rev 149)
@@ -18,7 +18,7 @@
bin_PROGRAMS=parser_gen
parser_gen_SOURCES=parser_gen_main.cc parser_gen.cc syntax.cc syntax.csf
-SUBDIRS=tests
+SUBDIRS=. tests
if BOOTSTRAP
CLEANFILES=syntax.hh
Modified: trunk/src/parser_generator/parser_gen.cc
===================================================================
--- trunk/src/parser_generator/parser_gen.cc 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/src/parser_generator/parser_gen.cc 2010-12-07 18:49:36 UTC (rev 149)
@@ -28,6 +28,7 @@
#include "strategies/generic/debug.hh"
#include "strategies/traversals/alltd.hh"
#include "strategies/lists/map.hh"
+#include "strategies/lists/const_map.hh"
#include "strategies/generic/where.hh"
#include "strategies/patterns/scope.hh"
#include "strategies/generic/side_effect_strategy.hh"
@@ -405,6 +406,8 @@
std::cout << " void operator()(r_t& R, const frame& f, stream& s, const node& cu) const {" << std::endl;
std::cout << ((get_cons_name < undouble_quote)(*attrcode)) << std::endl;
+ std::cout << " if (nofollow<"<<nt_name<<">::check(s))" << std::endl;
+ std::cout << " return ;" << std::endl;
std::cout << " cu.pop(R, ret, s);" << std::endl;
std::cout << " }" << std::endl;
std::cout << " unsigned hash() const {" << std::endl;
@@ -412,8 +415,17 @@
std::cout << " }" << std::endl;
std::cout << " };" << std::endl;
} catch (failure) {
- std::cout << " typedef pop<branch<" << nt_name << ","
- << index << "," << s << "> > res;" << std::endl;
+ std::cout << " struct res {" << std::endl;
+ std::cout << " void operator()(r_t& R, const frame&, stream& s, const node& cu) const {" << std::endl;
+
+ std::cout << " if (nofollow<"<<nt_name<<">::check(s))" << std::endl;
+ std::cout << " return ;" << std::endl;
+ std::cout << " cu.pop(R, void_return(), s);" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << " unsigned hash() const {" << std::endl;
+ std::cout << " return (unsigned)&typeid(res);" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << " };" << std::endl;
}
std::cout << "};" << std::endl;
return t;
@@ -475,12 +487,12 @@
}
T operator()(const T& in) {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, return_type;
+ V l, nt, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = in;
+ Rule[nt, NoParam, return_type, l, nofollow] = in;
if (set[*nt])
throw failure();
try {
@@ -590,14 +602,14 @@
}
T operator()(const T& in) {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
static C Chain("Chain", 2);
- V l, nt, attr, chain, return_type;
+ V l, nt, attr, chain, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = in;
+ Rule[nt, NoParam, return_type, l, nofollow] = in;
char_set_t c;
map(try_(scope(attr,
scope(chain,
@@ -720,13 +732,13 @@
}
T operator()(const T& in) {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, return_type;
+ V l, nt, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = in;
+ Rule[nt, NoParam, return_type, l, nofollow] = in;
char_set_t c;
//std::cerr << "rule: " << in << std::endl;
@@ -859,13 +871,13 @@
T operator()(const T& in) const {
static C Chain("Chain", 2);
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, return_type;
+ V l, nt, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = in;
+ Rule[nt, NoParam, return_type, l, nofollow] = in;
std::string nt_name = to_cxx_id(*nt);
map_index(gen_branch(nt_name))(*l);
std::cout << "struct " << nt_name << " {" << std::endl;
@@ -1071,13 +1083,13 @@
: build_first(other.build_first), build_empty(other.build_empty) {}
T operator()(const T& t) const {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static C Chain("Chain", 2);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, chain, attr, return_type;
+ V l, nt, chain, attr, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = t;
+ Rule[nt, NoParam, return_type, l, nofollow] = t;
std::cout << "/*" << *nt << "*/" << std::endl;
int i = 0;
@@ -1163,14 +1175,14 @@
build_empty(build_empty) {}
T operator()(const T& t) {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static C Chain("Chain", 2);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, chain, attr, return_type;
+ V l, nt, chain, attr, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = t;
+ Rule[nt, NoParam, return_type, l, nofollow] = t;
map(scope(chain, scope(attr, ~Chain[chain, attr] < !chain <
get_bin_empty_r(build_empty, &data))))(*l);
@@ -1191,13 +1203,13 @@
PrintLabelsKernel(): total(0) {}
T operator()(const T& t) {
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static C Chain("Chain", 2);
static V NoParam = T(C("NoParam"));
//static V Void = T(C("Void"));
- V l, nt, return_type;
+ V l, nt, return_type, nofollow;
- Rule[nt, NoParam, return_type, l] = t;
+ Rule[nt, NoParam, return_type, l, nofollow] = t;
int rule = 0;
for (T rt = *l; rt.constructor() == C::AS_LIST; rt = rt[1], ++rule) {
@@ -1230,21 +1242,22 @@
//std::cerr << "Building \"empty\" prediction table." << std::endl;
repeat(map_one(build_empty))(input);
- static C Rule("Rule", 4);
+ static C Rule("Rule", 5);
static V NoParam = T(C("NoParam"));
- V l, nt, return_type;
+ V l, nt, return_type, nofollow;
std::cout << "enum nonterm {" << std::endl;
//std::cerr << "Printing non-terminal list." << std::endl;
map(scope(nt, scope(l,
- ~Rule[nt, NoParam, return_type, l]
+ scope(nofollow,
+ ~Rule[nt, NoParam, return_type, l, nofollow]
< !nt
< [](const T& t) {
std::cout << " NT_" << to_cxx_id(t)
<< "," << std::endl;
return t;
- })
+ }))
)
)(input);
std::cout << "};" << std::endl;
@@ -1290,14 +1303,15 @@
//std::cerr << "Printing \"follow\" prediction table." << std::endl;
map(scope(nt,
scope(l,
- ~Rule[nt, NoParam, return_type, l]
+ scope(nofollow,
+ ~Rule[nt, NoParam, return_type, l, nofollow]
< !nt
< [&build_follow](const T& t) {
std::cout << " /*" << t << "*/ {";
print_bin(std::cout, build_follow[t]);
std::cout << "}," << std::endl;
return t;
- })
+ }))
)
)(input);
std::cout << "};" << std::endl;
@@ -1305,16 +1319,55 @@
//std::cerr << "Printing declartions." << std::endl;
map(scope(nt,
scope(l,
- ~Rule[nt, NoParam, return_type, l]
+ scope(nofollow,
+ ~Rule[nt, NoParam, return_type, l, nofollow]
< !l
< [&nt](const T& t) {
std::cout << "struct " << to_cxx_id(*nt)
<< ";" << std::endl;
return t;
- })
+ }))
)
)(input);
+ const_map([](const T& t) {
+ V l, nt, return_type, nofollow;
+ Rule[nt, NoParam, return_type, l, nofollow] = t;
+
+ if ((*nofollow)->constructor() != C::AS_EMPTY_LIST) {
+ std::cout << "template <>" << std::endl;
+ std::cout << "struct nofollow<" << to_cxx_id(*nt) << "> {" << std::endl;
+ std::cout << " static bool check(stream& s) {" << std::endl;
+ const_map([](const T& t) {
+ std::cout << " for (;;) {" << std::endl;
+ std::cout << " stream current = s;" << std::endl;
+ const_map([](const T& t) {
+ static C Class("Class", 1);
+
+ std::cout << " if (current.eof())" << std::endl;
+ std::cout << " break ;" << std::endl;
+ V s;
+ Class[s] = t;
+ std::string c = (get_cons_name < undouble_quote)(*s);
+ std::bitset<256> chars = class_to_set(c);
+ std::cout << " {" << std::endl;
+ std::cout << " static const unsigned char set[] = {";
+ print_bin(std::cout, chars);
+ std::cout << "};" << std::endl;
+ std::cout << " if (!set[*current >> 3]&(1 << (*current%8)))" << std::endl;
+ std::cout << " break ;" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << " ++current;" << std::endl;
+ })(t);
+ std::cout << " return true;" << std::endl;
+ std::cout << " }" << std::endl;
+ })(*nofollow);
+ std::cout << " return false;" << std::endl;
+ std::cout << " }" << std::endl;
+ std::cout << "};" << std::endl;
+ }
+ })(input);
+
//std::cerr << "Printing code." << std::endl;
map(print_rule(&build_first, &build_empty, &build_follow))(input);
}
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/src/parser_generator/syntax.csf 2010-12-07 18:49:36 UTC (rev 149)
@@ -51,7 +51,7 @@
Range ::= Char "-" Char
RangesOrChars ::= Range RangesOrChars? | Char RangesOrChars?
RangesOrChars? ::= RangesOrChars |
- ClassChar ::= $ ret_frame<stream> next_frame(f, s); $ "[" RangesOrChars "]"
+ CharClass ::= $ ret_frame<stream> next_frame(f, s); $ "[" RangesOrChars "]"
$
ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
@@ -96,41 +96,45 @@
$
<LAYOUT?> Rule ::=
- Symbol //rf3
- ParameterList //rf2
- RetType //rf1
+ Symbol
+ ParameterList
+ RetType
"::="
- ListOfChains //rf0
+ ListOfChains
+ Filtering?
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
- T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, rf0.t));
+ ret_frame<T> rf4 = rf3.parent.as<ret_frame<T> >();
+ T ret(C("Rule", 5), (rf4.t, rf3.t, rf2.t, rf1.t, rf0.t));
$
|
"<" AttrChainElt ">"
- Symbol //rf3
- ParameterList //rf2
- RetType //rf1
+ Symbol
+ ParameterList
+ RetType
"::="
- ListOfChains //rf0
+ ListOfChains
+ Filtering?
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
ret_frame<T> rf4 = rf3.parent.as<ret_frame<T> >();
+ ret_frame<T> rf5 = rf4.parent.as<ret_frame<T> >();
static C Chain("Chain", 2);
V chain, attr;
std::stack<T> chains;
T list = rf0.t;
const_map(scope(attr, scope(chain, ~Chain[chain, attr] < !chain <
- [&chains, &attr, &rf4](const T& c) {
+ [&chains, &attr, &rf5](const T& c) {
std::stack<T> syms;
- const_map([&syms, &rf4](const T& u) {
+ const_map([&syms, &rf5](const T& u) {
syms.push(u);
- syms.push(rf4.t);
+ syms.push(rf5.t);
})(c);
if (!syms.empty())
syms.pop();
@@ -143,13 +147,13 @@
(newl, *attr));
chains.push((T(Chain,
(newl, *attr))));
- })))(rf0.t);
+ })))(rf1.t);
T newchains = T(C::AS_EMPTY_LIST);
while (!chains.empty()) {
newchains = T(C::AS_LIST, (chains.top(), newchains));
chains.pop();
}
- T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, newchains));
+ T ret(C("Rule", 5), (rf4.t, rf3.t, rf2.t, newchains, rf0.t));
$
S ::= LAYOUT? SS LAYOUT? $
@@ -218,6 +222,20 @@
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C("AttrChainElt", 2), (rf1.t, rf0.t));
$
+
+ Filtering? ::= Filtering
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ T ret = rf0.t;
+ $ |
+ $ T ret(C::AS_EMPTY_LIST); $
+
+ <LAYOUT?> Filtering ::= "-/-" LookAhead+
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ T ret = rf0.t;
+ $
+
AttrRule ::=
LocalParameters LAYOUT? "$"
$ ret_frame<stream> next_frame(f, s); $
@@ -235,7 +253,7 @@
<LAYOUT?> ChainElt ::=
String
$ T ret(C("String", 1), f.as<ret_frame<T> >().t); $
- | ClassChar
+ | CharClass
$ T ret(C("Class", 1), f.as<ret_frame<T> >().t); $
| Symbol ArgumentList
$ ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -322,3 +340,30 @@
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
$
CIS ::= [A-Za-z_0-9] CIS |
+
+ <LAYOUT?> LookAhead? ::= "." LookAhead
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ T ret(rf0.t);
+ $
+ | $ T ret(C::AS_EMPTY_LIST); $
+ <LAYOUT?> LookAhead ::= CharClass LookAhead?
+ $
+ std::cerr << "a" << std::endl;
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ T ret(C::AS_LIST, (T(C("Class", 1), rf1.t), rf0.t));
+ $
+
+ <LAYOUT?> LookAhead* ::= "," LookAhead+
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ T ret(rf0.t);
+ $
+ | $ T ret(C::AS_EMPTY_LIST); $
+ <LAYOUT?> LookAhead+ ::= LookAhead LookAhead*
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ T ret(C::AS_LIST, (rf1.t, rf0.t));
+ $
Property changes on: trunk/src/parser_generator/tests
___________________________________________________________________
Modified: svn:ignore
- Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
layout.hh
layout
gamma_2.dir
layout.dir
layout.log
gamma_2.log
+ Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
layout.hh
layout
gamma_2.dir
layout.dir
layout.log
gamma_2.log
nofollow.log
nofollow.dir
nofollow.hh
nofollow
Modified: trunk/src/parser_generator/tests/Makefile.am
===================================================================
--- trunk/src/parser_generator/tests/Makefile.am 2010-12-06 18:07:18 UTC (rev 148)
+++ trunk/src/parser_generator/tests/Makefile.am 2010-12-07 18:49:36 UTC (rev 149)
@@ -17,17 +17,22 @@
include $(top_srcdir)/config/local_parser_gen.mk
-gamma_2_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"gamma_2\" -Igamma_2.dir
-layout_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"layout\" -Ilayout.dir
+tests_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS)
-check_PROGRAMS=gamma_2 layout
-TESTS=gamma_2 layout
+gamma_2_CPPFLAGS=$(tests_CPPFLAGS) -DMOD=\"gamma_2\" -Igamma_2.dir
+layout_CPPFLAGS=$(tests_CPPFLAGS) -DMOD=\"layout\" -Ilayout.dir
+nofollow_CPPFLAGS=$(tests_CPPFLAGS) -DMOD=\"nofollow\" -Inofollow.dir
+check_PROGRAMS=gamma_2 layout nofollow
+TESTS=gamma_2 layout nofollow
+
gamma_2.hh: $(CSF)
layout.hh: $(CSF)
+nofollow.hh: $(CSF)
parser.cc: gamma_2.dir/grammar.hh gamma_2.hh
parser.cc: layout.dir/grammar.hh layout.hh
+parser.cc: nofollow.dir/grammar.hh nofollow.hh
%.dir/grammar.hh:
dir=`dirname "$@"`; \
@@ -37,6 +42,11 @@
gamma_2_SOURCES=parser.cc gamma_2.csf
layout_SOURCES=parser.cc layout.csf
+nofollow_SOURCES=parser.cc nofollow.csf
-CLEANFILES=gamma_2.hh layout.hh gamma_2.dir/grammar.hh layout.dir/grammar.hh
-EXTRA_DIST=input_gamma_2.txt input_layout.txt
+CLEANFILES= \
+ gamma_2.hh gamma_2.dir/grammar.hh \
+ layout.hh layout.dir/grammar.hh \
+ nofollow.hh nofollow.dir/grammar.hh
+
+EXTRA_DIST=input_gamma_2.txt input_layout.txt input_nofollow.txt
Added: trunk/src/parser_generator/tests/input_nofollow.txt
===================================================================
--- trunk/src/parser_generator/tests/input_nofollow.txt (rev 0)
+++ trunk/src/parser_generator/tests/input_nofollow.txt 2010-12-07 18:49:36 UTC (rev 149)
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+//feofkewf
+
+
Added: trunk/src/parser_generator/tests/nofollow.csf
===================================================================
--- trunk/src/parser_generator/tests/nofollow.csf (rev 0)
+++ trunk/src/parser_generator/tests/nofollow.csf 2010-12-07 18:49:36 UTC (rev 149)
@@ -0,0 +1,9 @@
+ LAYOUT? ::= LAYOUT+
+ | -/- [ \r\n\t], [/].[/]
+ LAYOUT+ ::= LAYOUT LAYOUT?
+ LAYOUT ::=
+ " " | "\n" | "\r" | "\t"
+ | "//" Line
+ Line ::= "\n" | [^\n-\n] Line
+
+ S ::= LAYOUT? $ if (!s.eof()) throw 0; frame next_frame = f; $ LAYOUT?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-12-06 18:07:26
|
Revision: 148
http://aurelia.svn.sourceforge.net/aurelia/?rev=148&view=rev
Author: valentindavid
Date: 2010-12-06 18:07:18 +0000 (Mon, 06 Dec 2010)
Log Message:
-----------
2010-12-06 Valentin David <val...@ii...>
* src/parser_generator/syntax.csf: Use layout sugar.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/parser_generator/syntax.csf
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-12-06 17:19:03 UTC (rev 147)
+++ trunk/ChangeLog 2010-12-06 18:07:18 UTC (rev 148)
@@ -1,5 +1,9 @@
2010-12-06 Valentin David <val...@ii...>
+ * src/parser_generator/syntax.csf: Use layout sugar.
+
+2010-12-06 Valentin David <val...@ii...>
+
Handle sugar for layout parsing in parser generator.
* src/patterns/term_pattern.hh:
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-12-06 17:19:03 UTC (rev 147)
+++ trunk/src/parser_generator/syntax.csf 2010-12-06 18:07:18 UTC (rev 148)
@@ -95,15 +95,11 @@
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
$
- Rule ::=
+ <LAYOUT?> Rule ::=
Symbol //rf3
- LAYOUT?
ParameterList //rf2
- LAYOUT?
RetType //rf1
- LAYOUT?
"::="
- LAYOUT?
ListOfChains //rf0
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -113,15 +109,11 @@
T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, rf0.t));
$
|
- "<" LAYOUT? AttrChainElt LAYOUT? ">" LAYOUT?
+ "<" AttrChainElt ">"
Symbol //rf3
- LAYOUT?
ParameterList //rf2
- LAYOUT?
RetType //rf1
- LAYOUT?
"::="
- LAYOUT?
ListOfChains //rf0
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -147,6 +139,8 @@
newl = T(C::AS_LIST, (syms.top(), newl));
syms.pop();
}
+ T a(Chain,
+ (newl, *attr));
chains.push((T(Chain,
(newl, *attr))));
})))(rf0.t);
@@ -162,7 +156,7 @@
ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret = rf0.t;
$
- SS ::= Rule LAYOUT? SSS
+ <LAYOUT?> SS ::= Rule SSS
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
@@ -174,16 +168,16 @@
$
| $ T ret(C::AS_EMPTY_LIST); $
- ParameterList ::=
- "(" LAYOUT? Parameters LAYOUT? ")"
+ <LAYOUT?> ParameterList ::=
+ "(" Parameters ")"
$ T ret = f.as<ret_frame<T> >().t; $
| $ T ret(C("NoParam")); $
- LocalParameters ::= "{" LAYOUT? Parameters LAYOUT? "}"
+ <LAYOUT?> LocalParameters ::= "{" Parameters "}"
$ T ret(C("Some", 1), f.as<ret_frame<T> >().t); $
| $ T ret(C("None")); $
- ListOfChains ::= Chain LAYOUT? AttrRule? LAYOUT? ListOfChainsTail
+ <LAYOUT?> ListOfChains ::= Chain AttrRule? ListOfChainsTail
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
@@ -191,13 +185,13 @@
T ret(C::AS_LIST, (T(C("Chain", 2), (rf2.t, rf1.t)), rf0.t));
$
- ListOfChainsTail ::= "|" LAYOUT? ListOfChains $
+ <LAYOUT?> ListOfChainsTail ::= "|" ListOfChains $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret(rf0.t);
$
| $ T ret(C::AS_EMPTY_LIST); $
- RetType ::= ":" LAYOUT? CxxType
+ <LAYOUT?> RetType ::= ":" CxxType
$ ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret = rf0.t;
$
@@ -210,22 +204,26 @@
$
| $ T ret(C::AS_EMPTY_LIST); $
- NonEmptyChain ::=
- AttrChainElt LAYOUT? Chain
+ <LAYOUT?> NonEmptyChain ::=
+ AttrChainElt Chain
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C::AS_LIST, (rf1.t, rf0.t));
$
- AttrChainElt ::= AttrRule? LAYOUT? ChainElt
+ <LAYOUT?> AttrChainElt ::= AttrRule? ChainElt
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C("AttrChainElt", 2), (rf1.t, rf0.t));
$
AttrRule ::=
- LocalParameters LAYOUT? "$" $ ret_frame<stream> next_frame(f, s); $ CxxCode $ ret_frame<stream> next_frame(f, s); $ "$"
+ LocalParameters LAYOUT? "$"
+ $ ret_frame<stream> next_frame(f, s); $
+ CxxCode
+ $ ret_frame<stream> next_frame(f, s); $
+ "$"
$
ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
ret_frame<stream> rf1 = rf0.parent.as<ret_frame<stream> >();
@@ -234,86 +232,93 @@
T(C("\"" + stream_range_to_string(rf1.t, rf0.t) + "\"", 0))));
$
- ChainElt ::=
+ <LAYOUT?> ChainElt ::=
String
$ T ret(C("String", 1), f.as<ret_frame<T> >().t); $
| ClassChar
$ T ret(C("Class", 1), f.as<ret_frame<T> >().t); $
- | Symbol LAYOUT? ArgumentList
+ | Symbol ArgumentList
$ ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C("Symbol", 2), (rf1.t, rf0.t)); $
- ArgumentList ::= "(" LAYOUT? Arguments LAYOUT? ")" $
+ <LAYOUT?> ArgumentList ::= "(" Arguments ")" $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret(C("Args", 1), rf0.t);
$
| $ T ret(C("NoArg")); $
- OtherArguments ::= "," LAYOUT? Arguments $
+ <LAYOUT?> OtherArguments ::= "," Arguments $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret(rf0.t);
$
| $ T ret(C::AS_EMPTY_LIST); $
- Arguments ::= Argument LAYOUT? OtherArguments
+ <LAYOUT?> Arguments ::= Argument OtherArguments
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C::AS_LIST, (rf1.t, rf0.t));
$
- Argument ::= $ ret_frame<stream> next_frame(f, s); $ CxxExpression $
+ Argument ::=
+ $ ret_frame<stream> next_frame(f, s); $
+ CxxExpression
+ $
ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
$
- CxxExpression ::= CxxIdentifier
- | CxxExpression LAYOUT? "." LAYOUT? CxxIdentifier
+ <LAYOUT?> CxxExpression ::= CxxIdentifier
+ | CxxExpression "." CxxIdentifier
CxxCode ::= CxxChar CxxCode?
CxxCode? ::= CxxCode |
CxxChar ::= [^$]
- Parameter ::= CxxType LAYOUT CxxIdentifier
+ <LAYOUT+> Parameter ::= CxxType CxxIdentifier
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C("Parameter", 2), (rf1.t, rf0.t));
$
- CxxType ::= $ ret_frame<stream> next_frame(f, s); $ CxxIdentifier LAYOUT? TemplateArguments LAYOUT? ContCxxType
+ <LAYOUT?> CxxType ::=
+ $ ret_frame<stream> next_frame(f, s); $
+ CxxIdentifier TemplateArguments ContCxxType
$
ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
$
- ContCxxType ::= "::" LAYOUT? CxxType |
- TemplateArguments ::= "<" LAYOUT? CxxTypes LAYOUT? ">" |
- CxxTypes ::= CxxType LAYOUT CCT
- CCT ::= "," LAYOUT? CxxType |
+ <LAYOUT?> ContCxxType ::= "::" CxxType |
+ <LAYOUT?> TemplateArguments ::= "<" CxxTypes ">" |
+ <LAYOUT+> CxxTypes ::= CxxType CCT
+ <LAYOUT?> CCT ::= "," CxxType |
+
AttrRule? ::= AttrRule
$ T ret(T(C("Some", 1), f.as<ret_frame<T> >().t)); $
|
$ T ret(T(C("None"))); $
- Parameters ::= Parameter LAYOUT? CParameters
+ <LAYOUT?> Parameters ::= Parameter CParameters
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
T ret(C::AS_LIST, (rf1.t, rf0.t));
$
- CParameters ::= "," LAYOUT? Parameters $
+ <LAYOUT?> CParameters ::= "," Parameters $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
T ret(rf0.t);
$
| $ T ret(C::AS_EMPTY_LIST); $
- CxxIdentifier ::= $ ret_frame<stream> next_frame(f, s); $ [A-Za-z_] CIS
+ CxxIdentifier ::= $ ret_frame<stream> next_frame(f, s); $
+ [A-Za-z_] CIS
$
- ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
- T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
+ ret_frame<stream> rf0 = f.as<ret_frame<stream> >();
+ T ret(C("\"" + stream_range_to_string(rf0.t, s) + "\"", 0));
$
CIS ::= [A-Za-z_0-9] CIS |
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-12-06 17:19:10
|
Revision: 147
http://aurelia.svn.sourceforge.net/aurelia/?rev=147&view=rev
Author: valentindavid
Date: 2010-12-06 17:19:03 +0000 (Mon, 06 Dec 2010)
Log Message:
-----------
2010-12-06 Valentin David <val...@ii...>
Handle sugar for layout parsing in parser generator.
* src/patterns/term_pattern.hh:
Set a non-template function as inline to avoid linking errors.
* src/strategies/generic/fail.hh,
* src/strategies/generic/id.hh:
Set globals as extern to avoid linking errors.
* src/parser_generator/syntax.csf: Add extension as sugar.
* src/parser_generator/syntax.cc: Include and define
necessary environment for the parser.
* src/parser_generator/tests/parser.cc: New.
* src/parser_generator/tests/gamma_2.cc: Remove.
* src/parser_generator/tests/input.txt: Rename as...
* src/parser_generator/tests/input_gamma_2.txt: ... this.
* src/parser_generator/tests/layout.csf,
* src/parser_generator/tests/input_layout.txt: New.
* src/parser_generator/tests/Makefile.am: Update.
* src/strategies/patterns/scope.hh:
Allow void strategies to be used in a scope.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/parser_generator/syntax.cc
trunk/src/parser_generator/syntax.csf
trunk/src/parser_generator/tests/Makefile.am
trunk/src/patterns/term_pattern.hh
trunk/src/strategies/generic/fail.hh
trunk/src/strategies/generic/id.hh
trunk/src/strategies/patterns/scope.hh
Added Paths:
-----------
trunk/src/parser_generator/tests/input_gamma_2.txt
trunk/src/parser_generator/tests/input_layout.txt
trunk/src/parser_generator/tests/layout.csf
trunk/src/parser_generator/tests/parser.cc
Removed Paths:
-------------
trunk/src/parser_generator/tests/gamma_2.cc
trunk/src/parser_generator/tests/input.txt
Property Changed:
----------------
trunk/src/parser_generator/tests/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/ChangeLog 2010-12-06 17:19:03 UTC (rev 147)
@@ -1,3 +1,32 @@
+2010-12-06 Valentin David <val...@ii...>
+
+ Handle sugar for layout parsing in parser generator.
+
+ * src/patterns/term_pattern.hh:
+ Set a non-template function as inline to avoid linking errors.
+
+ * src/strategies/generic/fail.hh,
+ * src/strategies/generic/id.hh:
+ Set globals as extern to avoid linking errors.
+
+ * src/parser_generator/syntax.csf: Add extension as sugar.
+
+ * src/parser_generator/syntax.cc: Include and define
+ necessary environment for the parser.
+
+ * src/parser_generator/tests/parser.cc: New.
+ * src/parser_generator/tests/gamma_2.cc: Remove.
+ * src/parser_generator/tests/input.txt: Rename as...
+ * src/parser_generator/tests/input_gamma_2.txt: ... this.
+
+ * src/parser_generator/tests/layout.csf,
+ * src/parser_generator/tests/input_layout.txt: New.
+
+ * src/parser_generator/tests/Makefile.am: Update.
+
+ * src/strategies/patterns/scope.hh:
+ Allow void strategies to be used in a scope.
+
2010-11-15 Valentin David <val...@ii...>
Add terms for pretty printing.
Modified: trunk/src/parser_generator/syntax.cc
===================================================================
--- trunk/src/parser_generator/syntax.cc 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/syntax.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -18,18 +18,23 @@
#include <sstream>
#include <iostream>
#include <fstream>
+#include <stack>
#include "llstack/queue.hh"
#include "llstack/node.hh"
#include "streams/buf_stream.hh"
#include "llstack/label.hh"
#include "llstack/node.hpp"
#include "terms/term.hh"
+#include "patterns/term_pattern.hh"
+#include "strategies/patterns/scope.hh"
+#include "strategies/lists/const_map.hh"
using namespace aurelia;
using namespace llstack;
struct Main {};
typedef untyped_term<Main> T;
typedef untyped_constructor<Main> C;
+typedef variable<T> V;
frame pop_void(const frame& f) {
return f.as<ret_frame<void_return> >().parent;
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/syntax.csf 2010-12-06 17:19:03 UTC (rev 147)
@@ -97,13 +97,13 @@
Rule ::=
Symbol //rf3
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
ParameterList //rf2
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
RetType //rf1
- LAYOUT? $ frame next_frame(f); $
- "::=" $ frame next_frame(f); $
- LAYOUT? $ frame next_frame(f); $
+ LAYOUT?
+ "::="
+ LAYOUT?
ListOfChains //rf0
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -112,6 +112,51 @@
ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, rf0.t));
$
+ |
+ "<" LAYOUT? AttrChainElt LAYOUT? ">" LAYOUT?
+ Symbol //rf3
+ LAYOUT?
+ ParameterList //rf2
+ LAYOUT?
+ RetType //rf1
+ LAYOUT?
+ "::="
+ LAYOUT?
+ ListOfChains //rf0
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
+ ret_frame<T> rf3 = rf2.parent.as<ret_frame<T> >();
+ ret_frame<T> rf4 = rf3.parent.as<ret_frame<T> >();
+ static C Chain("Chain", 2);
+ V chain, attr;
+ std::stack<T> chains;
+ T list = rf0.t;
+ const_map(scope(attr, scope(chain, ~Chain[chain, attr] < !chain <
+ [&chains, &attr, &rf4](const T& c) {
+ std::stack<T> syms;
+ const_map([&syms, &rf4](const T& u) {
+ syms.push(u);
+ syms.push(rf4.t);
+ })(c);
+ if (!syms.empty())
+ syms.pop();
+ T newl = T(C::AS_EMPTY_LIST);
+ while (!syms.empty()) {
+ newl = T(C::AS_LIST, (syms.top(), newl));
+ syms.pop();
+ }
+ chains.push((T(Chain,
+ (newl, *attr))));
+ })))(rf0.t);
+ T newchains = T(C::AS_EMPTY_LIST);
+ while (!chains.empty()) {
+ newchains = T(C::AS_LIST, (chains.top(), newchains));
+ chains.pop();
+ }
+ T ret(C("Rule", 4), (rf3.t, rf2.t, rf1.t, newchains));
+ $
S ::= LAYOUT? SS LAYOUT? $
ret_frame<T> rf0 = f.as<ret_frame<T> >();
@@ -166,14 +211,19 @@
| $ T ret(C::AS_EMPTY_LIST); $
NonEmptyChain ::=
- AttrRule? LAYOUT? ChainElt LAYOUT? Chain
+ AttrChainElt LAYOUT? Chain
$
ret_frame<T> rf0 = f.as<ret_frame<T> >();
ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
- ret_frame<T> rf2 = rf1.parent.as<ret_frame<T> >();
- T ret(C::AS_LIST, (T(C("AttrChainElt", 2), (rf2.t, rf1.t)), rf0.t));
+ T ret(C::AS_LIST, (rf1.t, rf0.t));
$
+ AttrChainElt ::= AttrRule? LAYOUT? ChainElt
+ $
+ ret_frame<T> rf0 = f.as<ret_frame<T> >();
+ ret_frame<T> rf1 = rf0.parent.as<ret_frame<T> >();
+ T ret(C("AttrChainElt", 2), (rf1.t, rf0.t));
+ $
AttrRule ::=
LocalParameters LAYOUT? "$" $ ret_frame<stream> next_frame(f, s); $ CxxCode $ ret_frame<stream> next_frame(f, s); $ "$"
$
Property changes on: trunk/src/parser_generator/tests
___________________________________________________________________
Modified: svn:ignore
- Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
+ Makefile
Makefile.in
gamma_2.tree
gamma_2
gamma_2.hh
.deps
gamma_2.log
test-suite.log
layout.hh
layout
gamma_2.dir
layout.dir
layout.log
gamma_2.log
Modified: trunk/src/parser_generator/tests/Makefile.am
===================================================================
--- trunk/src/parser_generator/tests/Makefile.am 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/Makefile.am 2010-12-06 17:19:03 UTC (rev 147)
@@ -17,14 +17,26 @@
include $(top_srcdir)/config/local_parser_gen.mk
-gamma_2_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS)
+gamma_2_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"gamma_2\" -Igamma_2.dir
+layout_CPPFLAGS=-DSRCDIR=\"$(srcdir)\" $(AM_CPPFLAGS) -DMOD=\"layout\" -Ilayout.dir
-check_PROGRAMS=gamma_2
-TESTS=gamma_2
+check_PROGRAMS=gamma_2 layout
+TESTS=gamma_2 layout
gamma_2.hh: $(CSF)
+layout.hh: $(CSF)
-gamma_2_SOURCES=gamma_2.cc gamma_2.csf
+parser.cc: gamma_2.dir/grammar.hh gamma_2.hh
+parser.cc: layout.dir/grammar.hh layout.hh
-CLEANFILES=gamma_2.hh
-EXTRA_DIST=input.txt
+%.dir/grammar.hh:
+ dir=`dirname "$@"`; \
+ base=`basename "$$dir" .dir`; \
+ $(MKDIR_P) "$$dir"; \
+ echo "#include \"$$base.hh\"" >"$@"
+
+gamma_2_SOURCES=parser.cc gamma_2.csf
+layout_SOURCES=parser.cc layout.csf
+
+CLEANFILES=gamma_2.hh layout.hh gamma_2.dir/grammar.hh layout.dir/grammar.hh
+EXTRA_DIST=input_gamma_2.txt input_layout.txt
Deleted: trunk/src/parser_generator/tests/gamma_2.cc
===================================================================
--- trunk/src/parser_generator/tests/gamma_2.cc 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/gamma_2.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -1,91 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#include <sstream>
-#include <iostream>
-#include <fstream>
-#include "llstack/queue.hh"
-#include "llstack/node.hh"
-#include "streams/buf_stream.hh"
-#include "llstack/label.hh"
-#include "llstack/node.hpp"
-
-using namespace aurelia;
-using namespace llstack;
-#include "gamma_2.hh"
-
-bool found;
-
-struct start_label {
- void operator()(r_t&, const frame&, stream& s, const node&) const {
- if (s.eof()) {
- std::cerr << s.get_pos() << " " << "Found!" << std::endl;
- found = true;
- }
- }
-};
-
-struct end_label {
- void operator()(r_t&, const frame&, stream&, const node&) const {
- }
-};
-
-struct error {};
-
-bool main_loop(stream& s, const stream& end) {
- found = false;
- r_t R;
- if (s.eof()) {
- if (!is_empty_first(S_0_0))
- { throw error(); }
- }
- else if (!is_first(s, S_0_0)) {
- { throw error(); }
- }
- node u1 = node::boundary(start_label(), end);
- node u0 = node::boundary(end_label(), end);
- u1.parents().insert(u0);
- S start;
- start(R, empty_frame(), s, u1);
- int lastpos = -1;
- try {
- while (true) {
- descriptor d = R.pop();
- s = d.s;
- if (lastpos < s.get_pos()) {
- lastpos = s.get_pos();
- /* std::stringstream ss;
- ss << "graph." << s.get_pos();
- std::ofstream out(ss.str());*/
- std::cerr << lastpos << std::endl;
- //node::printnodes(out);
- }
- d.L.call(R, d.f, d.s, d.n);
- }
- } catch (r_t::eof) {
- }
-
- node::clear();
- return found;
-}
-
-int main() {
- std::ifstream in(SRCDIR"/input.txt");
- buf_stream bs(in);
- stream s = bs.begin();
- return !main_loop(s, bs.end());
-}
Deleted: trunk/src/parser_generator/tests/input.txt
===================================================================
--- trunk/src/parser_generator/tests/input.txt 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/parser_generator/tests/input.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -1 +0,0 @@
-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\ No newline at end of file
Copied: trunk/src/parser_generator/tests/input_gamma_2.txt (from rev 146, trunk/src/parser_generator/tests/input.txt)
===================================================================
--- trunk/src/parser_generator/tests/input_gamma_2.txt (rev 0)
+++ trunk/src/parser_generator/tests/input_gamma_2.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1 @@
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
\ No newline at end of file
Added: trunk/src/parser_generator/tests/input_layout.txt
===================================================================
--- trunk/src/parser_generator/tests/input_layout.txt (rev 0)
+++ trunk/src/parser_generator/tests/input_layout.txt 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,2 @@
+foo
+bar baz
Added: trunk/src/parser_generator/tests/layout.csf
===================================================================
--- trunk/src/parser_generator/tests/layout.csf (rev 0)
+++ trunk/src/parser_generator/tests/layout.csf 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,71 @@
+ LAYOUT? ::= LAYOUT+
+ $ if (!s.eof()) {
+ switch (*s) {
+ case ' ':
+ case '\r':
+ case '\n':
+ case '\t':
+ return ;
+ case '/':
+ {
+ buf_stream_iterator next = s;
+ ++next;
+ if (!next.eof()) {
+ if (*next == '/')
+ return ;
+ }
+ }
+ }
+ }
+ void_return ret;
+ $ |
+ $ if (!s.eof()) {
+ switch (*s) {
+ case ' ':
+ case '\r':
+ case '\n':
+ case '\t':
+ return ;
+ case '/':
+ {
+ buf_stream_iterator next = s;
+ ++next;
+ if (!next.eof()) {
+ if (*next == '/')
+ return ;
+ }
+ }
+ }
+ }
+ void_return ret;
+ $
+
+ LAYOUT+ ::= LAYOUT LAYOUT?
+ LAYOUT ::=
+ " " | "\n" | "\r" | "\t"
+ | "//" Line
+ Line ::= "\n" | [^\n-\n] Line
+
+ IdChar ::= [A-Z] | [a-z] | "_"
+ IdChar+ ::= IdChar IdChar*
+ IdChar* ::= IdChar+ |
+ Id ::= IdChar+ $
+ if (!s.eof()) {
+ switch (*s) {
+ case '_':
+ return ;
+ }
+ if (((*s) >= 'A') && (*s) <= 'Z')
+ return ;
+ if (((*s) >= 'a') && (*s) <= 'z')
+ return ;
+ }
+ void_return ret;
+ $
+
+ S ::= LAYOUT? SS LAYOUT?
+ <LAYOUT?> SS ::= Id* SSS
+ SSS ::= SS |
+
+ Id+ ::= Id Id*
+ Id* ::= Id+ |
Copied: trunk/src/parser_generator/tests/parser.cc (from rev 146, trunk/src/parser_generator/tests/gamma_2.cc)
===================================================================
--- trunk/src/parser_generator/tests/parser.cc (rev 0)
+++ trunk/src/parser_generator/tests/parser.cc 2010-12-06 17:19:03 UTC (rev 147)
@@ -0,0 +1,91 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include "llstack/queue.hh"
+#include "llstack/node.hh"
+#include "streams/buf_stream.hh"
+#include "llstack/label.hh"
+#include "llstack/node.hpp"
+
+using namespace aurelia;
+using namespace llstack;
+#include "grammar.hh"
+
+bool found;
+
+struct start_label {
+ void operator()(r_t&, const frame&, stream& s, const node&) const {
+ if (s.eof()) {
+ std::cerr << s.get_pos() << " " << "Found!" << std::endl;
+ found = true;
+ }
+ }
+};
+
+struct end_label {
+ void operator()(r_t&, const frame&, stream&, const node&) const {
+ }
+};
+
+struct error {};
+
+bool main_loop(stream& s, const stream& end) {
+ found = false;
+ r_t R;
+ if (s.eof()) {
+ if (!is_empty_first(S_0_0))
+ { throw error(); }
+ }
+ else if (!is_first(s, S_0_0)) {
+ { throw error(); }
+ }
+ node u1 = node::boundary(start_label(), end);
+ node u0 = node::boundary(end_label(), end);
+ u1.parents().insert(u0);
+ S start;
+ start(R, empty_frame(), s, u1);
+ int lastpos = -1;
+ try {
+ while (true) {
+ descriptor d = R.pop();
+ s = d.s;
+ if (lastpos < s.get_pos()) {
+ lastpos = s.get_pos();
+ /* std::stringstream ss;
+ ss << "graph." << s.get_pos();
+ std::ofstream out(ss.str());*/
+ std::cerr << lastpos << std::endl;
+ //node::printnodes(out);
+ }
+ d.L.call(R, d.f, d.s, d.n);
+ }
+ } catch (r_t::eof) {
+ }
+
+ node::clear();
+ return found;
+}
+
+int main() {
+ std::ifstream in(SRCDIR"/input_"MOD".txt");
+ buf_stream bs(in);
+ stream s = bs.begin();
+ return !main_loop(s, bs.end());
+}
Modified: trunk/src/patterns/term_pattern.hh
===================================================================
--- trunk/src/patterns/term_pattern.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/patterns/term_pattern.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -38,7 +38,7 @@
assign(tail(l), t);
}
- list_nil build(const list_nil&) {
+ inline list_nil build(const list_nil&) {
return list_nil();
}
Modified: trunk/src/strategies/generic/fail.hh
===================================================================
--- trunk/src/strategies/generic/fail.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/generic/fail.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -32,7 +32,7 @@
/*! \brief A strategy that always fails for any given input type.
* \ingroup Generic
*/
- fail_strategy fail;
+ extern fail_strategy fail;
}
Modified: trunk/src/strategies/generic/id.hh
===================================================================
--- trunk/src/strategies/generic/id.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/generic/id.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -33,8 +33,7 @@
/*! \brief A strategy that always succeeds for any given input type.
* \ingroup Generic
*/
- id_strategy id;
-
+ extern id_strategy id;
}
#endif
Modified: trunk/src/strategies/patterns/scope.hh
===================================================================
--- trunk/src/strategies/patterns/scope.hh 2010-11-15 17:42:27 UTC (rev 146)
+++ trunk/src/strategies/patterns/scope.hh 2010-12-06 17:19:03 UTC (rev 147)
@@ -39,15 +39,17 @@
<typename strategy_model<Strat, U>::model>::check
require;
- try {
- v.push();
- typename strategy_model<Strat, U>::model::output ret = s(t);
- v.pop();
- return ret;
- } catch (...) {
- v.pop();
- throw ;
- }
+ struct onexit {
+ const T& v;
+ onexit(const T& v): v(v) {
+ v.push();
+ }
+ ~onexit() {
+ v.pop();
+ }
+ };
+ onexit oe(v);
+ return s(t);
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-11-15 17:42:39
|
Revision: 146
http://aurelia.svn.sourceforge.net/aurelia/?rev=146&view=rev
Author: valentindavid
Date: 2010-11-15 17:42:27 +0000 (Mon, 15 Nov 2010)
Log Message:
-----------
2010-11-15 Valentin David <val...@ii...>
Add terms for pretty printing.
* src/box/box_terms.hh: New.
* src/box/Makefile.am: Update.
* src/box/tests/test_box_patterns.cc: New.
* src/box/tests/Makefile.am: Update.
* src/terms/term_utils.hh:
Define default traits to avoid error at linking.
Add term model.
* src/patterns/constant.hh: New.
* src/patterns/Makefile.am: Update.
* src/patterns/pattern_utils.hh:
Fix overloading of conversion operator of pattern builder.
Define model for pattern concept.
* src/strategies/patterns/match.hh,
* src/strategies/patterns/build.hh:
Add operator for all pattern types.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/box/Makefile.am
trunk/src/box/tests/Makefile.am
trunk/src/patterns/Makefile.am
trunk/src/patterns/pattern_utils.hh
trunk/src/strategies/patterns/build.hh
trunk/src/strategies/patterns/match.hh
trunk/src/terms/term_utils.hh
Added Paths:
-----------
trunk/src/box/box_terms.hh
trunk/src/box/tests/test_box_patterns.cc
trunk/src/patterns/constant.hh
Property Changed:
----------------
trunk/src/box/tests/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/ChangeLog 2010-11-15 17:42:27 UTC (rev 146)
@@ -1,3 +1,28 @@
+2010-11-15 Valentin David <val...@ii...>
+
+ Add terms for pretty printing.
+
+ * src/box/box_terms.hh: New.
+ * src/box/Makefile.am: Update.
+
+ * src/box/tests/test_box_patterns.cc: New.
+ * src/box/tests/Makefile.am: Update.
+
+ * src/terms/term_utils.hh:
+ Define default traits to avoid error at linking.
+ Add term model.
+
+ * src/patterns/constant.hh: New.
+ * src/patterns/Makefile.am: Update.
+
+ * src/patterns/pattern_utils.hh:
+ Fix overloading of conversion operator of pattern builder.
+ Define model for pattern concept.
+
+ * src/strategies/patterns/match.hh,
+ * src/strategies/patterns/build.hh:
+ Add operator for all pattern types.
+
2010-11-02 Valentin David <val...@ii...>
* src/memory/pool_allocator.hh: Fix portability issue by using
Modified: trunk/src/box/Makefile.am
===================================================================
--- trunk/src/box/Makefile.am 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/box/Makefile.am 2010-11-15 17:42:27 UTC (rev 146)
@@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
boxdir=$(aureliadir)/box
-nobase_box_HEADERS=box.hh
+nobase_box_HEADERS= \
+ box.hh \
+ box_terms.hh
SUBDIRS=tests
Added: trunk/src/box/box_terms.hh
===================================================================
--- trunk/src/box/box_terms.hh (rev 0)
+++ trunk/src/box/box_terms.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -0,0 +1,110 @@
+#ifndef __BOX_TERMS_HH
+# define __BOX_TERMS_HH
+
+# include "../terms/list_terms.hh"
+
+namespace aurelia {
+
+ struct box;
+ struct vbox_constr {};
+ struct hbox_constr {};
+ struct hvbox_constr {};
+ struct string_box_constr {};
+
+ pattern_generator<vbox_constr> vbox;
+ pattern_generator<hbox_constr> hbox;
+ pattern_generator<hvbox_constr> hvbox;
+ pattern_generator<string_box_constr> string_box;
+
+ //hs, vs, is
+ typedef std::tuple<unsigned, unsigned, unsigned> box_conf;
+
+ template <>
+ struct get_tuple<box, vbox_constr> {
+ typedef std::tuple<box_conf, list<box> > tuple;
+ };
+
+ template <>
+ struct get_tuple<box, hbox_constr> {
+ typedef std::tuple<box_conf, list<box> > tuple;
+ };
+
+ template <>
+ struct get_tuple<box, hvbox_constr> {
+ typedef std::tuple<box_conf, list<box> > tuple;
+ };
+
+ template <>
+ struct get_tuple<box, string_box_constr> {
+ typedef std::tuple<std::string> tuple;
+ };
+
+ struct box: public term<box,
+ vbox_constr,
+ hbox_constr,
+ hvbox_constr,
+ string_box_constr> {
+ typedef term<box,
+ vbox_constr,
+ hbox_constr,
+ hvbox_constr,
+ string_box_constr> super;
+ box() = default;
+ box(const super& other): super(other) {}
+ box(super&& other): super(std::move(other)) {}
+ };
+
+ struct vbox_term: public std_term<vbox_term, vbox_constr, box> {
+ typedef std_term<vbox_term, vbox_constr, box> super;
+ vbox_term(box_conf c, list<box> l): super(typename super::tuple(c, l)) {}
+ vbox_term(const vbox_term& other): super(other) {}
+ };
+
+ template <>
+ struct build_type<box, vbox_constr> {
+ typedef vbox_term type;
+ };
+
+ struct hbox_term: public std_term<hbox_term, hbox_constr, box> {
+ typedef std_term<hbox_term, hbox_constr, box> super;
+ hbox_term(box_conf c, list<box> l): super(typename super::tuple(c, l)) {}
+ hbox_term(const hbox_term& other): super(other) {}
+ };
+
+ template <>
+ struct build_type<box, hbox_constr> {
+ typedef hbox_term type;
+ };
+
+ struct hvbox_term: public std_term<hvbox_term, hvbox_constr, box> {
+ typedef std_term<hvbox_term, hvbox_constr, box> super;
+ hvbox_term(box_conf c, list<box> l): super(typename super::tuple(c, l)) {}
+ hvbox_term(const hvbox_term& other): super(other) {}
+ };
+
+ template <>
+ struct build_type<box, hvbox_constr> {
+ typedef hvbox_term type;
+ };
+
+ struct string_box_term: public std_term<string_box_term, string_box_constr, box> {
+ typedef std_term<string_box_term, string_box_constr, box> super;
+ string_box_term(std::string s): super(typename super::tuple(s)) {}
+ string_box_term(const string_box_term& other): super(other) {}
+ };
+
+ template <>
+ struct build_type<box, string_box_constr> {
+ typedef string_box_term type;
+ };
+
+ template <>
+ struct term_model<box> {
+ struct model {
+ typedef box type;
+ };
+ };
+
+}
+
+#endif
Property changes on: trunk/src/box/tests
___________________________________________________________________
Modified: svn:ignore
- Makefile
.deps
box_test
Makefile.in
box_test.log
test-suite.log
+ Makefile
.deps
box_test
Makefile.in
box_test.log
test-suite.log
test_box_patterns
test_box_patterns.log
Modified: trunk/src/box/tests/Makefile.am
===================================================================
--- trunk/src/box/tests/Makefile.am 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/box/tests/Makefile.am 2010-11-15 17:42:27 UTC (rev 146)
@@ -15,8 +15,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-check_PROGRAMS=box_test
+check_PROGRAMS=box_test test_box_patterns
box_test_SOURCES=box_test.cc
+test_box_patterns_SOURCES=test_box_patterns.cc
-TESTS=box_test
+TESTS=$(check_PROGRAMS)
Added: trunk/src/box/tests/test_box_patterns.cc
===================================================================
--- trunk/src/box/tests/test_box_patterns.cc (rev 0)
+++ trunk/src/box/tests/test_box_patterns.cc 2010-11-15 17:42:27 UTC (rev 146)
@@ -0,0 +1,55 @@
+#include <string>
+#include <box/box_terms.hh>
+#include <patterns/variable.hh>
+#include <patterns/constant.hh>
+#include <terms/list_terms.hh>
+#include <strategies/patterns/match.hh>
+#include <strategies/patterns/build.hh>
+
+namespace aurelia {
+ template <typename Strat>
+ int all_primitive(const Strat&, const std::string& s) {
+ return s;
+ }
+}
+
+using aurelia::list;
+using aurelia::constant;
+using aurelia::patterns::cons;
+using aurelia::patterns::nil;
+using aurelia::box;
+
+list<box> tobox_list(list<std::string> in) {
+ try {
+ std::function<list<box>(list<std::string>)> self(tobox_list);
+ using aurelia::variable;
+ using aurelia::string_box;
+ using aurelia::vbox;
+
+ variable<list<std::string> > l;
+ variable<std::string> s;
+ variable<list<box> > bl;
+
+ return (~(cons(s, l)) < !l < self < ~bl
+ < !cons(string_box(s), bl))
+ (in);
+ }
+ catch (aurelia::failure) {
+ return *aurelia::patterns::nil();
+ }
+}
+
+box tobox(list<std::string> l) {
+ constant<list<box> > lv = tobox_list(l);
+ constant<aurelia::box_conf> c = aurelia::box_conf(0, 2, 2);
+ return *aurelia::vbox(c, lv);
+}
+
+int main() {
+ constant<std::string> foo = "foo";
+ constant<std::string> bar = "bar";
+ constant<std::string> baz = "baz";
+ box toprint = tobox(*cons(foo, cons(bar, cons(baz, nil()))));
+
+ return 0;
+}
Modified: trunk/src/patterns/Makefile.am
===================================================================
--- trunk/src/patterns/Makefile.am 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/patterns/Makefile.am 2010-11-15 17:42:27 UTC (rev 146)
@@ -21,4 +21,5 @@
pair.hh \
term_pattern.hh \
variable.hh \
+ constant.hh \
pattern_utils.hh
Added: trunk/src/patterns/constant.hh
===================================================================
--- trunk/src/patterns/constant.hh (rev 0)
+++ trunk/src/patterns/constant.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -0,0 +1,85 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __CONSTANT_HH
+# define __CONSTANT_HH
+
+# include "pattern.hh"
+//# include "../lists/listable.hh"
+
+namespace aurelia {
+
+ template <typename T>
+ struct constant {
+ private:
+ T value;
+
+ public:
+ constant() = delete;
+ constant(const constant& v): value(v.value) {
+ }
+
+ constant(constant&& v): value(std::move(v.value)) {
+ }
+
+ constant(const T& v): value(v) {
+ }
+
+ constant(T&& v): value(std::move(v)) {
+ }
+
+ template <typename U,
+ typename = typename
+ std::enable_if<std::is_convertible<U, T>::value>::type>
+ constant(const U& v): value(v) {}
+
+ template <typename U,
+ typename = typename
+ std::enable_if<std::is_convertible<U, T>::value>::type>
+ constant(U&& v): value(std::move(v)) {}
+
+ const T& operator*() const {
+ return value;
+ }
+
+ const T& operator=(const T& c) const {
+ if (value != c)
+ throw failure();
+ return value;
+ }
+
+ };
+
+ /*! \ingroup Models
+ */
+ template <typename T>
+ struct pattern_model<constant<T> > {
+ struct model {
+ typedef constant<T> type;
+ typedef T build_type;
+ };
+ };
+
+ template <typename T>
+ struct listable_model<constant<T> > {
+ struct model {
+ typedef constant<T> type;
+ };
+ };
+
+}
+
+#endif
Modified: trunk/src/patterns/pattern_utils.hh
===================================================================
--- trunk/src/patterns/pattern_utils.hh 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/patterns/pattern_utils.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -39,7 +39,11 @@
builder(pattern<Constructor, SubPatterns...>&& p): p(std::move(p)) {}
template <typename T,
- typename M = typename term_model<T>::model>
+ typename M = typename term_model<T>::model,
+ typename = typename
+ std::enable_if<std::is_convertible<
+ typename build_type<T, Constructor>::type,
+ T>::value>::type>
operator T() {
return build_real_type<T, Constructor, 0, std::tuple<SubPatterns...>,
SubPatterns...>::build(p.subpatterns);
@@ -139,6 +143,14 @@
};
+ template <typename Constructor, typename ...SubPatterns>
+ struct pattern_model<pattern<Constructor, SubPatterns...> > {
+ struct model {
+ typedef pattern<Constructor, SubPatterns...> type;
+ typedef builder<pattern<Constructor, SubPatterns...> > build_type;
+ };
+ };
+
template <typename Constructor>
struct pattern_generator {
Constructor constructor;
Modified: trunk/src/strategies/patterns/build.hh
===================================================================
--- trunk/src/strategies/patterns/build.hh 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/strategies/patterns/build.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -72,6 +72,11 @@
return build_strategy<variable<T> >(v);
}
+ template <typename Pattern,
+ typename PattermModel = typename pattern_model<Pattern>::model>
+ build_strategy<Pattern> operator!(const Pattern& pattern) {
+ return build_strategy<Pattern>(pattern);
+ }
}
#endif
Modified: trunk/src/strategies/patterns/match.hh
===================================================================
--- trunk/src/strategies/patterns/match.hh 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/strategies/patterns/match.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -94,6 +94,12 @@
return match_strategy<untyped_term<Pool> >(t);
}
+
+ template <typename Pattern,
+ typename PattermModel = typename pattern_model<Pattern>::model>
+ match_strategy<Pattern> operator~(const Pattern& pattern) {
+ return match_strategy<Pattern>(pattern);
+ }
}
#endif
Modified: trunk/src/terms/term_utils.hh
===================================================================
--- trunk/src/terms/term_utils.hh 2010-11-02 14:36:26 UTC (rev 145)
+++ trunk/src/terms/term_utils.hh 2010-11-15 17:42:27 UTC (rev 146)
@@ -23,15 +23,13 @@
# include <max_shared/max_shared_ptr.hh>
# include "hash/tuple_hash.hh"
# include "type_traits/overloading_priority.hh"
+# include "term_concept.hh"
namespace aurelia {
template <typename Constructor, typename... SubPatterns>
struct pattern;
- template <typename Pattern>
- struct builder;
-
template <typename Term, typename Constr>
struct get_tuple {
};
@@ -137,7 +135,7 @@
};
template <typename Type, typename Constr>
- struct build_type;
+ struct build_type {};
template <typename Real, typename... Constrs>
struct term {
@@ -195,6 +193,13 @@
return term.all_prim(s);
}
+ template <typename Real, typename... Constrs>
+ struct term_model<term<Real, Constrs...> > {
+ struct model {
+ typedef term<Real, Constrs...> type;
+ };
+ };
+
template <typename Real, typename Constr, typename Super>
struct std_term: public Super::virt {
enum { constrnb = (size_t)ConstrNb<Constr, typename Super::virt>::value };
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-11-02 14:36:33
|
Revision: 145
http://aurelia.svn.sourceforge.net/aurelia/?rev=145&view=rev
Author: valentindavid
Date: 2010-11-02 14:36:26 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
2010-11-02 Valentin David <val...@ii...>
* src/memory/pool_allocator.hh: Fix portability issue by using
std::aligned_storage.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/memory/pool_allocator.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-29 21:48:51 UTC (rev 144)
+++ trunk/ChangeLog 2010-11-02 14:36:26 UTC (rev 145)
@@ -1,3 +1,8 @@
+2010-11-02 Valentin David <val...@ii...>
+
+ * src/memory/pool_allocator.hh: Fix portability issue by using
+ std::aligned_storage.
+
2010-10-29 Valentin David <val...@ii...>
Add premilinary support of generic typed terms and patterns
Modified: trunk/src/memory/pool_allocator.hh
===================================================================
--- trunk/src/memory/pool_allocator.hh 2010-10-29 21:48:51 UTC (rev 144)
+++ trunk/src/memory/pool_allocator.hh 2010-11-02 14:36:26 UTC (rev 145)
@@ -81,8 +81,8 @@
}
union block {
- char obj[sizeof(T)]
- __attribute__ ((aligned (__alignof__(T))));
+ typename std::aligned_storage<sizeof(T),
+ std::alignment_of<T>::value>::type obj;
block *next;
};
@@ -122,7 +122,7 @@
static size_t offset() {
block n;
- return (n.obj - (char*)&n);
+ return ((char*)&n.obj - (char*)&n);
}
static void del(void *p) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-29 21:48:58
|
Revision: 144
http://aurelia.svn.sourceforge.net/aurelia/?rev=144&view=rev
Author: valentindavid
Date: 2010-10-29 21:48:51 +0000 (Fri, 29 Oct 2010)
Log Message:
-----------
2010-10-29 Valentin David <val...@ii...>
Add premilinary support of generic typed terms and patterns
with non-strict evaluation of build.
* src/strategies/patterns/match.hh, src/strategies/patterns/build.hh,
* src/terms/constructor.hh, src/patterns/term_pattern.hh,
* src/patterns/pattern.hh:
Rename pattern to untyped_pattern.
* src/terms/term_concept.hh, src/terms/list_terms.hh,
* src/terms/term_utils.hh, src/patterns/pattern_utils.hh:
New.
* src/strategies/generic/ensure.hh,
* src/strategies/generic/only_for.hh:
New.
* src/terms/tests/Makefile.am, src/terms/tests/test_list.cc:
New.
* src/patterns/Makefile.am, src/strategies/Makefile.am,
* src/terms/Makefile.am, configure.ac:
Update.
* src/parser_generator/syntax.csf, src/parser_generator/syntax.cc:
Remove bootstrap tricks.
Modified Paths:
--------------
trunk/ChangeLog
trunk/configure.ac
trunk/src/parser_generator/syntax.cc
trunk/src/parser_generator/syntax.csf
trunk/src/patterns/Makefile.am
trunk/src/patterns/pattern.hh
trunk/src/patterns/term_pattern.hh
trunk/src/strategies/Makefile.am
trunk/src/strategies/patterns/build.hh
trunk/src/strategies/patterns/match.hh
trunk/src/terms/Makefile.am
trunk/src/terms/constructor.hh
Added Paths:
-----------
trunk/src/patterns/pattern_utils.hh
trunk/src/strategies/generic/ensure.hh
trunk/src/strategies/generic/only_for.hh
trunk/src/terms/list_terms.hh
trunk/src/terms/term_concept.hh
trunk/src/terms/term_utils.hh
trunk/src/terms/tests/
trunk/src/terms/tests/Makefile.am
trunk/src/terms/tests/test_list.cc
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/ChangeLog 2010-10-29 21:48:51 UTC (rev 144)
@@ -1,5 +1,33 @@
2010-10-29 Valentin David <val...@ii...>
+ Add premilinary support of generic typed terms and patterns
+ with non-strict evaluation of build.
+
+ * src/strategies/patterns/match.hh, src/strategies/patterns/build.hh,
+ * src/terms/constructor.hh, src/patterns/term_pattern.hh,
+ * src/patterns/pattern.hh:
+ Rename pattern to untyped_pattern.
+
+ * src/terms/term_concept.hh, src/terms/list_terms.hh,
+ * src/terms/term_utils.hh, src/patterns/pattern_utils.hh:
+ New.
+
+ * src/strategies/generic/ensure.hh,
+ * src/strategies/generic/only_for.hh:
+ New.
+
+ * src/terms/tests/Makefile.am, src/terms/tests/test_list.cc:
+ New.
+
+ * src/patterns/Makefile.am, src/strategies/Makefile.am,
+ * src/terms/Makefile.am, configure.ac:
+ Update.
+
+ * src/parser_generator/syntax.csf, src/parser_generator/syntax.cc:
+ Remove bootstrap tricks.
+
+2010-10-29 Valentin David <val...@ii...>
+
Big cleaning of code.
* src/aurelia.hh: Add brief documentation for namespaces.
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/configure.ac 2010-10-29 21:48:51 UTC (rev 144)
@@ -172,6 +172,7 @@
src/lists/tests/Makefile
src/type_traits/Makefile
src/terms/Makefile
+ src/terms/tests/Makefile
src/strategies/Makefile
src/patterns/Makefile
src/llstack/Makefile
Modified: trunk/src/parser_generator/syntax.cc
===================================================================
--- trunk/src/parser_generator/syntax.cc 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/parser_generator/syntax.cc 2010-10-29 21:48:51 UTC (rev 144)
@@ -35,14 +35,7 @@
return f.as<ret_frame<void_return> >().parent;
}
-//Just for bootstrap
-#define Rj_t rj_t
-#define R_t r_t
-#define VoidReturn void_return
#include "syntax.hh"
-#undef Rj_t
-#undef R_t
-#undef void_return
bool found;
T result;
Modified: trunk/src/parser_generator/syntax.csf
===================================================================
--- trunk/src/parser_generator/syntax.csf 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/parser_generator/syntax.csf 2010-10-29 21:48:51 UTC (rev 144)
@@ -17,7 +17,7 @@
}
}
}
- VoidReturn ret;
+ void_return ret;
$ |
$ if (!s.eof()) {
switch (*s) {
@@ -37,7 +37,7 @@
}
}
}
- VoidReturn ret;
+ void_return ret;
$
LAYOUT+ ::= LAYOUT LAYOUT?
Modified: trunk/src/patterns/Makefile.am
===================================================================
--- trunk/src/patterns/Makefile.am 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/patterns/Makefile.am 2010-10-29 21:48:51 UTC (rev 144)
@@ -20,4 +20,5 @@
pattern.hh \
pair.hh \
term_pattern.hh \
- variable.hh
+ variable.hh \
+ pattern_utils.hh
Modified: trunk/src/patterns/pattern.hh
===================================================================
--- trunk/src/patterns/pattern.hh 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/patterns/pattern.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -29,19 +29,22 @@
struct pattern_concept {
typedef typename Model::type type;
typedef typename Model::build_type build_type;
+ typedef decltype((std::declval<type&>() =
+ std::declval<build_type>()))
+ match_type;
+
+ typedef decltype(*(std::declval<type&>()))
+ builder_type;
+
#ifdef DOC_GEN
- build_type operator=(type&, build_type) throw (failure);
- build_type operator*(type) throw (failure)h;
+ match_type operator=(type&, build_type) throw (failure);
+ builder_type operator*(type) throw (failure);
#else
- static_assert(std::is_convertible<
- decltype(std::declval<type&>() = std::declval<build_type>()),
- build_type
- >::value,
- "operator= does not return the right type");
- static_assert(std::is_convertible<decltype(*(std::declval<type>())),
- build_type
- >::value,
- "operator* does not return the right type");
+ static_assert(std::is_convertible<builder_type, build_type>::value,
+ "builder_type is not convertible to build_type.");
+
+ static_assert(std::is_convertible<match_type, build_type>::value,
+ "builder_type is not convertible to build_type.");
#endif
/*! \ingroup Axioms
*/
Added: trunk/src/patterns/pattern_utils.hh
===================================================================
--- trunk/src/patterns/pattern_utils.hh (rev 0)
+++ trunk/src/patterns/pattern_utils.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,162 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __PATTERN_UTILS_HH
+# define __PATTERN_UTILS_HH
+
+# include "pattern.hh"
+# include "../terms/term_concept.hh"
+
+namespace aurelia {
+
+ template <typename T, typename Constr, size_t N,
+ typename tuple, typename... SubPatterns>
+ struct build_real_type;
+
+ template <typename Constructor, typename ...SubPatterns>
+ struct pattern;
+
+ template <typename Pattern>
+ struct builder;
+
+ template <typename Constructor, typename ...SubPatterns>
+ struct builder<pattern<Constructor, SubPatterns...> > {
+ pattern<Constructor, SubPatterns...> p;
+ builder(const pattern<Constructor, SubPatterns...>& p): p(p) {}
+ builder(pattern<Constructor, SubPatterns...>&& p): p(std::move(p)) {}
+
+ template <typename T,
+ typename M = typename term_model<T>::model>
+ operator T() {
+ return build_real_type<T, Constructor, 0, std::tuple<SubPatterns...>,
+ SubPatterns...>::build(p.subpatterns);
+ }
+ };
+
+ template <typename LHS, typename RHS, size_t N = 0,
+ size_t Last = std::tuple_size<LHS>::value>
+ struct assign_build {
+ static void do_it(LHS& lhs, const RHS& rhs) {
+ static_assert(std::tuple_size<LHS>::value == Last,
+ "Wrong size");
+ static_assert(std::tuple_size<RHS>::value == Last,
+ "Wrong size");
+ std::get<N>(lhs) = *std::get<N>(rhs);
+ assign_build<LHS, RHS, N+1, Last>::do_it(lhs, rhs);
+ }
+ };
+
+ template <typename LHS, typename RHS, size_t N>
+ struct assign_build<LHS, RHS, N, N> {
+ static void do_it(LHS&, const RHS&) {
+ static_assert(std::tuple_size<LHS>::value == N,
+ "Wrong size");
+ static_assert(std::tuple_size<RHS>::value == N,
+ "Wrong size");
+ }
+ };
+
+ template <typename T, typename U,
+ typename = decltype(std::declval<T>() =
+ *(std::declval<const U>()))>
+ std::true_type has_assign_build_helper(type_traits::try_first, T, U) {
+ return 0;
+ }
+
+ template <typename T, typename U>
+ std::false_type has_assign_build_helper(type_traits::try_second, T, U) {
+ return 0;
+ }
+
+ template <typename T, typename U>
+ struct can_match:
+ type_traits::itself<
+ decltype(has_assign_build_helper(type_traits::try_first(),
+ std::declval<T>(),
+ std::declval<U>()))>::type {
+ };
+
+ template <typename T, typename U, typename... TS, typename... US>
+ struct can_match<std::tuple<T, TS...>, std::tuple<U, US...> >
+ {
+ enum: bool { value = can_match<T,U>::value &&
+ can_match<std::tuple<TS...>, std::tuple<US...> >::value };
+ };
+
+ template <>
+ struct can_match<std::tuple<>, std::tuple<> >: public std::true_type {
+ };
+
+ template <typename Constructor, typename ...SubPatterns>
+ struct pattern {
+ Constructor constructor;
+ std::tuple<SubPatterns...> subpatterns;
+
+ pattern(const Constructor& constructor, SubPatterns... p):
+ constructor(constructor), subpatterns(p...) {}
+
+ template <typename Term,
+ typename M = typename term_model<Term>::model>
+ Term
+ operator=(const Term& t) throw (failure) {
+ typedef typename term_concept<M>::check require;
+ t.match(*this);
+ return t;
+ }
+
+ template <typename... OtherSubPatterns,
+ typename = typename
+ std::enable_if<can_match<std::tuple<SubPatterns...>,
+ std::tuple<OtherSubPatterns...> >
+ ::value>::type>
+ const builder<pattern<Constructor, OtherSubPatterns...> >&
+ operator=(const builder<pattern<Constructor, OtherSubPatterns...> >& b)
+ throw (failure) {
+ static_assert(sizeof...(SubPatterns)==sizeof...(OtherSubPatterns),
+ "Number of children in patterns not corresponding");
+ assign_build<std::tuple<SubPatterns...>,
+ std::tuple<OtherSubPatterns...> >
+ ::do_it(subpatterns, b.p.subpatterns);
+ return b;
+ }
+
+ builder<pattern> operator*() const {
+ return builder<pattern>(*this);
+ }
+
+ };
+
+ template <typename Constructor>
+ struct pattern_generator {
+ Constructor constructor;
+
+ pattern_generator() {}
+
+ pattern_generator(const Constructor& constructor):
+ constructor(constructor) {}
+
+ pattern_generator(const pattern_generator& other):
+ constructor(other.constructor) {}
+
+ template <typename ...A>
+ pattern<Constructor, A...> operator()(A... a) const {
+ return pattern<Constructor, A...>(constructor, std::forward<A>(a)...);
+ }
+ };
+
+}
+
+#endif
Modified: trunk/src/patterns/term_pattern.hh
===================================================================
--- trunk/src/patterns/term_pattern.hh 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/patterns/term_pattern.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -68,12 +68,13 @@
}
template <typename Pool, typename List>
- struct pattern {
+ struct untyped_pattern {
private:
untyped_constructor<Pool> c;
List l;
public:
- pattern(const untyped_constructor<Pool>& c, const List& l): c(c), l(l) {
+ untyped_pattern(const untyped_constructor<Pool>& c,
+ const List& l): c(c), l(l) {
}
const untyped_term<Pool>& operator=(const untyped_term<Pool>& t) {
@@ -91,17 +92,17 @@
/*! \ingroup Models
*/
template <typename Pool, typename List>
- struct pattern_model<pattern<Pool, List> > {
+ struct pattern_model<untyped_pattern<Pool, List> > {
struct model {
- typedef pattern<Pool, List> type;
+ typedef untyped_pattern<Pool, List> type;
typedef untyped_term<Pool> build_type;
};
};
template <typename Pool, typename List>
- struct listable_model<pattern<Pool, List> > {
+ struct listable_model<untyped_pattern<Pool, List> > {
struct model {
- typedef pattern<Pool, List> type;
+ typedef untyped_pattern<Pool, List> type;
};
};
@@ -112,8 +113,9 @@
template <typename> class,
typename,
typename>
- pattern<Pool, L> untyped_constructor<Pool>::operator[](const L& l) const {
- return pattern<Pool, L>(*this, l);
+ untyped_pattern<Pool, L>
+ untyped_constructor<Pool>::operator[](const L& l) const {
+ return untyped_pattern<Pool, L>(*this, l);
}
}
Modified: trunk/src/strategies/Makefile.am
===================================================================
--- trunk/src/strategies/Makefile.am 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/strategies/Makefile.am 2010-10-29 21:48:51 UTC (rev 144)
@@ -34,6 +34,8 @@
lists/map.hh \
lists/size.hh \
generic/choice.hh \
+ generic/only_for.hh \
+ generic/ensure.hh \
generic/where.hh \
generic/not.hh \
generic/side_effect_strategy.hh \
Added: trunk/src/strategies/generic/ensure.hh
===================================================================
--- trunk/src/strategies/generic/ensure.hh (rev 0)
+++ trunk/src/strategies/generic/ensure.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,46 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __ENSURE_HH
+# define __ENSURE_HH
+
+# include "../failure.hh"
+
+namespace aurelia {
+
+ template <typename Strat, typename T>
+ struct only_for_strategy {
+ Strat s;
+ only_for_strategy(const Strat& s): s(s) {}
+ template <typename T>
+ struct ensure {
+ T operator()(T&& in) const {
+ return std::move(in);
+ }
+
+ T operator()(const T& in) const {
+ return in;
+ }
+
+ template <typename U>
+ T operator()(U) const {
+ throw failure();
+ }
+ };
+
+}
+
+#endif
Added: trunk/src/strategies/generic/only_for.hh
===================================================================
--- trunk/src/strategies/generic/only_for.hh (rev 0)
+++ trunk/src/strategies/generic/only_for.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,53 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __ONLY_FOR_HH
+# define __ONLY_FOR_HH
+
+# include "../failure.hh"
+
+namespace aurelia {
+
+ template <typename Strat, typename T>
+ struct only_for_strategy {
+ Strat s;
+ only_for_strategy(const Strat& s): s(s) {}
+
+ T operator()(T&& in) const {
+ return s(std::move(in));
+ }
+
+ T operator()(const T& in) const {
+ return s(in);
+ }
+
+ template <typename U>
+ U operator()(U) const {
+ throw failure();
+ }
+ };
+
+ template <typename T>
+ struct only_for {
+ template <typename Strat>
+ only_for_strategy<Strat,T> operator()(const Strat& s) {
+ return s;
+ }
+ };
+
+}
+
+#endif
Modified: trunk/src/strategies/patterns/build.hh
===================================================================
--- trunk/src/strategies/patterns/build.hh 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/strategies/patterns/build.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -59,9 +59,9 @@
* \brief The strategy builds the pattern passed as parameter.
*/
template <typename Pool, typename List>
- build_strategy<pattern<Pool, List> >
- operator!(const pattern<Pool, List>& p) {
- return build_strategy<pattern<Pool, List> >(p);
+ build_strategy<untyped_pattern<Pool, List> >
+ operator!(const untyped_pattern<Pool, List>& p) {
+ return build_strategy<untyped_pattern<Pool, List> >(p);
}
/*! \ingroup Patterns
Modified: trunk/src/strategies/patterns/match.hh
===================================================================
--- trunk/src/strategies/patterns/match.hh 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/strategies/patterns/match.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -65,8 +65,9 @@
* \brief The strategy matches the pattern passed as parameter.
*/
template <typename Pool, typename List>
- match_strategy<pattern<Pool, List> > operator~(const pattern<Pool, List>& p) {
- return match_strategy<pattern<Pool, List> >(p);
+ match_strategy<untyped_pattern<Pool, List> >
+ operator~(const untyped_pattern<Pool, List>& p) {
+ return match_strategy<untyped_pattern<Pool, List> >(p);
}
/*! \ingroup Patterns
Modified: trunk/src/terms/Makefile.am
===================================================================
--- trunk/src/terms/Makefile.am 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/terms/Makefile.am 2010-10-29 21:48:51 UTC (rev 144)
@@ -19,4 +19,9 @@
terms_HEADERS= \
term.hh \
constructor.hh \
- baf_read.hh
+ baf_read.hh \
+ term_utils.hh \
+ list_terms.hh \
+ term_concept.hh
+
+SUBDIRS=tests
Modified: trunk/src/terms/constructor.hh
===================================================================
--- trunk/src/terms/constructor.hh 2010-10-29 19:10:34 UTC (rev 143)
+++ trunk/src/terms/constructor.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -29,7 +29,7 @@
struct untyped_term;
template <typename Pool, typename List>
- struct pattern;
+ struct untyped_pattern;
template <typename Pool>
struct untyped_constructor;
@@ -198,7 +198,8 @@
template <typename P,
typename = typename pattern_model<P>::model>
- pattern<Pool, list_cons<P, list_nil> > operator[](const P& p) const {
+ untyped_pattern<Pool, list_cons<P, list_nil> >
+ operator[](const P& p) const {
return (*this)[list_cons<P, list_nil>(p, list_nil())];
}
@@ -212,7 +213,7 @@
std::enable_if<!(all_elements<untyped_termPredicate, L>::value)>::type,
typename = typename
std::enable_if<all_elements<PatternPredicate, L>::value>::type>
- pattern<Pool, L> operator[](const L& l) const;
+ untyped_pattern<Pool, L> operator[](const L& l) const;
};
template <typename Pool>
Added: trunk/src/terms/list_terms.hh
===================================================================
--- trunk/src/terms/list_terms.hh (rev 0)
+++ trunk/src/terms/list_terms.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,95 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __LIST_TERMS_HH
+# define __LIST_TERMS_HH
+
+# include "term_utils.hh"
+# include "../patterns/pattern_utils.hh"
+
+namespace aurelia {
+
+ template <typename a>
+ struct list;
+
+ struct cons_constr {};
+ namespace patterns {
+ pattern_generator<cons_constr> cons;
+ }
+
+ template <typename a>
+ struct get_tuple<list<a>, cons_constr> {
+ typedef std::tuple<a, list<a> > tuple;
+ };
+
+ struct nil_constr {};
+ namespace patterns {
+ pattern_generator<nil_constr> nil;
+ }
+
+ template <typename a>
+ struct get_tuple<list<a>, nil_constr> {
+ typedef std::tuple<> tuple;
+ };
+
+ template <typename a>
+ struct cons_term;
+
+ template <typename a>
+ struct nil_term;
+
+ template <typename a>
+ struct list: public term<list<a>, nil_constr, cons_constr> {
+ typedef term<list<a>, nil_constr, cons_constr> super;
+ list() = default;
+ list(const super& other): super(other) {}
+ list(super&& other): super(std::move(other)) {}
+ };
+
+ template <typename a>
+ struct cons_term: public std_term<cons_term<a>, cons_constr, list<a> > {
+ typedef std_term<cons_term<a>, cons_constr, list<a> > super;
+ cons_term(a h, const list<a>& t): super(typename super::tuple(h, t)) {}
+ cons_term(const cons_term& other): super(other) {}
+ };
+
+ template <typename a>
+ struct build_type<list<a>, cons_constr> {
+ typedef cons_term<a> type;
+ };
+
+ template <typename a>
+ struct nil_term: public std_term<nil_term<a>, nil_constr, list<a> > {
+ typedef std_term<nil_term<a>, nil_constr, list<a> > super;
+ nil_term(): super(typename super::tuple()) {}
+ nil_term(const nil_term& other): super(other) {}
+ };
+
+ template <typename a>
+ struct build_type<list<a>, nil_constr> {
+ typedef nil_term<a> type;
+ };
+
+ template <typename a>
+ struct term_model<list<a> > {
+ struct model {
+ typedef list<a> type;
+ };
+ };
+
+}
+
+#endif
Added: trunk/src/terms/term_concept.hh
===================================================================
--- trunk/src/terms/term_concept.hh (rev 0)
+++ trunk/src/terms/term_concept.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,56 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __TERM_CONCEPT_HH
+# define __TERM_CONCEPT_HH
+
+namespace aurelia {
+
+ /*! \addtogroup Concepts
+ * @{
+ */
+ /*! \brief untyped_term concept
+ */
+ template <typename Model>
+ struct term_concept: public Model {
+ public:
+ typedef typename Model::type type;
+
+#ifdef DOC_GEN
+ //! require strategy_concept<strategy_model<Strat, Type> >::model
+ template <typename Strat>
+ typename strategy_model<Strat, Type>::model::output;
+ all_primitive(Strat, Type);
+
+ //! require strategy_concept<strategy_model<Strat, Type> >::model
+ template <typename Strat>
+ typename strategy_model<Strat, Type>::model::output;
+ one_primitive(Strat, Type);
+
+#endif
+
+ typedef void check;
+ };
+ /*! @} */
+
+ template <typename T>
+ struct term_model {
+ typedef void no_model;
+ };
+}
+
+#endif
Added: trunk/src/terms/term_utils.hh
===================================================================
--- trunk/src/terms/term_utils.hh (rev 0)
+++ trunk/src/terms/term_utils.hh 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,303 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __TERM_UTILS_HH
+# define __TERM_UTILS_HH
+
+# include <functional>
+# include <strategies/failure.hh>
+# include <max_shared/max_shared_ptr.hh>
+# include "hash/tuple_hash.hh"
+# include "type_traits/overloading_priority.hh"
+
+namespace aurelia {
+
+ template <typename Constructor, typename... SubPatterns>
+ struct pattern;
+
+ template <typename Pattern>
+ struct builder;
+
+ template <typename Term, typename Constr>
+ struct get_tuple {
+ };
+
+ template <typename Strat, typename tuple, size_t N, size_t size>
+ struct tuple_all {
+ static void apply(const Strat& s, tuple& t) {
+ std::get<N>(t) = s(std::get<N>(t));
+ tuple_all<Strat, tuple, N+1, size>::apply(s, t);
+ }
+ };
+
+ template <typename Strat, typename tuple, size_t size>
+ struct tuple_all<Strat, tuple, size, size> {
+ static void apply(const Strat&, tuple&) {
+ }
+ };
+
+ template <typename Term, typename Constr>
+ struct virtual_term_constr {
+ typedef typename get_tuple<Term,Constr>::tuple tuple;
+
+ virtual const tuple&
+ getvalues(const Constr&) const throw (failure) {
+ throw failure();
+ }
+
+ virtual Term build(tuple&&) const {
+ throw failure();
+ }
+
+ template <typename Strat>
+ Term all_prim(const Strat& s) const {
+ tuple out(getvalues(Constr()));
+ tuple_all<Strat, tuple, 0, std::tuple_size<tuple>::value>
+ ::apply(s, out);
+ return build(std::move(out));
+ }
+ };
+
+ template <typename T, typename... Tail>
+ struct pos_of;
+
+ template <typename T, typename Head, typename... Tail>
+ struct pos_of<T, Head, Tail...> {
+ enum: size_t { value = (size_t)pos_of<T, Tail...>::value+1 };
+ };
+
+ template <typename T, typename... Tail>
+ struct pos_of<T, T, Tail...> {
+ enum: size_t { value = 0 };
+ };
+
+ template <typename Term, typename VirtualTerm, typename Strat,
+ typename... Constrs>
+ struct dispatch_all {
+ static Term apply(const Strat&, size_t, const VirtualTerm&) {
+ throw failure();
+ }
+ };
+
+ template <typename Term, typename VirtualTerm, typename Strat,
+ typename Constr, typename... Constrs>
+ struct dispatch_all<Term, VirtualTerm, Strat, Constr, Constrs...> {
+ static Term apply(const Strat& s, size_t n, const VirtualTerm& v) {
+ if (n == 0)
+ return static_cast<const virtual_term_constr<Term, Constr>*>(&v)
+ ->all_prim(s);
+ return dispatch_all<Term, VirtualTerm, Strat, Constrs...>
+ ::apply(s, n-1, v);
+ }
+ };
+
+ template <typename Term, typename... Constr>
+ struct virtual_term: public virtual_term_constr<Term, Constr>... {
+ virtual size_t constr() const = 0;
+
+ template <typename C, typename ...V>
+ void match(pattern<C, V...>& p) const throw (failure) {
+ p.subpatterns =
+ ((const virtual_term_constr<Term,C>*)this)->getvalues(p.constructor);
+ }
+
+ template <typename Strat>
+ Term all_prim(const Strat& s) const {
+ return dispatch_all<Term, virtual_term, Strat, Constr...>
+ ::apply(s, constr(), *this);
+ }
+
+ virtual bool operator==(const virtual_term& other) const = 0;
+ virtual bool operator!=(const virtual_term& other) const = 0;
+
+ virtual size_t hash() const = 0;
+ };
+
+ template <typename Constr, typename Term>
+ struct ConstrNb {
+ };
+
+ template <typename Constr, typename Term, typename... Constrs>
+ struct ConstrNb<Constr, virtual_term<Term, Constrs...> > {
+ enum: size_t { value = (size_t)pos_of<Constr, Constrs...>::value };
+ };
+
+ template <typename Type, typename Constr>
+ struct build_type;
+
+ template <typename Real, typename... Constrs>
+ struct term {
+ typedef virtual_term<Real, Constrs...> virt;
+ std::shared_ptr<virt> l;
+
+ term(virt *ptr): l(ptr) {}
+
+ term(const term&) = default;
+
+ term(term&& other): l(std::move(other.l)) {
+ }
+
+ term(): l((virt*)NULL) {}
+
+ Real& operator=(term&& other) {
+ std::swap(l, other.l);
+ return *static_cast<Real*>(this);
+ }
+
+ Real& operator=(const term& other) {
+ if (&other == this)
+ return *static_cast<Real*>(this);
+ return *this = term(other);
+ }
+
+ template <typename Constr, typename ...V>
+ void match(pattern<Constr, V...>& p) const throw (failure) {
+ l->match(p);
+ }
+
+ bool operator==(const term& other) const {
+ return *l == *(other.l);
+ }
+
+ bool operator!=(const term& other) const {
+ return *l != *(other.l);
+ }
+
+ size_t hash() const {
+ if (l.get() == (virt*)NULL)
+ return 0;
+ return l->hash();
+ }
+
+ template <typename Strat>
+ term all_prim(const Strat& s) const {
+ return l->all_prim(s);
+ }
+ };
+
+ template <typename Strat, typename T, typename... Constrs>
+ term<T, Constrs...> all_primitive(const Strat& s,
+ const term<T, Constrs...>& term) {
+ return term.all_prim(s);
+ }
+
+ template <typename Real, typename Constr, typename Super>
+ struct std_term: public Super::virt {
+ enum { constrnb = (size_t)ConstrNb<Constr, typename Super::virt>::value };
+
+ typedef typename get_tuple<Super, Constr>::tuple tuple;
+ struct core_type {
+ tuple args;
+ size_t hash() const {
+ return std::hash<tuple>()(args);
+ };
+
+ core_type() = default;
+ core_type(tuple&& args): args(std::move(args)) {}
+ core_type(core_type&& other): args(std::move(other.args)) {
+ }
+
+ bool operator==(const core_type& other) const {
+ return args == other.args;
+ }
+
+ bool operator!=(const core_type& other) const {
+ return args != other.args;
+ }
+ };
+ max_shared_ptr<core_type> core;
+
+ virtual size_t constr() const {
+ return constrnb;
+ }
+
+ virtual Super build(tuple&& t) const {
+ return std_term(std::move(t));
+ }
+
+ virtual size_t hash() const {
+ return core->hash();
+ }
+
+ operator Super() const {
+ return Super((typename Super::virt*)new std_term(*this));
+ }
+
+ std_term(const tuple& args): core(args) {}
+ std_term(tuple&& args): core(std::move(args)) {}
+
+ std_term(const std_term& other): core(other.core) {}
+ std_term(std_term&& other): core(std::move(other.core)) {}
+
+ virtual const tuple& getvalues(const Constr&) const throw() {
+ return (*core).args;
+ }
+
+ virtual bool operator==(const typename Super::virt& other) const {
+ const std_term* ro = dynamic_cast<const std_term*>(&other);
+ if (ro == NULL)
+ return false;
+ return core == ro->core;
+ }
+
+ virtual bool operator!=(const typename Super::virt& other) const {
+ const std_term* ro = dynamic_cast<const std_term*>(&other);
+ if (ro == NULL)
+ return true;
+ return core != ro->core;
+ }
+ };
+
+ template <typename T, typename Constr, size_t N,
+ typename tuple, typename... SubPatterns>
+ struct build_real_type;
+
+ template <typename T, typename Constr, size_t N,
+ typename tuple, typename Head, typename... SubPatterns>
+ struct build_real_type<T,
+ Constr, N, tuple, Head, SubPatterns...> {
+ template <typename... Args>
+ static T
+ build(const tuple& t, Args... args) {
+ static_assert((N+sizeof...(SubPatterns)+1) ==
+ std::tuple_size<tuple>::value,
+ "Was not the right number of arguments");
+ static_assert(N == sizeof...(Args),
+ "Was not the right number of arguments");
+ return build_real_type<T, Constr, N+1, tuple, SubPatterns...>
+ ::build(t, std::forward<Args>(args)..., *std::get<N>(t));
+ }
+ };
+
+ template <typename T,
+ typename Constr, size_t N, typename tuple>
+ struct build_real_type<T, Constr, N, tuple> {
+ template <typename... Args>
+ static T
+ build(const tuple&, Args... args) {
+ static_assert(N == std::tuple_size<tuple>::value,
+ "Was not the right number of arguments");
+ static_assert(N == sizeof...(Args),
+ "Was not the right number of arguments");
+ return T(new typename build_type<T, Constr>::
+ type(std::forward<Args>(args)...));
+ }
+ };
+
+}
+
+#endif
Property changes on: trunk/src/terms/tests
___________________________________________________________________
Added: svn:ignore
+ test-suite.log
Makefile.in
test_list
test_list.log
.deps
Makefile
Added: trunk/src/terms/tests/Makefile.am
===================================================================
--- trunk/src/terms/tests/Makefile.am (rev 0)
+++ trunk/src/terms/tests/Makefile.am 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,26 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+check_PROGRAMS=test_list
+
+test_list_SOURCES=test_list.cc
+
+TESTS=$(check_PROGRAMS)
+
+if HAVE_VALGRIND
+TESTS_ENVIRONMENT=ulimit -s 8192; $(VALGRIND) --leak-check=full --show-reachable=yes --error-exitcode=1 >/dev/null --
+endif
Added: trunk/src/terms/tests/test_list.cc
===================================================================
--- trunk/src/terms/tests/test_list.cc (rev 0)
+++ trunk/src/terms/tests/test_list.cc 2010-10-29 21:48:51 UTC (rev 144)
@@ -0,0 +1,52 @@
+#include <terms/list_terms.hh>
+#include <patterns/variable.hh>
+#include <strategies/generic/only_for.hh>
+#include <strategies/generic/debug.hh>
+#include <strategies/traversals/alltd.hh>
+#include <iostream>
+
+namespace aurelia {
+ template <typename Strat>
+ int all_primitive(const Strat&, int i) {
+ return i;
+ }
+}
+
+int main() {
+ using aurelia::variable;
+ using aurelia::list;
+ using aurelia::cons_term;
+ using aurelia::nil_term;
+ using aurelia::only_for;
+ using aurelia::debug;
+ using aurelia::alltd;
+ using aurelia::patterns::cons;
+ using aurelia::patterns::nil;
+
+ variable<list<int> > a;
+ variable<int> c, d, e;
+
+
+ list<int> l(cons_term<int>(0, cons_term<int>(1, nil_term<int>())));
+
+ list<int> l2(cons_term<int>(0, nil_term<int>()));
+ // cons(c, nil()) = l2;
+
+ cons(c, cons(d, nil())) = l;
+ cons(e, a) = l;
+
+ // cons(e, cons(e, a)) = *cons(e, nil());
+ //cons(e, nil()) = *cons(e, cons(e, a));
+
+ //a = *cons(e, a);
+
+ //a = *nil();
+ //cons(e, a) = *cons(e, cons(e, a));
+
+ list<int> l3(*(cons(c, cons(d, nil()))));
+
+ //test(l, nil_term<int>());
+ std::cout << *c << " " << *d << std::endl;
+ alltd(only_for<int>()(debug("Found: ")))(l3);
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-29 19:10:44
|
Revision: 143
http://aurelia.svn.sourceforge.net/aurelia/?rev=143&view=rev
Author: valentindavid
Date: 2010-10-29 19:10:34 +0000 (Fri, 29 Oct 2010)
Log Message:
-----------
2010-10-29 Valentin David <val...@ii...>
Big cleaning of code.
* src/aurelia.hh: Add brief documentation for namespaces.
* src/hash/tuple_hash.hh: Add hash functor for empty tuples.
* src/box/tests/box_test.cc, src/box/box.hh,
* src/terms/baf_read.hh, src/terms/constructor.hh,
* src/terms/term.hh, src/llstack/tests/example.hh,
* src/llstack/queue.hh, src/llstack/node.hh,
* src/llstack/frame.hh, src/llstack/node.hpp,
* src/llstack/label.hh, src/llstack/utils.hh,
* src/lists/tests/test_listable.cc, src/lists/list_concept.hh,
* src/lists/list.hh, src/lists/listable.hh,
* src/patterns/term_pattern.hh, src/patterns/variable.hh,
* src/patterns/pair.hh src/patterns/pattern.hh
* src/parser_generator/tests/gamma_2.cc
* src/parser_generator/parser_gen.cc
* src/parser_generator/syntax.cc
* src/parser_generator/parser_gen_main.cc
* src/type_traits/has_model.hh src/memory/tests/test_pool.cc
* src/memory/pool_allocator.hh
* src/strategies/patterns/reset.hh
* src/strategies/patterns/scope.hh
* src/strategies/patterns/pair.hh
* src/strategies/patterns/match.hh
* src/strategies/patterns/build.hh src/strategies/failure.hh
* src/strategies/traversals/one.hh
* src/strategies/traversals/all.hh
* src/strategies/traversals/bottomup.hh
* src/strategies/traversals/topdown.hh
* src/strategies/traversals/innermost.hh
* src/strategies/traversals/alltd.hh
* src/strategies/strategies.hh
* src/strategies/strings/double_quote.hh
* src/strategies/strings/undouble_quote.hh
* src/strategies/terms/get_cons_name.hh
* src/strategies/generic/side_effect_strategy.hh
* src/strategies/generic/debug.hh
* src/strategies/generic/seq.hh
* src/strategies/generic/choice.hh
* src/strategies/generic/where.hh
* src/strategies/generic/fail.hh src/strategies/generic/id.hh
* src/strategies/generic/not.hh
* src/strategies/generic/repeat.hh
* src/strategies/lists/const_map.hh
* src/strategies/lists/map_index.hh
* src/strategies/lists/filter.hh src/strategies/lists/size.hh
* src/strategies/lists/map_join.hh src/strategies/lists/map.hh
* src/strategies/lists/map_one.hh
* src/strategies/lists/map_some.hh
* src/max_shared/max_shared_ptr.hh
* demos-from-stratego/01-constant-folding-rules.cc
* demos/13-constructors-with-typed-terms.cc demos/04-pools.cc
* demos/07-strategies.cc demos/12-maps.cc demos/06-patterns.cc
* demos/05-term-expr.cc demos/02-baf.cc demos/10-int.cc
* demos/01-terms.cc demos/03-threads.cc
* demos-from-rascal/03-java.cc demos-from-rascal/04-uninit.cc:
Fix use of concepts. Fix naming convention. Rename term
and constructor types as "untyped_".
* bootstrap: Check for version of Automake.
Modified Paths:
--------------
trunk/ChangeLog
trunk/bootstrap
trunk/demos/01-terms.cc
trunk/demos/02-baf.cc
trunk/demos/03-threads.cc
trunk/demos/04-pools.cc
trunk/demos/05-term-expr.cc
trunk/demos/06-patterns.cc
trunk/demos/07-strategies.cc
trunk/demos/10-int.cc
trunk/demos/12-maps.cc
trunk/demos/13-constructors-with-typed-terms.cc
trunk/demos-from-rascal/03-java.cc
trunk/demos-from-rascal/04-uninit.cc
trunk/demos-from-rascal/06-reaching-defs.cc
trunk/demos-from-stratego/01-constant-folding-rules.cc
trunk/src/aurelia.hh
trunk/src/box/box.hh
trunk/src/box/tests/box_test.cc
trunk/src/hash/tuple_hash.hh
trunk/src/lists/list.hh
trunk/src/lists/list_concept.hh
trunk/src/lists/listable.hh
trunk/src/lists/tests/test_listable.cc
trunk/src/llstack/frame.hh
trunk/src/llstack/label.hh
trunk/src/llstack/node.hh
trunk/src/llstack/node.hpp
trunk/src/llstack/queue.hh
trunk/src/llstack/tests/example.hh
trunk/src/llstack/utils.hh
trunk/src/max_shared/max_shared_ptr.hh
trunk/src/memory/pool_allocator.hh
trunk/src/memory/tests/test_pool.cc
trunk/src/parser_generator/Makefile.am
trunk/src/parser_generator/parser_gen.cc
trunk/src/parser_generator/parser_gen_main.cc
trunk/src/parser_generator/syntax.cc
trunk/src/parser_generator/tests/gamma_2.cc
trunk/src/patterns/pair.hh
trunk/src/patterns/pattern.hh
trunk/src/patterns/term_pattern.hh
trunk/src/patterns/variable.hh
trunk/src/strategies/failure.hh
trunk/src/strategies/generic/choice.hh
trunk/src/strategies/generic/debug.hh
trunk/src/strategies/generic/fail.hh
trunk/src/strategies/generic/id.hh
trunk/src/strategies/generic/not.hh
trunk/src/strategies/generic/repeat.hh
trunk/src/strategies/generic/seq.hh
trunk/src/strategies/generic/side_effect_strategy.hh
trunk/src/strategies/generic/where.hh
trunk/src/strategies/lists/const_map.hh
trunk/src/strategies/lists/filter.hh
trunk/src/strategies/lists/map.hh
trunk/src/strategies/lists/map_index.hh
trunk/src/strategies/lists/map_join.hh
trunk/src/strategies/lists/map_one.hh
trunk/src/strategies/lists/map_some.hh
trunk/src/strategies/lists/size.hh
trunk/src/strategies/patterns/build.hh
trunk/src/strategies/patterns/match.hh
trunk/src/strategies/patterns/pair.hh
trunk/src/strategies/patterns/reset.hh
trunk/src/strategies/patterns/scope.hh
trunk/src/strategies/strategies.hh
trunk/src/strategies/strings/double_quote.hh
trunk/src/strategies/strings/undouble_quote.hh
trunk/src/strategies/terms/get_cons_name.hh
trunk/src/strategies/traversals/all.hh
trunk/src/strategies/traversals/alltd.hh
trunk/src/strategies/traversals/bottomup.hh
trunk/src/strategies/traversals/innermost.hh
trunk/src/strategies/traversals/one.hh
trunk/src/strategies/traversals/topdown.hh
trunk/src/terms/baf_read.hh
trunk/src/terms/constructor.hh
trunk/src/terms/term.hh
trunk/src/type_traits/has_model.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/ChangeLog 2010-10-29 19:10:34 UTC (rev 143)
@@ -1,3 +1,68 @@
+2010-10-29 Valentin David <val...@ii...>
+
+ Big cleaning of code.
+
+ * src/aurelia.hh: Add brief documentation for namespaces.
+
+ * src/hash/tuple_hash.hh: Add hash functor for empty tuples.
+
+ * src/box/tests/box_test.cc, src/box/box.hh,
+ * src/terms/baf_read.hh, src/terms/constructor.hh,
+ * src/terms/term.hh, src/llstack/tests/example.hh,
+ * src/llstack/queue.hh, src/llstack/node.hh,
+ * src/llstack/frame.hh, src/llstack/node.hpp,
+ * src/llstack/label.hh, src/llstack/utils.hh,
+ * src/lists/tests/test_listable.cc, src/lists/list_concept.hh,
+ * src/lists/list.hh, src/lists/listable.hh,
+ * src/patterns/term_pattern.hh, src/patterns/variable.hh,
+ * src/patterns/pair.hh src/patterns/pattern.hh
+ * src/parser_generator/tests/gamma_2.cc
+ * src/parser_generator/parser_gen.cc
+ * src/parser_generator/syntax.cc
+ * src/parser_generator/parser_gen_main.cc
+ * src/type_traits/has_model.hh src/memory/tests/test_pool.cc
+ * src/memory/pool_allocator.hh
+ * src/strategies/patterns/reset.hh
+ * src/strategies/patterns/scope.hh
+ * src/strategies/patterns/pair.hh
+ * src/strategies/patterns/match.hh
+ * src/strategies/patterns/build.hh src/strategies/failure.hh
+ * src/strategies/traversals/one.hh
+ * src/strategies/traversals/all.hh
+ * src/strategies/traversals/bottomup.hh
+ * src/strategies/traversals/topdown.hh
+ * src/strategies/traversals/innermost.hh
+ * src/strategies/traversals/alltd.hh
+ * src/strategies/strategies.hh
+ * src/strategies/strings/double_quote.hh
+ * src/strategies/strings/undouble_quote.hh
+ * src/strategies/terms/get_cons_name.hh
+ * src/strategies/generic/side_effect_strategy.hh
+ * src/strategies/generic/debug.hh
+ * src/strategies/generic/seq.hh
+ * src/strategies/generic/choice.hh
+ * src/strategies/generic/where.hh
+ * src/strategies/generic/fail.hh src/strategies/generic/id.hh
+ * src/strategies/generic/not.hh
+ * src/strategies/generic/repeat.hh
+ * src/strategies/lists/const_map.hh
+ * src/strategies/lists/map_index.hh
+ * src/strategies/lists/filter.hh src/strategies/lists/size.hh
+ * src/strategies/lists/map_join.hh src/strategies/lists/map.hh
+ * src/strategies/lists/map_one.hh
+ * src/strategies/lists/map_some.hh
+ * src/max_shared/max_shared_ptr.hh
+ * demos-from-stratego/01-constant-folding-rules.cc
+ * demos/13-constructors-with-typed-terms.cc demos/04-pools.cc
+ * demos/07-strategies.cc demos/12-maps.cc demos/06-patterns.cc
+ * demos/05-term-expr.cc demos/02-baf.cc demos/10-int.cc
+ * demos/01-terms.cc demos/03-threads.cc
+ * demos-from-rascal/03-java.cc demos-from-rascal/04-uninit.cc:
+ Fix use of concepts. Fix naming convention. Rename term
+ and constructor types as "untyped_".
+
+ * bootstrap: Check for version of Automake.
+
2010-10-26 Valentin David <val...@ii...>
Add support for hashing tuples from standard library.
Modified: trunk/bootstrap
===================================================================
--- trunk/bootstrap 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/bootstrap 2010-10-29 19:10:34 UTC (rev 143)
@@ -1,4 +1,30 @@
-#! /bin/bash -e
+#! /bin/sh -e
-export AUTOMAKE="'${AUTOMAKE:-automake}' --libdir=:amlib"
-autoreconf -f -v -i
+AMVER="`${AUTOMAKE:-automake} --version 2>/dev/null | sed '1{;s/.* //g;q;};d'`"
+if test x"$AMVER" != x"1.11a"
+then
+ if test x"`automake-1.11a --version 2>/dev/null | sed '1{;s/.* //g;q;};d'`" = x"1.11a"
+ then
+ AUTOMAKE=automake-1.11a
+ else
+ echo "Cannot find automake 1.11a." 1>&2
+ exit 1
+ fi
+fi
+
+ACVER="`${ACLOCAL:-aclocal} --version 2>/dev/null | sed '1{;s/.* //g;q;};d'`"
+if test x"$ACVER" != x"1.11a"
+then
+ if test x"`aclocal-1.11a --version 2>/dev/null | sed '1{;s/.* //g;q;};d'`" = x"1.11a"
+ then
+ ACLOCAL=aclocal-1.11a
+ export ACLOCAL
+ else
+ echo "Cannot find aclocal 1.11a." 1>&2
+ exit 1
+ fi
+fi
+
+AUTOMAKE="'${AUTOMAKE:-automake}' --libdir=:amlib"
+export AUTOMAKE
+autoreconf -f -v -i -m
Modified: trunk/demos/01-terms.cc
===================================================================
--- trunk/demos/01-terms.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/01-terms.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -24,8 +24,8 @@
int main()
{
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
Cons a("a", 0);
Cons b("b", 0);
Modified: trunk/demos/02-baf.cc
===================================================================
--- trunk/demos/02-baf.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/02-baf.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -25,16 +25,16 @@
int main()
{
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- T t = readBaf(Main(), in);
+ T t = read_baf(Main(), in);
std::cout << t << std::endl;
} catch (std::ios_base::failure f) {
- std::cerr << "Failure while loading input file: "
+ std::cerr << "failure while loading input file: "
<< f.what() << std::endl;
return 1;
}
Modified: trunk/demos/03-threads.cc
===================================================================
--- trunk/demos/03-threads.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/03-threads.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -24,11 +24,11 @@
struct Main {};
-typedef Constructor <Main> Cons;
-typedef Term<Main> T;
+typedef untyped_constructor <Main> Cons;
+typedef untyped_term<Main> T;
struct MyThread {
- Term<Main> term;
+ untyped_term<Main> term;
MyThread() {
}
@@ -36,10 +36,10 @@
void operator()() {
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- term = readBaf(Main(), in);
+ term = read_baf(Main(), in);
}
catch (std::ios_base::failure f) {
- std::cerr << "Failure while loading input file: "
+ std::cerr << "failure while loading input file: "
<< f.what() << std::endl;
}
}
Modified: trunk/demos/04-pools.cc
===================================================================
--- trunk/demos/04-pools.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/04-pools.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -25,12 +25,12 @@
struct Main {};
struct Second {};
-typedef Constructor <Main> Cons;
-typedef Term<Main> T;
+typedef untyped_constructor <Main> Cons;
+typedef untyped_term<Main> T;
template <typename Pool>
struct MyThread {
- Term<Pool> term;
+ untyped_term<Pool> term;
MyThread() {
}
@@ -38,14 +38,14 @@
void operator()() {
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- term = readBaf(Pool(), in);
+ term = read_baf(Pool(), in);
}
catch (std::ios_base::failure f) {
- std::cerr << "Failure while loading input file: "
+ std::cerr << "failure while loading input file: "
<< f.what() << std::endl;
}
- catch (BadFormat) {
- std::cerr << "Failure while loading input file: bad format"
+ catch (bad_format) {
+ std::cerr << "failure while loading input file: bad format"
<< std::endl;
}
}
@@ -60,10 +60,10 @@
a.join();
b.join();
- if (t1.term == Term<Main>()) {
+ if (t1.term == untyped_term<Main>()) {
return 1;
}
- if (t2.term == Term<Second>()) {
+ if (t2.term == untyped_term<Second>()) {
return 1;
}
std::cout << (t1.term == t2.term) << std::endl;
Modified: trunk/demos/05-term-expr.cc
===================================================================
--- trunk/demos/05-term-expr.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/05-term-expr.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -24,8 +24,8 @@
int main()
{
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
Cons a("a", 0);
Cons b("b", 0);
Modified: trunk/demos/06-patterns.cc
===================================================================
--- trunk/demos/06-patterns.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/06-patterns.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -16,7 +16,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
-#include <patterns/pattern.hh>
+#include <patterns/term_pattern.hh>
+#include <patterns/variable.hh>
using namespace aurelia;
@@ -24,9 +25,9 @@
int main()
{
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
- typedef Variable<Term<Main> > V;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
+ typedef variable<untyped_term<Main> > V;
Cons a("a", 0);
Cons b("b", 0);
@@ -41,7 +42,7 @@
c[X, vb] = t;
std::cout << *X << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "Failed!" << std::endl;
}
@@ -50,7 +51,7 @@
c[X, vb] = c[b, b];
std::cout << *X << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "Failed!" << std::endl;
}
@@ -59,7 +60,7 @@
c[X, X] = t;
std::cout << *X << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "Failed!" << std::endl;
}
@@ -68,7 +69,7 @@
c[X, X] = c[a, a];
std::cout << c[*X,*X] << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "Failed!" << std::endl;
}
Modified: trunk/demos/07-strategies.cc
===================================================================
--- trunk/demos/07-strategies.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/07-strategies.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -16,9 +16,13 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
+#include <terms/term.hh>
#include <strategies/strategies.hh>
#include <strategies/generic/debug.hh>
#include <strategies/traversals/topdown.hh>
+#include <strategies/traversals/one.hh>
+#include <patterns/term_pattern.hh>
+#include <patterns/variable.hh>
using namespace aurelia;
@@ -26,9 +30,9 @@
int main()
{
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
- typedef Variable<Term<Main> > V;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
+ typedef variable<untyped_term<Main> > V;
Cons a("a", 0);
Cons b("b", 0);
@@ -55,7 +59,7 @@
all(~X)(c[b, b]);
std::cout << (!c[X,X])(t) << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "No." << std::endl;
}
@@ -64,7 +68,7 @@
all(~X)(c[b, a]);
std::cout << (!c[X,X])(t) << std::endl;
}
- catch (Failure) {
+ catch (failure) {
std::cout << "No." << std::endl;
}
Modified: trunk/demos/10-int.cc
===================================================================
--- trunk/demos/10-int.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/10-int.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -28,20 +28,20 @@
using namespace aurelia;
template <typename Pool>
-struct Int: Term<Pool> {
+struct Int: untyped_term<Pool> {
private:
int value;
public:
- typedef Term<Pool> super;
+ typedef untyped_term<Pool> super;
- Int(const Term<Pool>& t): super(t) {
+ Int(const untyped_term<Pool>& t): super(t) {
std::stringstream ss(t.constructor().name(), std::ios_base::in);
ss >> value;
if (ss.fail())
- throw Failure();
+ throw failure();
if (!ss.eof())
- throw Failure();
+ throw failure();
}
operator int() const {
@@ -52,7 +52,7 @@
struct IsInt {
public:
template <typename Pool>
- Int<Pool> operator()(const Term<Pool>& t) const {
+ Int<Pool> operator()(const untyped_term<Pool>& t) const {
return t;
}
template <typename Pool>
@@ -67,8 +67,8 @@
namespace aurelia {
template <typename Pool>
- struct StrategyModel<Max, Int<Pool>, false> {
- struct Model {
+ struct strategy_model<Max, Int<Pool>, false> {
+ struct model {
typedef Max Strat;
typedef Int<Pool> Input;
typedef Int<Pool> Ouput;
@@ -76,10 +76,10 @@
};
template <typename Pool>
- struct StrategyModel<Max, Term<Pool>, false> {
- struct Model {
+ struct strategy_model<Max, untyped_term<Pool>, false> {
+ struct model {
typedef Max Strat;
- typedef Term<Pool> Input;
+ typedef untyped_term<Pool> Input;
typedef Int<Pool> Ouput;
};
};
@@ -96,8 +96,8 @@
~Max() { if (master) delete i; }
template <typename T>
- typename StrategyModel<Max,T>::Model::Output operator()(const T& t) const {
- typename StrategyModel<Max,T>::Model::Output ret(t);
+ typename strategy_model<Max,T>::model::Output operator()(const T& t) const {
+ typename strategy_model<Max,T>::model::Output ret(t);
if (*i < (int)ret)
*i = (int)ret;
return ret;
@@ -109,19 +109,19 @@
};
int main() {
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- T t = readBaf(Main(), in);
+ T t = read_baf(Main(), in);
//topdown(try_((is_int<debug("Found integer: "))))(t);
Max max;
topdown(try_(id))(t);
std::cout << max << std::endl;
} catch (std::ios_base::failure f) {
- std::cerr << "Failure while loading input file: "
+ std::cerr << "failure while loading input file: "
<< f.what() << std::endl;
return 1;
}
Modified: trunk/demos/12-maps.cc
===================================================================
--- trunk/demos/12-maps.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/12-maps.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -25,10 +25,10 @@
struct Main {};
int main() {
- typedef Constructor <Main> Cons;
- typedef Term<Main> T;
+ typedef untyped_constructor <Main> Cons;
+ typedef untyped_term<Main> T;
- std::unordered_map<Term<Main>, Term<Main> > map;
+ std::unordered_map<untyped_term<Main>, untyped_term<Main> > map;
Cons c("c", 2);
Cons a("a", 0);
Modified: trunk/demos/13-constructors-with-typed-terms.cc
===================================================================
--- trunk/demos/13-constructors-with-typed-terms.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos/13-constructors-with-typed-terms.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -152,13 +152,13 @@
if (t == IntAndString<Pool>())
t = other;
else
- throw Failure();
+ throw failure();
}
return *this;
}
IntAndString<Pool> operator*() const {
if (t == IntAndString<Pool>())
- throw Failure();
+ throw failure();
return t;
}
};
@@ -183,7 +183,7 @@
IntVar& operator=(int other) {
if (*set) {
if (*i != other)
- throw Failure();
+ throw failure();
} else {
*i = other;
*set = true;
@@ -192,7 +192,7 @@
}
int operator*() const {
if (!*set)
- throw Failure();
+ throw failure();
return *i;
}
};
@@ -211,13 +211,13 @@
if (t == String<Pool>())
t = other;
else
- throw Failure();
+ throw failure();
}
return *this;
}
String<Pool> operator*() const {
if (t == String<Pool>())
- throw Failure();
+ throw failure();
return t;
}
};
Modified: trunk/demos-from-rascal/03-java.cc
===================================================================
--- trunk/demos-from-rascal/03-java.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos-from-rascal/03-java.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -21,7 +21,7 @@
auto USE = CALL | CONTAINMENT | INHERITANCE;
- Variable<Class> a;
+ variable<Class> a;
set<Class> ClassesInCycle =
filter(set<Class>(),
@@ -38,7 +38,7 @@
[&USETRANS](const Class& in) {
if (USETRANS[in].has(in))
return std::pair<Class, set<Class> >(in, USETRANS[in]);
- throw Failure();
+ throw failure();
})
(CLASSES);
Modified: trunk/demos-from-rascal/04-uninit.cc
===================================================================
--- trunk/demos-from-rascal/04-uninit.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos-from-rascal/04-uninit.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -44,7 +44,7 @@
[&PRED, &ROOT, &DEFS](const ve& V) {
if (reachX(PRED, set<expr>(ROOT), DEFS[V.first]).has(V.second))
return V;
- throw Failure();
+ throw failure();
})
(USES);
Modified: trunk/demos-from-rascal/06-reaching-defs.cc
===================================================================
--- trunk/demos-from-rascal/06-reaching-defs.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos-from-rascal/06-reaching-defs.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -10,9 +10,9 @@
template <typename stat, typename var>
rel_set<stat,std::pair<stat, var> > kill(const rel_set<stat,var>& DEFS){
typedef rel_set<stat,std::pair<stat, var> > out;
- Variable<rel_set<stat,var> > D;
- Variable<stat> S1, S2;
- Variable<var> V;
+ variable<rel_set<stat,var> > D;
+ variable<stat> S1, S2;
+ variable<var> V;
return (~D <
map_join(out(),
@@ -36,8 +36,8 @@
template <typename stat, typename var>
rel_set<stat,std::pair<stat, var> > definition(const rel_set<stat,var>& DEFS){
typedef rel_set<stat,std::pair<stat, var> > out;
- Variable<stat> S;
- Variable<var> V;
+ variable<stat> S;
+ variable<var> V;
return filter(out(),
scope(S, scope(V, ~p(S, V) < !p(S, p(S, V))))
@@ -47,8 +47,8 @@
template <typename stat, typename var>
rel_set<stat,std::pair<stat, var> > use(const rel_set<stat,var>& USES){
typedef rel_set<stat,std::pair<stat, var> > out;
- Variable<stat> S;
- Variable<var> V;
+ variable<stat> S;
+ variable<var> V;
return filter(out(),
scope(S, scope(V, ~p(S, V) < !p(S, p(S, V))))
Modified: trunk/demos-from-stratego/01-constant-folding-rules.cc
===================================================================
--- trunk/demos-from-stratego/01-constant-folding-rules.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/demos-from-stratego/01-constant-folding-rules.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -1,5 +1,6 @@
#include <terms/term.hh>
-#include <patterns/pattern.hh>
+#include <patterns/term_pattern.hh>
+#include <patterns/variable.hh>
#include <patterns/pair.hh>
#include <strategies/patterns/pair.hh>
#include <strategies/traversals/innermost.hh>
@@ -12,11 +13,11 @@
#include <iostream>
#include <terms/baf_read.hh>
-using aurelia::Term;
-using aurelia::Constructor;
-using aurelia::Variable;
-using aurelia::Failure;
-using aurelia::readBaf;
+using aurelia::untyped_term;
+using aurelia::untyped_constructor;
+using aurelia::variable;
+using aurelia::failure;
+using aurelia::read_baf;
using aurelia::innermost;
using aurelia::get_cons_name;
using aurelia::undouble_quote;
@@ -25,9 +26,9 @@
using aurelia::operator+;
struct Main {};
-typedef Term<Main> T;
-typedef Constructor<Main> C;
-typedef Variable<Term<Main> > V;
+typedef untyped_term<Main> T;
+typedef untyped_constructor<Main> C;
+typedef variable<untyped_term<Main> > V;
auto to_term = [] (const std::string& s) {
return T(C(s));
@@ -93,7 +94,7 @@
if (to_int(*i) < to_int(*j))
return t;
- throw Failure();
+ throw failure();
};
auto gtS = [] (const std::pair<T, T>& t) {
@@ -103,7 +104,7 @@
if (to_int(*i) > to_int(*j))
return t;
- throw Failure();
+ throw failure();
};
auto leqS = [] (const std::pair<T, T>& t) {
@@ -113,7 +114,7 @@
if (to_int(*i) <= to_int(*j))
return t;
- throw Failure();
+ throw failure();
};
auto geqS = [] (const std::pair<T, T>& t) {
@@ -123,7 +124,7 @@
if (to_int(*i) >= to_int(*j))
return t;
- throw Failure();
+ throw failure();
};
auto eqS = [] (const std::pair<T, T>& t) {
@@ -133,7 +134,7 @@
if (to_int(*i) == to_int(*j))
return t;
- throw Failure();
+ throw failure();
};
auto conc_strings = [] (const std::pair<T, T>& t) {
@@ -204,7 +205,7 @@
return b;
if (a.constructor() != C::AS_LIST)
- throw Failure();
+ throw failure();
return T(C::AS_LIST, (a[0], conc_lists(a[1], b)));
}
@@ -372,11 +373,11 @@
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- T t = readBaf(Main(), in);
+ T t = read_baf(Main(), in);
std::cout << til_simplify(t) << std::endl;
} catch (std::ios_base::failure f) {
- std::cerr << "Failure while loading input file: "
+ std::cerr << "failure while loading input file: "
<< f.what() << std::endl;
return 1;
}
Modified: trunk/src/aurelia.hh
===================================================================
--- trunk/src/aurelia.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/aurelia.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -26,4 +26,18 @@
namespace aurelia {
}
+//! \brief Lock-free data structures
+namespace lockfree {
+}
+
+namespace aurelia {
+ //! \brief Type traits
+ namespace type_traits {
+ }
+}
+
+//! \brief Fast bit operations
+namespace fast {
+}
+
#endif
Modified: trunk/src/box/box.hh
===================================================================
--- trunk/src/box/box.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/box/box.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -30,10 +30,10 @@
/*! \brief Abstract virtual class for box elements
*/
- struct VirtualBox {
+ struct virtual_box {
/*! \brief Virtual destructor
*/
- virtual ~VirtualBox() {}
+ virtual ~virtual_box() {}
/*! \brief Prints out the box
*
@@ -47,7 +47,7 @@
/*! \brief Abstract static class for box elements
*/
template <typename ExactType>
- struct Box: public VirtualBox {
+ struct box: public virtual_box {
//! \brief Downcast operator
operator ExactType&() {
return *static_cast<ExactType*>(this);
@@ -61,18 +61,18 @@
/*! \brief Wrap a string as a pretty printing box.
*/
- struct StringBox: public Box<StringBox> {
+ struct string_box: public box<string_box> {
private:
std::string s;
public:
- /*! \brief Constructor
+ /*! \brief untyped_constructor
*/
- StringBox(const std::string& s): s(s) {}
+ string_box(const std::string& s): s(s) {}
/*! \brief Copy constructor
*/
- StringBox(const StringBox& other): s(other.s) {}
+ string_box(const string_box& other): s(other.s) {}
/*! \brief String accessor
*/
@@ -82,14 +82,14 @@
/*! \brief Assignement
*/
- StringBox& operator=(StringBox other) {
+ string_box& operator=(string_box other) {
this->swap(other);
return *this;
}
/*! \brief Exception-free swap
*/
- void swap(StringBox& other) {
+ void swap(string_box& other) {
std::swap(this->s, other.s);
}
@@ -99,7 +99,7 @@
};
//! \brief Alias for building string boxes.
- typedef StringBox S;
+ typedef string_box S;
/*! \brief Directions as run-time values
*/
@@ -108,22 +108,22 @@
};
//! \brief Horizontal direction tag
- struct HBox {
+ struct h_box {
enum { dir = HDir };
};
//! \brief Vertical direction tag
- struct VBox {
+ struct v_box {
enum { dir = VDir };
};
//! \brief Horizontal or vertical direction tag
- struct HVBox {
+ struct hv_box {
enum { dir = HVDir };
};
- struct VirtualBoxList {
+ struct virtual_boxList {
/*! \brief Virtual Destructor
*/
- virtual ~VirtualBoxList() {}
+ virtual ~virtual_boxList() {}
/*! \brief Prints out the box
*/
@@ -135,7 +135,7 @@
/*! \brief Static abstract class for lists of pretty printing boxes.
*/
template <typename ExactType>
- struct BoxList: public VirtualBoxList {
+ struct box_list: public virtual_boxList {
//! \brief Downcast operator
operator ExactType&() {
return *static_cast<ExactType*>(this);
@@ -150,8 +150,8 @@
/*! \brief Represents and empty list of boxes
*/
- struct BoxListEnd:
- public BoxList<BoxListEnd> {
+ struct box_list_end:
+ public box_list<box_list_end> {
virtual unsigned to_text(std::ostream&, unsigned pos,
unsigned, unsigned, unsigned,
Dir, bool) const {
@@ -162,7 +162,7 @@
/*! \brief List of boxes
*/
template <typename Head, typename Tail>
- struct BoxListCons: public BoxList<BoxListCons<Head, Tail> > {
+ struct box_list_cons: public box_list<box_list_cons<Head, Tail> > {
private:
Head _head;
Tail _tail;
@@ -170,7 +170,7 @@
public:
/*! \brief Default constructor
*/
- BoxListCons(const Head& _head, const Tail& _tail):
+ box_list_cons(const Head& _head, const Tail& _tail):
_head(_head), _tail(_tail) {}
/*! \brief Head accessor
@@ -217,30 +217,30 @@
/*! \brief Box list wrapping a virtual box list.
*/
- struct AnyBoxList: public BoxList<AnyBoxList> {
+ struct any_box_list: public box_list<any_box_list> {
private:
- std::shared_ptr<VirtualBoxList> list;
+ std::shared_ptr<virtual_boxList> list;
public:
- /*! \brief Constructor
+ /*! \brief untyped_constructor
*/
template <typename ExactType>
- AnyBoxList(const BoxList<ExactType>& l): list(new ExactType(l)) {}
+ any_box_list(const box_list<ExactType>& l): list(new ExactType(l)) {}
/*! \brief Copy constructor
*/
- AnyBoxList(const AnyBoxList& other): list(other.list) {}
+ any_box_list(const any_box_list& other): list(other.list) {}
/*! \brief Assignment
*/
- AnyBoxList& operator=(AnyBoxList other) {
+ any_box_list& operator=(any_box_list other) {
this->swap(other);
return *this;
}
/*! \brief Exception-free swap
*/
- void swap(AnyBoxList& other) {
+ void swap(any_box_list& other) {
std::swap(this->list, other.list);
}
@@ -255,7 +255,7 @@
/*! \brief A container box with directions.
*
- * \tparam Direction One of VBox, HBox, HVBox
+ * \tparam Direction One of v_box, h_box, hv_box
* \tparam VS Vertical space
* \tparam HS Horizontal space
* \tparam IS Identation space
@@ -263,16 +263,16 @@
*/
template <typename Direction, unsigned VS, unsigned HS, unsigned IS,
typename List>
- struct ContainerBox:
- public Box<ContainerBox<Direction, VS, HS, IS, List> > {
+ struct container_box:
+ public box<container_box<Direction, VS, HS, IS, List> > {
private:
List list;
public:
- //! \brief Constructor
- ContainerBox(const List& list): list(list) {}
+ //! \brief untyped_constructor
+ container_box(const List& list): list(list) {}
//! \brief Copy constructor
- ContainerBox(const ContainerBox& other): list(other.list) {}
+ container_box(const container_box& other): list(other.list) {}
//! \brief Accessor to list methods
const List* operator->() const {
@@ -285,13 +285,13 @@
}
//! \brief Assignment
- ContainerBox& operator=(ContainerBox other) {
+ container_box& operator=(container_box other) {
this->swap(other);
return *this;
}
//! \brief Exception-free swap
- void swap(ContainerBox& other) {
+ void swap(container_box& other) {
this->list.swap(other.list);
}
@@ -303,31 +303,31 @@
/*! \brief Box wrapping a virtual box.
*/
- struct AnyBox: public Box<AnyBox> {
+ struct any_box: public box<any_box> {
private:
- std::shared_ptr<VirtualBox> box;
+ std::shared_ptr<virtual_box> _box;
public:
- /*! \brief Constructor
+ /*! \brief untyped_constructor
*/
template <typename RealType>
- explicit AnyBox(const Box<RealType>& b): box(new RealType(b)) {}
+ explicit any_box(const box<RealType>& b): _box(new RealType(b)) {}
/*! \brief Copy constructor
*/
- AnyBox(const AnyBox& other): box(other.box) {}
+ any_box(const any_box& other): _box(other._box) {}
/*! \brief Assignement
*/
- AnyBox& operator=(AnyBox other) {
+ any_box& operator=(any_box other) {
this->swap(other);
return (*this);
}
/*! \brief Exception-free swap
*/
- void swap(AnyBox& other) {
- std::swap(this->box, other.box);
+ void swap(any_box& other) {
+ std::swap(this->_box, other._box);
}
/*! \brief Prints out the box
@@ -338,18 +338,18 @@
/*! \brief Appends a box at the end of a list
*/
template <typename ExactBox>
- BoxListCons<ExactBox, BoxListEnd>
- append(const BoxListEnd&, const Box<ExactBox>& b) {
- return BoxListCons<ExactBox, BoxListEnd>(b, BoxListEnd());
+ box_list_cons<ExactBox, box_list_end>
+ append(const box_list_end&, const box<ExactBox>& b) {
+ return box_list_cons<ExactBox, box_list_end>(b, box_list_end());
}
/*! \brief Appends a box at the end of a list
*/
template <typename B, typename Tail, typename ExactBox>
- BoxListCons<B,decltype(append(std::declval<Tail>(),
+ box_list_cons<B,decltype(append(std::declval<Tail>(),
std::declval<ExactBox>()))>
- append(const BoxListCons<B, Tail>& l, const Box<ExactBox>& b) {
- return BoxListCons<B,decltype(append(std::declval<Tail>(),
+ append(const box_list_cons<B, Tail>& l, const box<ExactBox>& b) {
+ return box_list_cons<B,decltype(append(std::declval<Tail>(),
std::declval<ExactBox>()))>
(l.head(), append(l.tail(), b));
}
@@ -358,45 +358,45 @@
*/
template <typename ExactBox, typename ExactList>
decltype(append(std::declval<ExactList>(), std::declval<ExactBox>()))
- operator,(const BoxList<ExactList>& l, const Box<ExactBox>& s) {
+ operator,(const box_list<ExactList>& l, const box<ExactBox>& s) {
return append(ExactList(l), s);
}
/*! \brief Builds a list from boxes.
*/
template <typename ExactBox, typename ExactBox2>
- BoxListCons<ExactBox, BoxListCons<ExactBox2, BoxListEnd> >
- operator,(const Box<ExactBox>& s, const Box<ExactBox2>& t) {
- return BoxListCons<ExactBox, BoxListCons<ExactBox2, BoxListEnd> >
- (s, BoxListCons<ExactBox2, BoxListEnd>(t, BoxListEnd()));
+ box_list_cons<ExactBox, box_list_cons<ExactBox2, box_list_end> >
+ operator,(const box<ExactBox>& s, const box<ExactBox2>& t) {
+ return box_list_cons<ExactBox, box_list_cons<ExactBox2, box_list_end> >
+ (s, box_list_cons<ExactBox2, box_list_end>(t, box_list_end()));
}
/*! \brief Tuple for space configuration
*/
template <unsigned VS, unsigned HS, unsigned IS>
- struct SpaceConf {};
+ struct space_conf {};
//! \brief Creates a space configuration with vertical specification
template <unsigned VS>
- SpaceConf<VS, 0, 0> Vs() {
- return SpaceConf<VS, 0, 0>();
+ space_conf<VS, 0, 0> Vs() {
+ return space_conf<VS, 0, 0>();
}
//! \brief Creates a space configuration with horizontal specification
template <unsigned HS>
- SpaceConf<0, HS, 0> Hs() {
- return SpaceConf<0, HS, 0>();
+ space_conf<0, HS, 0> Hs() {
+ return space_conf<0, HS, 0>();
}
//! \brief Creates a space configuration with identation specification
template <unsigned IS>
- SpaceConf<0, 0, IS> Is() {
- return SpaceConf<0, 0, IS>();
+ space_conf<0, 0, IS> Is() {
+ return space_conf<0, 0, IS>();
}
//! \brief Gets a maximum value from two constants at compile-time
template <unsigned a, unsigned b>
- struct Max {
+ struct max {
enum : unsigned { ret = (a>b)?a:b };
};
@@ -404,67 +404,67 @@
//! \brief Merges two configurations
template <unsigned VS1, unsigned HS1, unsigned IS1,
unsigned VS2, unsigned HS2, unsigned IS2>
- SpaceConf<Max<VS1, VS2>::ret,
- Max<HS1, HS2>::ret,
- Max<IS1, IS2>::ret>
- operator,(const SpaceConf<VS1, HS1, IS1>&,
- const SpaceConf<VS2, HS2, IS2>&) {
- return SpaceConf<Max<VS1, VS2>::ret,
- Max<HS1, HS2>::ret,
- Max<IS1, IS2>::ret>();
+ space_conf<max<VS1, VS2>::ret,
+ max<HS1, HS2>::ret,
+ max<IS1, IS2>::ret>
+ operator,(const space_conf<VS1, HS1, IS1>&,
+ const space_conf<VS2, HS2, IS2>&) {
+ return space_conf<max<VS1, VS2>::ret,
+ max<HS1, HS2>::ret,
+ max<IS1, IS2>::ret>();
}
//! \brief Provides building operation for boxes.
template <typename Direction, unsigned VS, unsigned HS, unsigned IS>
- struct BoxArtifact {
+ struct box_artifact {
//! \brief Builds a box container from a list of boxes
template <typename ExactList>
- ContainerBox<Direction, VS, HS, IS, ExactList>
- operator[](const BoxList<ExactList>& l) const {
- return ContainerBox<Direction, VS, HS, IS, ExactList>(l);
+ container_box<Direction, VS, HS, IS, ExactList>
+ operator[](const box_list<ExactList>& l) const {
+ return container_box<Direction, VS, HS, IS, ExactList>(l);
}
//! \brief Builds a box container from a singleton of box
template <typename ExactBox>
- ContainerBox<Direction, VS, HS, IS, BoxListCons<ExactBox, BoxListEnd> >
- operator[](const Box<ExactBox>& l) const {
+ container_box<Direction, VS, HS, IS, box_list_cons<ExactBox, box_list_end> >
+ operator[](const box<ExactBox>& l) const {
return
- ContainerBox<Direction, VS, HS, IS, BoxListCons<ExactBox, BoxListEnd> >
- (BoxListCons<ExactBox, BoxListEnd>(l, BoxListEnd()));
+ container_box<Direction, VS, HS, IS, box_list_cons<ExactBox, box_list_end> >
+ (box_list_cons<ExactBox, box_list_end>(l, box_list_end()));
}
};
//! \brief Returns a builder for a horizontal box.
template <unsigned VS, unsigned HS, unsigned IS>
- BoxArtifact<HBox, VS, HS, IS> H(const SpaceConf<VS, HS, IS>&) {
- return BoxArtifact<HBox, VS, HS, IS>();
+ box_artifact<h_box, VS, HS, IS> H(const space_conf<VS, HS, IS>&) {
+ return box_artifact<h_box, VS, HS, IS>();
}
//! \brief Returns a builder for a horizontal box.
- BoxArtifact<HBox, 0, 1, 0> H() {
- return BoxArtifact<HBox, 0, 1, 0>();
+ box_artifact<h_box, 0, 1, 0> H() {
+ return box_artifact<h_box, 0, 1, 0>();
}
//! \brief Returns a builder for a vertical box.
template <unsigned VS, unsigned HS, unsigned IS>
- BoxArtifact<VBox, VS, HS, IS> V(const SpaceConf<VS, HS, IS>&) {
- return BoxArtifact<VBox, VS, HS, IS>();
+ box_artifact<v_box, VS, HS, IS> V(const space_conf<VS, HS, IS>&) {
+ return box_artifact<v_box, VS, HS, IS>();
}
//! \brief Returns a builder for a vertical box.
- BoxArtifact<VBox, 0, 0, 0> V() {
- return BoxArtifact<VBox, 0, 0, 0>();
+ box_artifact<v_box, 0, 0, 0> V() {
+ return box_artifact<v_box, 0, 0, 0>();
}
//! \brief Returns a builder for a horizontal/vertical box.
template <unsigned VS, unsigned HS, unsigned IS>
- BoxArtifact<HVBox, VS, HS, IS> HV(const SpaceConf<VS, HS, IS>&) {
- return BoxArtifact<HVBox, VS, HS, IS>();
+ box_artifact<hv_box, VS, HS, IS> HV(const space_conf<VS, HS, IS>&) {
+ return box_artifact<hv_box, VS, HS, IS>();
}
//! \brief Returns a builder for a horizontal/vertical box.
- BoxArtifact<HVBox, 0, 1, 0> HV() {
- return BoxArtifact<HVBox, 0, 1, 0>();
+ box_artifact<hv_box, 0, 1, 0> HV() {
+ return box_artifact<hv_box, 0, 1, 0>();
}
/*! \brief Prints out vertically a list of boxes
@@ -476,16 +476,16 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head, typename Head2, typename Tail>
- unsigned box_to_text(Stream& s, unsigned pos, const VBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListCons<Head,
- BoxListCons<Head2, Tail> >& bl) {
+ unsigned box_to_text(Stream& s, unsigned pos, const v_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_cons<Head,
+ box_list_cons<Head2, Tail> >& bl) {
box_to_text(s, pos, bl.head());
for (unsigned i = 0; i < (VS + 1); ++i)
s << std::endl;
for (unsigned i = 0; i < pos; ++i)
s << " ";
- return box_to_text(s, pos, VBox(), SpaceConf<VS, HS, IS>(), bl.tail());
+ return box_to_text(s, pos, v_box(), space_conf<VS, HS, IS>(), bl.tail());
}
/*! \brief Prints out vertically a singleton of box
@@ -497,9 +497,9 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head>
- unsigned box_to_text(Stream& s, unsigned pos, const VBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListCons<Head, BoxListEnd>& bl) {
+ unsigned box_to_text(Stream& s, unsigned pos, const v_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_cons<Head, box_list_end>& bl) {
return box_to_text(s, pos, bl.head());
}
@@ -510,9 +510,9 @@
* \returns The horizontal position achieved
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
- unsigned box_to_text(Stream&, unsigned pos, const VBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListEnd&) {
+ unsigned box_to_text(Stream&, unsigned pos, const v_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_end&) {
return pos;
}
@@ -550,14 +550,14 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head, typename Head2, typename Tail>
- unsigned box_to_text(Stream& s, unsigned pos, const HBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListCons<Head,
- BoxListCons<Head2, Tail> >& bl) {
+ unsigned box_to_text(Stream& s, unsigned pos, const h_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_cons<Head,
+ box_list_cons<Head2, Tail> >& bl) {
pos = box_to_text(s, pos, bl.head());
print_space<HS>::doit(s);
pos += HS;
- return box_to_text(s, pos, HBox(), SpaceConf<VS, HS, IS>(), bl.tail());
+ return box_to_text(s, pos, h_box(), space_conf<VS, HS, IS>(), bl.tail());
}
/*! \brief Prints out horizontally a singleton of box
@@ -569,9 +569,9 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head>
- unsigned box_to_text(Stream& s, unsigned pos, const HBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListCons<Head, BoxListEnd>& bl) {
+ unsigned box_to_text(Stream& s, unsigned pos, const h_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_cons<Head, box_list_end>& bl) {
return box_to_text(s, pos, bl.head());
}
@@ -583,34 +583,34 @@
* \returns The horizontal position achieved
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
- unsigned box_to_text(Stream&, unsigned pos, const HBox&,
- const SpaceConf<VS, HS, IS>&,
- const BoxListEnd&) {
+ unsigned box_to_text(Stream&, unsigned pos, const h_box&,
+ const space_conf<VS, HS, IS>&,
+ const box_list_end&) {
return pos;
}
- /*! \brief Prints out a StringBox
+ /*! \brief Prints out a string_box
*
* \param s A stream
* \param pos The current horizontal position
- * \param str The StringBox to print out
+ * \param str The string_box to print out
* \returns The horizontal position achieved
*/
template <typename Stream>
- unsigned box_to_text(Stream& s, unsigned pos, const StringBox& str) {
+ unsigned box_to_text(Stream& s, unsigned pos, const string_box& str) {
s << std::string(str);
return pos + std::string(str).size();
}
- /*! \brief Prints out an AnyBox
+ /*! \brief Prints out an any_box
*
* \param s A stream
* \param pos The current horizontal position
- * \param b The AnyBox to print out
+ * \param b The any_box to print out
* \returns The horizontal position achieved
*/
template <typename Stream>
- unsigned box_to_text(Stream& s, unsigned pos, const AnyBox& b) {
+ unsigned box_to_text(Stream& s, unsigned pos, const any_box& b) {
return b.to_text(s, pos);
}
@@ -624,15 +624,15 @@
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head, typename Tail>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<VBox, VS, HS, IS,
- BoxListCons<Head, Tail> >& b) {
+ const container_box<v_box, VS, HS, IS,
+ box_list_cons<Head, Tail> >& b) {
box_to_text(s, pos, b->head());
for (unsigned i = 0; i < (VS + 1); ++i)
s << std::endl;
pos+=IS;
for (unsigned i = 0; i < pos; ++i)
s << " ";
- return box_to_text(s, pos, VBox(), (Vs<VS>(), Is<IS>()), b->tail());
+ return box_to_text(s, pos, v_box(), (Vs<VS>(), Is<IS>()), b->tail());
}
/*! \brief Prints out an empty vertical box
@@ -643,7 +643,7 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<VBox, VS, HS, IS, BoxListEnd>&) {
+ const container_box<v_box, VS, HS, IS, box_list_end>&) {
return pos;
}
@@ -657,9 +657,9 @@
template <typename Stream, unsigned VS, unsigned HS, unsigned IS,
typename Head, typename Tail>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<HBox, VS, HS, IS,
- BoxListCons<Head, Tail> >& b) {
- return box_to_text(s, pos, HBox(), (Hs<HS>()), *b);
+ const container_box<h_box, VS, HS, IS,
+ box_list_cons<Head, Tail> >& b) {
+ return box_to_text(s, pos, h_box(), (Hs<HS>()), *b);
}
/*! \brief Prints out a horizontal box
@@ -671,8 +671,8 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<HBox, VS, HS, IS,
- AnyBoxList>& b) {
+ const container_box<h_box, VS, HS, IS,
+ any_box_list>& b) {
return b->to_text(s, pos, VS, HS, IS, HDir, true);
}
@@ -685,8 +685,8 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<VBox, VS, HS, IS,
- AnyBoxList>& b) {
+ const container_box<v_box, VS, HS, IS,
+ any_box_list>& b) {
return b->to_text(s, pos, VS, HS, IS, VDir, true);
}
@@ -698,7 +698,7 @@
*/
template <typename Stream, unsigned VS, unsigned HS, unsigned IS>
unsigned box_to_text(Stream& s, unsigned pos,
- const ContainerBox<HBox, VS, HS, IS, BoxListEnd>&) {
+ const container_box<h_box, VS, HS, IS, box_list_end>&) {
return pos;
}
@@ -709,17 +709,17 @@
* \returns The stream
*/
template <typename Stream, typename ExactBox>
- Stream& operator<<(Stream& s, const Box<ExactBox>& b) {
+ Stream& operator<<(Stream& s, const box<ExactBox>& b) {
box_to_text(s, 0U, (const ExactBox&)(b));
return s;
}
- unsigned StringBox::to_text(std::ostream& s, unsigned pos) const {
+ unsigned string_box::to_text(std::ostream& s, unsigned pos) const {
return box_to_text(s, pos, *this);
}
- unsigned AnyBox::to_text(std::ostream& s, unsigned pos) const {
- return this->box->to_text(s, pos);
+ unsigned any_box::to_text(std::ostream& s, unsigned pos) const {
+ return this->_box->to_text(s, pos);
}
}
Modified: trunk/src/box/tests/box_test.cc
===================================================================
--- trunk/src/box/tests/box_test.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/box/tests/box_test.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -60,12 +60,12 @@
if (!test(7, H(Hs<0>())[S("a"), S("b")], "ab"))
error = 1;
- AnyBox a(H(Hs<1>())[S("a"), S("b"), V()[S("c"), S("d")]]);
+ any_box a(H(Hs<1>())[S("a"), S("b"), V()[S("c"), S("d")]]);
if (!test(8, V(Is<2>())[a, S("e")],
"a b c\n d\n e"))
error = 1;
- AnyBoxList l = (H(Hs<1>())[S("a"), S("b"), V()[S("c"), S("d")]], S("e"));
+ any_box_list l = (H(Hs<1>())[S("a"), S("b"), V()[S("c"), S("d")]], S("e"));
if (!test(8, V(Is<2>())[l],
"a b c\n d\n e"))
error = 1;
Modified: trunk/src/hash/tuple_hash.hh
===================================================================
--- trunk/src/hash/tuple_hash.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/hash/tuple_hash.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -36,12 +36,13 @@
};
template <typename... T>
- struct get_hash<std::tuple<T...>, 0> {
+ struct get_hash<std::tuple<T...>, 0u> {
static void make(size_t& hash, const std::tuple<T...>& t) {
hash = mhash<typename std::tuple_element<0, std::tuple<T...> >::type>()
(std::get<0>(t));
}
};
+
}
namespace std {
@@ -53,6 +54,13 @@
return hash;
}
};
+
+ template <>
+ struct hash<tuple<> >: public unary_function<tuple<>, size_t> {
+ size_t operator()(const tuple<>& ) const {
+ return 0;
+ }
+ };
}
#endif
Modified: trunk/src/lists/list.hh
===================================================================
--- trunk/src/lists/list.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/lists/list.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -22,17 +22,17 @@
namespace aurelia {
- struct ListNil {
+ struct list_nil {
private:
public:
enum : unsigned { size = 0 };
- ListNil() {}
- ListNil(const ListNil&) {}
- ListNil(ListNil&&) {}
+ list_nil() {}
+ list_nil(const list_nil&) {}
+ list_nil(list_nil&&) {}
};
template <typename T, typename Tail>
- struct ListCons {
+ struct list_cons {
private:
T h;
Tail t;
@@ -40,22 +40,22 @@
public:
enum : unsigned { size = (unsigned)(Tail::size)+1 };
- ListCons(T&& h, const Tail& t):
+ list_cons(T&& h, const Tail& t):
h(std::move(h)), t(t) {}
- ListCons(T&& h, Tail&& t):
+ list_cons(T&& h, Tail&& t):
h(std::move(h)), t(std::move(t)) {}
- ListCons(const T& h, Tail&& t):
+ list_cons(const T& h, Tail&& t):
h(h), t(std::move(t)) {}
- ListCons(const T& h, const Tail& t):
+ list_cons(const T& h, const Tail& t):
h(h), t(t) {}
- ListCons(const ListCons& other):
+ list_cons(const list_cons& other):
h(other.h), t(other.t) {}
- ListCons(ListCons&& other):
+ list_cons(list_cons&& other):
h(std::move(other.h)), t(std::move(other.t)) {}
const T& head() const {
@@ -68,26 +68,26 @@
};
template <typename H, typename T>
- H head(const ListCons<H,T>& l) {
+ H head(const list_cons<H,T>& l) {
return l.head();
}
template <typename H, typename T>
- T tail(const ListCons<H,T>& l) {
+ T tail(const list_cons<H,T>& l) {
return l.tail();
}
template <typename H, typename T>
- ListCons<H,T> cons(const H& h, const T& t) {
- return ListCons<H,T>(h, t);
+ list_cons<H,T> cons(const H& h, const T& t) {
+ return list_cons<H,T>(h, t);
};
- void head(ListNil);
+ void head(list_nil);
- ListNil tail(ListNil);
+ list_nil tail(list_nil);
- ListNil cons();
+ list_nil cons();
}
Modified: trunk/src/lists/list_concept.hh
===================================================================
--- trunk/src/lists/list_concept.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/lists/list_concept.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -22,86 +22,89 @@
namespace aurelia {
template <typename T>
- struct ListModel;
+ struct list_model;
/*! \brief List Concept
* \ingroup Concepts
*/
template <typename Model>
- struct ListConcept: public Model {
- typedef typename Model::Cons Cons;
- typedef typename Model::Head Head;
- typedef typename Model::Tail Tail;
- enum { size = (unsigned)Model::size };
+ struct list_concept: public Model {
+ typedef typename Model::cons_t cons_t;
+ typedef typename Model::head_t head_t;
+ typedef typename Model::tail_t tail_t;
+ enum: unsigned { size = (unsigned)Model::size };
#ifdef DOC_GEN
- Head head(Cons);
- Tail tail(Cons);
- Cons cons(Head, Tail);
+ head head(cons);
+ tail tail(cons);
+ cons cons(head, tail);
#else
- static_assert(((unsigned)ListModel<Tail>::Model::size+1 == size) || ((size == 0) && ((unsigned)ListModel<Tail>::Model::size == 0)),
+ static_assert(((unsigned)list_model<tail_t>::model::size+1 == size)
+ || ((size == 0) &&
+ ((unsigned)list_model<tail_t>::model::size == 0)),
"Wrong size");
- static_assert(std::is_same<decltype(head(std::declval<Cons>())),
- Head>::value,
- "head(Cons) does not return the right type");
- static_assert(std::is_same<decltype(tail(std::declval<Cons>())),
- Tail>::value,
- "tail(Cons) does not return the right type");
- static_assert(std::is_same<decltype(cons(std::declval<Head>(),
- std::declval<Tail>())),
- Cons>::value,
- "cons(Head,Teail) does not return the right type");
- typedef void Check;
+ static_assert(std::is_same<decltype(head(std::declval<cons_t>())),
+ head_t>::value,
+ "head(cons) does not return the right type");
+ static_assert(std::is_same<decltype(tail(std::declval<cons_t>())),
+ tail_t>::value,
+ "tail(cons) does not return the right type");
+ static_assert(std::is_same<decltype(cons(std::declval<head_t>(),
+ std::declval<tail_t>())),
+ cons_t>::value,
+ "cons(head,tail) does not return the right type");
+
+ typedef void check;
#endif
};
/*! \ingroup Models
*/
template <typename T>
- struct ListModel {
- typedef void NoModel;
+ struct list_model {
+ typedef void no_model;
};
/*! \ingroup Models
*/
template <typename H, typename T>
- struct ListModel<ListCons<H, T> > {
- struct Model {
- typedef ListCons<H, T> Cons;
- typedef H Head;
- typedef T Tail;
- enum : unsigned { size = ListCons<H, T>::size };
+ struct list_model<list_cons<H, T> > {
+ struct model {
+ typedef list_cons<H, T> cons_t;
+ typedef H head_t;
+ typedef T tail_t;
+ enum : unsigned { size = list_cons<H, T>::size };
};
};
/*! \ingroup Models
*/
template <>
- struct ListModel<ListNil> {
- struct Model {
- typedef ListNil Cons;
- typedef void Head;
- typedef ListNil Tail;
- enum : unsigned { size = ListNil::size };
+ struct list_model<list_nil> {
+ struct model {
+ typedef list_nil cons;
+ typedef void head;
+ typedef list_nil tail;
+ enum : unsigned { size = list_nil::size };
};
};
template <template <typename> class Predicate,
typename T,
- typename M = typename aurelia::ListModel<T>::Model,
- bool = std::is_same<void, typename M::Head>::value,
- bool = Predicate<typename M::Head>::value>
- struct AllElements: public std::false_type {
+ typename M = typename aurelia::list_model<T>::model,
+ bool = std::is_same<void, typename M::head_t>::value,
+ bool = Predicate<typename M::head_t>::value>
+ struct all_elements: public std::false_type {
};
template <template <typename> class Predicate,
typename T, typename M, bool whatever>
- struct AllElements<Predicate, T, M, true, whatever>
- : public AllElements<Predicate, typename M::Tail> {
+ struct all_elements<Predicate, T, M, true, whatever>
+ : public all_elements<Predicate, typename M::tail_t> {
};
template <template <typename> class Predicate,
typename T, typename M>
- struct AllElements<Predicate, T, M, false, true>: public std::true_type {
+ struct all_elements<Predicate, T, M, false, true>: public std::true_type {
};
}
Modified: trunk/src/lists/listable.hh
===================================================================
--- trunk/src/lists/listable.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/lists/listable.hh 2010-10-29 19:10:34 UTC (rev 143)
@@ -23,30 +23,32 @@
namespace aurelia {
template <typename Model>
- struct ListableConcept: public Model {
+ struct listable_concept: public Model {
public:
- typedef typename Model::Type Type;
+ typedef typename Model::type type;
};
template <typename T>
- struct ListableModel {
- typedef void NoModel;
+ struct listable_model {
+ typedef void no_model;
};
}
template <typename H, typename T,
- typename = typename aurelia::ListableModel<H>::Model,
- typename = typename aurelia::ListModel<T>::Model>
-aurelia::ListCons<H,T> operator,(const T& t, const H& h) {
- return aurelia::ListCons<H,T>(h, t);
+ typename = typename aurelia::listable_model<H>::model,
+ typename = typename aurelia::list_model<T>::model>
+aurelia::list_cons<H,T> operator,(const T& t, const H& h) {
+ return aurelia::list_cons<H,T>(h, t);
}
template <typename H, typename T,
- typename = typename aurelia::ListableModel<H>::Model,
- typename = typename aurelia::ListableModel<T>::Model>
-aurelia::ListCons<H,aurelia::ListCons<T,aurelia::ListNil> > operator,(const T& t, const H& h) {
- return aurelia::ListCons<H,aurelia::ListCons<T,aurelia::ListNil> >(h, aurelia::ListCons<T,aurelia::ListNil>(t, aurelia::ListNil()));
+ typename = typename aurelia::listable_model<H>::model,
+ typename = typename aurelia::listable_model<T>::model>
+aurelia::list_cons<H,aurelia::list_cons<T,aurelia::list_nil> >
+operator,(const T& t, const H& h) {
+ return aurelia::list_cons<H,aurelia::list_cons<T,aurelia::list_nil> >
+ (h, aurelia::list_cons<T,aurelia::list_nil>(t, aurelia::list_nil()));
}
#endif
Modified: trunk/src/lists/tests/test_listable.cc
===================================================================
--- trunk/src/lists/tests/test_listable.cc 2010-10-26 14:59:54 UTC (rev 142)
+++ trunk/src/lists/tests/test_listable.cc 2010-10-29 19:10:34 UTC (rev 143)
@@ -38,9 +38,9 @@
namespace aurelia {
template <>
- struct ListableModel<Foo> {
- struct Model {
- typedef Foo Type;
+ struct listable_model<Foo> {
+ struct model {
+ typedef Foo type;
};
};
}
@@ -64,23 +64,25 @@
namespace aurelia {
template <>
- struct ListableModel<Bar> {
- struct Model {
- typedef Bar Type;
+ struct listable_model<Bar> {
+ struct model {
+ typedef Bar type;
};
};
}
static
-int p(const ListNil&) {
+int p(const list_nil&) {
return 0;
}
-template <typename T, typename M = typename aurelia::ListModel<T>::Model,
- typename = typename std::enable_if<!std::is_same<void, typename M::Head>::value>::type>
+template <typename T,
+ typename M = typename aurelia::list_model<T>::model,
+ typename = typename
+ std::enable_if<!std::is_same<void, typename M::head_t>::value>::type>
static
int p(const T& l) {
- typedef typename aurelia::ListConcept<M>::Check require;
+ typedef typename aurelia::list_concept<M>::check require;
return p(tail(l)) + head(l);
}
Modified: trunk/src/llstack/frame.hh
===================================================================
--- trunk/src/llstack/frame.hh 2010-10-26 14:59:54 UTC (rev 142)
+++ tru...
[truncated message content] |
|
From: <val...@us...> - 2010-10-26 15:00:02
|
Revision: 142
http://aurelia.svn.sourceforge.net/aurelia/?rev=142&view=rev
Author: valentindavid
Date: 2010-10-26 14:59:54 +0000 (Tue, 26 Oct 2010)
Log Message:
-----------
2010-10-26 Valentin David <val...@ii...>
Add support for hashing tuples from standard library.
* src/hash/tuple_hash.hh, src/hash/tests/test_tuple_hash.cc,
* src/hash/tests/Makefile.am:
New.
* src/hash/mhash.hh: Fix includes.
* src/hash/Makefile.am, configure.ac: Update.
Modified Paths:
--------------
trunk/ChangeLog
trunk/configure.ac
trunk/src/hash/Makefile.am
trunk/src/hash/mhash.hh
Added Paths:
-----------
trunk/src/hash/tests/
trunk/src/hash/tests/Makefile.am
trunk/src/hash/tests/test_tuple_hash.cc
trunk/src/hash/tuple_hash.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-23 16:58:32 UTC (rev 141)
+++ trunk/ChangeLog 2010-10-26 14:59:54 UTC (rev 142)
@@ -1,3 +1,15 @@
+2010-10-26 Valentin David <val...@ii...>
+
+ Add support for hashing tuples from standard library.
+
+ * src/hash/tuple_hash.hh, src/hash/tests/test_tuple_hash.cc,
+ * src/hash/tests/Makefile.am:
+ New.
+
+ * src/hash/mhash.hh: Fix includes.
+
+ * src/hash/Makefile.am, configure.ac: Update.
+
2010-10-23 Valentin David <val...@ii...>
Get rid of deprecated SharedObject.
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-10-23 16:58:32 UTC (rev 141)
+++ trunk/configure.ac 2010-10-26 14:59:54 UTC (rev 142)
@@ -165,6 +165,7 @@
src/lockfree/tests/Makefile
src/max_shared/Makefile
src/hash/Makefile
+ src/hash/tests/Makefile
src/memory/Makefile
src/memory/tests/Makefile
src/lists/Makefile
Modified: trunk/src/hash/Makefile.am
===================================================================
--- trunk/src/hash/Makefile.am 2010-10-23 16:58:32 UTC (rev 141)
+++ trunk/src/hash/Makefile.am 2010-10-26 14:59:54 UTC (rev 142)
@@ -17,4 +17,7 @@
hashdir=$(aureliadir)/hash
hash_HEADERS= \
- mhash.hh
+ mhash.hh \
+ tuple_hash.hh
+
+SUBDIRS=tests
Modified: trunk/src/hash/mhash.hh
===================================================================
--- trunk/src/hash/mhash.hh 2010-10-23 16:58:32 UTC (rev 141)
+++ trunk/src/hash/mhash.hh 2010-10-26 14:59:54 UTC (rev 142)
@@ -18,6 +18,7 @@
# define __MHASH_HH
# include "../type_traits/has_member_hash.hh"
+# include <functional>
namespace aurelia {
Property changes on: trunk/src/hash/tests
___________________________________________________________________
Added: svn:ignore
+ Makefile.in
test-suite.log
.deps
test_tuple_hash
test_tuple_hash.log
Makefile
Added: trunk/src/hash/tests/Makefile.am
===================================================================
--- trunk/src/hash/tests/Makefile.am (rev 0)
+++ trunk/src/hash/tests/Makefile.am 2010-10-26 14:59:54 UTC (rev 142)
@@ -0,0 +1,22 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+check_PROGRAMS=test_tuple_hash
+
+test_tuple_hash_SOURCES=test_tuple_hash.cc
+
+TESTS=$(check_PROGRAMS)
Added: trunk/src/hash/tests/test_tuple_hash.cc
===================================================================
--- trunk/src/hash/tests/test_tuple_hash.cc (rev 0)
+++ trunk/src/hash/tests/test_tuple_hash.cc 2010-10-26 14:59:54 UTC (rev 142)
@@ -0,0 +1,29 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include "../tuple_hash.hh"
+
+int main() {
+ typedef std::tuple<int, int, int> t;
+ t a(1, 2, 3);
+ t b(3, 2, 1);
+ std::hash<t> h;
+
+ if (h(a) == h(b))
+ return 1;
+
+ return 0;
+}
Added: trunk/src/hash/tuple_hash.hh
===================================================================
--- trunk/src/hash/tuple_hash.hh (rev 0)
+++ trunk/src/hash/tuple_hash.hh 2010-10-26 14:59:54 UTC (rev 142)
@@ -0,0 +1,58 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __TUPLE_HASH_HH
+# define __TUPLE_HASH_HH
+
+# include <tuple>
+# include "mhash.hh"
+
+namespace aurelia {
+ template <typename T, size_t N = 0>
+ struct get_hash {
+ };
+
+ template <typename... T, size_t N>
+ struct get_hash<std::tuple<T...>, N> {
+ static void make(size_t& hash, const std::tuple<T...>& t) {
+ get_hash<std::tuple<T...>, N-1>::make(hash, t);
+ hash = (hash << 11) | (hash >> 21);
+ hash ^= mhash<typename std::tuple_element<N, std::tuple<T...> >::type>()
+ (std::get<N>(t));
+ }
+ };
+
+ template <typename... T>
+ struct get_hash<std::tuple<T...>, 0> {
+ static void make(size_t& hash, const std::tuple<T...>& t) {
+ hash = mhash<typename std::tuple_element<0, std::tuple<T...> >::type>()
+ (std::get<0>(t));
+ }
+ };
+}
+
+namespace std {
+ template <typename... T>
+ struct hash<tuple<T...> >: public unary_function<tuple<T...>, size_t> {
+ size_t operator()(const tuple<T...>& t) const {
+ size_t hash = 0;
+ aurelia::get_hash<tuple<T...>, tuple_size<tuple<T...> >::value-1>::make(hash, t);
+ return hash;
+ }
+ };
+}
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-23 16:58:39
|
Revision: 141
http://aurelia.svn.sourceforge.net/aurelia/?rev=141&view=rev
Author: valentindavid
Date: 2010-10-23 16:58:32 +0000 (Sat, 23 Oct 2010)
Log Message:
-----------
2010-10-23 Valentin David <val...@ii...>
Get rid of deprecated SharedObject.
* src/lockfree/unordered_set.hh:
Fix move. Add assertions on inverted hash. Remember size of the
set.
* src/lockfree/sorted_forward_list.hh:
Return success boolean for erase methods.
* src/terms/shared_object.hh: Remove.
* src/terms/Makefile.am: Update.
* src/llstack/tests/example.hh:
Fix includes.
* src/llstack/queue.hh: Fix swap (use C++0x style).
* src/llstack/node.hh, src/llstack/node.hpp:
Use max_shared_ptr.
* src/llstack/frame.hh, src/llstack/label.hh:
Add default constructors.
* src/max_shared/max_shared_ptr.hh:
Add protected functionalities for LL stack nodes.
* demos/13-constructors-with-typed-terms.cc:
Use max_shared_ptr.
Modified Paths:
--------------
trunk/ChangeLog
trunk/demos/13-constructors-with-typed-terms.cc
trunk/src/llstack/frame.hh
trunk/src/llstack/label.hh
trunk/src/llstack/node.hh
trunk/src/llstack/node.hpp
trunk/src/llstack/queue.hh
trunk/src/llstack/tests/example.hh
trunk/src/lockfree/sorted_forward_list.hh
trunk/src/lockfree/unordered_set.hh
trunk/src/max_shared/max_shared_ptr.hh
trunk/src/terms/Makefile.am
Removed Paths:
-------------
trunk/src/terms/shared_object.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/ChangeLog 2010-10-23 16:58:32 UTC (rev 141)
@@ -1,3 +1,34 @@
+2010-10-23 Valentin David <val...@ii...>
+
+ Get rid of deprecated SharedObject.
+
+ * src/lockfree/unordered_set.hh:
+ Fix move. Add assertions on inverted hash. Remember size of the
+ set.
+
+ * src/lockfree/sorted_forward_list.hh:
+ Return success boolean for erase methods.
+
+ * src/terms/shared_object.hh: Remove.
+ * src/terms/Makefile.am: Update.
+
+ * src/llstack/tests/example.hh:
+ Fix includes.
+
+ * src/llstack/queue.hh: Fix swap (use C++0x style).
+
+ * src/llstack/node.hh, src/llstack/node.hpp:
+ Use max_shared_ptr.
+
+ * src/llstack/frame.hh, src/llstack/label.hh:
+ Add default constructors.
+
+ * src/max_shared/max_shared_ptr.hh:
+ Add protected functionalities for LL stack nodes.
+
+ * demos/13-constructors-with-typed-terms.cc:
+ Use max_shared_ptr.
+
2010-10-21 Valentin David <val...@ii...>
* src/fast/tests/test_invert_bits.cc,
Modified: trunk/demos/13-constructors-with-typed-terms.cc
===================================================================
--- trunk/demos/13-constructors-with-typed-terms.cc 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/demos/13-constructors-with-typed-terms.cc 2010-10-23 16:58:32 UTC (rev 141)
@@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <terms/shared_object.hh>
+#include <max_shared/max_shared_ptr.hh>
#include <strategies/failure.hh>
#include <string>
#include <iostream>
@@ -28,6 +28,8 @@
unsigned _hash;
public:
+ StringCore(): _hash(0) {}
+
StringCore(const std::string& s): s(s) {
_hash = std::hash<std::string>()(s);
}
@@ -42,24 +44,14 @@
};
template <typename Pool>
-struct String;
-
-namespace aurelia {
-template <typename Pool>
-struct CoreTypeOf<String<Pool> > {
- typedef StringCore res;
-};
-}
-
-template <typename Pool>
-struct String: public SharedObject<String<Pool> > {
+struct String: public aurelia::max_shared_ptr<StringCore> {
public:
- typedef SharedObject<String<Pool> > super;
+ typedef aurelia::max_shared_ptr<StringCore> super;
String(const std::string& s): super(StringCore(s)) {
}
- String(): super(NoBuild()) {}
+ String() = default;
};
template <typename Pool>
@@ -70,8 +62,10 @@
unsigned _hash;
public:
+ IntAndStringCore(): _hash(0) {}
+
IntAndStringCore(int i, const String<Pool>& s): i(i), s(s) {
- _hash = s.hash() + i;
+ _hash = s->hash() + i;
}
unsigned hash() const {
@@ -92,31 +86,21 @@
};
template <typename Pool>
-struct IntAndString;
-
-namespace aurelia {
-template <typename Pool>
-struct CoreTypeOf<IntAndString<Pool> > {
- typedef IntAndStringCore<Pool> res;
-};
-}
-
-template <typename Pool>
-struct IntAndString: public SharedObject<IntAndString<Pool> > {
+struct IntAndString: public aurelia::max_shared_ptr<IntAndStringCore<Pool> > {
public:
- typedef SharedObject<IntAndString<Pool> > super;
+ typedef aurelia::max_shared_ptr<IntAndStringCore<Pool> > super;
IntAndString(int i, const String<Pool>& s): super(IntAndStringCore<Pool>(i, s)) {
}
- IntAndString(): super(NoBuild()) {}
+ IntAndString() = default;
int get_i() const {
- return this->get().get_i();
+ return (*this)->get_i();
}
String<Pool> get_s() const {
- return this->get().get_s();
+ return (*this)->get_s();
}
};
@@ -257,7 +241,7 @@
IntVar<Main> Y;
int_and_string(Y, StringVar<Main>("foo")) = e;
-
+
std::cout << *Y << std::endl;
return 0;
Modified: trunk/src/llstack/frame.hh
===================================================================
--- trunk/src/llstack/frame.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/frame.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -18,6 +18,8 @@
#ifndef FRAME_HH
# define FRAME_HH
+# include "../memory/pool_allocator.hh"
+
namespace aurelia {
namespace llstack {
@@ -82,9 +84,12 @@
frame(const real_frame& rf): rf(rf.clone()), _hash(rf.hash()) {}
frame(const frame& other): rf(other.rf), _hash(other._hash) {}
- frame(frame&& other): rf(other.rf), _hash(other._hash) {
+ frame(frame&& other): rf(std::move(other.rf)), _hash(std::move(other._hash)) {
}
+ frame(): rf(), _hash(0) {
+ }
+
frame& operator=(const frame& other) {
return *this = frame(other);
}
Modified: trunk/src/llstack/label.hh
===================================================================
--- trunk/src/llstack/label.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/label.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -39,6 +39,11 @@
label(const label& other): fun(other.fun), type(other.type) {
}
+ label(label&& other): fun(std::move(other.fun)), type(other.type) {}
+
+ label() {
+ }
+
void call(R_t& R, const frame& f, stream& s, const node& n) const {
fun(R, f, s, n);
}
@@ -47,9 +52,14 @@
return type;
}
- void swap(label& other) {
+ label& operator=(const label& other) {
+ return *this = label(other);
+ }
+
+ label& operator=(label&& other) {
std::swap(fun, other.fun);
std::swap(type, other.type);
+ return *this;
}
bool operator==(const label& other) const {
Modified: trunk/src/llstack/node.hh
===================================================================
--- trunk/src/llstack/node.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/node.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -23,7 +23,7 @@
# include <map>
# include <unordered_set>
# include <forward_list>
-# include "../terms/shared_object.hh"
+# include "../max_shared/max_shared_ptr.hh"
# include "../streams/buf_stream.hh"
# include "../memory/pool_allocator.hh"
# include "label.hh"
@@ -79,6 +79,30 @@
_hash = other._hash;
}
+ node_core(node_core&& other): L(std::move(other.L)),
+ f(std::move(other.f)),
+ pos(other.pos),
+ _hash(other._hash) {
+ }
+
+ node_core& operator=(const node_core& other) {
+ return *this = node_core(other);
+ }
+
+ node_core& operator=(node_core&& other) {
+ std::swap(L, other.L);
+ std::swap(f, other.f);
+ std::swap(pos, other.pos);
+ std::swap(P, other.P);
+ std::swap(parents, other.parents);
+ std::swap(_hash, other._hash);
+ return *this;
+ }
+
+ node_core() {
+ _hash = 0;
+ }
+
unsigned hash() const {
return _hash;
}
@@ -124,49 +148,40 @@
}
};
-struct node;
-
- }
-template <>
-struct CoreTypeOf<llstack::node> {
- typedef llstack::node_core res;
-};
- namespace llstack {
-
-struct node: public SharedObject<node> {
+struct node: public max_shared_ptr<node_core> {
private:
- typedef SharedObject<node> super;
+ typedef max_shared_ptr<node_core> super;
- node(RealObject* ro): super(NoBuild()) {
- this->o = ro;
- this->o->inc();
+ explicit node(const typename super::set_t::iterator& other): super(other) {
}
- node(const label& l, const frame& f, int s): super(NoBuild()) {
- node_core tmp(l, f, s);
- new (static_cast<super*>(this)) super(tmp);
+ node(const label& l, const frame& f, int s): super(l, f, s) {
}
+ node(const label& l, frame&& f, int s): super(l, std::move(f), s) {
+ }
public:
- node(): super(NoBuild()) {
- }
+ node() = default;
node(const node& other): super(other) {
}
+ node(node&& other): super(std::move(other)) {
+ }
+
const node_core::node_set_t& parents() const {
- return this->get().get_parents();
+ return (*this)->get_parents();
}
node_core::node_set_t& parents() {
- return this->get().get_parents();
+ return const_cast<node_core*>(&**this)->get_parents();
}
const node_core::p_t& P() const {
- return this->get().get_P();
+ return (*this)->get_P();
}
node_core::p_t& P() {
- return this->get().get_P();
+ return const_cast<node_core*>(&**this)->get_P();
}
static node create(R_t& R, const label& l, const frame& f, const node& u,
@@ -175,30 +190,35 @@
static node boundary(const label&, const stream& s);
unsigned hash() const {
- return this->get().hash();
+ return (*this)->hash();
}
const label& get_label() const {
- return this->get().get_label();
+ return (*this)->get_label();
}
int pos() const {
- return this->get().get_pos();
+ return (*this)->get_pos();
}
node& operator=(const node& other) {
- return super::operator=(other);
+ return *this = node(other);
}
+ node& operator=(node&& other) {
+ super::operator=(std::move(other));
+ return *this;
+ }
+
static void drop(const stream& s) {
- super::o_map_it i = super::objects().begin();
- while (i != super::objects().end()) {
- super::RealObject* ro = const_cast<super::RealObject*>(&*i);
- ro->refs++;
- ro->data()->drop(s);
- ro->refs--;
- ro->destroy();
- i++;
+ super::set_t::iterator i = super::set().begin();
+ while (i != super::set().end()) {
+ super::Ptr& ro = *const_cast<super::Ptr*>(&*i);
+ ++ro.count();
+ const_cast<node_core*>(&*ro)->drop(s);
+ ++i;
+ if (0 == --ro.count())
+ set().erase(ro);
}
}
@@ -207,40 +227,40 @@
marks.insert(*this);
if (j.second) {
for (node_core::node_set_t::const_iterator i =
- this->get().get_parents().begin();
- i != this->get().get_parents().end(); ++i) {
+ parents().begin();
+ i != parents().end(); ++i) {
(*i).mark(marks);
}
}
}
static int nbnode() {
- return super::objects().size();
+ return super::set().size();
}
# ifndef NDEBUG
static void printnodes(std::ostream& o) {
//int status;
- super::o_map_it i = super::objects().begin();
+ super::set_t::iterator i = super::set().begin();
o << "digraph g {" << std::endl;
- while (i != super::objects().end()) {
- super::RealObject* ro = const_cast<super::RealObject*>(&*i);
+ while (i != super::set().end()) {
+ super::Ptr& ro = *const_cast<super::Ptr*>(&*i);
- o << "n_" << ro->data()->get_label().hash()
- << "_" << ro->data()->get_pos() << " [label=\""
- << ro->data()->get_label().hash()
- << ", " << ro->data()->get_pos() << "\"];" << std::endl;
+ o << "n_" << (*ro).get_label().hash()
+ << "_" << (*ro).get_pos() << " [label=\""
+ << (*ro).get_label().hash()
+ << ", " << (*ro).get_pos() << "\"];" << std::endl;
++i;
}
- i = super::objects().begin();
- while (i != super::objects().end()) {
- super::RealObject* ro = const_cast<super::RealObject*>(&*i);
+ i = super::set().begin();
+ while (i != super::set().end()) {
+ super::Ptr& ro = *const_cast<super::Ptr*>(&*i);
for (node_core::node_set_t::const_iterator j =
- ro->data()->get_parents().begin();
- j != ro->data()->get_parents().end(); ++j) {
- o << "n_" << (ro->data()->get_label().hash())
- << "_" << ro->data()->get_pos() << " -> " << "n_"
+ (*ro).get_parents().begin();
+ j != (*ro).get_parents().end(); ++j) {
+ o << "n_" << ((*ro).get_label().hash())
+ << "_" << (*ro).get_pos() << " -> " << "n_"
<< ((*j).get_label()).hash() << "_"
<< (*j).pos() << ";" << std::endl;
}
@@ -252,18 +272,18 @@
static void clear(std::unordered_set<node, std::hash<node>, std::equal_to<node>, pool_allocator<node> > marks
= std::unordered_set<node, std::hash<node>, std::equal_to<node>, pool_allocator<node> >()) {
- super::o_map_it i = super::objects().begin();
- while (i != super::objects().end()) {
- if (marks.find(node(const_cast<super::RealObject*>(&*i)))
+ super::set_t::iterator i = super::set().begin();
+ while (i != super::set().end()) {
+ if (marks.find(node(i))
== marks.end()) {
- super::RealObject* ro = const_cast<super::RealObject*>(&*i);
- ro->data()->get_P().clear();
- if (!(ro->data()->get_parents().empty())) {
- ro->refs++;
- ro->data()->get_parents().clear();
- ro->refs--;
- ro->destroy();
- i = super::objects().begin();
+ super::Ptr& ro = *const_cast<super::Ptr*>(&*i);
+ const_cast<node_core*>(&*ro)->get_P().clear();
+ if (!((*ro).get_parents().empty())) {
+ ++ro.count();
+ const_cast<node_core*>(&*ro)->get_parents().clear();
+ --ro.count();
+ set().erase(ro);
+ i = super::set().begin();
}
else {
i++;
Modified: trunk/src/llstack/node.hpp
===================================================================
--- trunk/src/llstack/node.hpp 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/node.hpp 2010-10-23 16:58:32 UTC (rev 141)
@@ -18,6 +18,8 @@
#ifndef __NODE_HPP
# define __NODE_HPP
+# include "queue.hh"
+
namespace std {
unsigned
hash<aurelia::llstack::node>::operator()(const aurelia::llstack::node& a)
@@ -66,23 +68,23 @@
}
void node::pop(R_t& queue, const VoidReturn&, stream& j) {
- this->P()[j].push_front(get().get_frame());
+ this->P()[j].push_front((*this)->get_frame());
switch (this->parents().size()) {
case 0:
return ;
case 1:
- this->get_label().call(queue, get().get_frame(), j, *(this->parents().begin()));
+ this->get_label().call(queue, (*this)->get_frame(), j, *(this->parents().begin()));
return ;
}
for (node_core::node_set_t::iterator i = this->parents().begin();
i != this->parents().end(); ++i) {
- queue.add(this->get_label(), get().get_frame(), *i, j);
+ queue.add(this->get_label(), (*this)->get_frame(), *i, j);
}
}
template <typename Ret>
void node::pop(R_t& queue, const Ret& ret_val, stream& j) {
- ret_frame<Ret> ret(get().get_frame(), ret_val);
+ ret_frame<Ret> ret((*this)->get_frame(), ret_val);
this->P()[j].push_front(ret);
switch (this->parents().size()) {
case 0:
@@ -91,6 +93,7 @@
this->get_label().call(queue, ret, j, *(this->parents().begin()));
return ;
}
+
for (node_core::node_set_t::iterator i = this->parents().begin();
i != this->parents().end(); ++i) {
queue.add(this->get_label(), ret, *i, j);
Modified: trunk/src/llstack/queue.hh
===================================================================
--- trunk/src/llstack/queue.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/queue.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -46,15 +46,15 @@
}
- ln& operator=(ln other) {
- this->swap(&other);
- return *this;
+ ln& operator=(const ln& other) {
+ return *this = ln(other);
}
- void swap(ln* other) {
- this->first.swap(other->first);
- this->second.swap(other->second);
- std::swap(_hash, other->_hash);
+ ln& operator=(ln&& other) {
+ std::swap(this->first, other.first);
+ std::swap(this->second, other.second);
+ std::swap(_hash, other._hash);
+ return *this;
}
};
Modified: trunk/src/llstack/tests/example.hh
===================================================================
--- trunk/src/llstack/tests/example.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/llstack/tests/example.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -19,7 +19,6 @@
#include <iostream>
#include <map>
#include <streams/buf_stream.hh>
-#include <terms/shared_object.hh>
#include <llstack/label.hh>
#include <llstack/node.hh>
#include <llstack/queue.hh>
@@ -320,7 +319,6 @@
try {
while (true) {
descriptor d = R.pop();
- //std::cerr << s.get_pos() << " " << typeid(*(d.L)).name() << ":" << d.s.get_pos() << std::endl;
s = d.s;
d.L.call(R, d.f, d.s, d.n);
}
Modified: trunk/src/lockfree/sorted_forward_list.hh
===================================================================
--- trunk/src/lockfree/sorted_forward_list.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/lockfree/sorted_forward_list.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -265,14 +265,14 @@
}
}
- void erase(node_base* item, node_base* hint) {
+ bool erase(node_base* item, node_base* hint) {
std::pair<node_base*, node_base*> found;
node_base* next;
while (true) {
found = search(hint, **item, item);
if ((found.second == NULL)?true:(found.second != item)) {
- return ;
+ return false;
}
next = found.second->get_next();
if (!details::is_marked(next))
@@ -285,9 +285,10 @@
free.push(static_cast<node*>(found.second));
if (!found.first->set_next(found.second, next))
search(hint, **found.second);
+ return true;
}
- void erase(const Elt& item, node_base* hint) {
+ bool erase(const Elt& item, node_base* hint) {
static_assert(!Multi::value, "Cannot erase elements on multilists");
std::pair<node_base*, node_base*> found;
node_base* next;
@@ -304,9 +305,10 @@
}
}
if (found.first->set_next(found.second, next)) {
- _size--;
+ --_size;
node_alloc.destroy(static_cast<node*>(found.second));
free.push(static_cast<node*>(found.second));
+ return true;
}
else {
search(hint, **found.second);
@@ -315,22 +317,22 @@
public:
- void erase(const Elt& elt) {
+ bool erase(const Elt& elt) {
static_assert(!Multi::value, "Cannot erase elements on multilists");
- erase(elt, &head);
+ return erase(elt, &head);
}
- void erase(const Elt& elt, const const_iterator& hint) {
+ bool erase(const Elt& elt, const const_iterator& hint) {
static_assert(!Multi::value, "Cannot erase elements on multilists");
- erase(elt, hint.get_node());
+ return erase(elt, hint.get_node());
}
- void erase(const const_iterator& it, const const_iterator& hint) {
- erase(it.get_node(), hint.get_node());
+ bool erase(const const_iterator& it, const const_iterator& hint) {
+ return erase(it.get_node(), hint.get_node());
}
- void erase(const iterator& it) {
- erase(it.get_node(), &head);
+ bool erase(const iterator& it) {
+ return erase(it.get_node(), &head);
}
private:
Modified: trunk/src/lockfree/unordered_set.hh
===================================================================
--- trunk/src/lockfree/unordered_set.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/lockfree/unordered_set.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -52,23 +52,33 @@
return elt();
}
elts(size_t _invhash, T&& elt): _invhash(_invhash) {
+ assert(_invhash & 0x1);
new (reinterpret_cast<T*>(&_elt)) T(std::move(elt));
}
elts(size_t _invhash): _invhash(_invhash) {
+ assert(!(_invhash & 0x1));
}
elts() = delete;
elts(const elts&) = delete;
- elts(elts&& other): _invhash(0) {
+ elts(elts&& other): _invhash(other._invhash) {
if (other._invhash & 0x1) {
new (reinterpret_cast<T*>(&_elt)) T(std::move(other.elt()));
}
- std::swap(_invhash, other._invhash);
}
elts& operator=(const elts&) = delete;
elts& operator=(elts&& other) {
- std::swap(_elt, other._elt);
+ if (_invhash & 0x1) {
+ if (other._invhash & 0x1)
+ std::swap(*reinterpret_cast<T*>(&_elt), *reinterpret_cast<T*>(&other._elt));
+ else
+ new (reinterpret_cast<T*>(&other._elt)) T(std::move(elt()));
+ }
+ else {
+ if (!(other._invhash & 0x1))
+ new (reinterpret_cast<T*>(&_elt)) T(std::move(other.elt()));
+ }
std::swap(_invhash, other._invhash);
return *this;
}
@@ -116,6 +126,8 @@
list_t list;
entries_t entries;
+ std::atomic<size_t> _size;
+
public:
unordered_set(Hash hash = Hash(), Eq eq = Eq(), Alloc alloc = Alloc()):
max_load_factor(.3),
@@ -123,6 +135,7 @@
alloc), entries(list.end(), alloc) {
entries.resize(1);
entries[0x0] = list.insert(elts(0x0)).first;
+ _size.store(0);
}
private:
@@ -149,6 +162,7 @@
public:
~unordered_set() {
+ clear();
while (collect()) ;
}
@@ -235,8 +249,8 @@
std::pair<typename list_t::const_iterator,bool> ret =
list.insert_after(std::move(toinsert), i);
if (ret.second) {
+ size_t nelts = ++_size;
size_t size = entries.size();
- size_t nelts = list.size();
if ((((double)nelts) / size) > max_load_factor) {
entries.resize(2*size);
}
@@ -247,6 +261,10 @@
return std::pair<iterator,bool>(iterator(ret.first),ret.second);
}
+ size_t size() const {
+ return _size.load();
+ }
+
bool collect() {
entries.collect();
return list.collect();
@@ -264,7 +282,8 @@
size_t h = (*j).invhash();
fast::invert_bits(h);
typename list_t::const_iterator b = get_bucket(h);
- list.erase(j, b);
+ if (list.erase(j, b))
+ --_size;
}
};
}
Modified: trunk/src/max_shared/max_shared_ptr.hh
===================================================================
--- trunk/src/max_shared/max_shared_ptr.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/max_shared/max_shared_ptr.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -36,12 +36,11 @@
typename EqnFunc = std::equal_to<T>,
typename Alloc = std::allocator<T> >
struct max_shared_ptr {
- private:
+ protected:
struct Ptr;
typedef lockfree::unordered_set<Ptr, deref_op<Hash>,
deref_op<EqnFunc>,
Alloc> set_t;
-
struct Ptr {
public:
std::atomic<long>& count() const {
@@ -63,6 +62,7 @@
//cleanup of allocators.
_set.insert(Ptr(T()));
_set.clear();
+ while (_set.collect()) ;
atexit(collect);
}
@@ -113,6 +113,7 @@
}
}
};
+ private:
typename set_t::iterator _ptr;
@@ -129,11 +130,18 @@
}
};
+ protected:
static set_t& set() {
static init_set _set;
return _set._set;
}
+ protected:
+ explicit max_shared_ptr(const typename set_t::iterator& other)
+ : _ptr(other) {
+ ++((*_ptr).count());
+ }
+
public:
~max_shared_ptr() {
if (_ptr == set().end())
Modified: trunk/src/terms/Makefile.am
===================================================================
--- trunk/src/terms/Makefile.am 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/terms/Makefile.am 2010-10-23 16:58:32 UTC (rev 141)
@@ -19,5 +19,4 @@
terms_HEADERS= \
term.hh \
constructor.hh \
- baf_read.hh \
- shared_object.hh
+ baf_read.hh
Deleted: trunk/src/terms/shared_object.hh
===================================================================
--- trunk/src/terms/shared_object.hh 2010-10-21 18:46:00 UTC (rev 140)
+++ trunk/src/terms/shared_object.hh 2010-10-23 16:58:32 UTC (rev 141)
@@ -1,327 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __SHARED_OBJECTS_HH
-# define __SHARED_OBJECTS_HH
-
-/*! \file
- * \brief Generic shared objects
- */
-
-# include <mutex>
-# include "../memory/pool_allocator.hh"
-# include <unordered_set>
-
-namespace aurelia {
-
-struct NoLock {
-public:
- void lock() const {
- }
-
- void unlock() const {
- }
-};
-
-//! \brief Type traits for selecting core type of shared objects
-template <typename T>
-struct CoreTypeOf {};
-
-struct NoBuild {};
-
-struct True {};
-struct False {};
-
-//! \brief Type traits for activating thread locks on shared objects
-template <typename T>
-struct ThreadSafe {
- typedef False res;
-};
-
-template <typename T>
-struct SOLock {
- typedef NoLock res;
-};
-
-template <>
-struct SOLock<True> {
- typedef std::mutex res;
-};
-
-template <typename HasLock>
-struct VirtualRealObject {
-public:
- int refs;
- void *vdata;
- typename SOLock<HasLock>::res ref_lock;
- virtual void destroy() = 0;
- void inc() {
- ref_lock.lock();
- refs++;
- ref_lock.unlock();
- }
-
- VirtualRealObject(): refs(0) {}
-};
-
-template <typename T>
-struct SharedObject;
-
-template <typename HasLock>
-struct VirtualSharedObject {
-protected:
- VirtualRealObject<HasLock> *o;
-
-public:
- VirtualSharedObject(const NoBuild&): o(NULL) {}
-
- VirtualRealObject<HasLock> *get_o() const {
- return o;
- }
-
- VirtualSharedObject(const VirtualSharedObject& other)
- : o(other.o) {
- if (o != NULL) {
- o->inc();
- }
- }
-
- template <typename T>
- VirtualSharedObject(const SharedObject<T>& other)
- : o(other.o) {
- if (o != NULL) {
- o->inc();
- }
- }
-
- ~VirtualSharedObject() {
- if (o == NULL)
- return ;
- o->ref_lock.lock();
- o->refs--;
- if (o->refs == 0) {
- o->ref_lock.unlock();
- o->destroy();
- o = NULL;
- return ;
- }
- o->ref_lock.unlock();
- o = NULL;
- }
-
-public:
- bool operator==(const VirtualSharedObject& other) const {
- return o == other.o;
- }
-
- bool operator!=(const VirtualSharedObject& other) const {
- return !(o == other.o);
- }
-
- void swap(VirtualSharedObject<HasLock>& so) {
- VirtualRealObject<HasLock> *a = o;
- o = so.o;
- so.o = a;
- }
-};
-
-template <typename T>
-struct SharedObject {
- friend class VirtualSharedObject<typename ThreadSafe<T>::res>;
-private:
- typedef typename SOLock<typename ThreadSafe<T>::res>::res Lock;
-public:
- struct RealObject;
-private:
- typedef typename CoreTypeOf<T>::res core_type;
-
- struct ROeq {
- bool operator()(const RealObject& a, const RealObject& b) const {
- return *a.data() == *b.data();
- }
- };
-
- struct ROhash {
- unsigned operator()(const RealObject& a) const {
- return a.data()->hash();
- }
- };
-
-protected:
- typedef std::unordered_set<RealObject, ROhash, ROeq, pool_allocator<RealObject> > o_map;
- typedef typename o_map::iterator o_map_it;
-
- static Lock& map_lock() {
- static Lock l;
- return l;
- }
-
- static o_map& objects() {
- static o_map o;
- return o;
- }
-
-public:
-
- struct RealObject
- : public VirtualRealObject<typename ThreadSafe<T>::res> {
- public:
- void set_data(core_type *d) {
- this->vdata = (void*)d;
- }
- core_type *data() {
- return (core_type*)(this->vdata);
- }
- const core_type *data() const {
- return (const core_type*)(this->vdata);
- }
-
- private:
- char realdata[sizeof(core_type)]
- __attribute__ ((aligned (__alignof__(core_type))));
-
- void delete_object(const True&) {
- o_map_it it = objects().find(*this);
- RealObject tmp;
- tmp.swap(this);
- map_lock().unlock();
- objects().erase(it);
- }
-
- void delete_object(const False&) {
- objects().erase(*this);
- map_lock().unlock();
- }
- public:
- virtual void destroy() {
- fast_destroy();
- }
- void fast_destroy() {
- map_lock().lock();
- this->ref_lock.lock();
- if (this->refs == 0) {
- this->ref_lock.unlock();
- delete_object(typename ThreadSafe<T>::res());
- return ;
- } else {
- map_lock().unlock();
- this->ref_lock.unlock();
- }
- }
-
- void swap(RealObject* other) {
- int r = this->refs;
- this->refs = other->refs;
- other->refs = r;
- data()->swap(other->data());
- }
- public:
- RealObject(core_type& d) {
- set_data(&d);
- }
-
- RealObject() {
- new (&realdata) core_type();
- set_data((core_type*)realdata);
- }
-
- ~RealObject() {
- if (this->vdata == realdata)
- data()->~core_type();
- }
-
- RealObject(const RealObject& o) {
- new (&realdata) core_type(*o.data());
- set_data((core_type*)realdata);
- }
- };
-protected:
- RealObject* o;
-
- RealObject* obj() const {
- return o;
- }
-
-public:
- SharedObject(const NoBuild&): o(NULL) {}
-
- SharedObject(const SharedObject& other): o(other.o) {
- if (o != NULL) {
- o->inc();
- }
- }
-
- SharedObject(const core_type& ct) {
- RealObject tmp(*const_cast<core_type*>(&ct));
- map_lock().lock();
- std::pair<o_map_it,bool> i = objects().insert(tmp);
- o = const_cast<RealObject*>(&(*(i.first)));
- o->inc();
- map_lock().unlock();
- }
-
- ~SharedObject() {
- if (o == NULL)
- return ;
- o->ref_lock.lock();
- o->refs--;
- if (o->refs == 0) {
- o->ref_lock.unlock();
- o->fast_destroy();
- o = NULL;
- return ;
- }
- o->ref_lock.unlock();
- o = NULL;
- }
-
-public:
- const core_type& get() const {
- return *(obj()->data());
- }
-
- core_type& get() {
- return *(obj()->data());
- }
-
- unsigned hash() const {
- return obj()->data()->hash();
- }
- T& operator=(T other) {
- if (this->o == other.o)
- return *static_cast<T*>(this);
- static_cast<T*>(this)->swap(other);
- return *static_cast<T*>(this);
- }
-
- bool operator==(const SharedObject& other) const {
- return o == other.o;
- }
-
- bool operator!=(const SharedObject& other) const {
- return !(o == other.o);
- }
-
- void swap(SharedObject& so) {
- RealObject *a = o;
- o = so.o;
- so.o = a;
- }
-};
-
-}
-
-#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-21 18:46:07
|
Revision: 140
http://aurelia.svn.sourceforge.net/aurelia/?rev=140&view=rev
Author: valentindavid
Date: 2010-10-21 18:46:00 +0000 (Thu, 21 Oct 2010)
Log Message:
-----------
2010-10-21 Valentin David <val...@ii...>
* src/fast/tests/test_invert_bits.cc,
* src/fast/tests/test_bin_log.cc,
* src/fast/tests/Makefile.am:
Use preprocessor to choose the type to test.
* src/fast/reset_msb.hh: Avoid costly substraction.
* src/fast/invert_bits.hh, src/fast/bin_log.hh:
Make it more generic.
* src/fast/bin_pow.hh: Fix overflow.
* src/fast/static_bin_log.hh: New.
* src/fast/Makefile.am: Update.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/fast/Makefile.am
trunk/src/fast/bin_log.hh
trunk/src/fast/bin_pow.hh
trunk/src/fast/invert_bits.hh
trunk/src/fast/reset_msb.hh
trunk/src/fast/tests/Makefile.am
trunk/src/fast/tests/test_bin_log.cc
trunk/src/fast/tests/test_invert_bits.cc
Added Paths:
-----------
trunk/src/fast/static_bin_log.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/ChangeLog 2010-10-21 18:46:00 UTC (rev 140)
@@ -1,5 +1,22 @@
2010-10-21 Valentin David <val...@ii...>
+ * src/fast/tests/test_invert_bits.cc,
+ * src/fast/tests/test_bin_log.cc,
+ * src/fast/tests/Makefile.am:
+ Use preprocessor to choose the type to test.
+
+ * src/fast/reset_msb.hh: Avoid costly substraction.
+
+ * src/fast/invert_bits.hh, src/fast/bin_log.hh:
+ Make it more generic.
+
+ * src/fast/bin_pow.hh: Fix overflow.
+
+ * src/fast/static_bin_log.hh: New.
+ * src/fast/Makefile.am: Update.
+
+2010-10-21 Valentin David <val...@ii...>
+
Make maximally shared terms fully lock-free.
* src/lockfree/vector.hh:
Modified: trunk/src/fast/Makefile.am
===================================================================
--- trunk/src/fast/Makefile.am 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/Makefile.am 2010-10-21 18:46:00 UTC (rev 140)
@@ -22,4 +22,5 @@
bin_pow.hh \
invert_bits.hh \
bin_log.hh \
+ static_bin_log.hh \
reset_msb.hh
Modified: trunk/src/fast/bin_log.hh
===================================================================
--- trunk/src/fast/bin_log.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/bin_log.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,6 +18,7 @@
# define __BIN_LOG_HH
# include "bin_pow.hh"
+# include "static_bin_log.hh"
# include <type_traits>
namespace fast {
@@ -48,8 +49,15 @@
integral_type bin_log(integral_type v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot use non integral types.");
+ static_assert(sizeof(integral_type) ==
+ 1<< static_bin_log<integral_type,
+ sizeof(integral_type)>::value,
+ "Type size is not a power of two.");
+
integral_type r = 0;
- bin_log_helper<integral_type, sizeof(integral_type)+1>::step(v, r);
+ bin_log_helper<integral_type,
+ static_bin_log<integral_type,
+ sizeof(integral_type)<<3>::value>::step(v, r);
return r;
}
Modified: trunk/src/fast/bin_pow.hh
===================================================================
--- trunk/src/fast/bin_pow.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/bin_pow.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,25 +18,33 @@
#ifndef __BIN_POW_HH
# define __BIN_POW_HH
+# include <type_traits>
+
namespace fast {
- template <typename integral_type, int N>
- struct bin_pow {
- enum: integral_type {
- value = bin_pow<integral_type, N-1>::value*2
- };
- };
+ template <typename integral_type, typename N>
+ struct bin_pow_wrapped: public
+ std::integral_constant<integral_type,
+ bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type,
+ N::value-1>
+ >::value*2> {};
+
template <typename integral_type>
- struct bin_pow<integral_type, 0> {
- enum: integral_type {
- value = 1
- };
- };
+ struct bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type, 0> >
+ : public std::integral_constant<integral_type, 1> {};
template <typename integral_type, integral_type N>
+ struct bin_pow:
+ public bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type, N> > {};
+
+ template <typename integral_type, integral_type N>
struct bin_pow_pow {
enum: integral_type {
- value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>::value
+ value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>
+ ::value
};
};
}
Modified: trunk/src/fast/invert_bits.hh
===================================================================
--- trunk/src/fast/invert_bits.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/invert_bits.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,6 +18,7 @@
# define __INVERT_BITS_HH
# include "bin_pow.hh"
+# include "static_bin_log.hh"
# include <type_traits>
namespace fast {
@@ -39,7 +40,7 @@
template <typename integral_type, int width, integral_type pattern>
struct repeat_pattern:
- public repeat_pattern_recurse<integral_type, 8*sizeof(integral_type),
+ public repeat_pattern_recurse<integral_type, sizeof(integral_type)<<3,
width, pattern>
{};
@@ -69,7 +70,14 @@
inline void invert_bits(integral_type& v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot invert bits on non integral types.");
- inversion_helper<integral_type, sizeof(integral_type)+1>::step(v);
+ static_assert(sizeof(integral_type) ==
+ 1<< static_bin_log<integral_type,
+ sizeof(integral_type)>::value,
+ "Type size is not a power of two.");
+
+ inversion_helper<integral_type,
+ static_bin_log<integral_type,
+ sizeof(integral_type)<<3>::value>::step(v);
}
}
Modified: trunk/src/fast/reset_msb.hh
===================================================================
--- trunk/src/fast/reset_msb.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/reset_msb.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -25,8 +25,7 @@
integral_type reset_msb(integral_type v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot use non integral types.");
- integral_type b = bin_log(v);
- return v&((1 << b)-1);
+ return v^(1 << bin_log(v));
}
}
Added: trunk/src/fast/static_bin_log.hh
===================================================================
--- trunk/src/fast/static_bin_log.hh (rev 0)
+++ trunk/src/fast/static_bin_log.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -0,0 +1,48 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __STATIC_BIN_LOG_HH
+# define __STATIC_BIN_LOG_HH
+
+# include <type_traits>
+
+namespace fast {
+ template <typename integral_type, typename N>
+ struct static_bin_log_wrapped: public
+ std::integral_constant<integral_type,
+ static_bin_log_wrapped<integral_type,
+ std::integral_constant<
+ integral_type,
+ (N::value>>1)> >
+ ::value+1> {};
+
+ template <typename integral_type>
+ struct static_bin_log_wrapped<integral_type,
+ std::integral_constant<integral_type,
+ 1> >:
+ public std::integral_constant<integral_type, 0> {};
+
+ template <typename integral_type, integral_type N>
+ struct static_bin_log: public
+ static_bin_log_wrapped<integral_type,
+ std::integral_constant<
+ integral_type,
+ N> >
+ {};
+}
+
+#endif
Modified: trunk/src/fast/tests/Makefile.am
===================================================================
--- trunk/src/fast/tests/Makefile.am 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/Makefile.am 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,7 +18,10 @@
check_PROGRAMS=test_invert_bits test_bin_log
test_invert_bits_SOURCES=test_invert_bits.cc
+test_invert_bits_CPPFLAGS=-DTYPE='unsigned'
+
test_bin_log_SOURCES=test_bin_log.cc
+test_bin_log_CPPFLAGS=-DTYPE='unsigned'
TESTS=$(check_PROGRAMS)
Modified: trunk/src/fast/tests/test_bin_log.cc
===================================================================
--- trunk/src/fast/tests/test_bin_log.cc 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/test_bin_log.cc 2010-10-21 18:46:00 UTC (rev 140)
@@ -20,10 +20,10 @@
using fast::bin_log;
-unsigned ref_impl(unsigned v) {
- unsigned res = 0;
+TYPE ref_impl(TYPE v) {
+ TYPE res = 0;
- for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ for (TYPE i = 0; i < (sizeof(TYPE)*8); ++i) {
if (v & 1)
res = i;
v >>= 1;
@@ -44,7 +44,7 @@
int main()
{
- unsigned v;
+ TYPE v;
test(0);
test(1);
Modified: trunk/src/fast/tests/test_invert_bits.cc
===================================================================
--- trunk/src/fast/tests/test_invert_bits.cc 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/test_invert_bits.cc 2010-10-21 18:46:00 UTC (rev 140)
@@ -20,10 +20,10 @@
using fast::invert_bits;
-unsigned ref_impl(unsigned v) {
- unsigned res = 0;
+TYPE ref_impl(TYPE v) {
+ TYPE res = 0;
- for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ for (TYPE i = 0; i < (sizeof(TYPE)*8); ++i) {
res <<= 1;
res |= v & 0x1;
v >>= 1;
@@ -44,7 +44,7 @@
int main()
{
- unsigned v;
+ TYPE v;
test(0x12345678);
test(0x00011111);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-21 17:31:18
|
Revision: 139
http://aurelia.svn.sourceforge.net/aurelia/?rev=139&view=rev
Author: valentindavid
Date: 2010-10-21 17:31:09 +0000 (Thu, 21 Oct 2010)
Log Message:
-----------
2010-10-21 Valentin David <val...@ii...>
Make maximally shared terms fully lock-free.
* src/lockfree/vector.hh:
Fix deallocation of segment tables. Add assertions on accessors.
* src/lockfree/unordered_set.hh:
Fix template parameter orders to match STL. Add constructors
and assignment to the type of elements put in the list (they
need to move back and forth in case of failure of insertion).
Pass parameter Multi to the list. Pass the allocator to the
bucket table.
Fix hash inversion method.
Fix iterator's ++ operator.
Add method clear.
Support return type to insert as in the STL. Fix insertion.
Fix erase.
Collect everything at destructor.
* src/lockfree/simple_stack.hh:
Fix deallocation of iterator. Remove useless std::move.
* src/lockfree/sorted_forward_list.hh:
Fix object move in insertion.
Fix search. Fix erase of iterator.
Destroy elements when erased (but do not deallocate them so that
the user can still look at the remains).
* src/terms/constructor.hh,
* src/terms/term.hh:
Fix move operations.
* src/llstack/frame.hh:
Fix assignement.
* src/memory/tests/test_pool.cc,
* src/memory/tests/Makefile.am:
Remove thread unsafe test as all tests are not thread safe.
* src/memory/pool_allocator.hh:
Remove deprecated thread-safety selector.
Make construct follow C++0x allocator style.
* src/max_shared/deref.hh:
Fix resolution of return type.
* src/max_shared/max_shared_ptr.hh:
Use lock free hash set.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/llstack/frame.hh
trunk/src/lockfree/simple_stack.hh
trunk/src/lockfree/sorted_forward_list.hh
trunk/src/lockfree/unordered_set.hh
trunk/src/lockfree/vector.hh
trunk/src/max_shared/deref.hh
trunk/src/max_shared/max_shared_ptr.hh
trunk/src/memory/pool_allocator.hh
trunk/src/memory/tests/Makefile.am
trunk/src/memory/tests/test_pool.cc
trunk/src/terms/constructor.hh
trunk/src/terms/term.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/ChangeLog 2010-10-21 17:31:09 UTC (rev 139)
@@ -1,3 +1,53 @@
+2010-10-21 Valentin David <val...@ii...>
+
+ Make maximally shared terms fully lock-free.
+
+ * src/lockfree/vector.hh:
+ Fix deallocation of segment tables. Add assertions on accessors.
+
+ * src/lockfree/unordered_set.hh:
+ Fix template parameter orders to match STL. Add constructors
+ and assignment to the type of elements put in the list (they
+ need to move back and forth in case of failure of insertion).
+ Pass parameter Multi to the list. Pass the allocator to the
+ bucket table.
+ Fix hash inversion method.
+ Fix iterator's ++ operator.
+ Add method clear.
+ Support return type to insert as in the STL. Fix insertion.
+ Fix erase.
+ Collect everything at destructor.
+
+ * src/lockfree/simple_stack.hh:
+ Fix deallocation of iterator. Remove useless std::move.
+
+ * src/lockfree/sorted_forward_list.hh:
+ Fix object move in insertion.
+ Fix search. Fix erase of iterator.
+ Destroy elements when erased (but do not deallocate them so that
+ the user can still look at the remains).
+
+ * src/terms/constructor.hh,
+ * src/terms/term.hh:
+ Fix move operations.
+
+ * src/llstack/frame.hh:
+ Fix assignement.
+
+ * src/memory/tests/test_pool.cc,
+ * src/memory/tests/Makefile.am:
+ Remove thread unsafe test as all tests are not thread safe.
+
+ * src/memory/pool_allocator.hh:
+ Remove deprecated thread-safety selector.
+ Make construct follow C++0x allocator style.
+
+ * src/max_shared/deref.hh:
+ Fix resolution of return type.
+
+ * src/max_shared/max_shared_ptr.hh:
+ Use lock free hash set.
+
2010-10-20 Valentin David <val...@ii...>
Add lock-free versions of data-structure needed by Aurelia.
Modified: trunk/src/llstack/frame.hh
===================================================================
--- trunk/src/llstack/frame.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/llstack/frame.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -86,7 +86,7 @@
}
frame& operator=(const frame& other) {
- return *this = std::move(other);
+ return *this = frame(other);
}
frame& operator=(frame&& other) {
Modified: trunk/src/lockfree/simple_stack.hh
===================================================================
--- trunk/src/lockfree/simple_stack.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/lockfree/simple_stack.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -52,13 +52,15 @@
return n->e;
}
~wrapped() {
- alloc.destroy(n);
- alloc.deallocate(n, 1);
+ if (n != NULL) {
+ alloc.destroy(n);
+ alloc.deallocate(n, 1);
+ }
}
};
void push(const Elt& e) {
- push(std::move(Elt(e)));
+ push(Elt(e));
}
void push(Elt&& e) {
Modified: trunk/src/lockfree/sorted_forward_list.hh
===================================================================
--- trunk/src/lockfree/sorted_forward_list.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/lockfree/sorted_forward_list.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -54,12 +54,22 @@
const Elt& operator*() const {
return static_cast<const node*>(this)->operator*();
}
+
+ node_base& operator=(node_base&& other) {
+ std::swap(next, other.next);
+ return *this;
+ }
};
struct node: public node_base {
private:
Elt e;
public:
- node(Elt&& e, node_base* next): node_base(next), e(e) {}
+ node(Elt&& e, node_base* next): node_base(next), e(std::move(e)) {}
+ node& operator=(node&& other) {
+ std::swap(e, other.e);
+ this->node_base::operator=((node_base&&)std::move(other));
+ return *this;
+ }
const Elt& operator*() const {
return e;
}
@@ -81,8 +91,10 @@
return _size.load();
}
- sorted_forward_list(Eq eq = Eq(), Compare compare = Compare(), Alloc alloc = Alloc())
- : node_alloc(alloc), eq(eq), compare(compare), head(NULL), free(alloc), _size(0) {}
+ sorted_forward_list(Eq eq = Eq(), Compare compare = Compare(),
+ Alloc alloc = Alloc())
+ : node_alloc(alloc), eq(eq), compare(compare), head(NULL), free(alloc),
+ _size(0) {}
struct iterator;
@@ -156,13 +168,6 @@
}
};
- /*
- iterator insert_after(const Elt& elt, const const_iterator& hint = begin(),
- bool once = !Multi::value) {
- return insert_after(Elt(elt), hint, once);
- }
- */
-
const_iterator begin() const {
return const_iterator(head.get_next());
}
@@ -179,18 +184,16 @@
return iterator(NULL);
}
- iterator insert_after(Elt&& elt, const const_iterator& hint,
- bool once = !Multi::value) {
+ std::pair<iterator,bool>
+ insert_after(Elt&& elt, const const_iterator& hint,
+ bool once = !Multi::value) {
return insert_after(std::move(elt), hint.get_node(), once);
}
private:
- std::pair<node_base*, node_base*> search(const Elt& e) const {
-
- }
-
- iterator insert_after(Elt&& elt, node_base* hint,
- bool once = !Multi::value) {
+ std::pair<iterator,bool>
+ insert_after(Elt&& elt, node_base* hint,
+ bool once = !Multi::value) {
node* n = node_alloc.allocate(1);
node_alloc.construct(n, std::move(elt), (node_base*)NULL);
@@ -199,27 +202,30 @@
found = search(hint, **n);
if (once)
if ((found.second==NULL)?false:eq(**found.second, **n)) {
+ std::swap(*const_cast<Elt*>(&**n), elt);
node_alloc.destroy(n);
node_alloc.deallocate(n, 1);
- return iterator(static_cast<node*>(found.second));
+ return std::pair<iterator,bool>
+ (iterator(static_cast<node*>(found.second)),
+ false);
}
n->force_set_next(found.second);
if (found.first->set_next(found.second, n)) {
_size++;
- return iterator(n);
+ return std::pair<iterator,bool>(iterator(n), true);
}
};
}
public:
- iterator insert(Elt&& elt) {
+ std::pair<iterator,bool> insert(Elt&& elt) {
return insert_after(std::move(elt), &head);
}
private:
std::pair<node_base*, node_base*>
- search(node_base* hint, const Elt& elt) {
+ search(node_base* hint, const Elt& elt, node_base* exact = NULL) {
typedef std::pair<node_base*, node_base*> rt;
node_base* before = NULL;
@@ -238,7 +244,10 @@
if (NULL == (t = details::unmarked(t_next)))
break ;
t_next = t->get_next();
- } while (details::is_marked(t_next)?true:compare(**t, elt));
+ } while (details::is_marked(t_next)?true:
+ (exact==NULL)?(compare(**t, elt)?true:
+ (!compare(elt, **t)?!eq(**t,elt):false)):
+ (exact==t)?false:!compare(elt, **t));
if (before_next == t) {
if ((t == NULL)?false:details::is_marked(t->get_next()))
@@ -261,7 +270,7 @@
node_base* next;
while (true) {
- found = search(hint, **item);
+ found = search(hint, **item, item);
if ((found.second == NULL)?true:(found.second != item)) {
return ;
}
@@ -272,6 +281,7 @@
}
}
_size--;
+ node_alloc.destroy(static_cast<node*>(found.second));
free.push(static_cast<node*>(found.second));
if (!found.first->set_next(found.second, next))
search(hint, **found.second);
@@ -294,6 +304,8 @@
}
}
if (found.first->set_next(found.second, next)) {
+ _size--;
+ node_alloc.destroy(static_cast<node*>(found.second));
free.push(static_cast<node*>(found.second));
}
else {
@@ -350,15 +362,18 @@
return find(elt, hint.get_node());
}
- void collect() {
+ bool collect() {
+ bool did = false;
while (true) {
typename sstack_t::wrapped w = free.pop();
if (w.end())
break ;
+ did = true;
node* n = *w;
- node_alloc.destroy(n);
+ //node_alloc.destroy(n);
node_alloc.deallocate(n, 1);
}
+ return did;
}
void clear() {
Modified: trunk/src/lockfree/unordered_set.hh
===================================================================
--- trunk/src/lockfree/unordered_set.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/lockfree/unordered_set.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -24,8 +24,10 @@
# include "../fast/invert_bits.hh"
namespace lockfree {
- template <typename T, typename Eq = std::equal_to<T>,
- typename Hash = std::hash<T>, typename Alloc = std::allocator<T>,
+ template <typename T,
+ typename Hash = std::hash<T>,
+ typename Eq = std::equal_to<T>,
+ typename Alloc = std::allocator<T>,
typename Multi = std::false_type>
class unordered_set {
struct elts {
@@ -55,6 +57,22 @@
elts(size_t _invhash): _invhash(_invhash) {
}
+ elts() = delete;
+ elts(const elts&) = delete;
+ elts(elts&& other): _invhash(0) {
+ if (other._invhash & 0x1) {
+ new (reinterpret_cast<T*>(&_elt)) T(std::move(other.elt()));
+ }
+ std::swap(_invhash, other._invhash);
+ }
+
+ elts& operator=(const elts&) = delete;
+ elts& operator=(elts&& other) {
+ std::swap(_elt, other._elt);
+ std::swap(_invhash, other._invhash);
+ return *this;
+ }
+
~elts() {
if (_invhash & 0x1)
elt().~T();
@@ -81,12 +99,16 @@
};
typedef typename Alloc::template rebind<elts>::other elt_alloc_t;
-
typedef sorted_forward_list<elts,
eq_elts, compare_elts,
- elt_alloc_t, std::false_type> list_t;
- typedef vector<typename list_t::const_iterator> entries_t;
+ elt_alloc_t, Multi> list_t;
+ typedef typename Alloc::template rebind<typename list_t::const_iterator>
+ ::other it_alloc_t;
+
+ typedef vector<typename list_t::const_iterator,
+ 1024u, it_alloc_t> entries_t;
+
double max_load_factor;
Eq eq;
Hash hash;
@@ -95,12 +117,12 @@
entries_t entries;
public:
- unordered_set(Eq eq = Eq(), Hash hash = Hash(), Alloc alloc = Alloc()):
+ unordered_set(Hash hash = Hash(), Eq eq = Eq(), Alloc alloc = Alloc()):
max_load_factor(.3),
eq(eq), hash(hash), list(eq_elts(eq), compare_elts(),
alloc), entries(list.end(), alloc) {
entries.resize(1);
- entries[0x0] = list.insert(elts(0x0));
+ entries[0x0] = list.insert(elts(0x0)).first;
}
private:
@@ -110,16 +132,15 @@
typename list_t::const_iterator parent =
_get_bucket(fast::reset_msb(b));
i = const_cast<unordered_set*>(this)->list
- .insert_after(elts(get_invert(b)&~0x1), parent, true);
+ .insert_after(elts(get_invert(b)&~0x1), parent, true).first;
const_cast<unordered_set*>(this)->entries[b] = i;
}
return i;
}
size_t get_invert(size_t h) const {
- size_t v = hash(h);
- fast::invert_bits(v);
- return v | 0x1;
+ fast::invert_bits(h);
+ return h | 0x1;
}
typename list_t::const_iterator get_bucket(size_t h) const {
@@ -127,6 +148,10 @@
}
public:
+ ~unordered_set() {
+ while (collect()) ;
+ }
+
struct iterator {
private:
typename list_t::const_iterator i;
@@ -156,7 +181,7 @@
return *this;
}
- iterator& operator++(int) {
+ iterator operator++(int) {
iterator tmp(*this);
++(*this);
return tmp;
@@ -178,6 +203,13 @@
return list.begin();
}
+ void clear() {
+ for (iterator i = begin(); i != end();) {
+ iterator tmp = i++;
+ erase(tmp);
+ }
+ }
+
iterator find(const T& elt) const {
size_t h = hash(elt);
typename list_t::const_iterator i = get_bucket(h);
@@ -196,22 +228,28 @@
return end();
}
- iterator insert(T&& elt) {
+ std::pair<iterator,bool> insert(T&& elt) {
size_t h = hash(elt);
typename list_t::const_iterator i = get_bucket(h);
- typename list_t::const_iterator ret =
- list.insert_after(elts(get_invert(h), std::move(elt)), i);
- size_t size = entries.size();
- size_t nelts = list.size();
- if ((((double)nelts) / size) > max_load_factor) {
- entries.resize(2*size);
+ elts toinsert(get_invert(h), std::move(elt));
+ std::pair<typename list_t::const_iterator,bool> ret =
+ list.insert_after(std::move(toinsert), i);
+ if (ret.second) {
+ size_t size = entries.size();
+ size_t nelts = list.size();
+ if ((((double)nelts) / size) > max_load_factor) {
+ entries.resize(2*size);
+ }
}
- return iterator(ret);
+ else {
+ std::swap(*const_cast<T*>(&*toinsert), elt);
+ }
+ return std::pair<iterator,bool>(iterator(ret.first),ret.second);
}
- void collect() {
- list.collect();
+ bool collect() {
entries.collect();
+ return list.collect();
}
void erase(const T& t) {
@@ -223,7 +261,8 @@
if (i == end())
return ;
typename list_t::const_iterator j = i;
- size_t h = hash(*i);
+ size_t h = (*j).invhash();
+ fast::invert_bits(h);
typename list_t::const_iterator b = get_bucket(h);
list.erase(j, b);
}
Modified: trunk/src/lockfree/vector.hh
===================================================================
--- trunk/src/lockfree/vector.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/lockfree/vector.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -19,6 +19,7 @@
# define __VECTOR_HH
# include <atomic>
+# include <cassert>
# include "simple_stack.hh"
namespace lockfree {
@@ -42,6 +43,9 @@
simple_stack<seg_table*> free;
T default_value;
+ /* This is not completely thread safe. However, for our use, the vector
+ * can be fixed if it was modified.
+ */
void set_size(size_t size) {
size_t isize = (size+SEG_SIZE-1)/SEG_SIZE;
seg_table* t = table.load();
@@ -61,7 +65,7 @@
alloc.deallocate(newt->segments[i], SEG_SIZE);
}
pt_alloc.deallocate(newt->segments, isize);
- st_alloc.deallocate(newt, isize);
+ st_alloc.deallocate(newt, 1);
return ;
}
size_t i = 0;
@@ -93,11 +97,13 @@
T& operator[](size_t n) {
seg_table* t = table.load();
+ assert(n < (SEG_SIZE*t->n_segments));
return t->segments[n/SEG_SIZE][n%SEG_SIZE];
}
const T& operator[](size_t n) const {
seg_table* t = table.load();
+ assert(n < (SEG_SIZE*t->n_segments));
return t->segments[n/SEG_SIZE][n%SEG_SIZE];
}
Modified: trunk/src/max_shared/deref.hh
===================================================================
--- trunk/src/max_shared/deref.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/max_shared/deref.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -19,6 +19,7 @@
# define __DEREF_HH
# include <type_traits>
+# include "../type_traits/is_callable_with.hh"
namespace aurelia {
@@ -28,7 +29,7 @@
template <typename... Args>
struct Return {
typedef decltype(std::declval<const Op>()
- ((*(std::declval<Args>()))...)) type;
+ ((*(std::declval<const Args>()))...)) type;
};
public:
Modified: trunk/src/max_shared/max_shared_ptr.hh
===================================================================
--- trunk/src/max_shared/max_shared_ptr.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/max_shared/max_shared_ptr.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -18,9 +18,8 @@
#ifndef __MAX_SHARED_PTR_HH
# define __MAX_SHARED_PTR_HH
-# include <unordered_set>
+# include "../lockfree/unordered_set.hh"
# include <memory>
-# include <mutex>
# include <atomic>
# include "../type_traits/has_constructor.hh"
@@ -35,10 +34,14 @@
*/
template <typename T, typename Hash = mhash<T>,
typename EqnFunc = std::equal_to<T>,
- typename Alloc = std::allocator<T>,
- typename Lock = std::mutex>
+ typename Alloc = std::allocator<T> >
struct max_shared_ptr {
private:
+ struct Ptr;
+ typedef lockfree::unordered_set<Ptr, deref_op<Hash>,
+ deref_op<EqnFunc>,
+ Alloc> set_t;
+
struct Ptr {
public:
std::atomic<long>& count() const {
@@ -54,6 +57,15 @@
}
public:
+ static void init(set_t& _set) {
+ //Ensure all allocators have been used before call to atexit
+ //so that collect will be called before any call to static
+ //cleanup of allocators.
+ _set.insert(Ptr(T()));
+ _set.clear();
+ atexit(collect);
+ }
+
const T& operator*() const {
return core;
}
@@ -67,74 +79,81 @@
}
Ptr(Ptr&& other): core(std::move(other.core)), _count() {
- _count.store(0);
+ _count.store(other._count.load());
}
Ptr& operator=(Ptr&& other) {
+ long tmp = _count.load();
+ _count.store(other._count.load());
+ other._count.store(tmp);
std::swap(core, other.core);
return *this;
}
- static const Ptr* create(T&& core) {
+ static const typename set_t::iterator create(T&& core) {
Ptr tmp(std::move(core));
- lock().lock();
- std::pair<typename set_t::iterator, bool> r =
- set().insert(std::move(tmp));
- const Ptr& ret = (*r.first);
- ret.count()++;
- lock().unlock();
- return &ret;
- }
+ while (true) {
+ std::pair<typename set_t::iterator, bool> r =
+ set().insert(std::move(tmp));
+ if (r.second) {
+ (*r.first).count()++;
+ return r.first;
+ }
+ long count = (*r.first).count().load();
+ if (count == 0)
+ //Either being built, or destroyed.
+ //Note in this case that ~Ptr has been already called, but
+ //not the deallocator. For this reason ~Ptr should never
+ //alter _count.
+ continue ;
+ if (!(*r.first).count().compare_exchange_strong(count, count+1))
+ continue ;
- void swap(Ptr& other) {
- std::swap(core, other.core);
+ return r.first;
+ }
}
};
- typedef std::unordered_set<Ptr, deref_op<Hash>,
- deref_op<EqnFunc>, deref_op<Alloc> > set_t;
+ typename set_t::iterator _ptr;
- const Ptr *_ptr;
-
- static Lock& lock() {
- static Lock _lock;
- return _lock;
+ public:
+ static void collect() {
+ while (set().collect()) ;
}
+ private:
+ struct init_set {
+ set_t _set;
+ init_set() {
+ Ptr::init(_set);
+ }
+ };
+
static set_t& set() {
- static set_t _set;
- return _set;
+ static init_set _set;
+ return _set._set;
}
public:
~max_shared_ptr() {
- if (_ptr == NULL)
+ if (_ptr == set().end())
return ;
- if (0 == --(_ptr->count())) {
- lock().lock();
- if (_ptr->count().load() != 0) {
- lock().unlock();
- _ptr = NULL;
- return ;
- }
- typename set_t::iterator i = set().find(*_ptr);
- Ptr tmp(std::move(*const_cast<Ptr*>(_ptr)));
- set().erase(i);
- lock().unlock();
+ if (0 == --((*_ptr).count())) {
+ set().erase(_ptr);
}
- _ptr = NULL;
+ _ptr = set().end();
}
max_shared_ptr(T&& core): _ptr(Ptr::create(std::move(core))) {
}
max_shared_ptr(const max_shared_ptr& other): _ptr(other._ptr) {
- if (_ptr != NULL)
- _ptr->count()++;
+ if (_ptr != set().end())
+ (*_ptr).count()++;
}
max_shared_ptr(max_shared_ptr&& other): _ptr(other._ptr) {
- other._ptr = NULL;
+ other._ptr = set().end();
}
max_shared_ptr& operator=(max_shared_ptr&& other) {
@@ -155,10 +174,10 @@
typename =
typename std::enable_if<type_traits::
has_constructor<T, Args...>::value>::type>
- max_shared_ptr(Args... args...): _ptr(Ptr::create(T(args...))) {
+ max_shared_ptr(Args... args...): _ptr(Ptr::create(T(std::forward<Args>(args)...))) {
}
- max_shared_ptr(): _ptr(NULL) {
+ max_shared_ptr(): _ptr(set().end()) {
}
bool operator==(const max_shared_ptr& other) const {
@@ -170,7 +189,7 @@
}
const T* get() const {
- return _ptr->get();
+ return (*_ptr).get();
}
const T* operator->() const {
Modified: trunk/src/memory/pool_allocator.hh
===================================================================
--- trunk/src/memory/pool_allocator.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/memory/pool_allocator.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -68,7 +68,6 @@
};
template <typename T,
- typename ThreadSafe = std::true_type,
int POOL_SIZE = 4096>
struct ChunkAlloc {
private:
@@ -135,9 +134,8 @@
};
template <typename T,
- typename ThreadSafe = std::true_type,
int POOL_SIZE = 4096,
- typename RealAlloc = ChunkAlloc<T, ThreadSafe, POOL_SIZE> >
+ typename RealAlloc = ChunkAlloc<T, POOL_SIZE> >
struct pool_allocator {
typedef size_t size_type;
typedef T* pointer;
@@ -148,11 +146,11 @@
template <typename U>
struct rebind {
- typedef pool_allocator<U, ThreadSafe, POOL_SIZE> other;
+ typedef pool_allocator<U, POOL_SIZE> other;
};
- template <typename U>
- pool_allocator(const pool_allocator<U>&) {}
+ template <typename U, int OTHERSIZE>
+ pool_allocator(const pool_allocator<U, OTHERSIZE>&) {}
pool_allocator() {}
pointer allocate(size_type n) {
@@ -173,8 +171,9 @@
p->~T();
}
- void construct(pointer p, const T& t) {
- new (p) T(t);
+ template <typename... Args>
+ void construct(pointer p, Args... args...) {
+ new (p) T(std::forward<Args>(args)...);
}
};
Modified: trunk/src/memory/tests/Makefile.am
===================================================================
--- trunk/src/memory/tests/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/memory/tests/Makefile.am 2010-10-21 17:31:09 UTC (rev 139)
@@ -15,13 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-check_PROGRAMS=test_pool test_pool_no_valgrind test_pool_no_thread
+check_PROGRAMS=test_pool test_pool_no_valgrind
test_pool_SOURCES=test_pool.cc
test_pool_no_valgrind_SOURCES=test_pool.cc
test_pool_no_valgrind_CPPFLAGS=-DNVALGRIND $(AM_CPPFLAGS)
-test_pool_no_thread_SOURCES=test_pool.cc
-test_pool_no_thread_CPPFLAGS=-DTS=std::false_type $(AM_CPPFLAGS)
TESTS=$(check_PROGRAMS)
Modified: trunk/src/memory/tests/test_pool.cc
===================================================================
--- trunk/src/memory/tests/test_pool.cc 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/memory/tests/test_pool.cc 2010-10-21 17:31:09 UTC (rev 139)
@@ -19,9 +19,6 @@
#include <cassert>
#include <list>
-#ifndef TS
-# define TS std::true_type
-#endif
#define A 10
#define B 256
#define SIZE 128
@@ -38,11 +35,11 @@
(size_t s) {
#endif
assert(sizeof(Foo) == s);
- return ChunkAlloc<Foo, TS, SIZE>::alloc();
+ return ChunkAlloc<Foo, SIZE>::alloc();
}
void operator delete(void* p) {
- return ChunkAlloc<Foo, TS, SIZE>::del(p);
+ return ChunkAlloc<Foo, SIZE>::del(p);
}
#endif
@@ -52,7 +49,7 @@
int main() {
#ifndef REF
-# define ALLOCATOR , pool_allocator<Foo*, TS, SIZE>
+# define ALLOCATOR , pool_allocator<Foo*, SIZE>
#else
# define ALLOCATOR
#endif
Modified: trunk/src/terms/constructor.hh
===================================================================
--- trunk/src/terms/constructor.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/terms/constructor.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -89,13 +89,13 @@
}
}
- ConstructorCore() {}
- ConstructorCore(ConstructorCore&& other) {
+ ConstructorCore(): _arity(0), _hash(0) {}
+ ConstructorCore(ConstructorCore&& other): _name(""), _arity(0), _hash(0) {
*this = std::move(other);
}
ConstructorCore& operator=(const ConstructorCore& other) {
- return *this = std::move(other);
+ return *this = ConstructorCore(other);
}
ConstructorCore& operator=(ConstructorCore&& other) {
@@ -136,9 +136,12 @@
Constructor(): super() {
}
- Constructor(const Constructor& other): super(other) {
+ Constructor(Constructor&& other): super((super&&)std::move(other)) {
}
+ Constructor(const Constructor& other): super((const super&)other) {
+ }
+
template <typename OtherPool,
typename =
typename
Modified: trunk/src/terms/term.hh
===================================================================
--- trunk/src/terms/term.hh 2010-10-20 14:45:10 UTC (rev 138)
+++ trunk/src/terms/term.hh 2010-10-21 17:31:09 UTC (rev 139)
@@ -50,7 +50,7 @@
}
}
- TermCore() {
+ TermCore(): _constructor("", 0), _hash(0) {
children = NULL;
}
@@ -132,7 +132,7 @@
}
}
- TermCore(TermCore&& other): _constructor(other._constructor),
+ TermCore(TermCore&& other): _constructor(std::move(other._constructor)),
children(NULL),
_hash(other._hash)
{
@@ -195,6 +195,9 @@
Term(const Term& other): super((const super&)(other)) {
}
+ Term(Term&& other): super((super&&)std::move(other)) {
+ }
+
Term(): super() {
}
@@ -291,6 +294,7 @@
}
}
+
template <typename Stream, typename Pool>
Stream& operator<<(Stream& s, const Term<Pool>& t) {
print(s, t);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <val...@us...> - 2010-10-20 14:45:18
|
Revision: 138
http://aurelia.svn.sourceforge.net/aurelia/?rev=138&view=rev
Author: valentindavid
Date: 2010-10-20 14:45:10 +0000 (Wed, 20 Oct 2010)
Log Message:
-----------
2010-10-20 Valentin David <val...@ii...>
Add lock-free versions of data-structure needed by Aurelia.
Parsing will also need hash maps.
* src/terms/fast_inversion.hh: Move to...
* src/fast/invert_bits.hh: ... there, and make it generic.
* src/terms/Makefile.am, src/terms/baf_read.hh: Update.
* src/fast/bin_log.hh: New. Calculate the position of MSB in log(N).
* src/fast/bin_pow.hh, src/fast/reset_msb.hh, src/fast/Makefile.am,
* src/fast/tests/Makefile.am, src/fast/tests/test_invert_bits.cc,
* src/fast/tests/test_bin_log.cc:
New.
* src/lockfree/vector.hh, src/lockfree/unordered_set.hh,
* src/lockfree/marked_pointer.hh,
* src/lockfree/tests/test_sorted_forward_list.cc,
* src/lockfree/tests/test_vector.cc,
* src/lockfree/tests/test_unordered_set.cc,
* src/lockfree/tests/test_marked.cc,
* src/lockfree/tests/Makefile.am, src/lockfree/Makefile.am,
* src/lockfree/simple_stack.hh, src/lockfree/sorted_forward_list.hh,
New.
* src/memory/pool_allocator.hh: Make it completely lock free.
* src/Makefile.am (SUBDIRS): Update.
* configure.ac (AC_CONFIG_FILES): Update.
Modified Paths:
--------------
trunk/ChangeLog
trunk/configure.ac
trunk/src/Makefile.am
trunk/src/memory/pool_allocator.hh
trunk/src/terms/Makefile.am
trunk/src/terms/baf_read.hh
Added Paths:
-----------
trunk/src/fast/
trunk/src/fast/Makefile.am
trunk/src/fast/bin_log.hh
trunk/src/fast/bin_pow.hh
trunk/src/fast/invert_bits.hh
trunk/src/fast/reset_msb.hh
trunk/src/fast/tests/
trunk/src/fast/tests/Makefile.am
trunk/src/fast/tests/test_bin_log.cc
trunk/src/fast/tests/test_invert_bits.cc
trunk/src/lockfree/
trunk/src/lockfree/Makefile.am
trunk/src/lockfree/marked_pointer.hh
trunk/src/lockfree/simple_stack.hh
trunk/src/lockfree/sorted_forward_list.hh
trunk/src/lockfree/tests/
trunk/src/lockfree/tests/Makefile.am
trunk/src/lockfree/tests/test_marked.cc
trunk/src/lockfree/tests/test_sorted_forward_list.cc
trunk/src/lockfree/tests/test_unordered_set.cc
trunk/src/lockfree/tests/test_vector.cc
trunk/src/lockfree/unordered_set.hh
trunk/src/lockfree/vector.hh
Removed Paths:
-------------
trunk/src/terms/fast_inversion.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/ChangeLog 2010-10-20 14:45:10 UTC (rev 138)
@@ -1,3 +1,35 @@
+2010-10-20 Valentin David <val...@ii...>
+
+ Add lock-free versions of data-structure needed by Aurelia.
+ Parsing will also need hash maps.
+
+ * src/terms/fast_inversion.hh: Move to...
+ * src/fast/invert_bits.hh: ... there, and make it generic.
+
+ * src/terms/Makefile.am, src/terms/baf_read.hh: Update.
+
+ * src/fast/bin_log.hh: New. Calculate the position of MSB in log(N).
+
+ * src/fast/bin_pow.hh, src/fast/reset_msb.hh, src/fast/Makefile.am,
+ * src/fast/tests/Makefile.am, src/fast/tests/test_invert_bits.cc,
+ * src/fast/tests/test_bin_log.cc:
+ New.
+
+ * src/lockfree/vector.hh, src/lockfree/unordered_set.hh,
+ * src/lockfree/marked_pointer.hh,
+ * src/lockfree/tests/test_sorted_forward_list.cc,
+ * src/lockfree/tests/test_vector.cc,
+ * src/lockfree/tests/test_unordered_set.cc,
+ * src/lockfree/tests/test_marked.cc,
+ * src/lockfree/tests/Makefile.am, src/lockfree/Makefile.am,
+ * src/lockfree/simple_stack.hh, src/lockfree/sorted_forward_list.hh,
+ New.
+
+ * src/memory/pool_allocator.hh: Make it completely lock free.
+
+ * src/Makefile.am (SUBDIRS): Update.
+ * configure.ac (AC_CONFIG_FILES): Update.
+
2010-10-06 Valentin David <val...@ii...>
Use C++0x thread library and remove all thread related Aurelia
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/configure.ac 2010-10-20 14:45:10 UTC (rev 138)
@@ -159,6 +159,10 @@
demos-from-rascal/Makefile
demos-from-stratego/Makefile
demos/Makefile
+ src/fast/Makefile
+ src/fast/tests/Makefile
+ src/lockfree/Makefile
+ src/lockfree/tests/Makefile
src/max_shared/Makefile
src/hash/Makefile
src/memory/Makefile
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/src/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -28,6 +28,8 @@
box \
max_shared \
hash \
+ lockfree \
+ fast \
parser_generator
nodist_aurelia_HEADERS=aurelia-config.hh
Property changes on: trunk/src/fast
___________________________________________________________________
Added: svn:ignore
+ Makefile
Makefile.in
Added: trunk/src/fast/Makefile.am
===================================================================
--- trunk/src/fast/Makefile.am (rev 0)
+++ trunk/src/fast/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,25 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SUBDIRS=tests
+
+fastdir=$(aureliadir)/fast
+fast_HEADERS= \
+ bin_pow.hh \
+ invert_bits.hh \
+ bin_log.hh \
+ reset_msb.hh
Added: trunk/src/fast/bin_log.hh
===================================================================
--- trunk/src/fast/bin_log.hh (rev 0)
+++ trunk/src/fast/bin_log.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,58 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __BIN_LOG_HH
+# define __BIN_LOG_HH
+
+# include "bin_pow.hh"
+# include <type_traits>
+
+namespace fast {
+
+ template <typename integral_type, int N>
+ struct bin_log_helper {
+ enum: integral_type {
+ shift = 1 << (N-1),
+ pattern = ((integral_type)bin_pow_pow<integral_type, N>::value-1)
+ << shift
+ };
+ static void step(integral_type& v, integral_type& r) {
+ if (v & pattern) {
+ v >>= shift;
+ r |= shift;
+ }
+ bin_log_helper<integral_type, N-1>::step(v, r);
+ }
+ };
+
+ template <typename integral_type>
+ struct bin_log_helper<integral_type, 0> {
+ static void step(integral_type&, integral_type&) {
+ }
+ };
+
+ template <typename integral_type>
+ integral_type bin_log(integral_type v) {
+ static_assert(std::is_integral<integral_type>::value,
+ "Cannot use non integral types.");
+ integral_type r = 0;
+ bin_log_helper<integral_type, sizeof(integral_type)+1>::step(v, r);
+ return r;
+ }
+
+}
+
+#endif
Added: trunk/src/fast/bin_pow.hh
===================================================================
--- trunk/src/fast/bin_pow.hh (rev 0)
+++ trunk/src/fast/bin_pow.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,44 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __BIN_POW_HH
+# define __BIN_POW_HH
+
+namespace fast {
+ template <typename integral_type, int N>
+ struct bin_pow {
+ enum: integral_type {
+ value = bin_pow<integral_type, N-1>::value*2
+ };
+ };
+
+ template <typename integral_type>
+ struct bin_pow<integral_type, 0> {
+ enum: integral_type {
+ value = 1
+ };
+ };
+
+ template <typename integral_type, integral_type N>
+ struct bin_pow_pow {
+ enum: integral_type {
+ value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>::value
+ };
+ };
+}
+
+#endif
Copied: trunk/src/fast/invert_bits.hh (from rev 134, trunk/src/terms/fast_inversion.hh)
===================================================================
--- trunk/src/fast/invert_bits.hh (rev 0)
+++ trunk/src/fast/invert_bits.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,76 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __INVERT_BITS_HH
+# define __INVERT_BITS_HH
+
+# include "bin_pow.hh"
+# include <type_traits>
+
+namespace fast {
+ template <typename integral_type, int size, int width, integral_type pattern>
+ struct repeat_pattern_recurse {
+ enum: integral_type {
+ value = (integral_type)repeat_pattern_recurse<integral_type,
+ size,
+ 2*width,
+ pattern |
+ (pattern << width)>::value
+ };
+ };
+
+ template <typename integral_type, int size, integral_type pattern>
+ struct repeat_pattern_recurse<integral_type, size, size, pattern> {
+ enum: integral_type { value = pattern };
+ };
+
+ template <typename integral_type, int width, integral_type pattern>
+ struct repeat_pattern:
+ public repeat_pattern_recurse<integral_type, 8*sizeof(integral_type),
+ width, pattern>
+ {};
+
+ template <typename integral_type, int N>
+ struct inversion_helper {
+ enum: integral_type
+ { shift = 1 << (N-1),
+ smallpattern = ((integral_type)bin_pow_pow<integral_type, N>::value-1)
+ << shift,
+ pattern = repeat_pattern<integral_type, 2*shift, smallpattern>::value
+ };
+ static void step(integral_type& v) {
+ integral_type l = v << shift;
+ v >>= shift;
+ v = (l & pattern)
+ | (v & (pattern >> shift));
+ inversion_helper<integral_type, N-1>::step(v);
+ }
+ };
+
+ template <typename integral_type>
+ struct inversion_helper<integral_type, 0> {
+ static void step(integral_type&) {}
+ };
+
+ template <typename integral_type>
+ inline void invert_bits(integral_type& v) {
+ static_assert(std::is_integral<integral_type>::value,
+ "Cannot invert bits on non integral types.");
+ inversion_helper<integral_type, sizeof(integral_type)+1>::step(v);
+ }
+}
+
+#endif
Added: trunk/src/fast/reset_msb.hh
===================================================================
--- trunk/src/fast/reset_msb.hh (rev 0)
+++ trunk/src/fast/reset_msb.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,34 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#ifndef __RESET_MSB_HH
+# define __RESET_MSB_HH
+
+# include "bin_log.hh"
+
+namespace fast {
+
+ template <typename integral_type>
+ integral_type reset_msb(integral_type v) {
+ static_assert(std::is_integral<integral_type>::value,
+ "Cannot use non integral types.");
+ integral_type b = bin_log(v);
+ return v&((1 << b)-1);
+ }
+
+}
+
+#endif
Property changes on: trunk/src/fast/tests
___________________________________________________________________
Added: svn:ignore
+ .deps
test_bin_log.log
test_invert_bits.log
test-suite.log
test_invert_bits
test_bin_log
Makefile.in
Makefile
Added: trunk/src/fast/tests/Makefile.am
===================================================================
--- trunk/src/fast/tests/Makefile.am (rev 0)
+++ trunk/src/fast/tests/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,27 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+check_PROGRAMS=test_invert_bits test_bin_log
+
+test_invert_bits_SOURCES=test_invert_bits.cc
+test_bin_log_SOURCES=test_bin_log.cc
+
+TESTS=$(check_PROGRAMS)
+
+if HAVE_VALGRIND
+TESTS_ENVIRONMENT=ulimit -s 8192; $(VALGRIND) --leak-check=full --show-reachable=yes --error-exitcode=1 >/dev/null --
+endif
Added: trunk/src/fast/tests/test_bin_log.cc
===================================================================
--- trunk/src/fast/tests/test_bin_log.cc (rev 0)
+++ trunk/src/fast/tests/test_bin_log.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,64 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "../bin_log.hh"
+#include <iostream>
+
+using fast::bin_log;
+
+unsigned ref_impl(unsigned v) {
+ unsigned res = 0;
+
+ for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ if (v & 1)
+ res = i;
+ v >>= 1;
+ }
+ return res;
+}
+
+#define test(X) \
+ v = X; \
+ v = bin_log(v); \
+ if (v != ref_impl(X)) { \
+ std::cerr << "With: " << std::hex << X << \
+ ", expected: " << std::hex << \
+ ref_impl(X) << ", got: " << \
+ std::hex << v << std::endl; \
+ return 1; \
+ }
+
+int main()
+{
+ unsigned v;
+
+ test(0);
+ test(1);
+ test(2);
+ test(3);
+ test(4);
+ test(5);
+ test(6);
+ test(7);
+ test(8);
+ test(0x01234567);
+ test(0x00011111);
+ test(42);
+ test(0xfedcba98);
+
+ return 0;
+}
Added: trunk/src/fast/tests/test_invert_bits.cc
===================================================================
--- trunk/src/fast/tests/test_invert_bits.cc (rev 0)
+++ trunk/src/fast/tests/test_invert_bits.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,55 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "../invert_bits.hh"
+#include <iostream>
+
+using fast::invert_bits;
+
+unsigned ref_impl(unsigned v) {
+ unsigned res = 0;
+
+ for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ res <<= 1;
+ res |= v & 0x1;
+ v >>= 1;
+ }
+ return res;
+}
+
+#define test(X) \
+ v = X; \
+ invert_bits(v); \
+ if (v != ref_impl(X)) { \
+ std::cerr << "With: " << std::hex << X << \
+ ", expected: " << std::hex << \
+ ref_impl(X) << ", got: " << \
+ std::hex << v << std::endl; \
+ return 1; \
+ }
+
+int main()
+{
+ unsigned v;
+
+ test(0x12345678);
+ test(0x00011111);
+ test(42);
+ test(0xfedcba98);
+
+ return 0;
+}
Property changes on: trunk/src/lockfree
___________________________________________________________________
Added: svn:ignore
+ Makefile.in
Makefile
Added: trunk/src/lockfree/Makefile.am
===================================================================
--- trunk/src/lockfree/Makefile.am (rev 0)
+++ trunk/src/lockfree/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,26 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SUBDIRS=tests
+
+lockfreedir=$(aureliadir)/lockfree
+lockfree_HEADERS= \
+ sorted_forward_list.hh \
+ unordered_set.hh \
+ marked_pointer.hh \
+ simple_stack.hh \
+ vector.hh
Added: trunk/src/lockfree/marked_pointer.hh
===================================================================
--- trunk/src/lockfree/marked_pointer.hh (rev 0)
+++ trunk/src/lockfree/marked_pointer.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,51 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __MARKED_POINTER_HH
+# define __MARKED_POINTER_HH
+
+# include <type_traits>
+
+namespace lockfree {
+ namespace details {
+ template <typename T>
+ void assert_align() {
+ static_assert(std::alignment_of<T>::value != 1,
+ "Pointer cannot be marked as its alignment is 1");
+ }
+
+ template <typename T>
+ bool is_marked(T* p) {
+ assert_align<T>();
+ return 0x1 & (size_t)p;
+ };
+
+ template <typename T>
+ T* unmarked(T* p) {
+ assert_align<T>();
+ return (T*)((~0x1) & (size_t)p);
+ };
+
+ template <typename T>
+ T* marked(T* p) {
+ assert_align<T>();
+ return (T*)(0x1 | (size_t)p);
+ };
+ }
+}
+
+#endif
Added: trunk/src/lockfree/simple_stack.hh
===================================================================
--- trunk/src/lockfree/simple_stack.hh (rev 0)
+++ trunk/src/lockfree/simple_stack.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,87 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __SIMPLE_STACK_HH
+# define __SIMPLE_STACK_HH
+
+# include <memory>
+
+namespace lockfree {
+
+ template <typename Elt,
+ typename Alloc = std::allocator<Elt>
+ >
+ class simple_stack {
+ private:
+ struct node {
+ Elt e;
+ node* next;
+ node(Elt&& e, node* next): e(std::move(e)), next(next) {}
+ };
+ typedef typename Alloc::template rebind<node>::other node_allocator_t;
+
+ node_allocator_t alloc;
+ std::atomic<node*> head;
+ public:
+ simple_stack(Alloc alloc = Alloc()): alloc(alloc), head(NULL) {}
+
+ struct wrapped {
+ private:
+ node_allocator_t& alloc;
+ node* n;
+ public:
+ wrapped(node_allocator_t& alloc, node *n): alloc(alloc), n(n) {}
+ bool end() const {
+ return (n == NULL);
+ }
+ Elt operator*() const {
+ return n->e;
+ }
+ ~wrapped() {
+ alloc.destroy(n);
+ alloc.deallocate(n, 1);
+ }
+ };
+
+ void push(const Elt& e) {
+ push(std::move(Elt(e)));
+ }
+
+ void push(Elt&& e) {
+ node* n = alloc.allocate(1);
+ alloc.construct(n, std::move(e), (node*)NULL);
+ node *h;
+ do {
+ h = head.load();
+ n->next = h;
+ } while (!head.compare_exchange_strong(h, n));
+ }
+
+ wrapped pop() {
+ node* n;
+ do {
+ n = head.load();
+ if (n == NULL)
+ return wrapped(alloc, NULL);
+ } while (!head.compare_exchange_strong(n, n->next));
+ return wrapped(alloc, n);
+ }
+ };
+
+}
+
+#endif
Added: trunk/src/lockfree/sorted_forward_list.hh
===================================================================
--- trunk/src/lockfree/sorted_forward_list.hh (rev 0)
+++ trunk/src/lockfree/sorted_forward_list.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,388 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __SORTED_FORWARD_LIST_HH
+# define __SORTED_FORWARD_LIST_HH
+
+# include <functional>
+# include <atomic>
+# include <cassert>
+# include "simple_stack.hh"
+# include "marked_pointer.hh"
+
+namespace lockfree {
+ template <typename Elt,
+ typename Eq = std::equal_to<Elt>,
+ typename Compare = std::less<Elt>,
+ typename Alloc = std::allocator<Elt>,
+ typename Multi = typename std::true_type
+ >
+ class sorted_forward_list {
+ private:
+ struct node;
+ struct node_base {
+ private:
+ std::atomic<node_base*> next;
+ public:
+ node_base(node_base* next): next(next) {}
+ node_base* get_next() const {
+ return next.load();
+ }
+ bool set_next(node_base* expected, node_base* newnext) {
+ return next.compare_exchange_strong(expected, newnext);
+ }
+ void force_set_next(node_base* newnext) {
+ node_base *old;
+ do
+ old = next.load();
+ while (!next.compare_exchange_strong(old, newnext));
+ }
+ const Elt& operator*() const {
+ return static_cast<const node*>(this)->operator*();
+ }
+ };
+ struct node: public node_base {
+ private:
+ Elt e;
+ public:
+ node(Elt&& e, node_base* next): node_base(next), e(e) {}
+ const Elt& operator*() const {
+ return e;
+ }
+ };
+
+ typedef typename Alloc::template rebind<node>::other node_allocator_t;
+ typedef simple_stack<node*,Alloc> sstack_t;
+
+ node_allocator_t node_alloc;
+ Eq eq;
+ Compare compare;
+ node_base head;
+ sstack_t free;
+ std::atomic<size_t> _size;
+
+ public:
+
+ size_t size() const {
+ return _size.load();
+ }
+
+ sorted_forward_list(Eq eq = Eq(), Compare compare = Compare(), Alloc alloc = Alloc())
+ : node_alloc(alloc), eq(eq), compare(compare), head(NULL), free(alloc), _size(0) {}
+
+ struct iterator;
+
+ struct const_iterator: private iterator {
+ explicit const_iterator(node_base* n): iterator(n) {}
+ const_iterator(const iterator& other): iterator(other) {}
+ const_iterator(const const_iterator& other): iterator(other) {}
+
+ node_base* get_node() const {
+ return this->iterator::get_node();
+ }
+
+ const Elt& operator*() const {
+ return this->iterator::operator*();
+ }
+ const_iterator& operator++() {
+ this->iterator::operator++();
+ return *this;
+ }
+ const_iterator& operator++(int) {
+ const_iterator tmp(*this);
+ this->iterator::operator++();
+ return tmp;
+ }
+ bool operator==(const const_iterator& other) const {
+ return this->iterator::operator==(other);
+ }
+ bool operator!=(const const_iterator& other) const {
+ return this->iterator::operator!=(other);
+ }
+ bool operator==(const iterator& other) const {
+ return this->iterator::operator==(other);
+ }
+ bool operator!=(const iterator& other) const {
+ return this->iterator::operator!=(other);
+ }
+ };
+
+ struct iterator {
+ private:
+ node_base* n;
+
+ public:
+ explicit iterator(node_base* n): n(n) {}
+ iterator(const iterator& other): n(other.n) {}
+
+ const Elt& operator*() const {
+ return **n;
+ }
+ iterator& operator++() {
+ n = n->get_next();
+ return *this;
+ }
+
+ iterator& operator++(int) {
+ iterator tmp(*this);
+ n = n->get_next();
+ return tmp;
+ }
+
+ bool operator==(const iterator& other) const {
+ return n == other.n;
+ }
+
+ bool operator!=(const iterator& other) const {
+ return n != other.n;
+ }
+
+ node_base* get_node() const {
+ return n;
+ }
+ };
+
+ /*
+ iterator insert_after(const Elt& elt, const const_iterator& hint = begin(),
+ bool once = !Multi::value) {
+ return insert_after(Elt(elt), hint, once);
+ }
+ */
+
+ const_iterator begin() const {
+ return const_iterator(head.get_next());
+ }
+
+ const_iterator end() const {
+ return const_iterator(NULL);
+ }
+
+ iterator begin() {
+ return iterator(head.get_next());
+ }
+
+ iterator end() {
+ return iterator(NULL);
+ }
+
+ iterator insert_after(Elt&& elt, const const_iterator& hint,
+ bool once = !Multi::value) {
+ return insert_after(std::move(elt), hint.get_node(), once);
+ }
+
+ private:
+ std::pair<node_base*, node_base*> search(const Elt& e) const {
+
+ }
+
+ iterator insert_after(Elt&& elt, node_base* hint,
+ bool once = !Multi::value) {
+ node* n = node_alloc.allocate(1);
+ node_alloc.construct(n, std::move(elt), (node_base*)NULL);
+
+ std::pair<node_base*,node_base*> found;
+ while (true) {
+ found = search(hint, **n);
+ if (once)
+ if ((found.second==NULL)?false:eq(**found.second, **n)) {
+ node_alloc.destroy(n);
+ node_alloc.deallocate(n, 1);
+ return iterator(static_cast<node*>(found.second));
+ }
+
+ n->force_set_next(found.second);
+ if (found.first->set_next(found.second, n)) {
+ _size++;
+ return iterator(n);
+ }
+ };
+ }
+
+ public:
+ iterator insert(Elt&& elt) {
+ return insert_after(std::move(elt), &head);
+ }
+
+ private:
+ std::pair<node_base*, node_base*>
+ search(node_base* hint, const Elt& elt) {
+ typedef std::pair<node_base*, node_base*> rt;
+
+ node_base* before = NULL;
+ node_base* before_next = NULL;
+
+ while (true) {
+ node_base* t = hint;
+ node_base* t_next = t->get_next();
+
+ do {
+ if (!details::is_marked(t_next)) {
+ before = t;
+ before_next = t_next;
+ }
+
+ if (NULL == (t = details::unmarked(t_next)))
+ break ;
+ t_next = t->get_next();
+ } while (details::is_marked(t_next)?true:compare(**t, elt));
+
+ if (before_next == t) {
+ if ((t == NULL)?false:details::is_marked(t->get_next()))
+ continue ;
+ else
+ return rt(before, t);
+ }
+
+ if (before->set_next(before_next, t)) {
+ if ((t == NULL)?false:!details::is_marked(t->get_next()))
+ continue ;
+ else
+ return rt(before, t);
+ }
+ }
+ }
+
+ void erase(node_base* item, node_base* hint) {
+ std::pair<node_base*, node_base*> found;
+ node_base* next;
+
+ while (true) {
+ found = search(hint, **item);
+ if ((found.second == NULL)?true:(found.second != item)) {
+ return ;
+ }
+ next = found.second->get_next();
+ if (!details::is_marked(next))
+ if (found.second->set_next(next, details::marked(next))) {
+ break ;
+ }
+ }
+ _size--;
+ free.push(static_cast<node*>(found.second));
+ if (!found.first->set_next(found.second, next))
+ search(hint, **found.second);
+ }
+
+ void erase(const Elt& item, node_base* hint) {
+ static_assert(!Multi::value, "Cannot erase elements on multilists");
+ std::pair<node_base*, node_base*> found;
+ node_base* next;
+
+ while (true) {
+ found = search(hint, item);
+ if ((found.second == NULL)?true:(!eq(**found.second,item))) {
+ return ;
+ }
+ next = found.second->get_next();
+ if (!details::is_marked(next))
+ if (found.second->set_next(next, details::marked(next))) {
+ break ;
+ }
+ }
+ if (found.first->set_next(found.second, next)) {
+ free.push(static_cast<node*>(found.second));
+ }
+ else {
+ search(hint, **found.second);
+ }
+ }
+
+
+ public:
+ void erase(const Elt& elt) {
+ static_assert(!Multi::value, "Cannot erase elements on multilists");
+ erase(elt, &head);
+ }
+
+ void erase(const Elt& elt, const const_iterator& hint) {
+ static_assert(!Multi::value, "Cannot erase elements on multilists");
+ erase(elt, hint.get_node());
+ }
+
+ void erase(const const_iterator& it, const const_iterator& hint) {
+ erase(it.get_node(), hint.get_node());
+ }
+
+ void erase(const iterator& it) {
+ erase(it.get_node(), &head);
+ }
+
+ private:
+ const_iterator find(const Elt& elt, node_base*hint) const {
+ return const_cast<sorted_forward_list*>(this)->find(elt, hint);
+ }
+
+ iterator find(const Elt& elt, node_base*hint) {
+ std::pair<node_base*, node_base*> found = search(hint, elt);
+ if (found.second == NULL)
+ return iterator(NULL);
+ if (eq(**found.second, elt))
+ return iterator(static_cast<node*>(found.second));
+ return iterator(NULL);
+ }
+
+ public:
+ const_iterator find(const Elt& elt) const {
+ return find(elt, &head);
+ }
+ const_iterator find(const Elt& elt, const const_iterator& hint) const {
+ return find(elt, hint.get_node());
+ }
+
+ iterator find(const Elt& elt) {
+ return find(elt, &head);
+ }
+ iterator find(const Elt& elt, const const_iterator& hint) {
+ return find(elt, hint.get_node());
+ }
+
+ void collect() {
+ while (true) {
+ typename sstack_t::wrapped w = free.pop();
+ if (w.end())
+ break ;
+ node* n = *w;
+ node_alloc.destroy(n);
+ node_alloc.deallocate(n, 1);
+ }
+ }
+
+ void clear() {
+ node* last = NULL;
+ for (node_base* n = head.get_next();
+ ; n = n->get_next()) {
+ if (last != NULL) {
+ node_alloc.destroy(last);
+ node_alloc.deallocate(last, 1);
+ }
+ if (n == NULL) {
+ head.force_set_next(NULL);
+ break ;
+ }
+ last = static_cast<node*>(n);
+ }
+ collect();
+ }
+
+ ~sorted_forward_list() {
+ clear();
+ }
+ };
+
+}
+
+#endif
Property changes on: trunk/src/lockfree/tests
___________________________________________________________________
Added: svn:ignore
+ .deps
Makefile
Makefile.in
test_marked.log
test_sorted_forward_list.log
test-suite.log
test_unordered_set.log
test_vector.log
test_unordered_set
test_vector
test_marked
test_sorted_forward_list
Added: trunk/src/lockfree/tests/Makefile.am
===================================================================
--- trunk/src/lockfree/tests/Makefile.am (rev 0)
+++ trunk/src/lockfree/tests/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,30 @@
+# This file is a part of Aurelia.
+# Copyright (C) 2010 Valentin David
+# Copyright (C) 2010 University of Bergen
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+check_PROGRAMS=test_sorted_forward_list test_marked test_vector \
+ test_unordered_set
+
+test_sorted_forward_list_SOURCES=test_sorted_forward_list.cc
+test_marked_SOURCES=test_marked.cc
+test_vector_SOURCES=test_vector.cc
+test_unordered_set_SOURCES=test_unordered_set.cc
+
+TESTS=$(check_PROGRAMS)
+
+if HAVE_VALGRIND
+TESTS_ENVIRONMENT=ulimit -s 8192; $(VALGRIND) --leak-check=full --show-reachable=yes --error-exitcode=1 >/dev/null --
+endif
Added: trunk/src/lockfree/tests/test_marked.cc
===================================================================
--- trunk/src/lockfree/tests/test_marked.cc (rev 0)
+++ trunk/src/lockfree/tests/test_marked.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,30 @@
+#include "../marked_pointer.hh"
+#include <memory>
+
+using namespace lockfree::details;
+
+int main() {
+ std::auto_ptr<int> somep(new int());
+ int *a = somep.get();
+ int *b = marked(a);
+
+ if (is_marked(a))
+ return 1;
+
+ if (!is_marked(b))
+ return 1;
+
+ if (unmarked(a) != a)
+ return 1;
+
+ if (marked(b) != b)
+ return 1;
+
+ if (unmarked(b) != a)
+ return 1;
+
+ if (marked(a) != b)
+ return 1;
+
+ return 0;
+}
Added: trunk/src/lockfree/tests/test_sorted_forward_list.cc
===================================================================
--- trunk/src/lockfree/tests/test_sorted_forward_list.cc (rev 0)
+++ trunk/src/lockfree/tests/test_sorted_forward_list.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,90 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <random>
+#include <thread>
+#include <list>
+#include <iostream>
+#include "../sorted_forward_list.hh"
+
+typedef lockfree::sorted_forward_list<int> L;
+
+struct insert_random {
+ L& l;
+ std::mt19937 engine;
+
+ insert_random() = delete;
+ insert_random(L& l): l(l) {
+ }
+ insert_random(const insert_random&) = default;
+
+ void operator()() {
+ L::iterator last_to_remove = l.end();
+ std::uniform_int_distribution<> r(0, 4096);
+ for (unsigned i = 0; i < 1000; ++i) {
+ l.insert(r(engine));
+ }
+ }
+};
+
+struct erase_random {
+ L& l;
+ std::mt19937 engine;
+
+ erase_random() = delete;
+ erase_random(L& l): l(l) {
+ }
+ erase_random(const erase_random&) = default;
+
+ void operator()() {
+ L::iterator last_to_remove = l.end();
+ std::uniform_int_distribution<> r(0, 4096);
+ for (unsigned i = 0; i < 1000; ++i) {
+ l.erase(l.find(r(engine)));
+ }
+ }
+};
+
+int main()
+{
+ L l;
+ std::list<std::thread> lt;
+ for (int i = 0; i < 10; ++i)
+ lt.push_front(std::thread(insert_random(l)));
+
+ for (int i = 0; i < 5; ++i)
+ lt.push_front(std::thread(erase_random(l)));
+
+ for (std::list<std::thread>::iterator i = lt.begin();
+ i != lt.end(); ++i) {
+ (*i).join();
+ }
+
+ l.collect();
+
+ int prev = -1;
+ for (L::iterator i = l.begin();
+ i != l.end(); ++i) {
+ if (prev > *i) {
+ std::cerr << prev << ">=" << *i << std::endl;
+ return 1;
+ }
+ prev = *i;
+ }
+
+ return 0;
+}
Added: trunk/src/lockfree/tests/test_unordered_set.cc
===================================================================
--- trunk/src/lockfree/tests/test_unordered_set.cc (rev 0)
+++ trunk/src/lockfree/tests/test_unordered_set.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,95 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <random>
+#include <thread>
+#include <list>
+#include <iostream>
+#include "../unordered_set.hh"
+
+typedef lockfree::unordered_set<int> L;
+
+struct insert_random {
+ L& l;
+ std::mt19937 engine;
+
+ insert_random() = delete;
+ insert_random(L& l): l(l) {
+ }
+ insert_random(const insert_random&) = default;
+
+ void operator()() {
+ std::uniform_int_distribution<> r(0, 4096);
+ for (unsigned i = 0; i < 1000; ++i) {
+ l.insert(r(engine));
+ }
+ }
+};
+
+struct erase_random {
+ L& l;
+ std::mt19937 engine;
+
+ erase_random() = delete;
+ erase_random(L& l): l(l) {
+ }
+ erase_random(const erase_random&) = default;
+
+ void operator()() {
+ std::uniform_int_distribution<> r(0, 4096);
+ for (unsigned i = 0; i < 1000; ++i) {
+ l.erase(r(engine));
+ }
+ }
+};
+
+int main()
+{
+ L l;
+ std::list<std::thread> lt;
+ for (int i = 0; i < 10; ++i)
+ lt.push_front(std::thread(insert_random(l)));
+
+ for (int i = 0; i < 5; ++i)
+ lt.push_front(std::thread(erase_random(l)));
+
+ for (std::list<std::thread>::iterator i = lt.begin();
+ i != lt.end(); ++i) {
+ (*i).join();
+ }
+
+ l.collect();
+
+ l.insert(10);
+ l.erase(10);
+ if (l.find(10) != l.end()) {
+ std::cerr << "Found after erase." << std::endl;
+ return 1;
+ }
+ l.insert(10);
+ if (l.find(10) == l.end()) {
+ std::cerr << "Not found after insert." << std::endl;
+ return 1;
+ }
+
+ if (*(l.find(10)) != 10) {
+ std::cerr << "Found: " << *(l.find(10)) << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
Added: trunk/src/lockfree/tests/test_vector.cc
===================================================================
--- trunk/src/lockfree/tests/test_vector.cc (rev 0)
+++ trunk/src/lockfree/tests/test_vector.cc 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,85 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <random>
+#include <thread>
+#include <list>
+#include <iostream>
+#include "../vector.hh"
+
+typedef lockfree::vector<int, 10> V;
+
+struct set_random {
+ V& v;
+ std::mt19937 engine;
+
+ set_random() = delete;
+ set_random(V& v): v(v) {
+ }
+ set_random(const set_random&) = default;
+
+ void operator()() {
+ std::uniform_int_distribution<> r(0, 4096);
+ for (unsigned i = 0; i < 1000; ++i) {
+ int pos = r(engine)*v.size()/4096;
+ if (pos > 0) v[pos] = pos;
+ }
+ }
+};
+
+struct resize {
+ V& v;
+
+ resize() = delete;
+ resize(V& v): v(v) {
+ }
+ resize(const resize&) = default;
+
+ void operator()() {
+ for (unsigned i = 0; i < 4096; ++i) {
+ v.resize(i);
+ }
+ }
+};
+
+int main()
+{
+ V v(10);
+ std::list<std::thread> lt;
+ for (int i = 0; i < 10; ++i)
+ lt.push_front(std::thread(set_random(v)));
+
+ for (int i = 0; i < 5; ++i)
+ lt.push_front(std::thread(resize(v)));
+
+ for (std::list<std::thread>::iterator i = lt.begin();
+ i != lt.end(); ++i) {
+ (*i).join();
+ }
+
+ v.collect();
+
+ for (int i = 0;
+ i < 4096; ++i) {
+ if ((v[i] != i) && (v[i] != 10)) {
+ std::cerr << "v[" << i << "]=" << v[i] << std::endl;
+ return 1;
+ }
+ }
+
+ return 0;
+}
Added: trunk/src/lockfree/unordered_set.hh
===================================================================
--- trunk/src/lockfree/unordered_set.hh (rev 0)
+++ trunk/src/lockfree/unordered_set.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,233 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __UNORDERED_SET_HH
+# define __UNORDERED_SET_HH
+
+# include "sorted_forward_list.hh"
+# include "vector.hh"
+# include "../fast/reset_msb.hh"
+# include "../fast/invert_bits.hh"
+
+namespace lockfree {
+ template <typename T, typename Eq = std::equal_to<T>,
+ typename Hash = std::hash<T>, typename Alloc = std::allocator<T>,
+ typename Multi = std::false_type>
+ class unordered_set {
+ struct elts {
+ private:
+ size_t _invhash;
+ typename std::aligned_storage<sizeof(T),
+ std::alignment_of<T>::value>::type _elt;
+
+ T& elt() {
+ return *reinterpret_cast<T*>(&_elt);
+ }
+ const T& elt() const {
+ return *reinterpret_cast<const T*>(&_elt);
+ }
+
+ public:
+ size_t invhash() const {
+ return _invhash;
+ }
+
+ const T& operator*() const {
+ return elt();
+ }
+ elts(size_t _invhash, T&& elt): _invhash(_invhash) {
+ new (reinterpret_cast<T*>(&_elt)) T(std::move(elt));
+ }
+ elts(size_t _invhash): _invhash(_invhash) {
+ }
+
+ ~elts() {
+ if (_invhash & 0x1)
+ elt().~T();
+ }
+ };
+
+ struct compare_elts {
+ bool operator()(const elts& a, const elts& b) const {
+ return a.invhash() < b.invhash();
+ }
+ };
+
+ struct eq_elts {
+ Eq eq;
+ eq_elts(Eq eq): eq(eq) {}
+
+ bool operator()(const elts& a, const elts& b) const {
+ if (a.invhash() != b.invhash())
+ return false;
+ if (!(a.invhash()&0x1))
+ return false;
+ return eq(*a, *b);
+ }
+ };
+
+ typedef typename Alloc::template rebind<elts>::other elt_alloc_t;
+
+ typedef sorted_forward_list<elts,
+ eq_elts, compare_elts,
+ elt_alloc_t, std::false_type> list_t;
+ typedef vector<typename list_t::const_iterator> entries_t;
+
+ double max_load_factor;
+ Eq eq;
+ Hash hash;
+
+ list_t list;
+ entries_t entries;
+
+ public:
+ unordered_set(Eq eq = Eq(), Hash hash = Hash(), Alloc alloc = Alloc()):
+ max_load_factor(.3),
+ eq(eq), hash(hash), list(eq_elts(eq), compare_elts(),
+ alloc), entries(list.end(), alloc) {
+ entries.resize(1);
+ entries[0x0] = list.insert(elts(0x0));
+ }
+
+ private:
+ typename list_t::const_iterator _get_bucket(size_t b) const {
+ typename list_t::const_iterator i = entries[b];
+ if (i == list.end()) {
+ typename list_t::const_iterator parent =
+ _get_bucket(fast::reset_msb(b));
+ i = const_cast<unordered_set*>(this)->list
+ .insert_after(elts(get_invert(b)&~0x1), parent, true);
+ const_cast<unordered_set*>(this)->entries[b] = i;
+ }
+ return i;
+ }
+
+ size_t get_invert(size_t h) const {
+ size_t v = hash(h);
+ fast::invert_bits(v);
+ return v | 0x1;
+ }
+
+ typename list_t::const_iterator get_bucket(size_t h) const {
+ return _get_bucket(h%entries.size());
+ }
+
+ public:
+ struct iterator {
+ private:
+ typename list_t::const_iterator i;
+
+ public:
+ iterator(const typename list_t::const_iterator& i): i(i) {
+ while ((this->i.get_node() == NULL)?false
+ :(!((*(this->i)).invhash()&0x1)))
+ ++(this->i);
+ }
+ iterator(const iterator&) = default;
+ iterator() = delete;
+
+ const T& operator*() const {
+ return **i;
+ }
+
+ operator const typename list_t::const_iterator&() const {
+ return i;
+ }
+
+ iterator& operator++() {
+ do
+ ++i;
+ while ((this->i.get_node() == NULL)?false
+ :(!((*(this->i)).invhash()&0x1)));
+ return *this;
+ }
+
+ iterator& operator++(int) {
+ iterator tmp(*this);
+ ++(*this);
+ return tmp;
+ }
+
+ bool operator==(const iterator& other) const {
+ return i == other.i;
+ }
+ bool operator!=(const iterator& other) const {
+ return i != other.i;
+ }
+ };
+
+ iterator end() const {
+ return list.end();
+ }
+
+ iterator begin() const {
+ return list.begin();
+ }
+
+ iterator find(const T& elt) const {
+ size_t h = hash(elt);
+ typename list_t::const_iterator i = get_bucket(h);
+ size_t inv = get_invert(h);
+ typename list_t::const_iterator was_found = i;
+ size_t f = 0;
+ for (;
+ i != list.end(); ++i) {
+ if (inv < (*i).invhash())
+ return end();
+ if (inv == (*i).invhash())
+ if (eq(**i, elt))
+ return iterator(i);
+ ++f;
+ }
+ return end();
+ }
+
+ iterator insert(T&& elt) {
+ size_t h = hash(elt);
+ typename list_t::const_iterator i = get_bucket(h);
+ typename list_t::const_iterator ret =
+ list.insert_after(elts(get_invert(h), std::move(elt)), i);
+ size_t size = entries.size();
+ size_t nelts = list.size();
+ if ((((double)nelts) / size) > max_load_factor) {
+ entries.resize(2*size);
+ }
+ return iterator(ret);
+ }
+
+ void collect() {
+ list.collect();
+ entries.collect();
+ }
+
+ void erase(const T& t) {
+ static_assert(!Multi::value, "Cannot erase elements on multiset");
+ erase(find(t));
+ }
+
+ void erase(const iterator& i) {
+ if (i == end())
+ return ;
+ typename list_t::const_iterator j = i;
+ size_t h = hash(*i);
+ typename list_t::const_iterator b = get_bucket(h);
+ list.erase(j, b);
+ }
+ };
+}
+
+#endif
Added: trunk/src/lockfree/vector.hh
===================================================================
--- trunk/src/lockfree/vector.hh (rev 0)
+++ trunk/src/lockfree/vector.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -0,0 +1,140 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __VECTOR_HH
+# define __VECTOR_HH
+
+# include <atomic>
+# include "simple_stack.hh"
+
+namespace lockfree {
+
+ template <typename T, size_t SEG_SIZE = 1024u,
+ typename Alloc = std::allocator<T> >
+ struct vector {
+ private:
+ struct seg_table {
+ size_t n_segments;
+ T** segments;
+ };
+
+ typedef typename Alloc::template rebind<seg_table>::other st_alloc_t;
+ typedef typename Alloc::template rebind<T*>::other pt_alloc_t;
+
+ Alloc alloc;
+ st_alloc_t st_alloc;
+ pt_alloc_t pt_alloc;
+ std::atomic<seg_table*> table;
+ simple_stack<seg_table*> free;
+ T default_value;
+
+ void set_size(size_t size) {
+ size_t isize = (size+SEG_SIZE-1)/SEG_SIZE;
+ seg_table* t = table.load();
+ if (t->n_segments >= isize) {
+ return ;
+ }
+ seg_table* newt = st_alloc.allocate(1);
+ newt->n_segments = isize;
+ newt->segments = pt_alloc.allocate(isize);
+ size_t delete_from = isize;
+ do {
+ t = table.load();
+ if (t->n_segments >= isize) {
+ for (size_t i = delete_from; i < isize; ++i) {
+ for (size_t j = 0; j < SEG_SIZE; ++j)
+ alloc.destroy(newt->segments[i] + j);
+ alloc.deallocate(newt->segments[i], SEG_SIZE);
+ }
+ pt_alloc.deallocate(newt->segments, isize);
+ st_alloc.deallocate(newt, isize);
+ return ;
+ }
+ size_t i = 0;
+ for (; (i < t->n_segments); ++i) {
+ if (i >= delete_from) {
+ for (size_t j = 0; j < SEG_SIZE; ++j)
+ alloc.destroy(newt->segments[i] + j);
+ alloc.deallocate(newt->segments[i], SEG_SIZE);
+ }
+ newt->segments[i] = t->segments[i];
+ }
+ size_t delete_from_next = i;
+ for (; (i < delete_from); ++i) {
+ newt->segments[i] = alloc.allocate(SEG_SIZE);
+ for (size_t j = 0; j < SEG_SIZE; ++j)
+ alloc.construct(newt->segments[i] + j, default_value);
+ }
+ delete_from = delete_from_next;
+ } while (!table.compare_exchange_strong(t, newt));
+ free.push((seg_table*)(t));
+ }
+
+ public:
+ vector(T default_value = T(), Alloc alloc = Alloc())
+ : alloc(alloc), st_alloc(alloc), pt_alloc(alloc),
+ table(st_alloc.allocate(1)), default_value(default_value) {
+ table.load()->n_segments = 0;
+ }
+
+ T& operator[](size_t n) {
+ seg_table* t = table.load();
+ return t->segments[n/SEG_SIZE][n%SEG_SIZE];
+ }
+
+ const T& operator[](size_t n) const {
+ seg_table* t = table.load();
+ return t->segments[n/SEG_SIZE][n%SEG_SIZE];
+ }
+
+ void resize(size_t size) {
+ set_size(size);
+ }
+
+ void collect() {
+ while (true) {
+ typename simple_stack<seg_table*>::wrapped w = free.pop();
+ if (w.end())
+ break ;
+ seg_table *t = *w;
+ if (t->n_segments > 0)
+ pt_alloc.deallocate(t->segments, t->n_segments);
+ st_alloc.deallocate(t, 1);
+ }
+ }
+
+ size_t size() const {
+ return table.load()->n_segments * SEG_SIZE;
+ }
+
+ ~vector() {
+ collect();
+ seg_table* t = table.load();
+ for (size_t i = 0; i < t->n_segments; ++i) {
+ for (size_t j = 0; j < SEG_SIZE; ++j) {
+ alloc.destroy(t->segments[i] + j);
+ }
+ alloc.deallocate(t->segments[i], SEG_SIZE);
+ }
+ if (t->n_segments > 0)
+ pt_alloc.deallocate(t->segments, t->n_segments);
+ st_alloc.deallocate(t, 1);
+ }
+ };
+}
+
+#endif
Modified: trunk/src/memory/pool_allocator.hh
===================================================================
--- trunk/src/memory/pool_allocator.hh 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/src/memory/pool_allocator.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -20,7 +20,8 @@
# include <aurelia-config.hh>
-# include <mutex>
+# include <atomic>
+# include "../lockfree/simple_stack.hh"
# ifdef HAVE_VALGRIND_VALGRIND_H
# include <valgrind/valgrind.h>
@@ -36,32 +37,33 @@
# include <cstdlib>
# include <memory>
-# include <forward_list>
namespace aurelia {
template <int SIZE>
struct BlockList {
private:
- std::forward_list<void*> blocks;
- std::mutex _lock;
+ lockfree::simple_stack<void*> blocks;
+
public:
BlockList() {}
- BlockList(const BlockList& other): blocks(other.blocks), _lock() {}
+ BlockList(const BlockList&) = delete;
void* new_block() {
void *p = malloc(SIZE);
if (p == NULL)
throw std::bad_alloc();
- std::unique_lock<std::mutex> l(_lock);
- blocks.push_front(p);
+ blocks.push(p);
return p;
}
~BlockList() {
- for (std::forward_list<void*>::iterator i = blocks.begin();
- i != blocks.end(); ++i)
- free(*i);
+ while (true) {
+ lockfree::simple_stack<void*>::wrapped w = blocks.pop();
+ if (w.end())
+ return ;
+ free(*w);
+ }
}
};
Modified: trunk/src/terms/Makefile.am
===================================================================
--- trunk/src/terms/Makefile.am 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/src/terms/Makefile.am 2010-10-20 14:45:10 UTC (rev 138)
@@ -20,5 +20,4 @@
term.hh \
constructor.hh \
baf_read.hh \
- shared_object.hh \
- fast_inversion.hh
+ shared_object.hh
Modified: trunk/src/terms/baf_read.hh
===================================================================
--- trunk/src/terms/baf_read.hh 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/src/terms/baf_read.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -17,7 +17,7 @@
#ifndef __BAF_READ_HH
# define __BAF_READ_HH
-# include "fast_inversion.hh"
+# include "../fast/invert_bits.hh"
# include "term.hh"
# include "constructor.hh"
# include <fstream>
@@ -101,7 +101,7 @@
nr_bits = 0;
}
}
- invertbits(val);
+ fast::invert_bits(val);
}
};
Deleted: trunk/src/terms/fast_inversion.hh
===================================================================
--- trunk/src/terms/fast_inversion.hh 2010-10-06 14:54:56 UTC (rev 137)
+++ trunk/src/terms/fast_inversion.hh 2010-10-20 14:45:10 UTC (rev 138)
@@ -1,79 +0,0 @@
-// This file is a part of Aurelia.
-// Copyright (C) 2010 Valentin David
-// Copyright (C) 2010 University of Bergen
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#ifndef __FAST_INVERSION_HH
-# define __FAST_INVERSION_HH
-
-namespace aurelia {
-
-template <int step>
-struct InverseConstants {
-};
-
-template <>
-struct InverseConstants<0> {
- enum { shift = 1,
- pattern = 0xAAAAAAAA
- };
-};
-
-template <>
-struct InverseConstants<1> {
- enum { shift = 2,
- pattern = 0xCCCCCCCC
- };
-};
-
-template <>
-struct InverseConstants<2> {
- enum { shift = 4,
- pattern = 0xF0F0F0F0
- };
-};
-
-template <>
- struct InverseConstants<3> {
- enum { shift = 8,
- pattern = 0xFF00FF00
- };
-};
-
-template <>
- struct InverseConstants<4> {
- enum { shift = 16,
- pattern = 0xFFFF0000
- };
-};
-
-template <int step>
-inline void dostep(unsigned& v) {
- unsigned l = v << InverseConstants<step>::shift;
- v >>= InverseConstants<step>::shift;
- v = (l & InverseConstants<step>::pattern)
- | (v & (InverseConstants<step>::pattern >> InverseConstants<step>::shift));
-}
-
-inline void invertbits(unsigned& v) {
- dostep<0>(v);
- dostep<1>(v);
- dostep<2>(v);
- dostep<3>(v);
- dostep<4>(v);
-}
-
-}
-
-#endif
This was sent by the SourceForge...
[truncated message content] |
|
From: <val...@us...> - 2010-10-06 14:55:06
|
Revision: 137
http://aurelia.svn.sourceforge.net/aurelia/?rev=137&view=rev
Author: valentindavid
Date: 2010-10-06 14:54:56 +0000 (Wed, 06 Oct 2010)
Log Message:
-----------
2010-10-06 Valentin David <val...@ii...>
Use C++0x thread library and remove all thread related Aurelia
code. Thread local support with non trivial destructors is lost.
However the only use was actually a bug.
* src/threads/specific.hh, src/threads/thread.hh,
* src/threads/lock.hh, src/threads/Makefile.am:
Remove.
* demos/04-pools.cc, demos/03-threads.cc,
* src/terms/shared_object.hh, src/memory/pool_allocator.hh:
Use C++0x thread library.
* src/Makefile.am (SUBDIRS): Update.
* config/cxx.m4: Add check for thread_local keyword or for fallback.
* configure.ac: Update config files. Check for thread_local.
* src/aurelia-config.hh.in:
Export fallback for thread_local.
* src/parser_generator/parser_gen_main.cc:
Fix missing include.
Modified Paths:
--------------
trunk/ChangeLog
trunk/config/cxx.m4
trunk/configure.ac
trunk/demos/03-threads.cc
trunk/demos/04-pools.cc
trunk/src/Makefile.am
trunk/src/aurelia-config.hh.in
trunk/src/memory/pool_allocator.hh
trunk/src/parser_generator/parser_gen_main.cc
trunk/src/terms/shared_object.hh
Removed Paths:
-------------
trunk/src/threads/
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/ChangeLog 2010-10-06 14:54:56 UTC (rev 137)
@@ -1,3 +1,28 @@
+2010-10-06 Valentin David <val...@ii...>
+
+ Use C++0x thread library and remove all thread related Aurelia
+ code. Thread local support with non trivial destructors is lost.
+ However the only use was actually a bug.
+
+ * src/threads/specific.hh, src/threads/thread.hh,
+ * src/threads/lock.hh, src/threads/Makefile.am:
+ Remove.
+
+ * demos/04-pools.cc, demos/03-threads.cc,
+ * src/terms/shared_object.hh, src/memory/pool_allocator.hh:
+ Use C++0x thread library.
+
+ * src/Makefile.am (SUBDIRS): Update.
+
+ * config/cxx.m4: Add check for thread_local keyword or for fallback.
+ * configure.ac: Update config files. Check for thread_local.
+
+ * src/aurelia-config.hh.in:
+ Export fallback for thread_local.
+
+ * src/parser_generator/parser_gen_main.cc:
+ Fix missing include.
+
2010-10-05 Valentin David <val...@ii...>
Use max_shared_ptr for generic terms. Now shared_object is only
Modified: trunk/config/cxx.m4
===================================================================
--- trunk/config/cxx.m4 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/config/cxx.m4 2010-10-06 14:54:56 UTC (rev 137)
@@ -158,3 +158,27 @@
AC_LANG_POP
fi
])
+
+AC_DEFUN([CXX0X_THREAD_LOCAL],[
+AC_MSG_CHECKING([whether the compiler supports thread_local])
+AC_LANG_PUSH([C++])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int test() {
+ thread_local int i = 10;
+ return i;
+}
+]])],[AC_MSG_RESULT([yes])],[dnl
+ AC_MSG_CHECKING([whether the compiler supports static __thread])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int test() {
+ static __thread int i = 10;
+ return i;
+ }
+ ]])],[dnl
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([thread_local],[static __thread],[Replacement for thread_local])
+ ],[dnl
+ AC_MSG_RESULT([no])
+ NOTCXX0X([thread_local is not supported])
+ ])
+])
+AC_LANG_POP
+])
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/configure.ac 2010-10-06 14:54:56 UTC (rev 137)
@@ -70,6 +70,7 @@
CXX0X_TYPED_ENUMS
CXX0X_AUTO
CXX0X_DECLTYPE
+CXX0X_THREAD_LOCAL
AC_CHECK_HEADERS([cxxabi.h])
@@ -170,7 +171,6 @@
src/patterns/Makefile
src/llstack/Makefile
src/llstack/tests/Makefile
- src/threads/Makefile
src/Makefile
src/relations/Makefile
src/parser_generator/Makefile
Modified: trunk/demos/03-threads.cc
===================================================================
--- trunk/demos/03-threads.cc 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/demos/03-threads.cc 2010-10-06 14:54:56 UTC (rev 137)
@@ -18,7 +18,7 @@
#include <iostream>
#include <fstream>
#include <terms/baf_read.hh>
-#include <threads/thread.hh>
+#include <thread>
using namespace aurelia;
@@ -27,13 +27,13 @@
typedef Constructor <Main> Cons;
typedef Term<Main> T;
-struct MyThread: public Thread<MyThread> {
+struct MyThread {
Term<Main> term;
MyThread() {
}
- void start() {
+ void operator()() {
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
term = readBaf(Main(), in);
@@ -50,8 +50,10 @@
{
MyThread t1;
MyThread t2;
- t1.wait();
- t2.wait();
+ std::thread a(std::ref(t1));
+ std::thread b(std::ref(t2));
+ a.join();
+ b.join();
if (t1.term == T()) {
return 1;
Modified: trunk/demos/04-pools.cc
===================================================================
--- trunk/demos/04-pools.cc 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/demos/04-pools.cc 2010-10-06 14:54:56 UTC (rev 137)
@@ -18,7 +18,7 @@
#include <iostream>
#include <fstream>
#include <terms/baf_read.hh>
-#include <threads/thread.hh>
+#include <thread>
using namespace aurelia;
@@ -29,18 +29,16 @@
typedef Term<Main> T;
template <typename Pool>
-struct MyThread: public Thread<MyThread<Pool> > {
- Term<Pool> *term;
- Lock lock;
+struct MyThread {
+ Term<Pool> term;
- MyThread(): term(NULL) {
- lock.lock();
+ MyThread() {
}
- void start() {
+ void operator()() {
try {
std::ifstream in(SRCDIR"/input", std::ios_base::in);
- term = new Term<Pool>(readBaf(Pool(), in));
+ term = readBaf(Pool(), in);
}
catch (std::ios_base::failure f) {
std::cerr << "Failure while loading input file: "
@@ -50,7 +48,6 @@
std::cerr << "Failure while loading input file: bad format"
<< std::endl;
}
- lock.unlock();
}
};
@@ -58,22 +55,18 @@
{
MyThread<Main> t1;
MyThread<Second> t2;
- t1.lock.lock();
- t2.lock.lock();
+ std::thread a(std::ref(t1));
+ std::thread b(std::ref(t2));
+ a.join();
+ b.join();
- if (t1.term == NULL) {
- if (t2.term != NULL)
- delete t2.term;
+ if (t1.term == Term<Main>()) {
return 1;
}
- if (t2.term == NULL) {
- delete t1.term;
+ if (t2.term == Term<Second>()) {
return 1;
}
+ std::cout << (t1.term == t2.term) << std::endl;
- std::cout << (*(t1.term) == *(t2.term)) << std::endl;
- delete t1.term;
- delete t2.term;
-
return 0;
}
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/src/Makefile.am 2010-10-06 14:54:56 UTC (rev 137)
@@ -25,7 +25,6 @@
strategies \
streams \
terms \
- threads \
box \
max_shared \
hash \
Modified: trunk/src/aurelia-config.hh.in
===================================================================
--- trunk/src/aurelia-config.hh.in 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/src/aurelia-config.hh.in 2010-10-06 14:54:56 UTC (rev 137)
@@ -62,3 +62,6 @@
# undef WORDS_BIGENDIAN
# endif
#endif
+
+/* Replacement for thread_local */
+#undef thread_local
Modified: trunk/src/memory/pool_allocator.hh
===================================================================
--- trunk/src/memory/pool_allocator.hh 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/src/memory/pool_allocator.hh 2010-10-06 14:54:56 UTC (rev 137)
@@ -18,55 +18,43 @@
#ifndef __POOL_ALLOCATOR_HH
# define __POOL_ALLOCATOR_HH
-#include <aurelia-config.hh>
+# include <aurelia-config.hh>
-#ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-# include "../threads/specific.hh"
-#endif
+# include <mutex>
-# include "../threads/lock.hh"
+# ifdef HAVE_VALGRIND_VALGRIND_H
+# include <valgrind/valgrind.h>
+# include <valgrind/memcheck.h>
+# else
+# define VALGRIND_CREATE_MEMPOOL(X, Y, Z)
+# define VALGRIND_MAKE_MEM_NOACCESS(X, Y)
+# define VALGRIND_MEMPOOL_ALLOC(X, Y, Z)
+# define VALGRIND_MEMPOOL_FREE(X, Y)
+# define VALGRIND_MAKE_MEM_DEFINED(X, Y)
+# define VALGRIND_MAKE_MEM_UNDEFINED(X, Y)
+# endif
-#ifdef HAVE_VALGRIND_VALGRIND_H
-# include <valgrind/valgrind.h>
-# include <valgrind/memcheck.h>
-#else
-# define VALGRIND_CREATE_MEMPOOL(X, Y, Z)
-# define VALGRIND_MAKE_MEM_NOACCESS(X, Y)
-# define VALGRIND_MEMPOOL_ALLOC(X, Y, Z)
-# define VALGRIND_MEMPOOL_FREE(X, Y)
-# define VALGRIND_MAKE_MEM_DEFINED(X, Y)
-# define VALGRIND_MAKE_MEM_UNDEFINED(X, Y)
-#endif
+# include <cstdlib>
+# include <memory>
+# include <forward_list>
-#include <cstdlib>
-#include <memory>
-#include <forward_list>
-#include <cassert>
-
-#include <iostream>
-
namespace aurelia {
template <int SIZE>
struct BlockList {
private:
std::forward_list<void*> blocks;
-#ifdef HAVE_PTHREAD_H
- Lock _lock;
-#else
- NoLock _lock;
-#endif
+ std::mutex _lock;
public:
BlockList() {}
+ BlockList(const BlockList& other): blocks(other.blocks), _lock() {}
void* new_block() {
void *p = malloc(SIZE);
if (p == NULL)
throw std::bad_alloc();
- _lock.lock();
+ std::unique_lock<std::mutex> l(_lock);
blocks.push_front(p);
- _lock.unlock();
return p;
}
@@ -97,27 +85,15 @@
Block *next;
};
-#if defined(HAVE_PTHREAD_H)
static Block*& free() {
- static ThreadSpecific<Block*> _free = NULL;
- return *_free;
+ thread_local Block* _free = NULL;
+ return _free;
}
static BlockList<sizeof(Block)*POOL_SIZE>& blocks() {
- static ThreadSpecific<BlockList<sizeof(Block)*POOL_SIZE>, std::true_type> _blocks;
- return *_blocks;
- }
-#else
- static Block*& free() {
- static Block* _free = NULL;
- return *free;
- }
-
- static BlockList<sizeof(Block)*POOL_SIZE>& blocks() {
static BlockList<sizeof(Block)*POOL_SIZE> _blocks;
return _blocks;
}
-#endif
static Block* ensure_blocks() {
Block* f = free();
Modified: trunk/src/parser_generator/parser_gen_main.cc
===================================================================
--- trunk/src/parser_generator/parser_gen_main.cc 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/src/parser_generator/parser_gen_main.cc 2010-10-06 14:54:56 UTC (rev 137)
@@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <iostream>
#include <fstream>
#include "terms/term.hh"
Modified: trunk/src/terms/shared_object.hh
===================================================================
--- trunk/src/terms/shared_object.hh 2010-10-05 21:13:23 UTC (rev 136)
+++ trunk/src/terms/shared_object.hh 2010-10-06 14:54:56 UTC (rev 137)
@@ -21,12 +21,21 @@
* \brief Generic shared objects
*/
-# include "../threads/lock.hh"
+# include <mutex>
# include "../memory/pool_allocator.hh"
# include <unordered_set>
namespace aurelia {
+struct NoLock {
+public:
+ void lock() const {
+ }
+
+ void unlock() const {
+ }
+};
+
//! \brief Type traits for selecting core type of shared objects
template <typename T>
struct CoreTypeOf {};
@@ -49,7 +58,7 @@
template <>
struct SOLock<True> {
- typedef Lock res;
+ typedef std::mutex res;
};
template <typename HasLock>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|