From 753a9d37cd163fb8be1488ee3143cd440717b9dc Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Wed, 17 Nov 2010 18:47:53 +0100
Subject: [PATCH] FunExecContext - Function execution context class. Functions
 operate on it now instead of on just SentenceContext. It's open to additions
 in future. Main purpose atm is to hold Variables as well as SentenceContext.
 Done some cleanup in code too. Updated tests to reflect the FunExecContext
 change as well.

---
 libwccl/ops/affix.cpp          |  2 +-
 libwccl/ops/affix.h            |  5 +---
 libwccl/ops/and.cpp            |  5 +++-
 libwccl/ops/and.h              |  8 ++----
 libwccl/ops/conditional.h      | 13 ++++------
 libwccl/ops/constant.h         |  3 +--
 libwccl/ops/equals.h           |  8 ++----
 libwccl/ops/formatters.h       |  4 ---
 libwccl/ops/functions.h        |  6 ++---
 libwccl/ops/funexeccontext.h   | 47 ++++++++++++++++++++++++++++++++++
 libwccl/ops/intersects.h       | 15 +----------
 libwccl/ops/issubsetof.h       | 13 +---------
 libwccl/ops/logicalpredicate.h |  3 ---
 libwccl/ops/nor.cpp            |  4 ++-
 libwccl/ops/nor.h              |  7 +----
 libwccl/ops/or.cpp             |  4 ++-
 libwccl/ops/or.h               |  7 +----
 libwccl/ops/predicate.h        |  2 --
 libwccl/ops/regex.cpp          |  7 +++--
 libwccl/ops/regex.h            |  7 +----
 libwccl/ops/setpredicate.h     |  7 +++--
 libwccl/ops/tolower.cpp        |  2 +-
 libwccl/ops/tolower.h          |  5 +---
 libwccl/ops/toupper.cpp        |  2 +-
 libwccl/ops/toupper.h          |  5 +---
 tests/conditional.cpp          | 10 +++++---
 tests/constant_tests.cpp       | 14 +++++-----
 tests/logicalpredicates.cpp    | 33 +++++++++++++-----------
 tests/regex.cpp                | 10 +++++---
 tests/strsetfunctions.cpp      | 20 ++++++++-------
 30 files changed, 138 insertions(+), 140 deletions(-)
 create mode 100644 libwccl/ops/funexeccontext.h

diff --git a/libwccl/ops/affix.cpp b/libwccl/ops/affix.cpp
index 892a3c0..59562af 100644
--- a/libwccl/ops/affix.cpp
+++ b/libwccl/ops/affix.cpp
@@ -20,7 +20,7 @@ std::string Affix::to_raw_string() const {
 	return str.str();
 }
 
-Affix::BaseRetValPtr Affix::apply_internal(const SentenceContext& context) const
+Affix::BaseRetValPtr Affix::apply_internal(const FunExecContext& context) const
 {
 	if(affix_length_ == 0) {
 		return strset_expr_->apply(context);
diff --git a/libwccl/ops/affix.h b/libwccl/ops/affix.h
index fc38e59..f52129d 100644
--- a/libwccl/ops/affix.h
+++ b/libwccl/ops/affix.h
@@ -1,7 +1,6 @@
 #ifndef LIBWCCL_OPS_AFFIX_H
 #define LIBWCCL_OPS_AFFIX_H
 
-#include <boost/shared_ptr.hpp>
 #include <libwccl/values/strset.h>
 #include <libwccl/ops/functions.h>
 
@@ -45,13 +44,11 @@ protected:
 	const StrSetFunctionPtr strset_expr_;
 	const int affix_length_;
 
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Get a string set from the argument expression and return copy of the set
 	 * with all strings converted into prefixes or suffixes of given length
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const;
 };
 
 } /* end ns Wccl */
diff --git a/libwccl/ops/and.cpp b/libwccl/ops/and.cpp
index 758ce19..0e119a7 100644
--- a/libwccl/ops/and.cpp
+++ b/libwccl/ops/and.cpp
@@ -1,8 +1,11 @@
 #include <libwccl/ops/and.h>
