initializeRebuildingContext(true);
}
- ~NavigationImpl() {
+ ~NavigationImpl()
+ {
terminate();
}
Mode mode;
};
Monitor<TTSInfo> ttsInfo;
- std::unordered_map<std::string, EvaluationValue_> variables;
+ std::unordered_map<std::string, EvaluationValue> variables;
std::ostream &output;
// NOTE: constructor of TestExecutor must be called on main thread
registerCb<NavigationCallbackType::ContextChanged>(std::move(updateContextInfo));
}
- EvaluationValue_ getVariableByName(const std::string &name) override
+ EvaluationValue getVariableByName(const std::string &name) override
{
auto it = variables.find(name);
if (it != variables.end())
void insertMethods()
{
- variables["sleep"] = [&](double tm) -> EvaluationValue_ {
+ variables["sleep"] = [&](double tm) -> EvaluationValue {
if (tm > 0)
{
auto sleepTime = std::chrono::milliseconds{ static_cast<int>(std::floor(1000.0 * tm + 0.5)) };
}
return {};
};
- variables["print"] = [&](std::string txt) -> EvaluationValue_ {
+ variables["print"] = [&](std::string txt) -> EvaluationValue {
output << txt << "\n";
return {};
};
- variables["get_at_point"] = [&](Point pt) -> EvaluationValue_ {
+ variables["get_at_point"] = [&](Point pt) -> EvaluationValue {
return convertToUIElement(pt);
};
- variables["assert"] = [&](bool condition) -> EvaluationValue_ {
+ variables["assert"] = [&](bool condition) -> EvaluationValue {
if (!condition) throw EvaluationFailure{} << "assertion failed";
return {};
};
- variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name, std::vector<int> roles, std::vector<int> states) -> EvaluationValue_ {
+ variables["find_by_name"] = EvaluationValueFunction{ [&](std::string name, std::vector<int> roles, std::vector<int> states) -> EvaluationValue {
auto root = getVisibleRoot();
if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
ASSERT(root->getObject());
}
};
- auto waitTTSImpl = [&](std::string pattern) -> EvaluationValue_ {
+ auto waitTTSImpl = [&](std::string pattern) -> EvaluationValue {
std::regex regex;
if (!pattern.empty())
{
impl->self = this;
impl->untilMoment = std::chrono::high_resolution_clock::now() + 3s;
impl->pattern = std::move(pattern);
- return EvaluationValue_{ impl };
+ return EvaluationValue{ impl };
};
- variables["tts"] = EvaluationValueFunction{ std::move(waitTTSImpl), { { "pattern", EvaluationValue_{ "" } } } };
+ variables["tts"] = EvaluationValueFunction{ std::move(waitTTSImpl), { { "pattern", EvaluationValue{ "" } } } };
struct WaitGuiImpl : public EvaluationValueWaitInterface {
TestExecutor *self;
}
};
- auto waitGuiImpl = [&](std::string name) -> EvaluationValue_ {
+ auto waitGuiImpl = [&](std::string name) -> EvaluationValue {
auto impl = std::make_shared<WaitGuiImpl>();
impl->self = this;
impl->untilMoment = std::chrono::high_resolution_clock::now() + 3s;
impl->currentRootName = h->rootName;
impl->searchForAnyChange = true;
}
- return EvaluationValue_{ impl };
+ return EvaluationValue{ impl };
};
- variables["gui"] = EvaluationValueFunction{ std::move(waitGuiImpl), { { "name", EvaluationValue_{ "" } } } };
+ variables["gui"] = EvaluationValueFunction{ std::move(waitGuiImpl), { { "name", EvaluationValue{ "" } } } };
}
void insertActivities()
{
for (auto activityName : ActivityFactory::getInstance()->getAllActivityTypes()) {
- variables[activityName] = [ = ](EvaluationValueFunction::Args args) -> EvaluationValue_ {
+ variables[activityName] = [ = ](EvaluationValueFunction::Args args) -> EvaluationValue {
auto activity = executeOnMainThread([&]()
{
return ActivityFactory::getInstance()->createActivity(activityName);
}
};
+void threadFunc(StatPtr result, std::unique_ptr<TestExecutor> exec, std::unique_ptr<std::ostream> outputPtr, Dlog dlog)
+{
+ EvaluationContext ec(*exec);
+ exec->outputStream() << "waiting for context change...\n";
+ auto until = std::chrono::high_resolution_clock::now() + std::chrono::seconds{ 2 };
+ bool hasContext = false;
+ {
+ auto h = exec->contextInfo.lock();
+ hasContext = h.waitForCondition(until, [&]() {
+ // h->root is pointer to root of visible at-spi hierarchy
+ // if it's null, then either context building machinery didn't yet finish,
+ // there's nothing visible to show or something went wrong
+ // here we wait for it to be non-null (context finished constructing)
+ // if it timeouts - something went wrong, so we bail out with an error
+ return bool(h->root);
+ });
+ }
+ if (hasContext) {
+ auto ttsMainRegex = std::regex {
+ "^D/SCREEN-READER[^>]*?> READ COMMAND PARAMS, TEXT: (.*?), DISCARDABLE: 0",
+ std::regex_constants::optimize | std::regex_constants::ECMAScript
+ };
+ auto ttsDlogHandler = dlog.registerCallback([&exec, ttsMainRegex = std::move(ttsMainRegex)](const std::string & txt) {
+ auto h = exec->ttsInfo.lock();
+ if (h->mode == TestExecutor::TTSInfo::Mode::search) {
+ if (!h->searchLine) {
+ h->mode = TestExecutor::TTSInfo::Mode::found;
+ } else {
+ std::smatch result;
+ if (std::regex_search(txt, result, ttsMainRegex)) {
+ auto sub = result[1].str();
+ if (std::regex_search(sub, *h->searchLine))
+ h->mode = TestExecutor::TTSInfo::Mode::found;
+ }
+ }
+ }
+ });
+ exec->outputStream() << "evaluation started\n";
+ try {
+ result->evaluate();
+ exec->outputStream() << "evaluation successed\n";
+ } catch (EvaluationFailure &e) {
+ if (e.hasLocation())
+ exec->outputStream() << e.location().toString() << ": ";
+ exec->outputStream() << e.message() << "\nevaluation failed\n";
+ } catch (...) {
+ exec->outputStream() << "unhandled exception\nevaluation failed\n";
+ }
+ } else {
+ exec->outputStream() << "timeouted\n";
+ DEBUG("timeouted, when waiting for context change");
+ }
+ outputPtr->flush();
+ executeOnMainThread([]() {
+ ecore_main_loop_quit();
+ });
+ DEBUG("done batch");
+}
+
Optional<std::thread> runBatch(const std::array<Optional<std::string>, (size_t)utils::Argument::_count> &arguments)
{
const std::string &sourceName = *arguments[static_cast<size_t>(utils::Argument::SourcePath)];
*outputPtr << os.str() << "\n\n";
}
auto exec = std::make_unique<TestExecutor>(*outputPtr);
- auto threadFunc = [result = std::move(result), exec = std::move(exec), outputPtr = std::move(outputPtr), dlog = std::move(dlog) ]() mutable {
- EvaluationContext ec(*exec);
- exec->outputStream() << "waiting for context change...\n";
- auto until = std::chrono::high_resolution_clock::now() + std::chrono::seconds{ 2 };
- bool hasContext = false;
- {
- auto h = exec->contextInfo.lock();
- hasContext = h.waitForCondition(until, [&]()
- {
- // h->root is pointer to root of visible at-spi hierarchy
- // if it's null, then either context building machinery didn't yet finish,
- // there's nothing visible to show or something went wrong
- // here we wait for it to be non-null (context finished constructing)
- // if it timeouts - something went wrong, so we bail out with an error
- return bool(h->root);
- });
- }
- if (hasContext)
- {
- auto ttsMainRegex = std::regex {
- "^D/SCREEN-READER[^>]*?> READ COMMAND PARAMS, TEXT: (.*?), DISCARDABLE: 0",
- std::regex_constants::optimize | std::regex_constants::ECMAScript
- };
- auto ttsDlogHandler = dlog.registerCallback([&exec, ttsMainRegex = std::move(ttsMainRegex)](const std::string & txt) {
- auto h = exec->ttsInfo.lock();
- if (h->mode == TestExecutor::TTSInfo::Mode::search) {
- if (!h->searchLine) {
- h->mode = TestExecutor::TTSInfo::Mode::found;
- } else {
- std::smatch result;
- if (std::regex_search(txt, result, ttsMainRegex)) {
- auto sub = result[1].str();
- if (std::regex_search(sub, *h->searchLine))
- h->mode = TestExecutor::TTSInfo::Mode::found;
- }
- }
- }
- });
- exec->outputStream() << "evaluation started\n";
- try {
- result->evaluate();
- exec->outputStream() << "evaluation successed\n";
- } catch (EvaluationFailure &e) {
- if (e.hasLocation())
- exec->outputStream() << e.location().toString() << ": ";
- exec->outputStream() << e.message() << "\nevaluation failed\n";
- } catch (...) {
- exec->outputStream() << "unhandled exception\nevaluation failed\n";
- }
- } else
- {
- exec->outputStream() << "timeouted\n";
- DEBUG("timeouted, when waiting for context change");
- }
- outputPtr->flush();
- executeOnMainThread([]()
- {
- ecore_main_loop_quit();
- });
- DEBUG("done batch");
- };
- return std::thread { std::move(threadFunc) };
+ return std::thread { threadFunc, std::move(result), std::move(exec), std::move(outputPtr), std::move(dlog) };
}
return globalContext->executionInterface;
}
-void EvaluationContext::setVariable(const std::string &ident, EvaluationValue_ val)
+void EvaluationContext::setVariable(const std::string &ident, EvaluationValue val)
{
variables[ident] = std::move(val);
}
-EvaluationValue_ EvaluationContext::getVariable(const Optional<TokenLocation> &loc, const std::string &ident)
+EvaluationValue EvaluationContext::getVariable(const Optional<TokenLocation> &loc, const std::string &ident)
{
EvaluationContext *self = this;
while (self) {
throw EvaluationFailure{} << "convertToUIElement from String not implemeneted";
}
-EvaluationValue_ ExecutorInterface::getVariableByName(const std::string &name)
+EvaluationValue ExecutorInterface::getVariableByName(const std::string &name)
{
throw EvaluationFailure{} << "getVariableByName not implemeneted";
}
* }
* will print 1 even if getVariableByName would return different value for foo.
*/
- virtual EvaluationValue_ getVariableByName(const std::string &name);
+ virtual EvaluationValue getVariableByName(const std::string &name);
/**
* @brief Finds object on screen by position
* This variables hides variable with the same name from some parent EvaluationContext,
* but it doesn't overwrite it.
*/
- void setVariable(const std::string &ident, EvaluationValue_ val);
+ void setVariable(const std::string &ident, EvaluationValue val);
/**
* @brief Returns variable with name
* order until value is found. At last ExecutionInterface object will be requested to provide the value
* by calling getVariableByName.
*/
- EvaluationValue_ getVariable(const Optional<TokenLocation> &loc, const std::string &ident);
+ EvaluationValue getVariable(const Optional<TokenLocation> &loc, const std::string &ident);
/**
* @brief Returns reference to ExecutionInterface object
private:
void initializeGlobalContext(ExecutorInterface &ei);
- std::unordered_map<std::string, EvaluationValue_> variables;
+ std::unordered_map<std::string, EvaluationValue> variables;
EvaluationContext *parent = nullptr;
std::shared_ptr<GlobalContext> globalContext;
};
#include "../UniversalSwitch.hpp"
#include <cmath>
-EvaluationValue_::EvaluationValue_() : value(EvaluationValueBase::create())
+EvaluationValue::EvaluationValue() : value(EvaluationValueBase::create())
{
}
-EvaluationValue_::EvaluationValue_(std::nullptr_t) : value(EvaluationValueBase::create())
+EvaluationValue::EvaluationValue(std::nullptr_t) : value(EvaluationValueBase::create())
{
}
-EvaluationValue_::EvaluationValue_(EvaluationValuePtr v) : value(std::move(v))
+EvaluationValue::EvaluationValue(EvaluationValuePtr v) : value(std::move(v))
{
}
-void EvaluationValue_::convertTo(int &v) const
+void EvaluationValue::convertTo(int &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
v = static_cast<std::remove_reference<decltype(v)>::type>(tmp);
}
-void EvaluationValue_::convertTo(unsigned int &v) const
+void EvaluationValue::convertTo(unsigned int &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
v = static_cast<std::remove_reference<decltype(v)>::type>(tmp);
}
-void EvaluationValue_::convertTo(short &v) const
+void EvaluationValue::convertTo(short &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
v = static_cast<std::remove_reference<decltype(v)>::type>(tmp);
}
-void EvaluationValue_::convertTo(unsigned short &v) const
+void EvaluationValue::convertTo(unsigned short &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
v = static_cast<std::remove_reference<decltype(v)>::type>(tmp);
}
-void EvaluationValue_::convertTo(signed char &v) const
+void EvaluationValue::convertTo(signed char &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
v = static_cast<std::remove_reference<decltype(v)>::type>(tmp);
}
-void EvaluationValue_::convertTo(unsigned char &v) const
+void EvaluationValue::convertTo(unsigned char &v) const
{
EvaluationValueInteger tmp = {};
convertTo(tmp);
}
#define Q(type) \
- EvaluationValue_::EvaluationValue_(EvaluationValue ## type v) : value(EvaluationValueBase::create(std::move(v))) { } \
- EvaluationValue ## type EvaluationValue_::convertTo ## type() const { \
+ EvaluationValue::EvaluationValue(EvaluationValue ## type v) : value(EvaluationValueBase::create(std::move(v))) { } \
+ EvaluationValue ## type EvaluationValue::convertTo ## type() const { \
EvaluationValue ## type tmp; \
convertTo(tmp); \
return std::move(tmp); \
} \
- const EvaluationValue ## type &EvaluationValue_::as ## type() { return value->as ## type(); } \
- bool EvaluationValue_::is ## type() const { return value->is ## type(); } \
- void EvaluationValue_::convertTo(EvaluationValue ## type &r) const { \
+ const EvaluationValue ## type &EvaluationValue::as ## type() { return value->as ## type(); } \
+ bool EvaluationValue::is ## type() const { return value->is ## type(); } \
+ void EvaluationValue::convertTo(EvaluationValue ## type &r) const { \
auto t = value->convertTo ## type(); \
if (t.get() == value.get()) r = value->as ## type(); \
else r = std::move(t->as ## type()); \
Q(Wait)
#undef Q
-std::string EvaluationValue_::typeName() const
+std::string EvaluationValue::typeName() const
{
return value->typeName();
}
-bool EvaluationValue_::operator == (const EvaluationValue_ &other) const
+bool EvaluationValue::operator == (const EvaluationValue &other) const
{
return value->oper_cmp(EvaluationValueBase::Cmp::Equal, other.value);
}
-bool EvaluationValue_::operator != (const EvaluationValue_ &other) const
+bool EvaluationValue::operator != (const EvaluationValue &other) const
{
return value->oper_cmp(EvaluationValueBase::Cmp::NotEqual, other.value);
}
-bool EvaluationValue_::operator < (const EvaluationValue_ &other) const
+bool EvaluationValue::operator < (const EvaluationValue &other) const
{
return value->oper_order(EvaluationValueBase::Order::Less, other.value);
}
-bool EvaluationValue_::operator > (const EvaluationValue_ &other) const
+bool EvaluationValue::operator > (const EvaluationValue &other) const
{
return value->oper_order(EvaluationValueBase::Order::More, other.value);
}
-bool EvaluationValue_::operator <= (const EvaluationValue_ &other) const
+bool EvaluationValue::operator <= (const EvaluationValue &other) const
{
return value->oper_order(EvaluationValueBase::Order::LessThan, other.value);
}
-bool EvaluationValue_::operator >= (const EvaluationValue_ &other) const
+bool EvaluationValue::operator >= (const EvaluationValue &other) const
{
return value->oper_order(EvaluationValueBase::Order::MoreThan, other.value);
}
-size_t EvaluationValue_::hash() const
+size_t EvaluationValue::hash() const
{
return value->oper_hash();
}
-bool EvaluationValue_::contains(const EvaluationValue_ &val) const
+bool EvaluationValue::contains(const EvaluationValue &val) const
{
return value->oper_contains(val.value);
}
-EvaluationValue_::operator bool() const
+EvaluationValue::operator bool() const
{
return value->oper_is_true();
}
-EvaluationValue_ EvaluationValue_::operator()(const std::vector<EvaluationValue_> &values, const std::unordered_map<std::string, EvaluationValue_> &keyArgs)
+EvaluationValue EvaluationValue::operator()(const std::vector<EvaluationValue> &values, const std::unordered_map<std::string, EvaluationValue> &keyArgs)
{
return value->oper_call(values, keyArgs);
}
-EvaluationValue_ EvaluationValue_::index_get(const EvaluationValue_ &i1) const
+EvaluationValue EvaluationValue::index_get(const EvaluationValue &i1) const
{
return value->oper_index_get(i1.value);
}
-EvaluationValue_ EvaluationValue_::index_get(const EvaluationValue_ &i1, const EvaluationValue_ &i2) const
+EvaluationValue EvaluationValue::index_get(const EvaluationValue &i1, const EvaluationValue &i2) const
{
return value->oper_index_get(i1.value, i2.value);
}
-EvaluationValue_ EvaluationValue_::index_set(const EvaluationValue_ &i1, const EvaluationValue_ &val)
+EvaluationValue EvaluationValue::index_set(const EvaluationValue &i1, const EvaluationValue &val)
{
return value->oper_index_set(i1.value, val.value);
}
-EvaluationValue_ EvaluationValue_::index_set(const EvaluationValue_ &i1, const EvaluationValue_ &i2, const EvaluationValue_ &val)
+EvaluationValue EvaluationValue::index_set(const EvaluationValue &i1, const EvaluationValue &i2, const EvaluationValue &val)
{
return value->oper_index_set(i1.value, i2.value, val.value);
}
-EvaluationValue_ EvaluationValue_::operator - () const
+EvaluationValue EvaluationValue::operator - () const
{
return value->oper_negate();
}
-EvaluationValue_ EvaluationValue_::attr_get(const std::string &name) const
+EvaluationValue EvaluationValue::attr_get(const std::string &name) const
{
return value->oper_attr_get(name);
}
-EvaluationValue_ EvaluationValue_::attr_set(const std::string &name, const EvaluationValue_ &val)
+EvaluationValue EvaluationValue::attr_set(const std::string &name, const EvaluationValue &val)
{
return value->oper_attr_set(name, val.value);
}
-std::ostream &operator << (std::ostream &s, const EvaluationValue_ &v)
+std::ostream &operator << (std::ostream &s, const EvaluationValue &v)
{
return s << v.value;
}
mutable std::string cachedText;
};
-class EvaluationValue_;
+class EvaluationValue;
namespace std
{
- template <> struct hash<EvaluationValue_> {
- size_t operator()(const EvaluationValue_ &) const;
+ template <> struct hash<EvaluationValue> {
+ size_t operator()(const EvaluationValue &) const;
};
}
using EvaluationValueBoolean = bool;
using EvaluationValuePoint = Point;
class EvaluationValueFunction;
-using EvaluationValueVector = std::vector<EvaluationValue_>;
-using EvaluationValueSet = std::unordered_set<EvaluationValue_>;
-using EvaluationValueDict = std::unordered_map<EvaluationValue_, EvaluationValue_>;
+using EvaluationValueVector = std::vector<EvaluationValue>;
+using EvaluationValueSet = std::unordered_set<EvaluationValue>;
+using EvaluationValueDict = std::unordered_map<EvaluationValue, EvaluationValue>;
class EvaluationValueWaitInterface
{
* implementing values of all supported types (see EvaluationValue***.cpp files). Those classes
* override virtual methods of the EvaluationValueBase interface to add required functionality.
*
- * EvaluationValue_ supports implicit cast from C++ types, which can be used in batch script (for example
+ * EvaluationValue supports implicit cast from C++ types, which can be used in batch script (for example
* chars shorts and ints can be converted to EvaluationValueInteger, std::string can be converted to
* EvaluationValueString and so on).
*/
-class EvaluationValue_
+class EvaluationValue
{
public:
- EvaluationValue_();
- EvaluationValue_(const EvaluationValue_ &) = default;
- EvaluationValue_(EvaluationValue_ &&) = default;
- EvaluationValue_(std::nullptr_t);
- EvaluationValue_(EvaluationValuePtr v);
- EvaluationValue_(unsigned char v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- EvaluationValue_(signed char v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- EvaluationValue_(unsigned short v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- EvaluationValue_(short v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- EvaluationValue_(unsigned int v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- EvaluationValue_(int v) : EvaluationValue_(static_cast<EvaluationValueInteger>(v)) { }
- template <typename T> EvaluationValue_(std::vector<T> tmp) : EvaluationValue_(fromVector(std::move(tmp))) { }
- template <typename T> EvaluationValue_(std::unordered_set<T> tmp) : EvaluationValue_(fromSet(std::move(tmp))) { }
- template <typename K, typename EvaluationValuePtr> EvaluationValue_(std::unordered_map<K, EvaluationValuePtr> tmp) : EvaluationValue_(fromMap(std::move(tmp))) { }
-
- EvaluationValue_ &operator = (const EvaluationValue_ &) = default;
- EvaluationValue_ &operator = (EvaluationValue_ &&) = default;
- template <typename T> EvaluationValue_ &operator = (T &&t)
+ EvaluationValue();
+ EvaluationValue(const EvaluationValue &) = default;
+ EvaluationValue(EvaluationValue &&) = default;
+ EvaluationValue(std::nullptr_t);
+ EvaluationValue(EvaluationValuePtr v);
+ EvaluationValue(unsigned char v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ EvaluationValue(signed char v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ EvaluationValue(unsigned short v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ EvaluationValue(short v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ EvaluationValue(unsigned int v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ EvaluationValue(int v) : EvaluationValue(static_cast<EvaluationValueInteger>(v)) { }
+ template <typename T> EvaluationValue(std::vector<T> tmp) : EvaluationValue(fromVector(std::move(tmp))) { }
+ template <typename T> EvaluationValue(std::unordered_set<T> tmp) : EvaluationValue(fromSet(std::move(tmp))) { }
+ template <typename K, typename EvaluationValuePtr> EvaluationValue(std::unordered_map<K, EvaluationValuePtr> tmp) : EvaluationValue(fromMap(std::move(tmp))) { }
+
+ EvaluationValue &operator = (const EvaluationValue &) = default;
+ EvaluationValue &operator = (EvaluationValue &&) = default;
+ template <typename T> EvaluationValue &operator = (T &&t)
{
- *this = EvaluationValue_{ std::forward<T>(t) };
+ *this = EvaluationValue{ std::forward<T>(t) };
return *this;
}
- void convertTo(EvaluationValue_ &o) const
+ void convertTo(EvaluationValue &o) const
{
o = *this;
}
}
}
#define Q(type) \
- EvaluationValue_(EvaluationValue ## type); \
+ EvaluationValue(EvaluationValue ## type); \
EvaluationValue ## type convertTo ## type() const; \
void convertTo(EvaluationValue ## type &) const; \
const EvaluationValue ## type &as ## type(); \
#undef Q
std::string typeName() const;
- bool operator == (const EvaluationValue_ &) const;
- bool operator != (const EvaluationValue_ &) const;
- bool operator < (const EvaluationValue_ &) const;
- bool operator > (const EvaluationValue_ &) const;
- bool operator <= (const EvaluationValue_ &) const;
- bool operator >= (const EvaluationValue_ &) const;
+ bool operator == (const EvaluationValue &) const;
+ bool operator != (const EvaluationValue &) const;
+ bool operator < (const EvaluationValue &) const;
+ bool operator > (const EvaluationValue &) const;
+ bool operator <= (const EvaluationValue &) const;
+ bool operator >= (const EvaluationValue &) const;
size_t hash() const;
- bool contains(const EvaluationValue_ &) const;
+ bool contains(const EvaluationValue &) const;
explicit operator bool() const;
- EvaluationValue_ operator()(const std::vector<EvaluationValue_> &values, const std::unordered_map<std::string, EvaluationValue_> &keyArgs);
- EvaluationValue_ index_get(const EvaluationValue_ &) const;
- EvaluationValue_ index_get(const EvaluationValue_ &, const EvaluationValue_ &) const;
- EvaluationValue_ index_set(const EvaluationValue_ &, const EvaluationValue_ &value);
- EvaluationValue_ index_set(const EvaluationValue_ &, const EvaluationValue_ &, const EvaluationValue_ &value);
+ EvaluationValue operator()(const std::vector<EvaluationValue> &values, const std::unordered_map<std::string, EvaluationValue> &keyArgs);
+ EvaluationValue index_get(const EvaluationValue &) const;
+ EvaluationValue index_get(const EvaluationValue &, const EvaluationValue &) const;
+ EvaluationValue index_set(const EvaluationValue &, const EvaluationValue &value);
+ EvaluationValue index_set(const EvaluationValue &, const EvaluationValue &, const EvaluationValue &value);
- EvaluationValue_ operator - () const;
+ EvaluationValue operator - () const;
- EvaluationValue_ attr_get(const std::string &name) const;
- EvaluationValue_ attr_set(const std::string &name, const EvaluationValue_ &value);
+ EvaluationValue attr_get(const std::string &name) const;
+ EvaluationValue attr_set(const std::string &name, const EvaluationValue &value);
const auto &getInternalValue() const
{
return value;
}
- friend std::ostream &operator << (std::ostream &s, const EvaluationValue_ &v);
+ friend std::ostream &operator << (std::ostream &s, const EvaluationValue &v);
private:
EvaluationValuePtr value;
template <typename SARGS, typename ... ARGS> static void convert(std::tuple<ARGS...> &dst,
const SARGS &sourceArgs,
size_t firstDefaultArgIndex,
- const std::vector<EvaluationValue_> &defaultArguments,
+ const std::vector<EvaluationValue> &defaultArguments,
size_t consumeOnlyArguments = std::numeric_limits<size_t>::max())
{
DEBUG("%d %d", (int)I, (int)consumeOnlyArguments);
Converter < I + 1, S >::convert(dst, sourceArgs, firstDefaultArgIndex, defaultArguments, consumeOnlyArguments);
}
template <typename ... ARGS> static void convertSingleArgumentByIndex(std::tuple<ARGS...> &dst,
- const EvaluationValue_ &arg,
+ const EvaluationValue &arg,
size_t index)
{
if (I == index) {
};
template <size_t S> struct Converter<S, S> {
template <typename SARGS, typename ... ARGS> static void convert(std::tuple<ARGS...> &, const SARGS &,
- size_t, const std::vector<EvaluationValue_> &, size_t = std::numeric_limits<size_t>::max())
+ size_t, const std::vector<EvaluationValue> &, size_t = std::numeric_limits<size_t>::max())
{
}
template <typename ... ARGS> static void convertSingleArgumentByIndex(std::tuple<ARGS...> &,
- const EvaluationValue_ &,
+ const EvaluationValue &,
size_t)
{
ASSERT(0);
template <> struct is_allowed_evaluatation_value_type<unsigned char> {
enum { value = 1 };
};
- template <> struct is_allowed_evaluatation_value_type<EvaluationValue_> {
+ template <> struct is_allowed_evaluatation_value_type<EvaluationValue> {
enum { value = 1 };
};
template <> struct is_allowed_evaluatation_value_type<EvaluationValueEmpty> {
{
template<typename T> struct make_tuple_from_args { };
template<typename C, typename ... ARGS>
- struct make_tuple_from_args<EvaluationValue_(C::*)(ARGS...)> {
+ struct make_tuple_from_args<EvaluationValue(C::*)(ARGS...)> {
using type = std::tuple<ARGS...>;
};
template<typename C, typename ... ARGS>
- struct make_tuple_from_args<EvaluationValue_(C::*)(ARGS...) const> {
+ struct make_tuple_from_args<EvaluationValue(C::*)(ARGS...) const> {
using type = std::tuple<ARGS...>;
};
}
{
ASSERT(!this->name.empty());
}
- Arg(std::string name, EvaluationValue_ val) : name(std::move(name)), defaultValue(std::move(val)) { }
+ Arg(std::string name, EvaluationValue val) : name(std::move(name)), defaultValue(std::move(val)) { }
std::string getName() const
{
{
return bool(defaultValue);
}
- EvaluationValue_ stealDefaultValue()
+ EvaluationValue stealDefaultValue()
{
auto tmp = std::move(*defaultValue);
defaultValue = {};
}
private:
std::string name;
- Optional<EvaluationValue_> defaultValue;
+ Optional<EvaluationValue> defaultValue;
};
class Args
{
public:
- Args(const std::vector<EvaluationValue_> &args,
- const std::unordered_map<std::string, EvaluationValue_> &keyArgs = {}) : args(args), keyArgs(keyArgs) { }
+ Args(const std::vector<EvaluationValue> &args,
+ const std::unordered_map<std::string, EvaluationValue> &keyArgs = {}) : args(args), keyArgs(keyArgs) { }
bool empty() const
{
{
return args.size();
}
- const EvaluationValue_ &operator [](size_t index) const
+ const EvaluationValue &operator [](size_t index) const
{
return args[index];
}
- const std::unordered_map<std::string, EvaluationValue_> &keywords() const
+ const std::unordered_map<std::string, EvaluationValue> &keywords() const
{
return keyArgs;
}
return !keyArgs.empty();
}
private:
- const std::vector<EvaluationValue_> &args;
- const std::unordered_map<std::string, EvaluationValue_> &keyArgs;
+ const std::vector<EvaluationValue> &args;
+ const std::unordered_map<std::string, EvaluationValue> &keyArgs;
};
- using Type = std::function<EvaluationValue_(const Args &)>;
+ using Type = std::function<EvaluationValue(const Args &)>;
EvaluationValueFunction() = default;
template <typename T, typename ARGS_TUPLE = typename detail::get_args_as_tuple_from_lambda<T>::type,
EvaluationValueFunction(T && f, std::vector<Arg> argDescriptions = {}) :
function(constructConvertingArgsFunction<ARGS_TUPLE>(std::move(f), std::move(argDescriptions))) { }
- template <typename T, typename = typename std::enable_if<std::is_constructible<std::function<EvaluationValue_(Args)>, T>::value>::type>
+ template <typename T, typename = typename std::enable_if<std::is_constructible<std::function<EvaluationValue(Args)>, T>::value>::type>
EvaluationValueFunction(T && f) : function(std::move(f)) { }
explicit operator bool () const
return bool(function);
}
- EvaluationValue_ operator()(const Args &args) const
+ EvaluationValue operator()(const Args &args) const
{
return function(args);
}
{
constexpr auto expectedArgCount = std::tuple_size<ARGS_TUPLE>::value;
ASSERT(expectedArgCount >= argDescriptions.size());
- std::vector<EvaluationValue_> defaultArguments;
+ std::vector<EvaluationValue> defaultArguments;
for (auto it = argDescriptions.rbegin(); it != argDescriptions.rend() && it->hasDefaultValue(); ++it) {
defaultArguments.push_back(std::move(it->stealDefaultValue()));
++argIndex;
}
return [f = std::move(f), defaultArguments = std::move(defaultArguments), firstDefaultArgIndex, keywordIndexes = std::move(keywordIndexes)]
- (const Args & sourceArgs) -> EvaluationValue_ {
+ (const Args & sourceArgs) -> EvaluationValue {
ARGS_TUPLE args;
if (!sourceArgs.hasKeywords())
{
namespace std
{
- size_t hash<EvaluationValue_>::operator()(const EvaluationValue_ &v) const
+ size_t hash<EvaluationValue>::operator()(const EvaluationValue &v) const
{
return v.hash();
}
throw EvaluationFailure{} << "unsupported operation, " << typeName() << " is not a container";
}
-EvaluationValuePtr EvaluationValueBase::oper_call(const std::vector<EvaluationValue_> &, const std::unordered_map<std::string, EvaluationValue_> &)
+EvaluationValuePtr EvaluationValueBase::oper_call(const std::vector<EvaluationValue> &, const std::unordered_map<std::string, EvaluationValue> &)
{
throw EvaluationFailure{} << "unsupported operation, " << typeName() << " is not a callable";
}
virtual size_t oper_hash();
virtual bool oper_contains(const EvaluationValuePtr &value);
virtual bool oper_is_true() = 0;
- virtual EvaluationValuePtr oper_call(const std::vector<EvaluationValue_> &args, const std::unordered_map<std::string, EvaluationValue_> &keyArgs);
+ virtual EvaluationValuePtr oper_call(const std::vector<EvaluationValue> &args, const std::unordered_map<std::string, EvaluationValue> &keyArgs);
virtual EvaluationValuePtr oper_attr_get(const std::string &name);
virtual EvaluationValuePtr oper_attr_set(const std::string &name, const EvaluationValuePtr &);
virtual EvaluationValuePtr oper_negate();
{
return true;
}
- EvaluationValuePtr oper_call(const std::vector<EvaluationValue_> &args, const std::unordered_map<std::string, EvaluationValue_> &keyArgs) override
+ EvaluationValuePtr oper_call(const std::vector<EvaluationValue> &args, const std::unordered_map<std::string, EvaluationValue> &keyArgs) override
{
return value(EvaluationValueFunction::Args{ args, keyArgs }).getInternalValue();
}
EvaluationValuePtr oper_index_get(const EvaluationValuePtr &from, const EvaluationValuePtr &to) override
{
auto indexes = getDoubleIndexes(from, to, value.size());
- std::vector<EvaluationValue_> tmp;
+ std::vector<EvaluationValue> tmp;
tmp.reserve(indexes.second - indexes.first);
for (auto i = indexes.first; i < indexes.second; ++i)
tmp.push_back(value[i]);
return EvaluationValueBase::oper_index_set(from, to, val);
auto indexes = getDoubleIndexes(from, to, value.size());
- std::vector<EvaluationValue_> tmp;
+ std::vector<EvaluationValue> tmp;
tmp.reserve(value.size() - (indexes.second - indexes.first) + val->asVector().size());
for (size_t i = 0; i < indexes.first; ++i)
tmp.push_back(value[i]);
{
return other->isBoolean() && value == other->asWait();
}
- EvaluationValuePtr oper_call(const std::vector<EvaluationValue_> &args, const std::unordered_map<std::string, EvaluationValue_> &keyArgs) override
+ EvaluationValuePtr oper_call(const std::vector<EvaluationValue> &args, const std::unordered_map<std::string, EvaluationValue> &keyArgs) override
{
EvaluationValueFunction::validateArgumentCount(args.size(), 0, 0);
if (!keyArgs.empty()) throw EvaluationFailure{} << "wait object doesn't accept keyword arguments, when called";
}
}
-EvaluationValue_ ExpressionEvaluator::evaluate() const
+EvaluationValue ExpressionEvaluator::evaluate() const
{
return evaluateHelper(std::to_string(getDebugId()), location(), [&]() {
return evaluateImpl();
IdentifierEvaluator::IdentifierEvaluator(TokenLocation tokenLocation, std::string identifier) :
ExpressionEvaluator(std::move(tokenLocation)), identifier(std::move(identifier)) { }
-EvaluationValue_ IdentifierEvaluator::evaluateImpl() const
+EvaluationValue IdentifierEvaluator::evaluateImpl() const
{
return EvaluationContext::getCurrentEvaluationContext().getVariable(location(), identifier);
}
AttributeEvaluator::AttributeEvaluator(TokenLocation tokenLocation, ExprPtr self, std::string identifier) :
ExpressionEvaluator(std::move(tokenLocation)), self(std::move(self)), identifier(std::move(identifier)) { }
-EvaluationValue_ AttributeEvaluator::evaluateImpl() const
+EvaluationValue AttributeEvaluator::evaluateImpl() const
{
return self->evaluate().attr_get(identifier);
}
AttributeSetterEvaluator::AttributeSetterEvaluator(TokenLocation tokenLocation, ExprPtr self, std::string identifier, ExprPtr value) :
ExpressionEvaluator(std::move(tokenLocation)), self(std::move(self)), value(std::move(value)), identifier(std::move(identifier)) { }
-EvaluationValue_ AttributeSetterEvaluator::evaluateImpl() const
+EvaluationValue AttributeSetterEvaluator::evaluateImpl() const
{
auto val = value->evaluate();
return self->evaluate().attr_set(identifier, std::move(val));
SetterEvaluator::SetterEvaluator(TokenLocation tokenLocation, std::string identifier, ExprPtr value) :
ExpressionEvaluator(std::move(tokenLocation)), value(std::move(value)), identifier(std::move(identifier)) { }
-EvaluationValue_ SetterEvaluator::evaluateImpl() const
+EvaluationValue SetterEvaluator::evaluateImpl() const
{
auto v = value->evaluate();
EvaluationContext::getCurrentEvaluationContext().setVariable(identifier, v);
PointEvaluator::PointEvaluator(TokenLocation tokenLocation, ExprPtr x, ExprPtr y) :
ExpressionEvaluator(std::move(tokenLocation)), x(std::move(x)), y(std::move(y)) { }
-EvaluationValue_ PointEvaluator::evaluateImpl() const
+EvaluationValue PointEvaluator::evaluateImpl() const
{
auto xInt = x->evaluate().convertToInteger();
auto yInt = y->evaluate().convertToInteger();
IntegerEvaluator::IntegerEvaluator(TokenLocation tokenLocation, int64_t value) :
ExpressionEvaluator(std::move(tokenLocation)), value(value) { }
-EvaluationValue_ IntegerEvaluator::evaluateImpl() const
+EvaluationValue IntegerEvaluator::evaluateImpl() const
{
return value;
}
DoubleEvaluator::DoubleEvaluator(TokenLocation tokenLocation, double value) :
ExpressionEvaluator(std::move(tokenLocation)), value(value) { }
-EvaluationValue_ DoubleEvaluator::evaluateImpl() const
+EvaluationValue DoubleEvaluator::evaluateImpl() const
{
return value;
}
StringEvaluator::StringEvaluator(TokenLocation tokenLocation, std::string value) :
ExpressionEvaluator(std::move(tokenLocation)), value(std::move(value)) { }
-EvaluationValue_ StringEvaluator::evaluateImpl() const
+EvaluationValue StringEvaluator::evaluateImpl() const
{
return value;
}
ArraySetDictEvaluator::ArraySetDictEvaluator(TokenLocation tokenLocation, ExprPtrs values, Kind kind) :
ExpressionEvaluator(std::move(tokenLocation)), values(std::move(values)), kind(kind) { }
-EvaluationValue_ ArraySetDictEvaluator::evaluateImpl() const
+EvaluationValue ArraySetDictEvaluator::evaluateImpl() const
{
- std::vector<EvaluationValue_> vals;
+ std::vector<EvaluationValue> vals;
for (auto &v : values)
vals.push_back(v->evaluate());
OperatorEvaluator::OperatorEvaluator(TokenLocation tokenLocation, ExprPtrs args, Kind kind) :
ExpressionEvaluator(std::move(tokenLocation)), args(std::move(args)), kind(kind) { }
-EvaluationValue_ OperatorEvaluator::evaluateImpl() const
+EvaluationValue OperatorEvaluator::evaluateImpl() const
{
- std::vector<EvaluationValue_> vals;
+ std::vector<EvaluationValue> vals;
for (auto &a : args)
vals.push_back(a->evaluate());
CompOperatorEvaluator::CompOperatorEvaluator(TokenLocation tokenLocation, ExprPtrs args, std::vector<Kind> kinds, std::vector<TokenLocation> locations) :
ExpressionEvaluator(std::move(tokenLocation)), args(std::move(args)), kinds(kinds), locations(std::move(locations)) { }
-EvaluationValue_ CompOperatorEvaluator::evaluateImpl() const
+EvaluationValue CompOperatorEvaluator::evaluateImpl() const
{
- auto cmp = [](const EvaluationValue_ & l, const EvaluationValue_ & r, const TokenLocation & loc, Kind kind) {
+ auto cmp = [](const EvaluationValue & l, const EvaluationValue & r, const TokenLocation & loc, Kind kind) {
switch (kind) {
case Kind::EQ:
return l == r;
BooleanEvaluator::BooleanEvaluator(TokenLocation tokenLocation, bool value) :
ExpressionEvaluator(std::move(tokenLocation)), value(std::move(value)) { }
-EvaluationValue_ BooleanEvaluator::evaluateImpl() const
+EvaluationValue BooleanEvaluator::evaluateImpl() const
{
return value;
}
CallEvaluator::CallEvaluator(TokenLocation tokenLocation, ExprPtr function, ExprPtrs args, ExprMapPtrs keywordArgs) :
ExpressionEvaluator(tokenLocation), function(std::move(function)), args(std::move(args)), keywordArgs(std::move(keywordArgs)) { }
-EvaluationValue_ CallEvaluator::evaluateImpl() const
+EvaluationValue CallEvaluator::evaluateImpl() const
{
- std::vector<EvaluationValue_> values;
- std::unordered_map<std::string, EvaluationValue_> keywordValues;
+ std::vector<EvaluationValue> values;
+ std::unordered_map<std::string, EvaluationValue> keywordValues;
values.reserve(args.size());
for (auto &arg : args) {
values.push_back(arg->evaluate());
void WaitEvaluator::evaluateImpl() const
{
- std::vector<EvaluationValue_> waitsValues;
+ std::vector<EvaluationValue> waitsValues;
waitsValues.reserve(waits.size());
for (auto &w : waits) {
auto r = w->evaluate();
#include <unordered_map>
#include <sstream>
-class EvaluationValue_;
+class EvaluationValue;
/**
* @brief Class for printing debug information, when evaluation batch
* Calling this function will evaluate given expression (by calling evaluateImpl).
* It will also deal with debug printing (if any).
*/
- EvaluationValue_ evaluate() const;
+ EvaluationValue evaluate() const;
protected:
/**
* @brief Virtual evaluation function.
* Calling this function will evaluate given expression, including it's all children,
* and return produced value. Might raise an EvaluationFailure exception.
*/
- virtual EvaluationValue_ evaluateImpl() const = 0;
+ virtual EvaluationValue evaluateImpl() const = 0;
};
/**
{
std::string identifier;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
IdentifierEvaluator(TokenLocation location_, std::string identifier);
ExprPtr self;
std::string identifier;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
AttributeEvaluator(TokenLocation location_, ExprPtr self, std::string identifier);
ExprPtr self, value;
std::string identifier;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
AttributeSetterEvaluator(TokenLocation location_, ExprPtr self, std::string identifier, ExprPtr value);
ExprPtr value;
std::string identifier;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
SetterEvaluator(TokenLocation location_, std::string identifier, ExprPtr value);
{
ExprPtr x, y;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
PointEvaluator(TokenLocation location_, ExprPtr x, ExprPtr y);
{
int64_t value;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
IntegerEvaluator(TokenLocation location_, int64_t value);
{
double value;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
DoubleEvaluator(TokenLocation location_, double value);
{
bool value;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
BooleanEvaluator(TokenLocation location_, bool value);
{
std::string value;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
StringEvaluator(TokenLocation location_, std::string value);
class ArraySetDictEvaluator : public ExpressionEvaluator
{
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
enum class Kind {
SET, VECTOR, DICT
ExprPtrs args;
ExprMapPtrs keywordArgs;
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
CallEvaluator(TokenLocation location_, ExprPtr function, ExprPtrs args, ExprMapPtrs keywordArgs);
class OperatorEvaluator : public ExpressionEvaluator
{
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
enum class Kind {
IN, GET, SET, MINUS, NOT
class CompOperatorEvaluator : public ExpressionEvaluator
{
protected:
- EvaluationValue_ evaluateImpl() const override;
+ EvaluationValue evaluateImpl() const override;
public:
enum class Kind {
EQ, NE, LE, LT, GE, GT
#include "batch/Evaluator.hpp"
#include <sstream>
-using VarsType = std::unordered_map<std::string, EvaluationValue_>;
+using VarsType = std::unordered_map<std::string, EvaluationValue>;
using ActsType = std::unordered_map<std::string, EvaluationValueFunction>;
struct TestExecutor : ExecutorInterface {
variables(std::move(variables)), activities(std::move(activities)),
pointToUI(std::move(pointToUI)), stringToUI(std::move(stringToUI)) { }
- EvaluationValue_ getVariableByName(const std::string &name) override
+ EvaluationValue getVariableByName(const std::string &name) override
{
auto it = variables.find(name);
if (it == variables.end()) throw EvaluationFailure{} << "no variable " << name;
std::string result2;
VarsType vars;
- vars["foo"] = [&](int v1, std::string v2, std::string v3, bool v4) -> EvaluationValue_ {
+ vars["foo"] = [&](int v1, std::string v2, std::string v3, bool v4) -> EvaluationValue {
return std::to_string(v1) + "," + v2 + "," + v3 + "," + (v4 ? "true" : "false");
};
- vars["bar"] = [&](std::string value) -> EvaluationValue_ {
+ vars["bar"] = [&](std::string value) -> EvaluationValue {
result2 = value;
return {};
};
ScriptTest()
{
- vars["assert"] = [this](bool val) -> EvaluationValue_ {
+ vars["assert"] = [this](bool val) -> EvaluationValue {
if (!val) throw EvaluationFailure{} << "assertion failed";
++assertCount;
return {};
};
- vars["print"] = [this](EvaluationValue_ val) -> EvaluationValue_ {
+ vars["print"] = [this](EvaluationValue val) -> EvaluationValue {
output << ">>> " << val << "\n";
return {};
};
std::tuple<int, int, int, int> val, expected;
vars["func"] = EvaluationValueFunction{
- [&](int a1, int a2, int a3, int a4) -> EvaluationValue_ {
+ [&](int a1, int a2, int a3, int a4) -> EvaluationValue {
std::get<0>(val) = a1;
std::get<1>(val) = a2;
std::get<2>(val) = a3;
std::tuple<int, int, int, int> val, expected;
vars["func"] = EvaluationValueFunction{
- [&](int a1, int a2, int a3, int a4) -> EvaluationValue_ {
+ [&](int a1, int a2, int a3, int a4) -> EvaluationValue {
std::get<0>(val) = a1;
std::get<1>(val) = a2;
std::get<2>(val) = a3;