replace the global contextTask with a Context field
This commit is contained in:
committed by
Tomas Babej
parent
53127bf844
commit
65830dd705
@@ -129,6 +129,7 @@ public:
|
|||||||
// CurrentTask resets Context::currentTask to NULL on destruction; this ensures
|
// CurrentTask resets Context::currentTask to NULL on destruction; this ensures
|
||||||
// that this context value is not a dangling pointer.
|
// that this context value is not a dangling pointer.
|
||||||
class CurrentTask {
|
class CurrentTask {
|
||||||
|
public:
|
||||||
~CurrentTask();
|
~CurrentTask();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
18
src/Eval.cpp
18
src/Eval.cpp
@@ -35,8 +35,6 @@
|
|||||||
#include <shared.h>
|
#include <shared.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
|
|
||||||
extern Task* contextTask;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Supported operators, borrowed from C++, particularly the precedence.
|
// Supported operators, borrowed from C++, particularly the precedence.
|
||||||
// Note: table is sorted by length of operator string, so searches match
|
// Note: table is sorted by length of operator string, so searches match
|
||||||
@@ -106,7 +104,7 @@ static bool namedConstants (const std::string& name, Variant& value)
|
|||||||
// Support for evaluating DOM references (add with `e.AddSource(domSource)`)
|
// Support for evaluating DOM references (add with `e.AddSource(domSource)`)
|
||||||
bool domSource (const std::string& identifier, Variant& value)
|
bool domSource (const std::string& identifier, Variant& value)
|
||||||
{
|
{
|
||||||
if (getDOM (identifier, contextTask, value))
|
if (getDOM (identifier, Context::getContext ().currentTask, value))
|
||||||
{
|
{
|
||||||
value.source (identifier);
|
value.source (identifier);
|
||||||
return true;
|
return true;
|
||||||
@@ -292,6 +290,8 @@ void Eval::evaluatePostfixStack (
|
|||||||
Variant left = values.back ();
|
Variant left = values.back ();
|
||||||
values.pop_back ();
|
values.pop_back ();
|
||||||
|
|
||||||
|
auto contextTask = Context::getContext ().currentTask;
|
||||||
|
|
||||||
// Ordering these by anticipation frequency of use is a good idea.
|
// Ordering these by anticipation frequency of use is a good idea.
|
||||||
Variant result;
|
Variant result;
|
||||||
if (token.first == "and") result = left && right;
|
if (token.first == "and") result = left && right;
|
||||||
@@ -313,10 +313,14 @@ void Eval::evaluatePostfixStack (
|
|||||||
else if (token.first == "^") result = left ^ right;
|
else if (token.first == "^") result = left ^ right;
|
||||||
else if (token.first == "%") result = left % right;
|
else if (token.first == "%") result = left % right;
|
||||||
else if (token.first == "xor") result = left.operator_xor (right);
|
else if (token.first == "xor") result = left.operator_xor (right);
|
||||||
else if (token.first == "~") result = left.operator_match (right, *contextTask);
|
else if (contextTask) {
|
||||||
else if (token.first == "!~") result = left.operator_nomatch (right, *contextTask);
|
if (token.first == "~") result = left.operator_match (right, *contextTask);
|
||||||
else if (token.first == "_hastag_") result = left.operator_hastag (right, *contextTask);
|
else if (token.first == "!~") result = left.operator_nomatch (right, *contextTask);
|
||||||
else if (token.first == "_notag_") result = left.operator_notag (right, *contextTask);
|
else if (token.first == "_hastag_") result = left.operator_hastag (right, *contextTask);
|
||||||
|
else if (token.first == "_notag_") result = left.operator_notag (right, *contextTask);
|
||||||
|
else
|
||||||
|
throw format ("Unsupported operator '{1}'.", token.first);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw format ("Unsupported operator '{1}'.", token.first);
|
throw format ("Unsupported operator '{1}'.", token.first);
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,6 @@
|
|||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <shared.h>
|
#include <shared.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Context for DOM evaluations
|
|
||||||
const Task* contextTask = NULL;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Take an input set of tasks and filter into a subset.
|
// Take an input set of tasks and filter into a subset.
|
||||||
void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output)
|
void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output)
|
||||||
@@ -66,7 +62,7 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
|
|||||||
for (auto& task : input)
|
for (auto& task : input)
|
||||||
{
|
{
|
||||||
// Set up context for any DOM references.
|
// Set up context for any DOM references.
|
||||||
contextTask = &task;
|
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||||
|
|
||||||
Variant var;
|
Variant var;
|
||||||
eval.evaluateCompiledExpression (var);
|
eval.evaluateCompiledExpression (var);
|
||||||
@@ -118,7 +114,7 @@ void Filter::subset (std::vector <Task>& output)
|
|||||||
for (auto& task : pending)
|
for (auto& task : pending)
|
||||||
{
|
{
|
||||||
// Set up context for any DOM references.
|
// Set up context for any DOM references.
|
||||||
contextTask = &task;
|
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||||
|
|
||||||
Variant var;
|
Variant var;
|
||||||
eval.evaluateCompiledExpression (var);
|
eval.evaluateCompiledExpression (var);
|
||||||
@@ -137,7 +133,7 @@ void Filter::subset (std::vector <Task>& output)
|
|||||||
for (auto& task : completed)
|
for (auto& task : completed)
|
||||||
{
|
{
|
||||||
// Set up context for any DOM references.
|
// Set up context for any DOM references.
|
||||||
contextTask = &task;
|
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||||
|
|
||||||
Variant var;
|
Variant var;
|
||||||
eval.evaluateCompiledExpression (var);
|
eval.evaluateCompiledExpression (var);
|
||||||
|
|||||||
@@ -60,8 +60,6 @@
|
|||||||
|
|
||||||
#define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery.
|
#define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery.
|
||||||
|
|
||||||
extern Task* contextTask;
|
|
||||||
|
|
||||||
static const float epsilon = 0.000001;
|
static const float epsilon = 0.000001;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2273,7 +2271,7 @@ void Task::modify (modType type, bool text_required /* = false */)
|
|||||||
|
|
||||||
// while reading the parse tree, consider DOM references in the context of
|
// while reading the parse tree, consider DOM references in the context of
|
||||||
// this task
|
// this task
|
||||||
contextTask = this;
|
auto currentTask = Context::getContext ().withCurrentTask(this);
|
||||||
|
|
||||||
// Need this for later comparison.
|
// Need this for later comparison.
|
||||||
auto originalStatus = getStatus ();
|
auto originalStatus = getStatus ();
|
||||||
|
|||||||
Reference in New Issue
Block a user