+#include <boost/foreach.hpp>
+#undef foreach
+#define foreach         BOOST_FOREACH
 
 namespace Wccl {
 
-And::BaseRetValPtr And::apply_internal(const SentenceContext &context) const
+And::BaseRetValPtr And::apply_internal(const FunExecContext& context) const
 {
 	foreach(boost::shared_ptr< Function<Bool> > expression, *expressions_) {
 		if(!(expression->apply(context)->get_value())) {
diff --git a/libwccl/ops/and.h b/libwccl/ops/and.h
index 9e3b50e..46b74a3 100644
--- a/libwccl/ops/and.h
+++ b/libwccl/ops/and.h
@@ -1,9 +1,6 @@
 #ifndef LIBWCCL_OPS_AND_H
 #define LIBWCCL_OPS_AND_H
 
-#include <boost/foreach.hpp>
-#define foreach         BOOST_FOREACH
-
 #include <libwccl/ops/logicalpredicate.h>
 
 namespace Wccl {
@@ -20,14 +17,13 @@ public:
 	}
 
 protected :
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr ;
-
 	/**
 	 * "And" predicate evaluates each expression from left to right,
      * and returns False once an expression evaluating to False is found.
      * If all expressions were True, it returns True.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext&) const;
+	virtual BaseRetValPtr apply_internal(
+		const FunExecContext& context) const;
 
 	virtual const std::string raw_operator_name() const;
 };
diff --git a/libwccl/ops/conditional.h b/libwccl/ops/conditional.h
index dfae932..80398fd 100644
--- a/libwccl/ops/conditional.h
+++ b/libwccl/ops/conditional.h
@@ -1,17 +1,15 @@
 #ifndef LIBWCCL_OPS_CONDITIONAL_H
 #define LIBWCCL_OPS_CONDITIONAL_H
 
-#include <boost/shared_ptr.hpp>
 #include <boost/mpl/list.hpp>
-#include <boost/mpl/assert.hpp>
 #include <boost/mpl/count.hpp>
-#include <libwccl/ops/predicate.h>
-#include <libwccl/ops/formatters.h>
-#include <libwccl/ops/constant.h>
-
 #include <sstream>
 #include <boost/format.hpp>
 
+#include <libwccl/ops/predicate.h>
+#include <libwccl/ops/constant.h>
+#include <libwccl/ops/formatters.h>
+
 namespace Wccl {
 
 /**
@@ -65,13 +63,12 @@ protected:
 	}
 
 	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Evaluate the predicate. If it is true, evaluate and return value of
 	 * iftrue_expression. If predicate is false, evalute and return value
 	 * of iffalse_expression.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const {
 		if(this->cond_expr_->apply(context)->get_value()) {
 			return iftrue_expr_->apply(context);
 		}
diff --git a/libwccl/ops/constant.h b/libwccl/ops/constant.h
index 67f15ef..c5c933f 100644
--- a/libwccl/ops/constant.h
+++ b/libwccl/ops/constant.h
@@ -42,11 +42,10 @@ public:
 
 protected :
 	typedef FunctionBase::BaseRetValPtr BaseRetValPtr ;
-
 	/**
 	 * Applying Constant function returns the held value of a constant
 	 */
-	virtual BaseRetValPtr  apply_internal(const SentenceContext&) const {
+	virtual BaseRetValPtr  apply_internal(const FunExecContext&) const {
 		return BaseRetValPtr (new T(*value_));
 	}
 
diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h
index 7864afd..0b1b6d4 100644
--- a/libwccl/ops/equals.h
+++ b/libwccl/ops/equals.h
@@ -1,9 +1,7 @@
 #ifndef LIBWCCL_OPS_EQUALS_H
 #define LIBWCCL_OPS_EQUALS_H
 
-#include <boost/shared_ptr.hpp>
 #include <boost/mpl/list.hpp>
-#include <boost/mpl/assert.hpp>
 #include <boost/mpl/count.hpp>
 #include <libwccl/ops/predicate.h>
 #include <libwccl/ops/formatters.h>
@@ -41,13 +39,11 @@ protected:
 	const ArgFunctionPtr arg1_expr_;
 	const ArgFunctionPtr arg2_expr_;
 
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Take values of arguments from expressions and return True if they are equal,
 	 * False otherwise.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const {
 		boost::shared_ptr<T> arg1 = this->arg1_expr_->apply(context);
 		boost::shared_ptr<T> arg2 = this->arg2_expr_->apply(context);
 		if(arg1->equals(*arg2)) {
@@ -94,7 +90,7 @@ protected:
 	 * Take values of arguments from expressions and return True if they are equal,
 	 * False otherwise.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const {
 		boost::shared_ptr<Position> arg1 = this->arg1_expr_->apply(context);
 		boost::shared_ptr<Position> arg2 = this->arg2_expr_->apply(context);
 		if(arg1->equals(*arg2)) {
diff --git a/libwccl/ops/formatters.h b/libwccl/ops/formatters.h
index cc7a089..985ef6f 100644
--- a/libwccl/ops/formatters.h
+++ b/libwccl/ops/formatters.h
@@ -1,10 +1,6 @@
 #ifndef LIBWCCL_OPS_FORMATTERS_H
 #define LIBWCCL_OPS_FORMATTERS_H
 
-#include <boost/shared_ptr.hpp>
-
-#include <libcorpus2/tagset.h>
-
 #include <libwccl/ops/functions.h>
 
 namespace Wccl {
diff --git a/libwccl/ops/functions.h b/libwccl/ops/functions.h
index 8139575..34acfe0 100644
--- a/libwccl/ops/functions.h
+++ b/libwccl/ops/functions.h
@@ -8,7 +8,7 @@
 
 #include <libwccl/ops/operator.h>
 #include <libwccl/values/value.h>
-#include <libwccl/sentencecontext.h>
+#include <libwccl/ops/funexeccontext.h>
 
 namespace Wccl {
 
@@ -21,7 +21,7 @@ protected:
 	/**
 	 * Applies the function, given the sentence context.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const = 0;
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const = 0;
 };
 
 /**
@@ -44,7 +44,7 @@ public:
 	 * type of Value (as shared pointer). Uses apply_internal which has to
 	 * be specified in derived classes.
 	 */
-	RetValPtr apply(const SentenceContext& context) const {
+	RetValPtr apply(const FunExecContext& context) const {
 		RetValPtr v = boost::dynamic_pointer_cast<T>(apply_internal(context));
 		BOOST_ASSERT(v);
 		return v;
diff --git a/libwccl/ops/funexeccontext.h b/libwccl/ops/funexeccontext.h
new file mode 100644
index 0000000..4a41ccc
--- /dev/null
+++ b/libwccl/ops/funexeccontext.h
@@ -0,0 +1,47 @@
+#ifndef LIBWCCL_OPS_FUNEXECCONTEXT_H
+#define LIBWCCL_OPS_FUNEXECCONTEXT_H
+
+#include <boost/noncopyable.hpp>
+#include <libwccl/variables.h>
+#include <libwccl/sentencecontext.h>
+
+namespace Wccl {
+
+/**
+ * Class holding execution context of a functional operator
+ * i.e. state that the function should operate on.
+ */
+class FunExecContext : public boost::noncopyable {
+public:
+	FunExecContext( const SentenceContext& sentence_context,
+					const boost::shared_ptr<Variables>& vars)
+		: sentence_context_(sentence_context), vars_(vars)
+	{
+	}
+
+	/**
+	 * @returns Context of a sentence the operator is applied to.
+	 * @note Functional operators should not change sentence state,
+	 * hence the const reference.
+	 */
+	const SentenceContext& sentence_context() const {
+		return sentence_context_;
+	}
+
+	/**
+	 * @returns Pointer to variables the operator should operate with.
+	 * @note Variables should be accesible to modifications, but overall
+	 * object should not get replaced, hence the const pointer.
+	 */
+	const boost::shared_ptr<Variables>& variables() const {
+		return vars_;
+	}
+
+private:
+	const SentenceContext& sentence_context_;
+	const boost::shared_ptr<Variables> vars_;
+};
+
+} /* end ns Wccl */
+
+#endif // LIBWCCL_OPS_FUNEXECCONTEXT_H
diff --git a/libwccl/ops/intersects.h b/libwccl/ops/intersects.h
index 87308f4..9a3a160 100644
--- a/libwccl/ops/intersects.h
+++ b/libwccl/ops/intersects.h
@@ -1,15 +1,7 @@
 #ifndef LIBWCCL_OPS_INTERSECTS_H
 #define LIBWCCL_OPS_INTERSECTS_H
 
-#include <boost/shared_ptr.hpp>
-
-#include <libcorpus2/tagset.h>
-
-#include <libwccl/values/strset.h>
-#include <libwccl/values/tset.h>
-#include <libwccl/values/bool.h>
 #include <libwccl/ops/setpredicate.h>
-#include <libwccl/ops/formatters.h>
 
 namespace Wccl {
 
@@ -20,8 +12,6 @@ template <class T>
 class Intersects : public SetPredicate<T>
 {
 public:
-	typedef typename SetPredicate<T>::SetFunctionPtr SetFunctionPtr;
-
 	Intersects(const SetFunctionPtr& set1_expr, const SetFunctionPtr& set2_expr)
 		: SetPredicate<T>(set1_expr, set2_expr)
 	{
@@ -32,14 +22,11 @@ public:
 	}
 
 protected:
-
-	typedef typename SetPredicate<T>::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Take values for both sets and return True if they intersect,
 	 * False otherwise.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const {
 		boost::shared_ptr<T> set1 = this->set1_expr_->apply(context);
 		boost::shared_ptr<T> set2 = this->set2_expr_->apply(context);
 		if(set1->is_subset_of(*set2)) {
diff --git a/libwccl/ops/issubsetof.h b/libwccl/ops/issubsetof.h
index 55692a2..685e833 100644
--- a/libwccl/ops/issubsetof.h
+++ b/libwccl/ops/issubsetof.h
@@ -1,15 +1,7 @@
 #ifndef LIBWCCL_OPS_ISSUBSETOF_H
 #define LIBWCCL_OPS_ISSUBSETOF_H
 
-#include <boost/shared_ptr.hpp>
-
-#include <libcorpus2/tagset.h>
-
-#include <libwccl/values/strset.h>
-#include <libwccl/values/tset.h>
-#include <libwccl/values/bool.h>
 #include <libwccl/ops/setpredicate.h>
-#include <libwccl/ops/formatters.h>
 
 namespace Wccl {
 
@@ -32,16 +24,13 @@ public:
 	}
 
 protected:
-
-	typedef typename SetPredicate<T>::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Take value of possible subset in question. If it is an empty set, return False.
 	 * Otherwise, take value of the set that is being compared to.
 	 * Return True if the possible subset is indeed a subset of the compared set,
 	 * otherwise return False.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const {
 		boost::shared_ptr<T> possible_subset = this->set1_expr_->apply(context);
 		if(!possible_subset->empty()) {
 			boost::shared_ptr<T> set_compared_to = this->set2_expr_->apply(context);
diff --git a/libwccl/ops/logicalpredicate.h b/libwccl/ops/logicalpredicate.h
index 384c962..02c6280 100644
--- a/libwccl/ops/logicalpredicate.h
+++ b/libwccl/ops/logicalpredicate.h
@@ -2,9 +2,6 @@
 #define LIBWCCL_OPS_LOGICALPREDICATE_H
 
 #include <vector>
-#include <boost/shared_array.hpp>
-#include <boost/assert.hpp>
-#include <libcorpus2/tagset.h>
 
 #include <libwccl/ops/predicate.h>
 
diff --git a/libwccl/ops/nor.cpp b/libwccl/ops/nor.cpp
index d547da3..4798819 100644
--- a/libwccl/ops/nor.cpp
+++ b/libwccl/ops/nor.cpp
@@ -1,8 +1,10 @@
 #include <libwccl/ops/nor.h>
+#include <boost/foreach.hpp>
+#define foreach         BOOST_FOREACH
 
 namespace Wccl {
 
-Nor::BaseRetValPtr Nor::apply_internal(const SentenceContext &context) const
+Nor::BaseRetValPtr Nor::apply_internal(const FunExecContext& context) const
 {
 	foreach(BoolFunctionPtr expression, *expressions_) {
 		if(expression->apply(context)->get_value()) {
diff --git a/libwccl/ops/nor.h b/libwccl/ops/nor.h
index e826365..1b5e10a 100644
--- a/libwccl/ops/nor.h
+++ b/libwccl/ops/nor.h
@@ -1,9 +1,6 @@
 #ifndef LIBWCCL_OPS_NOR_H
 #define LIBWCCL_OPS_NOR_H
 
-#include <boost/foreach.hpp>
-#define foreach         BOOST_FOREACH
-
 #include <libwccl/ops/logicalpredicate.h>
 
 namespace Wccl {
@@ -21,15 +18,13 @@ public:
 	}
 
 protected :
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr ;
-
 	/**
 	 * "Nor" (aka "not") predicate evaluates expressions one by one in order
      * from left to right, and False is returned once an expression evaluating
      * to True is found.
 	 * If all of the expressions were False, True is returned.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext&) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext&) const;
 
 	virtual const std::string raw_operator_name() const;
 };
diff --git a/libwccl/ops/or.cpp b/libwccl/ops/or.cpp
index 7d9cf16..bdce8c6 100644
--- a/libwccl/ops/or.cpp
+++ b/libwccl/ops/or.cpp
@@ -1,8 +1,10 @@
 #include <libwccl/ops/or.h>
+#include <boost/foreach.hpp>
+#define foreach         BOOST_FOREACH
 
 namespace Wccl {
 
-Or::BaseRetValPtr Or::apply_internal(const SentenceContext &context) const
+Or::BaseRetValPtr Or::apply_internal(const FunExecContext& context) const
 {
 	foreach(BoolFunctionPtr expression, *expressions_) {
 		if(expression->apply(context)->get_value()) {
diff --git a/libwccl/ops/or.h b/libwccl/ops/or.h
index 574f9bd..22b3597 100644
--- a/libwccl/ops/or.h
+++ b/libwccl/ops/or.h
@@ -1,9 +1,6 @@
 #ifndef LIBWCCL_OPS_OR_H
 #define LIBWCCL_OPS_OR_H
 
-#include <boost/foreach.hpp>
-#define foreach         BOOST_FOREACH
-
 #include <libwccl/ops/logicalpredicate.h>
 
 namespace Wccl {
@@ -20,14 +17,12 @@ public:
 	}
 
 protected :
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr ;
-
 	/**
 	 * "Or" predicate evaluates expressions one by one in order from left to right,
 	 * and True is returned once an expression evaluating to True is found.
 	 * If all of the expressions were False, False is returned.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext&) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext&) const;
 
 	virtual const std::string raw_operator_name() const;
 };
diff --git a/libwccl/ops/predicate.h b/libwccl/ops/predicate.h
index d4d84ec..f064bee 100644
--- a/libwccl/ops/predicate.h
+++ b/libwccl/ops/predicate.h
@@ -1,11 +1,9 @@
 #ifndef LIBWCCL_OPS_PREDICATE_H
 #define LIBWCCL_OPS_PREDICATE_H
 
-#include <boost/shared_ptr.hpp>
 #include <boost/scoped_ptr.hpp>
 
 #include <libwccl/values/bool.h>
-#include <libwccl/ops/functions.h>
 #include <libwccl/ops/constant.h>
 
 namespace Wccl {
diff --git a/libwccl/ops/regex.cpp b/libwccl/ops/regex.cpp
index 8b44177..0c4dca7 100644
--- a/libwccl/ops/regex.cpp
+++ b/libwccl/ops/regex.cpp
@@ -1,4 +1,7 @@
 #include <libwccl/ops/regex.h>
+#include <boost/foreach.hpp>
+#define foreach         BOOST_FOREACH
+
 #include <sstream>
 #include <libpwrutils/util.h>
 
@@ -69,8 +72,8 @@ std::string Regex::to_raw_string() const {
 	return ss.str();
 }
 
-Regex::BaseRetValPtr Regex::apply_internal(const SentenceContext& context) const {
-	const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context);
+Regex::BaseRetValPtr Regex::apply_internal(const FunExecContext& context) const {
+	const boost::shared_ptr<StrSet>& set = strset_expr_->apply(context);
 	if(set->empty()) {
 		return Predicate::False->apply(context);
 	}
diff --git a/libwccl/ops/regex.h b/libwccl/ops/regex.h
index 63784f0..7c87cf9 100644
--- a/libwccl/ops/regex.h
+++ b/libwccl/ops/regex.h
@@ -1,12 +1,9 @@
 #ifndef LIBWCCL_OPS_REGEX_H
 #define LIBWCCL_OPS_REGEX_H
 
-#include <boost/shared_ptr.hpp>
-#include <boost/scoped_ptr.hpp>
 #include <unicode/regex.h>
 
 #include <libwccl/exception.h>
-#include <libwccl/values/bool.h>
 #include <libwccl/values/strset.h>
 #include <libwccl/ops/predicate.h>
 
@@ -42,15 +39,13 @@ public:
 	}
 
 protected:	
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Get a string set from the argument expression,
 	 * apply regular expression to each string one by one,
 	 * return false if a string not matching expression is found.
 	 * Return true if all strings matched the regular espression.
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const;
 
 private:
 	const StrSetFunctionPtr strset_expr_;
diff --git a/libwccl/ops/setpredicate.h b/libwccl/ops/setpredicate.h
index 5ca8c57..c8e0ca9 100644
--- a/libwccl/ops/setpredicate.h
+++ b/libwccl/ops/setpredicate.h
@@ -1,11 +1,12 @@
 #ifndef LIBWCCL_OPS_SETPREDICATE_H
 #define LIBWCCL_OPS_SETPREDICATE_H
 
-#include <boost/shared_ptr.hpp>
 #include <boost/mpl/list.hpp>
-#include <boost/mpl/assert.hpp>
 #include <boost/mpl/count.hpp>
 #include <libwccl/ops/predicate.h>
+#include <libwccl/values/strset.h>
+#include <libwccl/values/tset.h>
+
 #include <libwccl/ops/formatters.h>
 
 namespace Wccl {
@@ -37,8 +38,6 @@ public:
 protected:
 	const SetFunctionPtr set1_expr_;
 	const SetFunctionPtr set2_expr_;
-
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
 };
 
 } /* end ns Wccl */
diff --git a/libwccl/ops/tolower.cpp b/libwccl/ops/tolower.cpp
index d553cc7..52ad8c3 100644
--- a/libwccl/ops/tolower.cpp
+++ b/libwccl/ops/tolower.cpp
@@ -12,7 +12,7 @@ std::string ToLower::to_raw_string() const {
 	return UnaryFunctionFormatter::to_raw_string(*this, *strset_expr_);
 }
 
-ToLower::BaseRetValPtr ToLower::apply_internal(const SentenceContext& context) const {
+ToLower::BaseRetValPtr ToLower::apply_internal(const FunExecContext& context) const {
 	const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context);
 	boost::shared_ptr<StrSet > l_set = boost::make_shared<StrSet>();
 	//TODO: should tolower be a method of StrSet as well?
diff --git a/libwccl/ops/tolower.h b/libwccl/ops/tolower.h
index 8edcba2..6f7bd30 100644
--- a/libwccl/ops/tolower.h
+++ b/libwccl/ops/tolower.h
@@ -1,7 +1,6 @@
 #ifndef LIBWCCL_OPS_TOLOWER_H
 #define LIBWCCL_OPS_TOLOWER_H
 
-#include <boost/shared_ptr.hpp>
 #include <libwccl/values/strset.h>
 #include <libwccl/ops/functions.h>
 
@@ -42,13 +41,11 @@ public:
 protected:
 	const StrSetFunctionPtr strset_expr_;
 
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Get a string set from the argument expression and return copy of the set
 	 * with all strings in lower case form
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const;
 };
 
 } /* end ns Wccl */
diff --git a/libwccl/ops/toupper.cpp b/libwccl/ops/toupper.cpp
index 1e94d31..ec55211 100644
--- a/libwccl/ops/toupper.cpp
+++ b/libwccl/ops/toupper.cpp
@@ -12,7 +12,7 @@ std::string ToUpper::to_raw_string() const {
 	return UnaryFunctionFormatter::to_raw_string(*this, *strset_expr_);
 }
 
-ToUpper::BaseRetValPtr ToUpper::apply_internal(const SentenceContext& context) const {
+ToUpper::BaseRetValPtr ToUpper::apply_internal(const FunExecContext& context) const {
 	const boost::shared_ptr<StrSet >& set = strset_expr_->apply(context);
 	boost::shared_ptr<StrSet > u_set = boost::make_shared<StrSet>();
 	//TODO: should tolower be a method of StrSet as well?
diff --git a/libwccl/ops/toupper.h b/libwccl/ops/toupper.h
index 6491d92..c3414d3 100644
--- a/libwccl/ops/toupper.h
+++ b/libwccl/ops/toupper.h
@@ -1,7 +1,6 @@
 #ifndef LIBWCCL_OPS_TOUPPER_H
 #define LIBWCCL_OPS_TOUPPER_H
 
-#include <boost/shared_ptr.hpp>
 #include <libwccl/values/strset.h>
 #include <libwccl/ops/functions.h>
 
@@ -42,13 +41,11 @@ public:
 protected:
 	const StrSetFunctionPtr strset_expr_;
 
-	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
-
 	/**
 	 * Get a string set from the argument expression and return copy of the set
 	 * with all strings in upper case form
 	 */
-	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const;
+	virtual BaseRetValPtr apply_internal(const FunExecContext& context) const;
 };
 
 } /* end ns Wccl */
diff --git a/tests/conditional.cpp b/tests/conditional.cpp
index 5b482e2..cfa78ab 100644
--- a/tests/conditional.cpp
+++ b/tests/conditional.cpp
@@ -20,6 +20,7 @@ struct CondFix
 {
 	CondFix()
 		: sc(boost::make_shared<Corpus2::Sentence>()),
+		  cx(sc, boost::make_shared<Variables>()),
 		  tagset(),
 		  true_value(true),
 		  false_value(false),
@@ -28,6 +29,7 @@ struct CondFix
 	{		
 	}
 	SentenceContext sc;
+	FunExecContext cx;
 	Corpus2::Tagset tagset;
 
 	Bool true_value;
@@ -78,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(true_condition_strset, CondFixStrSet)
 		iftrue_strset_expr,
 		iffalse_strset_expr));
 
-	BOOST_CHECK(iftrue_strset.equals(*(cond->apply(sc))));
+	BOOST_CHECK(iftrue_strset.equals(*(cond->apply(cx))));
 }
 
 BOOST_FIXTURE_TEST_CASE(false_condition_strset, CondFixStrSet)
@@ -88,7 +90,7 @@ BOOST_FIXTURE_TEST_CASE(false_condition_strset, CondFixStrSet)
 			iftrue_strset_expr,
 			iffalse_strset_expr));
 
-	BOOST_CHECK(iffalse_strset.equals(*(cond->apply(sc))));
+	BOOST_CHECK(iffalse_strset.equals(*(cond->apply(cx))));
 }
 
 BOOST_FIXTURE_TEST_CASE(true_condition_op_strset, CondFixStrSet)
@@ -97,7 +99,7 @@ BOOST_FIXTURE_TEST_CASE(true_condition_op_strset, CondFixStrSet)
 		true_constant,
 		iftrue_strset_expr));
 
-	BOOST_CHECK(iftrue_strset.equals(*(cond->apply(sc))));
+	BOOST_CHECK(iftrue_strset.equals(*(cond->apply(cx))));
 }
 
 BOOST_FIXTURE_TEST_CASE(false_condition_op_strset, CondFixStrSet)
@@ -106,7 +108,7 @@ BOOST_FIXTURE_TEST_CASE(false_condition_op_strset, CondFixStrSet)
 			false_constant,
 			iftrue_strset_expr));
 
-	BOOST_CHECK(empty_strset.equals(*(cond->apply(sc))));
+	BOOST_CHECK(empty_strset.equals(*(cond->apply(cx))));
 }
 
 //------ to_string test cases -------
diff --git a/tests/constant_tests.cpp b/tests/constant_tests.cpp
index 8939e95..b4754c7 100644
--- a/tests/constant_tests.cpp
+++ b/tests/constant_tests.cpp
@@ -16,6 +16,7 @@ struct BoolFix
 {
 	BoolFix()
 		: sc(boost::make_shared<Corpus2::Sentence>()),
+		  cx(sc, boost::make_shared<Variables>()),
 		  tagset(),
 		  true_value(true),
 		  false_value(false),
@@ -24,6 +25,7 @@ struct BoolFix
 	{
 	}
 	SentenceContext sc;
+	FunExecContext cx;
 	Corpus2::Tagset tagset;
 
 	Bool true_value;
@@ -35,9 +37,9 @@ struct BoolFix
 BOOST_FIXTURE_TEST_CASE(bool_apply, BoolFix)
 {
 	BOOST_CHECK_EQUAL(true, true_value.get_value());
-	BOOST_CHECK_EQUAL(true, true_constant.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(true, true_constant.apply(cx)->get_value());
 	BOOST_CHECK_EQUAL(false, false_value.get_value());
-	BOOST_CHECK_EQUAL(false, false_constant.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(false, false_constant.apply(cx)->get_value());
 }
 
 BOOST_FIXTURE_TEST_CASE(bool_to_string, BoolFix)
@@ -58,12 +60,12 @@ BOOST_FIXTURE_TEST_CASE(bool_to_raw_string, BoolFix)
 
 BOOST_FIXTURE_TEST_CASE(bool_value_preserved, BoolFix)
 {
-	boost::shared_ptr<Bool> v = true_constant.apply(sc);
+	boost::shared_ptr<Bool> v = true_constant.apply(cx);
 	v->set_value(false);
-	BOOST_CHECK_EQUAL(true, true_constant.apply(sc)->get_value());
-	v = false_constant.apply(sc);
+	BOOST_CHECK_EQUAL(true, true_constant.apply(cx)->get_value());
+	v = false_constant.apply(cx);
 	v->set_value(true);
-	BOOST_CHECK_EQUAL(false, false_constant.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(false, false_constant.apply(cx)->get_value());
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/logicalpredicates.cpp b/tests/logicalpredicates.cpp
index 5bb4f21..0de82f5 100644
--- a/tests/logicalpredicates.cpp
+++ b/tests/logicalpredicates.cpp
@@ -23,7 +23,8 @@ struct PredFix
 		  true_value(true),
 		  false_value(false),
 		  true_constant(new Constant<Bool>(true_value)),
-		  false_constant(new Constant<Bool>(false_value))
+		  false_constant(new Constant<Bool>(false_value)),
+		  cx(sc, boost::make_shared<Variables>())
 	{
 	}
 	SentenceContext sc;
@@ -33,12 +34,14 @@ struct PredFix
 	Bool false_value;
 	LogicalPredicate::BoolFunctionPtr true_constant;
 	LogicalPredicate::BoolFunctionPtr false_constant;
+
+	FunExecContext cx;
 };
 
 BOOST_FIXTURE_TEST_CASE(predicate_constants, PredFix)
 {
-	BOOST_CHECK_EQUAL(true, Predicate::True->apply(sc)->get_value());
-	BOOST_CHECK_EQUAL(false, Predicate::False->apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(true, Predicate::True->apply(cx)->get_value());
+	BOOST_CHECK_EQUAL(false, Predicate::False->apply(cx)->get_value());
 }
 
 BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix)
@@ -46,10 +49,10 @@ BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix)
 	boost::shared_ptr<And::BoolFunctionPtrVector> v(new And::BoolFunctionPtrVector());
 	v->push_back(true_constant);
 	And pred_and(v);
-	BOOST_CHECK_EQUAL(true, pred_and.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(true, pred_and.apply(cx)->get_value());
 	v->clear();
 	v->push_back(false_constant);
-	BOOST_CHECK_EQUAL(false, pred_and.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(false, pred_and.apply(cx)->get_value());
 }
 
 
@@ -61,7 +64,7 @@ BOOST_FIXTURE_TEST_CASE(and_2arg, PredFix)
 			v->push_back(arg1 != 0 ? true_constant : false_constant);
 			v->push_back(arg2 != 0 ? true_constant : false_constant);
 			And pred_and(v);
-			BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0), pred_and.apply(sc)->get_value());
+			BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0), pred_and.apply(cx)->get_value());
 		}
 	}
 }
@@ -76,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(and_3arg, PredFix)
 				v->push_back(arg2 != 0 ? true_constant : false_constant);
 				v->push_back(arg3 != 0 ? true_constant : false_constant);
 				And pred_and(v);
-				BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0) && (arg3 != 0), pred_and.apply(sc)->get_value());
+				BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0) && (arg3 != 0), pred_and.apply(cx)->get_value());
 			}
 		}
 	}
@@ -87,10 +90,10 @@ BOOST_FIXTURE_TEST_CASE(or_1arg, PredFix)
     boost::shared_ptr<Or::BoolFunctionPtrVector> v(new Or::BoolFunctionPtrVector());
     v->push_back(true_constant);
     Or pred_or(v);
-    BOOST_CHECK_EQUAL(true, pred_or.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(true, pred_or.apply(cx)->get_value());
     v->clear();
     v->push_back(false_constant);
-    BOOST_CHECK_EQUAL(false, pred_or.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(false, pred_or.apply(cx)->get_value());
 }
 
 
@@ -102,7 +105,7 @@ BOOST_FIXTURE_TEST_CASE(or_2arg, PredFix)
             v->push_back(arg1 != 0 ? true_constant : false_constant);
             v->push_back(arg2 != 0 ? true_constant : false_constant);
             Or pred_or(v);
-            BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0), pred_or.apply(sc)->get_value());
+			BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0), pred_or.apply(cx)->get_value());
         }
     }
 }
