Fix minor regressions, add [[noreturn]] attrib
This commit is contained in:
parent
1bcedc2bbb
commit
725dc1bf2d
|
|
@ -428,22 +428,6 @@ const func_builtins & global_builtins() {
|
||||||
bool res = it != builtins.end();
|
bool res = it != builtins.end();
|
||||||
return mk_val<value_bool>(res);
|
return mk_val<value_bool>(res);
|
||||||
}},
|
}},
|
||||||
{"test_is_in", [](const func_args & args) -> value {
|
|
||||||
args.ensure_count(2, 2);
|
|
||||||
value val_needle = args.get_pos(0);
|
|
||||||
value val_haystack = args.get_pos(1);
|
|
||||||
const auto & haystack = is_val<value_array>(val_haystack) ? val_haystack->as_array() : std::vector<value>(1, val_haystack);
|
|
||||||
for (auto it = haystack.cbegin(); it != haystack.cend(); it++) {
|
|
||||||
if ((*it)->type() == val_needle->type()) {
|
|
||||||
if (is_val<value_string>(val_haystack) ?
|
|
||||||
(*it)->as_string().str().find(val_needle->as_string().str()) != std::string::npos :
|
|
||||||
value_compare(*it, val_needle, value_compare_op::eq)) {
|
|
||||||
return mk_val<value_bool>(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mk_val<value_bool>(false);
|
|
||||||
}},
|
|
||||||
{"test_is_sameas", [](const func_args & args) -> value {
|
{"test_is_sameas", [](const func_args & args) -> value {
|
||||||
// Check if an object points to the same memory address as another object
|
// Check if an object points to the same memory address as another object
|
||||||
(void)args;
|
(void)args;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace jinja {
|
namespace jinja {
|
||||||
|
|
||||||
|
|
@ -126,27 +127,27 @@ struct value_t {
|
||||||
// Note: only for debugging and error reporting purposes
|
// Note: only for debugging and error reporting purposes
|
||||||
virtual std::string type() const { return ""; }
|
virtual std::string type() const { return ""; }
|
||||||
|
|
||||||
virtual int64_t as_int() const { throw std::runtime_error(type() + " is not an int value"); }
|
[[noreturn]] virtual int64_t as_int() const { throw std::runtime_error(type() + " is not an int value"); }
|
||||||
virtual double as_float() const { throw std::runtime_error(type() + " is not a float value"); }
|
[[noreturn]] virtual double as_float() const { throw std::runtime_error(type() + " is not a float value"); }
|
||||||
virtual string as_string() const { throw std::runtime_error(type() + " is not a string value"); }
|
[[noreturn]] virtual string as_string() const { throw std::runtime_error(type() + " is not a string value"); }
|
||||||
virtual bool as_bool() const { throw std::runtime_error(type() + " is not a bool value"); }
|
[[noreturn]] virtual bool as_bool() const { throw std::runtime_error(type() + " is not a bool value"); }
|
||||||
virtual const std::vector<value> & as_array() const { throw std::runtime_error(type() + " is not an array value"); }
|
[[noreturn]] virtual const std::vector<value> & as_array() const { throw std::runtime_error(type() + " is not an array value"); }
|
||||||
virtual const std::vector<std::pair<value, value>> & as_ordered_object() const { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual const std::vector<std::pair<value, value>> & as_ordered_object() const { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value invoke(const func_args &) const { throw std::runtime_error(type() + " is not a function value"); }
|
[[noreturn]] virtual value invoke(const func_args &) const { throw std::runtime_error(type() + " is not a function value"); }
|
||||||
virtual bool is_none() const { return false; }
|
virtual bool is_none() const { return false; }
|
||||||
virtual bool is_undefined() const { return false; }
|
virtual bool is_undefined() const { return false; }
|
||||||
virtual const func_builtins & get_builtins() const {
|
[[noreturn]] virtual const func_builtins & get_builtins() const {
|
||||||
throw std::runtime_error("No builtins available for type " + type());
|
throw std::runtime_error("No builtins available for type " + type());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool has_key(const value &) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual bool has_key(const value &) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual void insert(const value & /* key */, const value & /* val */) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual void insert(const value & /* key */, const value & /* val */) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value & at(const value & /* key */, value & /* default_val */) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual value & at(const value & /* key */, value & /* default_val */) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value & at(const value & /* key */) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual value & at(const value & /* key */) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value & at(const std::string & /* key */, value & /* default_val */) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual value & at(const std::string & /* key */, value & /* default_val */) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value & at(const std::string & /* key */) { throw std::runtime_error(type() + " is not an object value"); }
|
[[noreturn]] virtual value & at(const std::string & /* key */) { throw std::runtime_error(type() + " is not an object value"); }
|
||||||
virtual value & at(int64_t /* idx */, value & /* default_val */) { throw std::runtime_error(type() + " is not an array value"); }
|
[[noreturn]] virtual value & at(int64_t /* idx */, value & /* default_val */) { throw std::runtime_error(type() + " is not an array value"); }
|
||||||
virtual value & at(int64_t /* idx */) { throw std::runtime_error(type() + " is not an array value"); }
|
[[noreturn]] virtual value & at(int64_t /* idx */) { throw std::runtime_error(type() + " is not an array value"); }
|
||||||
|
|
||||||
virtual bool is_numeric() const { return false; }
|
virtual bool is_numeric() const { return false; }
|
||||||
virtual bool is_hashable() const { return false; }
|
virtual bool is_hashable() const { return false; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue