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
|
||||
// that this context value is not a dangling pointer.
|
||||
class CurrentTask {
|
||||
public:
|
||||
~CurrentTask();
|
||||
|
||||
private:
|
||||
|
||||
12
src/Eval.cpp
12
src/Eval.cpp
@@ -35,8 +35,6 @@
|
||||
#include <shared.h>
|
||||
#include <format.h>
|
||||
|
||||
extern Task* contextTask;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Supported operators, borrowed from C++, particularly the precedence.
|
||||
// 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)`)
|
||||
bool domSource (const std::string& identifier, Variant& value)
|
||||
{
|
||||
if (getDOM (identifier, contextTask, value))
|
||||
if (getDOM (identifier, Context::getContext ().currentTask, value))
|
||||
{
|
||||
value.source (identifier);
|
||||
return true;
|
||||
@@ -292,6 +290,8 @@ void Eval::evaluatePostfixStack (
|
||||
Variant left = values.back ();
|
||||
values.pop_back ();
|
||||
|
||||
auto contextTask = Context::getContext ().currentTask;
|
||||
|
||||
// Ordering these by anticipation frequency of use is a good idea.
|
||||
Variant result;
|
||||
if (token.first == "and") result = left && right;
|
||||
@@ -313,12 +313,16 @@ void Eval::evaluatePostfixStack (
|
||||
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 == "~") result = left.operator_match (right, *contextTask);
|
||||
else if (contextTask) {
|
||||
if (token.first == "~") result = left.operator_match (right, *contextTask);
|
||||
else if (token.first == "!~") result = left.operator_nomatch (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
|
||||
throw format ("Unsupported operator '{1}'.", token.first);
|
||||
|
||||
values.push_back (result);
|
||||
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
#include <format.h>
|
||||
#include <shared.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Context for DOM evaluations
|
||||
const Task* contextTask = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Take an input set of tasks and filter into a subset.
|
||||
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)
|
||||
{
|
||||
// Set up context for any DOM references.
|
||||
contextTask = &task;
|
||||
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||
|
||||
Variant var;
|
||||
eval.evaluateCompiledExpression (var);
|
||||
@@ -118,7 +114,7 @@ void Filter::subset (std::vector <Task>& output)
|
||||
for (auto& task : pending)
|
||||
{
|
||||
// Set up context for any DOM references.
|
||||
contextTask = &task;
|
||||
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||
|
||||
Variant var;
|
||||
eval.evaluateCompiledExpression (var);
|
||||
@@ -137,7 +133,7 @@ void Filter::subset (std::vector <Task>& output)
|
||||
for (auto& task : completed)
|
||||
{
|
||||
// Set up context for any DOM references.
|
||||
contextTask = &task;
|
||||
auto currentTask = Context::getContext ().withCurrentTask(&task);
|
||||
|
||||
Variant var;
|
||||
eval.evaluateCompiledExpression (var);
|
||||
|
||||
@@ -60,8 +60,6 @@
|
||||
|
||||
#define APPROACHING_INFINITY 1000 // Close enough. This isn't rocket surgery.
|
||||
|
||||
extern Task* contextTask;
|
||||
|
||||
static const float epsilon = 0.000001;
|
||||
#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
|
||||
// this task
|
||||
contextTask = this;
|
||||
auto currentTask = Context::getContext ().withCurrentTask(this);
|
||||
|
||||
// Need this for later comparison.
|
||||
auto originalStatus = getStatus ();
|
||||
|
||||
Reference in New Issue
Block a user