@@ -117,7 +120,7 @@ BOOST_FIXTURE_TEST_CASE(or_3arg, PredFix)
                 v->push_back(arg2 != 0 ? true_constant : false_constant);
                 v->push_back(arg3 != 0 ? true_constant : false_constant);
                 Or pred_or(v);
-                BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0) || (arg3 != 0), pred_or.apply(sc)->get_value());
+				BOOST_CHECK_EQUAL((arg1 != 0) || (arg2 != 0) || (arg3 != 0), pred_or.apply(cx)->get_value());
             }
         }
     }
@@ -128,10 +131,10 @@ BOOST_FIXTURE_TEST_CASE(nor_1arg, PredFix)
     boost::shared_ptr<Nor::BoolFunctionPtrVector> v(new Nor::BoolFunctionPtrVector());
     v->push_back(true_constant);
     Nor pred_nor(v);
-    BOOST_CHECK_EQUAL(false, pred_nor.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(false, pred_nor.apply(cx)->get_value());
     v->clear();
     v->push_back(false_constant);
-    BOOST_CHECK_EQUAL(true, pred_nor.apply(sc)->get_value());
+	BOOST_CHECK_EQUAL(true, pred_nor.apply(cx)->get_value());
 }
 
 
@@ -143,7 +146,7 @@ BOOST_FIXTURE_TEST_CASE(nor_2arg, PredFix)
             v->push_back(arg1 != 0 ? true_constant : false_constant);
             v->push_back(arg2 != 0 ? true_constant : false_constant);
             Nor pred_nor(v);
-            BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0)), pred_nor.apply(sc)->get_value());
+			BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0)), pred_nor.apply(cx)->get_value());
         }
     }
 }
@@ -158,7 +161,7 @@ BOOST_FIXTURE_TEST_CASE(nor_3arg, PredFix)
                 v->push_back(arg2 != 0 ? true_constant : false_constant);
                 v->push_back(arg3 != 0 ? true_constant : false_constant);
                 Nor pred_nor(v);
-                BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0) || (arg3 != 0)), pred_nor.apply(sc)->get_value());
+				BOOST_CHECK_EQUAL(!((arg1 != 0) || (arg2 != 0) || (arg3 != 0)), pred_nor.apply(cx)->get_value());
             }
         }
     }
diff --git a/tests/regex.cpp b/tests/regex.cpp
index f0b87e1..8884567 100644
--- a/tests/regex.cpp
+++ b/tests/regex.cpp
@@ -18,11 +18,13 @@ struct RegexFix
 {
 	RegexFix()
 		: sc(boost::make_shared<Corpus2::Sentence>()),
-		  tagset()
+		  tagset(),
+		  cx(sc, boost::make_shared<Variables>())
 	{
 	}
 	SentenceContext sc;
 	Corpus2::Tagset tagset;
+	FunExecContext cx;
 };
 
 BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix)
@@ -31,7 +33,7 @@ BOOST_FIXTURE_TEST_CASE(positive_sanity_check, RegexFix)
 	sanity.insert("word");
 	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
 	Regex r(sanity_expr, "word");
-	BOOST_CHECK(r.apply(sc)->get_value());
+	BOOST_CHECK(r.apply(cx)->get_value());
 }
 
 BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix)
@@ -40,7 +42,7 @@ BOOST_FIXTURE_TEST_CASE(negative_sanity_check, RegexFix)
 	sanity.insert("word");
 	boost::shared_ptr<Function<StrSet> > sanity_expr(new Constant<StrSet>(sanity));
 	Regex r(sanity_expr, "Word");
-	BOOST_CHECK(!r.apply(sc)->get_value());
+	BOOST_CHECK(!r.apply(cx)->get_value());
 }
 
 //TODO: need more regex tests...
@@ -65,4 +67,4 @@ BOOST_AUTO_TEST_CASE(regex_to_raw_string)
 	BOOST_CHECK_EQUAL("regex([\"word\"], \"Word\")", r.to_raw_string());
 }
 
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/strsetfunctions.cpp b/tests/strsetfunctions.cpp
index bf0ecc9..d87b402 100644
--- a/tests/strsetfunctions.cpp
+++ b/tests/strsetfunctions.cpp
@@ -20,6 +20,7 @@ struct StrSetFix
 	StrSetFix()
 		: sc(boost::make_shared<Corpus2::Sentence>()),
 		  tagset(),
+		  cx(sc, boost::make_shared<Variables>()),
 		  strset(),
 		  strset_expr()
 	{
@@ -36,6 +37,7 @@ struct StrSetFix
 	}
 	SentenceContext sc;
 	Corpus2::Tagset tagset;
+	FunExecContext cx;
 
 	StrSet strset;
 	boost::shared_ptr<Function<StrSet> > strset_expr;
@@ -55,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(lower, StrSetFix)
 
 	ToLower to_lower(strset_expr);
 
-	BOOST_CHECK(lowerset.equals(*to_lower.apply(sc)));
+	BOOST_CHECK(lowerset.equals(*to_lower.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(upper, StrSetFix)
@@ -72,7 +74,7 @@ BOOST_FIXTURE_TEST_CASE(upper, StrSetFix)
 
 	ToUpper to_upper(strset_expr);
 
-	BOOST_CHECK(upperset.equals(*to_upper.apply(sc)));
+	BOOST_CHECK(upperset.equals(*to_upper.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(prefix, StrSetFix)
@@ -89,7 +91,7 @@ BOOST_FIXTURE_TEST_CASE(prefix, StrSetFix)
 
     Affix prefix(strset_expr, 7);
 
-    BOOST_CHECK(prefixset.equals(*prefix.apply(sc)));
+	BOOST_CHECK(prefixset.equals(*prefix.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(suffix, StrSetFix)
@@ -106,13 +108,13 @@ BOOST_FIXTURE_TEST_CASE(suffix, StrSetFix)
 
     Affix suffix(strset_expr, -7);
 
-    BOOST_CHECK(suffixset.equals(*suffix.apply(sc)));
+	BOOST_CHECK(suffixset.equals(*suffix.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(affix_0, StrSetFix)
 {
 	Affix affix_0(strset_expr, 0);
-	BOOST_CHECK(strset.equals(*affix_0.apply(sc)));
+	BOOST_CHECK(strset.equals(*affix_0.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(lower_locale, StrSetFix)
@@ -135,7 +137,7 @@ BOOST_FIXTURE_TEST_CASE(lower_locale, StrSetFix)
 	ToLower to_lower(boost::shared_ptr<Function<StrSet> >(
 		new Constant<StrSet>(upperset)));
 
-	BOOST_CHECK(lowerset.equals(*to_lower.apply(sc)));
+	BOOST_CHECK(lowerset.equals(*to_lower.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(upper_locale, StrSetFix)
@@ -158,7 +160,7 @@ BOOST_FIXTURE_TEST_CASE(upper_locale, StrSetFix)
 	ToUpper to_upper(boost::shared_ptr<Function<StrSet> >(
 		new Constant<StrSet>(lowerset)));
 
-	BOOST_CHECK(upperset.equals(*to_upper.apply(sc)));
+	BOOST_CHECK(upperset.equals(*to_upper.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(lower_empty, StrSetFix)
@@ -168,7 +170,7 @@ BOOST_FIXTURE_TEST_CASE(lower_empty, StrSetFix)
 	ToLower to_lower(boost::shared_ptr<Function<StrSet> >(
 		new Constant<StrSet>(emptyset)));
 
-	BOOST_CHECK(emptyset.equals(*to_lower.apply(sc)));
+	BOOST_CHECK(emptyset.equals(*to_lower.apply(cx)));
 }
 
 BOOST_FIXTURE_TEST_CASE(upper_empty, StrSetFix)
@@ -178,7 +180,7 @@ BOOST_FIXTURE_TEST_CASE(upper_empty, StrSetFix)
 	ToUpper to_upper(boost::shared_ptr<Function<StrSet> >(
 		new Constant<StrSet>(emptyset)));
 
-	BOOST_CHECK(emptyset.equals(*to_upper.apply(sc)));
+	BOOST_CHECK(emptyset.equals(*to_upper.apply(cx)));
 }
 
 //------ to_string test cases -------
-- 
GitLab